init
This commit is contained in:
		
						commit
						341a877b4a
					
				
					 2338 changed files with 1346408 additions and 0 deletions
				
			
		
							
								
								
									
										27
									
								
								Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using Cinemachine; | ||||
| 
 | ||||
| public class CMCameraTrigger : MonoBehaviour{ | ||||
| 
 | ||||
|     CinemachineVirtualCamera vcam; | ||||
| 
 | ||||
|     // Start is called before the first frame update | ||||
|     void Awake(){ | ||||
|         vcam = GetComponentInChildren<CinemachineVirtualCamera>(); | ||||
|         vcam.gameObject.SetActive(false); | ||||
|     } | ||||
| 
 | ||||
|     void OnTriggerEnter2D(Collider2D col){ | ||||
|         if (col.CompareTag("Player")){ | ||||
|             vcam.gameObject.SetActive(true); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void OnTriggerExit2D(Collider2D col){ | ||||
|         if (col.CompareTag("Player")){ | ||||
|             vcam.gameObject.SetActive(false); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs.meta
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: 368758c1440a4cb4c867e140e8934c09 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
|  | @ -0,0 +1,8 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: 64770ab13b014f446bb4ad495e0b508c | ||||
| folderAsset: yes | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
|  | @ -0,0 +1,105 @@ | |||
| using Cinemachine; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| 
 | ||||
| public class CMCameraRail : MonoBehaviour{ | ||||
| 
 | ||||
|     [SerializeField] CinemachineVirtualCamera dollyTrackCamera = default; | ||||
|     CinemachineTrackedDolly cameraTrack; | ||||
| 
 | ||||
|     [Space] | ||||
|     [SerializeField] Waypoint[] waypoints = default; | ||||
|     int totalCount; | ||||
|     int currentCount; | ||||
| 
 | ||||
|     bool finished; | ||||
|     bool paused; | ||||
| 
 | ||||
|     float easedPercentBetweenWaypoints; | ||||
|     float speed; | ||||
|     float currentEase; | ||||
|     float percentBetweenWaypoints; | ||||
|     float nextPos; | ||||
|     float lastFieldOfView; | ||||
| 
 | ||||
|     void Awake(){ | ||||
|         totalCount = waypoints.Length - 1; | ||||
|         if(dollyTrackCamera != null){ | ||||
|             cameraTrack = dollyTrackCamera.GetCinemachineComponent<CinemachineTrackedDolly>(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // Update is called once per frame | ||||
|     void Update(){ | ||||
|         if(!finished && !paused){ | ||||
|             Waypoint waypoint = waypoints[currentCount]; | ||||
| 
 | ||||
|             if(currentCount == 0){ | ||||
|                 speed = Time.deltaTime / waypoint.timeBetweenWaypoints * waypoint.endWaypoint; | ||||
|                 percentBetweenWaypoints += speed / waypoint.endWaypoint; | ||||
|                 percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints); | ||||
|                 easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints); | ||||
| 
 | ||||
|                 nextPos = easedPercentBetweenWaypoints * waypoint.endWaypoint; | ||||
|             }else{ | ||||
|                 speed = Time.deltaTime / waypoint.timeBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint); | ||||
|                 percentBetweenWaypoints += speed / (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint); | ||||
|                 percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints); | ||||
|                 easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints); | ||||
| 
 | ||||
|                 nextPos = waypoints[currentCount - 1].endWaypoint + easedPercentBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint); | ||||
|             } | ||||
| 
 | ||||
|             dollyTrackCamera.m_Lens.FieldOfView = Mathf.Lerp(lastFieldOfView, waypoint.fieldOfView, easedPercentBetweenWaypoints); | ||||
| 
 | ||||
|             if (cameraTrack.m_PathPosition < waypoint.endWaypoint){ | ||||
|                 cameraTrack.m_PathPosition = nextPos; | ||||
|             }else{ | ||||
|                 NextWaypoint(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     float Ease(float x){ | ||||
|         if (waypoints[currentCount].ease){ | ||||
|             float a = currentEase + 1; | ||||
|             return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a)); | ||||
|         }else{ | ||||
|             return x; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> Starts playing the cutscene. </summary> | ||||
|     public void StartRail(){ | ||||
|         lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView; | ||||
|         Waypoint waypoint = waypoints[currentCount]; | ||||
|         if (waypoint.startDelay > 0){ | ||||
|             paused = true; | ||||
|             StartCoroutine(DelayMovement(waypoint.startDelay)); | ||||
|         } | ||||
|         currentEase = waypoint.ease ? waypoint.easeAmount : 1; | ||||
|     } | ||||
| 
 | ||||
|     void NextWaypoint(){ | ||||
|         lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView; | ||||
|         if (currentCount >= totalCount){ | ||||
|             Debug.Log("Finish"); | ||||
|             finished = true; | ||||
|         }else{ | ||||
|             percentBetweenWaypoints = 0; | ||||
|             currentCount++; | ||||
|             Waypoint waypoint = waypoints[currentCount]; | ||||
|             if(waypoint.startDelay > 0){ | ||||
|                 paused = true; | ||||
|                 StartCoroutine(DelayMovement(waypoint.startDelay)); | ||||
|             } | ||||
|             currentEase = waypoint.ease ? waypoint.easeAmount : 1; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     IEnumerator DelayMovement(float delay){ | ||||
|         yield return new WaitForSeconds(delay); | ||||
|         paused = false; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,11 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: 6e80df5e5cd6b984396c057f7ce9a9c7 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
|  | @ -0,0 +1,18 @@ | |||
| using UnityEngine; | ||||
| 
 | ||||
| [System.Serializable] | ||||
| public class Waypoint{ | ||||
| 
 | ||||
|     [Min(0)] public float startDelay; | ||||
| 
 | ||||
|     [Header("Easing")] | ||||
|     public bool ease; | ||||
|     [Range(0f, 2f)] public float easeAmount; | ||||
| 
 | ||||
|     [Header("Waypoints")] | ||||
|     [Min(0)] public float timeBetweenWaypoints; | ||||
|     [Min(0)] public int endWaypoint; | ||||
| 
 | ||||
|     [Header("Field of View")] | ||||
|     [Range(1, 179)] public float fieldOfView = 60; | ||||
| } | ||||
|  | @ -0,0 +1,11 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: cbcbf05409a71c34498aea255a6ba921 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										39
									
								
								Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,39 @@ | |||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using Cinemachine; | ||||
| 
 | ||||
| public class ScreenShakeCall : MonoBehaviour{ | ||||
| 
 | ||||
|     CinemachineVirtualCamera vCam; | ||||
|     float shakeTimer; | ||||
|     float shakeTimerTotal; | ||||
|     float startingIntensity; | ||||
| 
 | ||||
|     public static ScreenShakeCall instance { get; private set; } | ||||
| 
 | ||||
|     void Awake(){ | ||||
|         instance = this; | ||||
|         vCam = GetComponent<CinemachineVirtualCamera>(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> Smoothly shakes with a certain intensity and duration </summary> | ||||
|     public void ShakeCamera(float intensity, float time){ | ||||
|         startingIntensity = intensity; | ||||
|         shakeTimer = shakeTimerTotal = time; | ||||
|     } | ||||
| 
 | ||||
|     public void StopShaking(){ | ||||
|         shakeTimer = 0; | ||||
|         CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>(); | ||||
|         multiChannelPerlin.m_AmplitudeGain = 0; | ||||
|     } | ||||
| 
 | ||||
|     void Update(){ | ||||
|         if (shakeTimer > 0){ | ||||
|             shakeTimer -= Time.deltaTime; | ||||
|             CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>(); | ||||
|             multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs.meta
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: f000cf598e480f345a7feb226d3b026a | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gerard Gascón
						Gerard Gascón