plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent ed7b223c04
commit fd87a6ffd5
14441 changed files with 13711084 additions and 20 deletions

View File

@@ -0,0 +1,374 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class dynamicSplitScreenSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool dynamicSplitScreenActive = true;
//The distance at which the splitscreen will be activated.
public float splitDistance = 5;
//The color and width of the splitter which splits the two screens up.
public Color splitterColor;
public float splitterWidth;
public LayerMask secondPlayerCameraCullingMask;
public LayerMask regularCameraCullingMask;
[Space]
[Header ("Other Settings")]
[Space]
public Vector3 extraPositionOffset1TopDown;
public Vector3 extraPositionOffset2TopDown;
//
// public Vector3 extraPositionOffset12_5dX;
// public Vector3 extraPositionOffset22_5dX;
//
// public Vector3 extraPositionOffset12_5dZ;
// public Vector3 extraPositionOffset22_5dZ;
public bool usingTopDownView;
public float screenRotationSpeed = 20;
[Space]
[Header ("2.5D Settings")]
[Space]
public bool using2_5dView;
public bool movingOnXAxis;
public float minHorizontalAxisDistanceToOffset2_5d;
public float horizontaAxisOffset2_5d;
public float maxHorizontalDistanceForVerticalSplit = 20;
public bool reverseMovementDirection;
public Vector2 farScreenRotationClampValues;
public Vector2 closeScreenRotationClampValues;
[Space]
[Header ("Debug")]
[Space]
public bool maxDistanceReached;
public bool player1OnLowerPosition;
public float currentScreenRotation;
public bool player1OnLeftSide;
public float currentHorizontalDistance;
public float currentDistance;
public Vector3 currentExtraPositionOffset1;
public Vector3 currentExtraPositionOffset2;
public bool closeVerticalPosition;
[Space]
[Header ("Components")]
[Space]
public Transform player1;
public Transform player2;
//The two cameras, both of which are initalized/referenced in the start function.
public playerCamera mainPlayerCameraManager1;
public playerCamera mainPlayerCameraManager2;
public Camera camera1;
public Camera camera2;
//The two quads used to draw the second screen, both of which are initalized in the start function.
public GameObject split;
public GameObject splitter;
bool positionCompare;
void Start ()
{
if (!dynamicSplitScreenActive) {
return;
}
splitter.GetComponent<Renderer> ().sortingOrder = 2;
if (camera1 != null) {
camera1.depth = 1;
} else {
dynamicSplitScreenActive = false;
}
if (camera2 != null) {
camera2.depth = 0;
} else {
dynamicSplitScreenActive = false;
}
}
void FixedUpdate ()
{
if (!dynamicSplitScreenActive) {
if (maxDistanceReached) {
mainPlayerCameraManager1.setFollowingMultipleTargetsState (true, false);
mainPlayerCameraManager2.setFollowingMultipleTargetsState (true, false);
mainPlayerCameraManager1.setextraPositionOffsetValue (Vector3.zero);
mainPlayerCameraManager2.setextraPositionOffsetValue (Vector3.zero);
maxDistanceReached = false;
}
return;
}
//Gets the z axis distance between the two players and just the standard distance.
currentDistance = GKC_Utils.distance (player1.position, player2.position);
//Sets the angle of the player up, depending on who's leading on the x axis.
currentScreenRotation = 0;
if (usingTopDownView) {
float zDistance = player1.position.z - player2.position.z;
if (player1.position.x <= player2.position.x) {
currentScreenRotation = Mathf.Rad2Deg * Mathf.Acos (zDistance / currentDistance);
} else {
currentScreenRotation = Mathf.Rad2Deg * Mathf.Asin (zDistance / currentDistance) - 90;
}
}
player1OnLeftSide = false;
if (using2_5dView) {
closeVerticalPosition = (player1.position - player2.position).y < 0.5f;
player1OnLowerPosition = player1.position.y <= player2.position.y;
if (movingOnXAxis) {
if (reverseMovementDirection) {
positionCompare = player1.position.x >= player2.position.x;
} else {
positionCompare = player1.position.x <= player2.position.x;
}
} else {
if (reverseMovementDirection) {
positionCompare = player1.position.z >= player2.position.z;
} else {
positionCompare = player1.position.z <= player2.position.z;
}
}
if (movingOnXAxis) {
if (positionCompare) {
player1OnLeftSide = true;
}
} else {
if (positionCompare) {
player1OnLeftSide = true;
}
}
currentHorizontalDistance = 0;
if (movingOnXAxis) {
currentHorizontalDistance = player1.position.x - player2.position.x;
} else {
currentHorizontalDistance = player1.position.z - player2.position.z;
}
if (player1OnLeftSide) {
currentScreenRotation = Mathf.Rad2Deg * Mathf.Asin (currentHorizontalDistance / currentDistance);
} else {
currentScreenRotation = Mathf.Rad2Deg * Mathf.Acos (currentHorizontalDistance / currentDistance) + 90;
}
if (player1OnLeftSide) {
if (currentDistance > maxHorizontalDistanceForVerticalSplit) {
currentScreenRotation = Mathf.Clamp (currentScreenRotation, farScreenRotationClampValues.x, farScreenRotationClampValues.y);
} else {
currentScreenRotation = Mathf.Clamp (currentScreenRotation, closeScreenRotationClampValues.x, closeScreenRotationClampValues.y);
}
} else {
if (currentDistance > maxHorizontalDistanceForVerticalSplit) {
currentScreenRotation = Mathf.Clamp (currentScreenRotation, 180 + farScreenRotationClampValues.x, 180 + farScreenRotationClampValues.y);
} else {
currentScreenRotation = Mathf.Clamp (currentScreenRotation, 180 + closeScreenRotationClampValues.x, 180 + closeScreenRotationClampValues.y);
}
}
}
//Rotates the splitter according to the new angle.
Quaternion targetRotation = Quaternion.Euler (new Vector3 (0, 0, currentScreenRotation));
splitter.transform.localRotation = Quaternion.Lerp (splitter.transform.localRotation, targetRotation, Time.deltaTime * screenRotationSpeed);
//Gets the exact midpoint between the two players.
Vector3 midPoint = new Vector3 ((player1.position.x + player2.position.x) / 2, (player1.position.y + player2.position.y) / 2, (player1.position.z + player2.position.z) / 2);
//Waits for the two cameras to split and then calcuates a midpoint relevant to the difference in position between the two cameras.
if (currentDistance > splitDistance) {
Vector3 offset = midPoint - player1.position;
offset.x = Mathf.Clamp (offset.x, -splitDistance / 2, splitDistance / 2);
offset.y = Mathf.Clamp (offset.y, -splitDistance / 2, splitDistance / 2);
offset.z = Mathf.Clamp (offset.z, -splitDistance / 2, splitDistance / 2);
midPoint = player1.position + offset;
Vector3 offset2 = midPoint - player2.position;
offset2.x = Mathf.Clamp (offset.x, -splitDistance / 2, splitDistance / 2);
offset2.y = Mathf.Clamp (offset.y, -splitDistance / 2, splitDistance / 2);
offset2.z = Mathf.Clamp (offset.z, -splitDistance / 2, splitDistance / 2);
Vector3 midPoint2 = player2.position - offset;
//Sets the splitter and camera to active and sets the second camera position as to avoid lerping continuity errors.
if (splitter.activeSelf == false) {
splitter.SetActive (true);
camera2.enabled = true;
}
if (!maxDistanceReached) {
mainPlayerCameraManager1.setFollowingMultipleTargetsState (false, false);
mainPlayerCameraManager2.setFollowingMultipleTargetsState (false, false);
maxDistanceReached = true;
}
if (usingTopDownView) {
currentExtraPositionOffset1 = extraPositionOffset1TopDown;
currentExtraPositionOffset2 = extraPositionOffset2TopDown;
}
if (using2_5dView) {
if (movingOnXAxis) {
currentExtraPositionOffset1.y = Mathf.Lerp (horizontaAxisOffset2_5d, 0, currentHorizontalDistance / minHorizontalAxisDistanceToOffset2_5d);
currentExtraPositionOffset2.y = Mathf.Lerp (horizontaAxisOffset2_5d, 0, currentHorizontalDistance / minHorizontalAxisDistanceToOffset2_5d);
if (closeVerticalPosition) {
currentExtraPositionOffset1.y = Mathf.Lerp (currentExtraPositionOffset1.y, 0, Time.deltaTime * 3);
currentExtraPositionOffset2.y = Mathf.Lerp (currentExtraPositionOffset2.y, 0, Time.deltaTime * 3);
} else {
if (player1OnLeftSide) {
if (player1OnLowerPosition) {
currentExtraPositionOffset2.y = -currentExtraPositionOffset2.y;
} else {
currentExtraPositionOffset1.y = -currentExtraPositionOffset1.y;
}
} else {
if (player1OnLowerPosition) {
currentExtraPositionOffset1.y = -currentExtraPositionOffset1.y;
} else {
currentExtraPositionOffset2.y = -currentExtraPositionOffset2.y;
}
}
}
// }else{
// currentExtraPositionOffset1 = Mathf.Lerp (currentExtraPositionOffset1, multipleTargetsMaxFov, currentMultipleTargetsFov / multipleTargetsFovSpeed);
// currentExtraPositionOffset2 = Mathf.Lerp (multipleTargetsMinFov, multipleTargetsMaxFov, currentMultipleTargetsFov / multipleTargetsFovSpeed);
// }
// if (playerOnLowerPosition) {
// currentExtraPositionOffset1 = extraPositionOffset12_5dX;
// currentExtraPositionOffset2 = -extraPositionOffset22_5dX;
// } else {
// currentExtraPositionOffset1 = -extraPositionOffset12_5dX;
// currentExtraPositionOffset2 = extraPositionOffset22_5dX;
// }
} else {
// if (playerOnLowerPosition) {
// currentExtraPositionOffset1 = -extraPositionOffset12_5dZ;
// currentExtraPositionOffset2 = extraPositionOffset22_5dZ;
// } else {
// currentExtraPositionOffset1 = extraPositionOffset12_5dZ;
// currentExtraPositionOffset2 = -extraPositionOffset22_5dZ;
// }
}
midPoint.y = player1.position.y;
midPoint2.y = player2.position.y;
}
mainPlayerCameraManager1.setextraPositionOffsetValue (currentExtraPositionOffset1 + midPoint - mainPlayerCameraManager1.transform.position);
mainPlayerCameraManager2.setextraPositionOffsetValue (currentExtraPositionOffset2 + midPoint2 - mainPlayerCameraManager2.transform.position);
} else {
//Deactivates the splitter and camera once the distance is less than the splitting distance (assuming it was at one point).
if (splitter.activeSelf) {
splitter.SetActive (false);
camera2.enabled = false;
}
if (maxDistanceReached) {
mainPlayerCameraManager1.setFollowingMultipleTargetsState (true, false);
mainPlayerCameraManager2.setFollowingMultipleTargetsState (true, false);
mainPlayerCameraManager1.setextraPositionOffsetValue (Vector3.zero);
mainPlayerCameraManager2.setextraPositionOffsetValue (Vector3.zero);
maxDistanceReached = false;
}
}
}
public void setDynamicSplitScreenActiveState (bool state, GameObject newPlayer1, GameObject newPlayer2, bool creatingCharactersOnEditor)
{
dynamicSplitScreenActive = state;
enabled = state;
if (newPlayer1 != null) {
player1 = newPlayer1.transform;
playerComponentsManager mainPlayerComponentsManager1 = player1.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager1 != null) {
mainPlayerCameraManager1 = mainPlayerComponentsManager1.getPlayerCamera ();
camera1 = mainPlayerCameraManager1.getMainCamera ();
}
}
if (newPlayer2 != null) {
player2 = newPlayer2.transform;
playerComponentsManager mainPlayerComponentsManager2 = player2.GetComponent<playerComponentsManager> ();
if (mainPlayerComponentsManager2 != null) {
mainPlayerCameraManager2 = mainPlayerComponentsManager2.getPlayerCamera ();
camera2 = mainPlayerCameraManager2.getMainCamera ();
if (state) {
camera2.cullingMask = secondPlayerCameraCullingMask;
} else {
camera2.cullingMask = regularCameraCullingMask;
}
}
}
print ("Setting dynamic split camera state as " + state);
if (creatingCharactersOnEditor) {
updateComponent ();
}
}
public void setDynamicSplitScreenActiveState (bool state)
{
dynamicSplitScreenActive = state;
enabled = state;
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 9d6eb807371edd8489e16de2e70df1fb
timeCreated: 1575070643
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Camera/Others/dynamicSplitScreenSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,268 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerCullingSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool cullingSystemEnabled = true;
public float minDistanceToApplyShader = 1;
public float minCullingShaderValue = 0.2f;
public float slerpCullingSpeed = 1;
public float stippleSize;
public string transparentAmountName = "_TransparentAmount";
public bool setStippleSize;
public string stippleSizeName = "_StippleSize";
[Space]
[Header ("Player GameObject List")]
[Space]
public List<GameObject> playerGameObjectList = new List<GameObject> ();
public List<GameObject> playerGameObjectWithChildList = new List<GameObject> ();
[Space]
[Header ("Debug")]
[Space]
public bool pauseCullingState;
public float cullingAmountToApply;
public bool cullingActive;
public float currentDistance;
public float currentCullingValue;
public bool materialsChangedChecked;
[Space]
[Header ("Components")]
[Space]
public Shader cullingShader;
public Transform playerTransform;
public Transform cameraTransform;
public playerCamera mainPlayerCamera;
public List<Renderer> rendererParts = new List<Renderer> ();
public List<Shader> originalShader = new List<Shader> ();
public List<Material> materialList = new List<Material> ();
float previousCullingValue;
bool materialsStored;
int transparentAmountID;
int stippleSizeID;
float previousStippleSize = -1;
int materialsCount;
Material temporalMaterial;
void Start ()
{
if (rendererParts.Count == 0) {
storePlayerRenderer ();
}
transparentAmountID = Shader.PropertyToID (transparentAmountName);
stippleSizeID = Shader.PropertyToID (stippleSizeName);
}
void FixedUpdate ()
{
if (!cullingSystemEnabled) {
return;
}
currentDistance = GKC_Utils.distance (playerTransform.position, cameraTransform.position);
if (!pauseCullingState && currentDistance < minDistanceToApplyShader) {
cullingAmountToApply = currentDistance / minDistanceToApplyShader;
cullingActive = true;
} else {
cullingActive = false;
cullingAmountToApply = 1;
}
if (cullingActive) {
if (mainPlayerCamera.isFirstPersonActive ()) {
cullingActive = false;
} else {
if (mainPlayerCamera.isFullBodyAwarenessActive ()) {
cullingActive = false;
} else {
bool isCameraTypeFree = mainPlayerCamera.isCameraTypeFree ();
if (!isCameraTypeFree) {
cullingActive = false;
} else {
if (mainPlayerCamera.isPlayerAiming ()) {
cullingAmountToApply = 1;
}
}
}
}
}
if (materialsChangedChecked != cullingActive) {
materialsChangedChecked = cullingActive;
if (!materialsStored) {
getMaterialList ();
materialsStored = true;
}
materialsCount = materialList.Count;
for (int j = 0; j < materialsCount; j++) {
temporalMaterial = materialList [j];
if (cullingActive) {
temporalMaterial.shader = cullingShader;
if (setStippleSize) {
if (stippleSize != previousStippleSize) {
previousStippleSize = stippleSize;
temporalMaterial.SetFloat (stippleSizeID, stippleSize);
}
}
} else {
temporalMaterial.shader = originalShader [j];
}
}
}
currentCullingValue = Mathf.Lerp (currentCullingValue, cullingAmountToApply, Time.deltaTime * slerpCullingSpeed);
if (currentCullingValue <= 1) {
if (Mathf.Abs (currentCullingValue - previousCullingValue) > 0.01f) {
materialsCount = materialList.Count;
for (int j = 0; j < materialsCount; j++) {
materialList [j].SetFloat (transparentAmountID, currentCullingValue);
}
previousCullingValue = currentCullingValue;
}
}
}
public void setPauseCullingState (bool state)
{
pauseCullingState = state;
}
public void getMaterialList ()
{
if (materialList.Count == 0) {
int rendererPartsCount = rendererParts.Count;
for (int i = 0; i < rendererPartsCount; i++) {
Renderer currentRenderer = rendererParts [i];
if (currentRenderer != null) {
if (currentRenderer.material.shader != null) {
int materialsLength = currentRenderer.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = currentRenderer.materials [j];
if (currentMaterial != null) {
materialList.Add (currentMaterial);
originalShader.Add (currentMaterial.shader);
}
}
}
}
}
}
}
public void clearRendererList ()
{
rendererParts.Clear ();
originalShader.Clear ();
}
public void storePlayerRenderer ()
{
clearRendererList ();
for (int i = 0; i < playerGameObjectList.Count; i++) {
GameObject currentObject = playerGameObjectList [i];
if (currentObject != null) {
Renderer currentRenderer = currentObject.GetComponent<Renderer> ();
rendererParts.Add (currentRenderer);
}
}
for (int i = 0; i < playerGameObjectWithChildList.Count; i++) {
GameObject currentObject = playerGameObjectWithChildList [i];
if (currentObject != null) {
Component[] components = currentObject.GetComponentsInChildren (typeof(Renderer));
int componentsLength = components.Length;
for (int j = 0; j < componentsLength; j++) {
rendererParts.Add (components [j] as Renderer);
}
}
}
print ("Total amount of " + rendererParts.Count + " render found");
}
public void storePlayerRendererFromEditor ()
{
storePlayerRenderer ();
updateComponent ();
}
public void clearRendererListFromEditor ()
{
clearRendererList ();
updateComponent ();
}
public void setCullingSystemEnabledState (bool state)
{
cullingSystemEnabled = state;
}
public void setCullingSystemEnabledStateFromEditor (bool state)
{
setCullingSystemEnabledState (state);
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Player Culling System", gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: deebc3595353be54bbbde2b69855bab7
timeCreated: 1582305065
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Camera/Others/playerCullingSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,332 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class setTransparentSurfaces : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool checkSurfaceEnabled = true;
public bool checkSurfaceActiveAtStart;
public bool checkSurfaceActive;
public bool lockedCameraActive;
public LayerMask layer;
public float capsuleCastRadius = 0.3f;
public bool useCustomShader;
public Shader customShader;
public string mainManagerName = "Set Transparent Surfaces Manager";
[Space]
[Header ("Debug")]
[Space]
public bool surfaceFound;
public bool surfaceFoundPreviously;
public bool playerIsUsingDevices;
public bool playerIsUsingDevicesPreviously;
public List<GameObject> currentSurfaceGameObjectFoundList = new List<GameObject> ();
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventsOnStartCheckSurface;
public UnityEvent eventOnStartCheckSurface;
public bool useEventsOnStopCheckSurface;
public UnityEvent eventOnStopCheckSurface;
public bool useEventOnSurfaceFound;
public UnityEvent eventOnSurfaceFound;
public bool useEventOnNoSurfaceFound;
public UnityEvent eventOnNoSurfaceFound;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color sphereColor = Color.green;
public Color cubeColor = Color.blue;
[Space]
[Header ("Components")]
[Space]
public playerController playerControllerManager;
public int playerID;
public Transform rayOriginPositionFreeCamera;
public Transform rayTargetPositionFreeCamera;
public Transform rayOriginPositionLockedCamera;
public Transform rayTargetPositionLockedCamera;
public setTransparentSurfacesSystem setTransparentSurfacesManager;
RaycastHit[] hits;
float distanceToTarget;
Vector3 rayDirection;
List<GameObject> surfaceGameObjectList = new List<GameObject> ();
Vector3 point1;
Vector3 point2;
GameObject currentSurfaceGameObjectFound;
setTransparentSurfacesSystem.surfaceInfo currentSurfaceInfo;
Transform currentRayOriginPosition;
Transform currentRayTargetPosition;
bool playerLocated;
bool setTransparentSurfacesManagerLocated;
void Start ()
{
setTransparentSurfacesManagerLocated = setTransparentSurfacesManager != null;
if (!setTransparentSurfacesManagerLocated) {
setTransparentSurfacesManager = setTransparentSurfacesSystem.Instance;
setTransparentSurfacesManagerLocated = setTransparentSurfacesManager != null;
}
if (!setTransparentSurfacesManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (setTransparentSurfacesSystem.getMainManagerName (), typeof(setTransparentSurfacesSystem), true);
setTransparentSurfacesManager = setTransparentSurfacesSystem.Instance;
setTransparentSurfacesManagerLocated = setTransparentSurfacesManager != null;
}
if (!setTransparentSurfacesManagerLocated) {
setTransparentSurfacesManager = FindObjectOfType<setTransparentSurfacesSystem> ();
setTransparentSurfacesManagerLocated = setTransparentSurfacesManager != null;
}
if (!setTransparentSurfacesManagerLocated) {
checkSurfaceEnabled = false;
checkSurfaceActive = false;
}
if (playerControllerManager != null) {
playerID = playerControllerManager.getPlayerID ();
playerLocated = true;
}
if (checkSurfaceActiveAtStart) {
setCheckSurfaceActiveState (true);
}
}
void Update ()
{
if (checkSurfaceActive) {
if (lockedCameraActive) {
currentRayOriginPosition = rayOriginPositionLockedCamera;
currentRayTargetPosition = rayTargetPositionLockedCamera;
} else {
currentRayOriginPosition = rayOriginPositionFreeCamera;
currentRayTargetPosition = rayTargetPositionFreeCamera;
}
distanceToTarget = GKC_Utils.distance (currentRayOriginPosition.position, currentRayTargetPosition.position);
rayDirection = currentRayOriginPosition.position - currentRayTargetPosition.position;
rayDirection = rayDirection / rayDirection.magnitude;
if (showGizmo) {
Debug.DrawLine (currentRayTargetPosition.position, (distanceToTarget * rayDirection) + currentRayTargetPosition.position, Color.red, 2);
}
point1 = currentRayOriginPosition.position - capsuleCastRadius * rayDirection;
point2 = currentRayTargetPosition.position + capsuleCastRadius * rayDirection;
hits = Physics.CapsuleCastAll (point1, point2, capsuleCastRadius, rayDirection, 0, layer);
surfaceFound = hits.Length > 0;
if (surfaceFound != surfaceFoundPreviously) {
surfaceFoundPreviously = surfaceFound;
if (surfaceFoundPreviously) {
if (useEventOnSurfaceFound) {
eventOnSurfaceFound.Invoke ();
}
} else {
if (useEventOnNoSurfaceFound) {
eventOnNoSurfaceFound.Invoke ();
}
}
}
if (playerLocated) {
playerIsUsingDevices = playerControllerManager.isUsingDevice ();
}
if (playerIsUsingDevices != playerIsUsingDevicesPreviously) {
playerIsUsingDevicesPreviously = playerIsUsingDevices;
changeSurfacesToTransparentOrRegularTemporaly (!playerIsUsingDevices);
}
surfaceGameObjectList.Clear ();
for (int i = 0; i < hits.Length; i++) {
currentSurfaceGameObjectFound = hits [i].collider.gameObject;
if (!setTransparentSurfacesManager.listContainsSurface (currentSurfaceGameObjectFound)) {
if (useCustomShader) {
setTransparentSurfacesManager.addNewSurface (currentSurfaceGameObjectFound, customShader);
} else {
setTransparentSurfacesManager.addNewSurface (currentSurfaceGameObjectFound, null);
}
} else {
setTransparentSurfacesManager.checkSurfaceToSetTransparentAgain (currentSurfaceGameObjectFound);
}
if (!currentSurfaceGameObjectFoundList.Contains (currentSurfaceGameObjectFound)) {
currentSurfaceGameObjectFoundList.Add (currentSurfaceGameObjectFound);
setTransparentSurfacesManager.addPlayerIDToSurface (playerID, currentSurfaceGameObjectFound);
}
surfaceGameObjectList.Add (currentSurfaceGameObjectFound);
}
for (int i = 0; i < setTransparentSurfacesManager.surfaceInfoList.Count; i++) {
currentSurfaceInfo = setTransparentSurfacesManager.surfaceInfoList [i];
if (!surfaceGameObjectList.Contains (currentSurfaceInfo.surfaceGameObject)) {
if (currentSurfaceInfo.playerIDs.Contains (playerID)) {
setTransparentSurfacesManager.removePlayerIDToSurface (playerID, i);
}
if (currentSurfaceGameObjectFoundList.Contains (currentSurfaceInfo.surfaceGameObject)) {
currentSurfaceGameObjectFoundList.Remove (currentSurfaceInfo.surfaceGameObject);
}
if (currentSurfaceInfo.numberOfPlayersFound < 1 && !currentSurfaceInfo.changingToOriginalActive) {
setTransparentSurfacesManager.setSurfaceToRegular (i, true);
i = 0;
}
}
}
}
}
public void checkSurfacesToRemove ()
{
for (int i = 0; i < setTransparentSurfacesManager.surfaceInfoList.Count; i++) {
currentSurfaceInfo = setTransparentSurfacesManager.surfaceInfoList [i];
if (currentSurfaceGameObjectFoundList.Contains (currentSurfaceInfo.surfaceGameObject)) {
if (currentSurfaceInfo.playerIDs.Contains (playerID)) {
setTransparentSurfacesManager.removePlayerIDToSurface (playerID, i);
}
}
}
}
public void changeSurfacesToTransparentOrRegularTemporaly (bool state)
{
for (int i = 0; i < setTransparentSurfacesManager.surfaceInfoList.Count; i++) {
currentSurfaceInfo = setTransparentSurfacesManager.surfaceInfoList [i];
if (currentSurfaceGameObjectFoundList.Contains (currentSurfaceInfo.surfaceGameObject)) {
if (currentSurfaceInfo.playerIDs.Contains (playerID)) {
setTransparentSurfacesManager.changeSurfacesToTransparentOrRegularTemporaly (playerID, i, state);
}
}
}
}
public void setCheckSurfaceActiveState (bool state)
{
if (!checkSurfaceEnabled) {
return;
}
checkSurfaceActive = state;
if (!checkSurfaceActive) {
checkSurfacesToRemove ();
setTransparentSurfacesManager.checkSurfacesToRemove ();
}
if (checkSurfaceActive) {
if (useEventsOnStartCheckSurface) {
eventOnStartCheckSurface.Invoke ();
}
} else {
if (useEventsOnStopCheckSurface) {
eventOnStopCheckSurface.Invoke ();
}
}
}
public void setLockedCameraActiveState (bool state)
{
lockedCameraActive = state;
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo && Application.isPlaying && checkSurfaceActive) {
Gizmos.color = sphereColor;
Gizmos.DrawSphere (point1, capsuleCastRadius);
Gizmos.DrawSphere (point2, capsuleCastRadius);
Gizmos.color = cubeColor;
Vector3 scale = new Vector3 (capsuleCastRadius * 2, capsuleCastRadius * 2, distanceToTarget - capsuleCastRadius * 2);
Matrix4x4 cubeTransform = Matrix4x4.TRS (((distanceToTarget / 2) * rayDirection) +
currentRayTargetPosition.position,
Quaternion.LookRotation (rayDirection, point1 - point2), scale);
Matrix4x4 oldGizmosMatrix = Gizmos.matrix;
Gizmos.matrix *= cubeTransform;
Gizmos.DrawCube (Vector3.zero, Vector3.one);
Gizmos.matrix = oldGizmosMatrix;
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 15cc78e4af696e94f99b606eee2b0242
timeCreated: 1529702572
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Camera/Others/setTransparentSurfaces.cs
uploadId: 814740

View File

@@ -0,0 +1,363 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class setTransparentSurfacesSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool checkSurfaceEnabled = true;
public Shader transparentShader;
public float alphaBlendSpeed = 5;
public float alphaTransparency = 0.2f;
public bool useAlphaColor = true;
public string transparentAmountName = "_TransparentAmount";
public string colorPropertyName = "_Color";
[Space]
[Header ("Debug")]
[Space]
public List<surfaceInfo> surfaceInfoList = new List<surfaceInfo> ();
public List<GameObject> surfaceGameObjectList = new List<GameObject> ();
surfaceInfo newSurfaceInfo;
materialInfo newMaterialInfo;
int transparentAmountID = -1;
public const string mainManagerName = "Set Transparent Surfaces Manager";
public static string getMainManagerName ()
{
return mainManagerName;
}
private static setTransparentSurfacesSystem _setTransparentSurfacesSystemInstance;
public static setTransparentSurfacesSystem Instance { get { return _setTransparentSurfacesSystemInstance; } }
bool instanceInitialized;
public void getComponentInstance ()
{
if (instanceInitialized) {
return;
}
if (_setTransparentSurfacesSystemInstance != null && _setTransparentSurfacesSystemInstance != this) {
Destroy (this.gameObject);
return;
}
_setTransparentSurfacesSystemInstance = this;
instanceInitialized = true;
}
void Awake ()
{
getComponentInstance ();
}
public void addNewSurface (GameObject newSurface, Shader customShader)
{
if (!checkSurfaceEnabled) {
return;
}
newSurfaceInfo = new surfaceInfo ();
newSurfaceInfo.surfaceGameObject = newSurface;
Component[] components = newSurfaceInfo.surfaceGameObject.GetComponentsInChildren (typeof(Renderer));
int componentsLength = components.Length;
int colorID = Shader.PropertyToID (colorPropertyName);
for (int i = 0; i < componentsLength; i++) {
Renderer child = components [i] as Renderer;
if (child.material.shader != null) {
int materialsLength = child.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = child.materials [j];
newMaterialInfo = new materialInfo ();
newMaterialInfo.surfaceMaterial = currentMaterial;
float colorValue = 1;
if (colorID != -1) {
if (currentMaterial.HasProperty (colorID)) {
Color alpha = currentMaterial.color;
colorValue = alpha.a;
}
}
newMaterialInfo.originalAlphaColor = colorValue;
newSurfaceInfo.materialInfoList.Add (newMaterialInfo);
newSurfaceInfo.originalShader.Add (currentMaterial.shader);
if (customShader != null) {
currentMaterial.shader = customShader;
newSurfaceInfo.customShader = customShader;
} else {
currentMaterial.shader = transparentShader;
newSurfaceInfo.customShader = transparentShader;
}
newSurfaceInfo.materialsAmount++;
}
}
}
setSurfaceTransparent (newSurfaceInfo);
surfaceInfoList.Add (newSurfaceInfo);
surfaceGameObjectList.Add (newSurfaceInfo.surfaceGameObject);
}
public bool listContainsSurface (GameObject surfaceToCheck)
{
if (!checkSurfaceEnabled) {
return false;
}
if (surfaceGameObjectList.Contains (surfaceToCheck)) {
return true;
}
return false;
}
public void setSurfaceToRegular (int surfaceIndex, bool removeSurfaceAtEnd)
{
if (!checkSurfaceEnabled) {
return;
}
surfaceInfo currentSurfaceToCheck = surfaceInfoList [surfaceIndex];
currentSurfaceToCheck.changingToOriginalActive = true;
currentSurfaceToCheck.currentMaterialsChangedAmount = 0;
currentSurfaceToCheck.changingToTransparentActive = false;
currentSurfaceToCheck.changingToOriginalTemporaly = !removeSurfaceAtEnd;
for (int j = 0; j < currentSurfaceToCheck.materialInfoList.Count; j++) {
setAlphaValue (currentSurfaceToCheck, j, currentSurfaceToCheck.materialInfoList [j].surfaceMaterial,
false, currentSurfaceToCheck.originalShader [j], currentSurfaceToCheck.materialInfoList [j].originalAlphaColor, removeSurfaceAtEnd);
}
}
public void checkSurfaceToSetTransparentAgain (GameObject surfaceToCheck)
{
if (!checkSurfaceEnabled) {
return;
}
int surfaceIndex = surfaceGameObjectList.IndexOf (surfaceToCheck);
if (surfaceIndex > -1) {
surfaceInfo currentSurfaceToCheck = surfaceInfoList [surfaceIndex];
if (currentSurfaceToCheck.changingToOriginalActive && !currentSurfaceToCheck.changingToOriginalTemporaly) {
// print ("changing to original, stopping");
setSurfaceTransparent (currentSurfaceToCheck);
}
}
}
public void setSurfaceTransparent (surfaceInfo currentSurfaceToCheck)
{
currentSurfaceToCheck.changingToOriginalActive = false;
currentSurfaceToCheck.currentMaterialsChangedAmount = 0;
currentSurfaceToCheck.changingToTransparentActive = true;
for (int j = 0; j < currentSurfaceToCheck.materialInfoList.Count; j++) {
setAlphaValue (currentSurfaceToCheck, j, currentSurfaceToCheck.materialInfoList [j].surfaceMaterial,
true, currentSurfaceToCheck.originalShader [j], currentSurfaceToCheck.materialInfoList [j].originalAlphaColor, false);
}
}
public void setAlphaValue (surfaceInfo currentSurfaceToCheck, int surfaceIndex, Material currentMaterial,
bool changingToTransparent, Shader originalShader, float originalAlphaColor, bool removeSurfaceAtEnd)
{
if (currentSurfaceToCheck.materialInfoList [surfaceIndex].alphaBlendCoroutine != null) {
StopCoroutine (currentSurfaceToCheck.materialInfoList [surfaceIndex].alphaBlendCoroutine);
}
currentSurfaceToCheck.materialInfoList [surfaceIndex].alphaBlendCoroutine =
StartCoroutine (setAlphaValueCoroutine (currentSurfaceToCheck, currentMaterial,
changingToTransparent, originalShader, originalAlphaColor, removeSurfaceAtEnd));
}
IEnumerator setAlphaValueCoroutine (surfaceInfo currentSurfaceToCheck, Material currentMaterial, bool changingToTransparent,
Shader originalShader, float originalAlphaColor, bool removeSurfaceAtEnd)
{
float targetValue = originalAlphaColor;
if (changingToTransparent) {
targetValue = alphaTransparency;
if (currentSurfaceToCheck.changingToOriginalTemporaly) {
currentMaterial.shader = currentSurfaceToCheck.customShader;
}
}
if (useAlphaColor) {
Color alpha = currentMaterial.color;
while (alpha.a != targetValue) {
alpha.a = Mathf.MoveTowards (alpha.a, targetValue, Time.deltaTime * alphaBlendSpeed);
currentMaterial.color = alpha;
yield return null;
}
} else {
if (transparentAmountID == -1) {
transparentAmountID = Shader.PropertyToID (transparentAmountName);
}
if (currentMaterial.HasProperty (transparentAmountID)) {
float currentTransparentAmount = currentMaterial.GetFloat (transparentAmountID);
while (currentTransparentAmount != targetValue) {
currentTransparentAmount = Mathf.MoveTowards (currentTransparentAmount, targetValue, Time.deltaTime * alphaBlendSpeed);
currentMaterial.SetFloat (transparentAmountID, currentTransparentAmount);
yield return null;
}
} else {
yield return null;
}
}
if (!changingToTransparent) {
currentMaterial.shader = originalShader;
}
if (currentSurfaceToCheck.changingToOriginalActive) {
currentSurfaceToCheck.currentMaterialsChangedAmount++;
if (removeSurfaceAtEnd) {
if (currentSurfaceToCheck.currentMaterialsChangedAmount == currentSurfaceToCheck.materialsAmount) {
surfaceInfoList.Remove (currentSurfaceToCheck);
surfaceGameObjectList.Remove (currentSurfaceToCheck.surfaceGameObject);
}
}
} else {
currentSurfaceToCheck.currentMaterialsChangedAmount++;
if (currentSurfaceToCheck.currentMaterialsChangedAmount == currentSurfaceToCheck.materialsAmount) {
currentSurfaceToCheck.changingToTransparentActive = false;
currentSurfaceToCheck.changingToOriginalTemporaly = false;
}
}
}
public void checkSurfacesToRemove ()
{
if (!checkSurfaceEnabled) {
return;
}
for (int i = 0; i < surfaceInfoList.Count; i++) {
surfaceInfo currentSurfaceToCheck = surfaceInfoList [i];
if (currentSurfaceToCheck.numberOfPlayersFound == 0) {
setSurfaceToRegular (i, true);
}
}
}
public void changeSurfacesToTransparentOrRegularTemporaly (int playerID, int surfaceIndex, bool setTransparentSurface)
{
if (surfaceInfoList [surfaceIndex].playerIDs.Contains (playerID)) {
if (setTransparentSurface) {
// print ("transparent");
setSurfaceTransparent (surfaceInfoList [surfaceIndex]);
} else {
// print ("regular");
setSurfaceToRegular (surfaceIndex, false);
}
}
}
public void addPlayerIDToSurface (int playerID, GameObject surfaceToCheck)
{
if (!checkSurfaceEnabled) {
return;
}
for (int i = 0; i < surfaceInfoList.Count; i++) {
if (surfaceInfoList [i].surfaceGameObject == surfaceToCheck) {
if (!surfaceInfoList [i].playerIDs.Contains (playerID)) {
surfaceInfoList [i].playerIDs.Add (playerID);
surfaceInfoList [i].numberOfPlayersFound++;
return;
}
}
}
}
public void removePlayerIDToSurface (int playerID, int surfaceIndex)
{
if (!checkSurfaceEnabled) {
return;
}
if (surfaceInfoList [surfaceIndex].playerIDs.Contains (playerID)) {
surfaceInfoList [surfaceIndex].playerIDs.Remove (playerID);
surfaceInfoList [surfaceIndex].numberOfPlayersFound--;
}
}
[System.Serializable]
public class surfaceInfo
{
public GameObject surfaceGameObject;
public List<Shader> originalShader = new List<Shader> ();
public List<materialInfo> materialInfoList = new List<materialInfo> ();
public List<int> playerIDs = new List<int> ();
public int numberOfPlayersFound;
public bool changingToTransparentActive;
public bool changingToOriginalActive;
public bool changingToOriginalTemporaly;
public int materialsAmount;
public int currentMaterialsChangedAmount;
public Shader customShader;
}
[System.Serializable]
public class materialInfo
{
public Material surfaceMaterial;
public Coroutine alphaBlendCoroutine;
public float originalAlphaColor;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2d8959f593f74574daf408f241e16f77
timeCreated: 1551482151
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Camera/Others/setTransparentSurfacesSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,174 @@
using UnityEngine;
using System.Collections;
public class simpleMoveCameraToPosition : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool cameraMovementActive = true;
public bool smoothCameraMovement = true;
public bool useFixedLerpMovement = true;
public float fixedLerpMovementSpeed = 2;
public float cameraMovementSpeedThirdPerson = 1;
public float cameraMovementSpeedFirstPerson = 0.2f;
[Space]
[Header ("Debug")]
[Space]
public bool movingCamera;
public bool moveCameraActive;
[Space]
[Header ("Components")]
[Space]
public GameObject cameraPosition;
public Camera mainCamera;
public GameObject currentPlayer;
public playerCamera playerCameraManager;
Transform cameraParentTransform;
Vector3 mainCameraTargetPosition;
Quaternion mainCameraTargetRotation;
Coroutine cameraState;
playerComponentsManager mainPlayerComponentsManager;
public void moveCamera (bool state)
{
moveCameraActive = state;
if (cameraPosition == null) {
cameraPosition = gameObject;
}
mainCameraTargetRotation = Quaternion.identity;
mainCameraTargetPosition = Vector3.zero;
if (moveCameraActive) {
if (cameraMovementActive) {
if (cameraParentTransform == null) {
cameraParentTransform = mainCamera.transform.parent;
mainCamera.transform.SetParent (cameraPosition.transform);
}
}
} else {
if (cameraMovementActive) {
if (cameraParentTransform != null) {
mainCamera.transform.SetParent (cameraParentTransform);
cameraParentTransform = null;
}
}
}
if (cameraMovementActive) {
if (smoothCameraMovement) {
stopMovement ();
cameraState = StartCoroutine (adjustCamera ());
} else {
mainCamera.transform.localRotation = mainCameraTargetRotation;
mainCamera.transform.localPosition = mainCameraTargetPosition;
}
}
}
IEnumerator adjustCamera ()
{
movingCamera = true;
Transform mainCameraTransform = mainCamera.transform;
if (useFixedLerpMovement) {
float i = 0;
//store the current rotation of the camera
Quaternion currentQ = mainCameraTransform.localRotation;
//store the current position of the camera
Vector3 currentPos = mainCameraTransform.localPosition;
//translate position and rotation camera
while (i < 1) {
i += Time.deltaTime * fixedLerpMovementSpeed;
mainCameraTransform.localRotation = Quaternion.Lerp (currentQ, mainCameraTargetRotation, i);
mainCameraTransform.localPosition = Vector3.Lerp (currentPos, mainCameraTargetPosition, i);
yield return null;
}
} else {
bool isFirstPersonActive = playerCameraManager.isFirstPersonActive ();
float currentCameraMovementSpeed = cameraMovementSpeedThirdPerson;
if (isFirstPersonActive) {
currentCameraMovementSpeed = cameraMovementSpeedFirstPerson;
}
float dist = GKC_Utils.distance (mainCameraTransform.localPosition, mainCameraTargetPosition);
float duration = dist / currentCameraMovementSpeed;
float t = 0;
float movementTimer = 0;
bool targetReached = false;
float angleDifference = 0;
float positionDifference = 0;
while (!targetReached) {
t += Time.deltaTime / duration;
mainCameraTransform.localPosition = Vector3.Lerp (mainCameraTransform.localPosition, mainCameraTargetPosition, t);
mainCameraTransform.localRotation = Quaternion.Lerp (mainCameraTransform.localRotation, mainCameraTargetRotation, t);
angleDifference = Quaternion.Angle (mainCameraTransform.localRotation, mainCameraTargetRotation);
positionDifference = GKC_Utils.distance (mainCameraTransform.localPosition, mainCameraTargetPosition);
movementTimer += Time.deltaTime;
if ((positionDifference < 0.01f && angleDifference < 0.2f) || movementTimer > (duration + 1)) {
targetReached = true;
}
yield return null;
}
}
movingCamera = false;
}
public void setCurrentPlayer (GameObject player)
{
currentPlayer = player;
if (currentPlayer != null) {
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
playerCameraManager = mainPlayerComponentsManager.getPlayerCamera ();
mainCamera = playerCameraManager.getMainCamera ();
}
}
public void stopMovement ()
{
if (cameraState != null) {
StopCoroutine (cameraState);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 36538b8ea8712ae4e919fb7a63513456
timeCreated: 1662737835
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Camera/Others/simpleMoveCameraToPosition.cs
uploadId: 814740