diff --git a/Assets/scenes/Main.unity b/Assets/scenes/Main.unity index b690e059..f2ba0fe0 100644 --- a/Assets/scenes/Main.unity +++ b/Assets/scenes/Main.unity @@ -177,6 +177,11 @@ Prefab: propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} + - target: {fileID: 23607902342867652, guid: da42a4da83762402ab84356f1fafda0e, + type: 2} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: da42a4da83762402ab84356f1fafda0e, type: 2} m_IsPrefabParent: 0 @@ -846,7 +851,7 @@ Prefab: - target: {fileID: 224211405682033542, guid: 0b856abfdd5ce4931b2113cd82c17491, type: 2} propertyPath: m_AnchoredPosition.x - value: 1.4542847 + value: 1.4550781 objectReference: {fileID: 0} - target: {fileID: 224211405682033542, guid: 0b856abfdd5ce4931b2113cd82c17491, type: 2} @@ -1106,23 +1111,7 @@ GameObject: m_PrefabParentObject: {fileID: 1161922269846664, guid: e057f9a5ad71a4f15b8d50ed6d9ed9ee, type: 2} m_PrefabInternal: {fileID: 1710198126} ---- !u!1 &926934035 stripped -GameObject: - m_PrefabParentObject: {fileID: 1873917874005640, guid: 29d749ee6243b4c488f4ff171f361ea5, - type: 2} - m_PrefabInternal: {fileID: 320500250} ---- !u!114 &926934038 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 926934035} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1f993cbe253a7004eb2c659247555094, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!84 &946754072 +--- !u!84 &864947714 RenderTexture: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} @@ -1133,8 +1122,8 @@ RenderTexture: Hash: 00000000000000000000000000000000 m_ForcedFallbackFormat: 4 m_DownscaleFallback: 0 - m_Width: 782 - m_Height: 440 + m_Width: 846 + m_Height: 476 m_AntiAliasing: 1 m_DepthFormat: 2 m_ColorFormat: 0 @@ -1153,6 +1142,22 @@ RenderTexture: m_WrapW: 1 m_Dimension: 2 m_VolumeDepth: 1 +--- !u!1 &926934035 stripped +GameObject: + m_PrefabParentObject: {fileID: 1873917874005640, guid: 29d749ee6243b4c488f4ff171f361ea5, + type: 2} + m_PrefabInternal: {fileID: 320500250} +--- !u!114 &926934038 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 926934035} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1f993cbe253a7004eb2c659247555094, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &955045869 stripped GameObject: m_PrefabParentObject: {fileID: 1319377659274120, guid: 0b856abfdd5ce4931b2113cd82c17491, @@ -1842,7 +1847,7 @@ Prefab: type: 2} propertyPath: m_TargetTexture value: - objectReference: {fileID: 2115282473} + objectReference: {fileID: 864947714} - target: {fileID: 20754644307438984, guid: 6849b8a20f320f04dabdfd7ed9070271, type: 2} propertyPath: m_HDR @@ -1871,6 +1876,16 @@ Prefab: propertyPath: orthographic value: 1 objectReference: {fileID: 0} + - target: {fileID: 114091424562538916, guid: 6849b8a20f320f04dabdfd7ed9070271, + type: 2} + propertyPath: maxSize + value: 9 + objectReference: {fileID: 0} + - target: {fileID: 114091424562538916, guid: 6849b8a20f320f04dabdfd7ed9070271, + type: 2} + propertyPath: panSpeed + value: 15 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 6849b8a20f320f04dabdfd7ed9070271, type: 2} m_IsPrefabParent: 0 @@ -2092,34 +2107,3 @@ GameObject: m_PrefabParentObject: {fileID: 1536250208252664, guid: 2f16d96d8e95f4ee893d3f69273b7e64, type: 2} m_PrefabInternal: {fileID: 1727813781} ---- !u!84 &2115282473 -RenderTexture: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_Name: - m_ImageContentsHash: - serializedVersion: 2 - Hash: 00000000000000000000000000000000 - m_ForcedFallbackFormat: 4 - m_DownscaleFallback: 0 - m_Width: 782 - m_Height: 440 - m_AntiAliasing: 1 - m_DepthFormat: 2 - m_ColorFormat: 0 - m_MipMap: 0 - m_GenerateMips: 1 - m_SRGB: 0 - m_UseDynamicScale: 0 - m_BindMS: 0 - m_TextureSettings: - serializedVersion: 2 - m_FilterMode: 1 - m_Aniso: 0 - m_MipBias: 0 - m_WrapU: 1 - m_WrapV: 1 - m_WrapW: 1 - m_Dimension: 2 - m_VolumeDepth: 1 diff --git a/Assets/scripts/CameraControllerScript.cs b/Assets/scripts/CameraControllerScript.cs index 0583b787..c1b454f8 100644 --- a/Assets/scripts/CameraControllerScript.cs +++ b/Assets/scripts/CameraControllerScript.cs @@ -1,24 +1,30 @@ using UnityEngine; using System.Collections; -public class CameraControllerScript : MonoBehaviour +public class CameraControllerScript : MonoBehaviour { - public float panSpeed = 30f; - public float panBoardThickness = 10f; - public float scrollSpeed = 5f; - public float scrollMaxSensibility = 1f; - public float moduleDimension; - public float minY = 10f; - public float maxY = 80f; + public float panSpeed = 30f; + public float panBoardThickness = 10f; + public float scrollSpeed = 5f; + public float scrollMaxSensibility = 1f; + public float moduleDimension; + + [Header("Perspective atributes")] + public float minY = 10f; + public float maxY = 80f; + + [Header("Orthographic atributes")] + public float maxSize = 10; + public float minSize = 3; private float frontRation; private float backRation; private float rightRation; private float leftRation; - private float minXInMaxY = 10f; - private float maxXInMaxY = 80f; - private float minZInMaxY = 10f; - private float maxZInMaxY = 80f; + private float minXInMaxY = 10f; + private float maxXInMaxY = 80f; + private float minZInMaxY = 10f; + private float maxZInMaxY = 80f; private float minX = 10f; private float maxX = 80f; private float minZ = 10f; @@ -28,137 +34,151 @@ public class CameraControllerScript : MonoBehaviour float posY; float posZ; - private Animator anim; + private Animator anim; - private void Update () + private void Update() { - MoveScreen (); - ZoomScroll (); - LimitPosition (); + MoveScreen(); + ZoomScroll(); + LimitPosition(); - if (Input.GetKeyDown(KeyCode.C) && Application.isEditor) - ShakeBySpeed(1f, 1f); - } + if (Input.GetKeyDown(KeyCode.C) && Application.isEditor) + ShakeBySpeed(1f, 1f); + } - private void Start() + private void Start() { minXInMaxY = (-1f) * moduleDimension - 8.5f; maxXInMaxY = moduleDimension - 23f; - minZInMaxY = (-1f)*moduleDimension - 16.5f; + minZInMaxY = (-1f) * moduleDimension - 16.5f; maxZInMaxY = moduleDimension - 33f; frontRation = (maxZInMaxY - moduleDimension) / maxY; - backRation = ( minZInMaxY + moduleDimension ) / maxY; - leftRation = ( minXInMaxY + moduleDimension ) / maxY; + backRation = (minZInMaxY + moduleDimension) / maxY; + leftRation = (minXInMaxY + moduleDimension) / maxY; rightRation = (maxXInMaxY - moduleDimension) / maxY; - anim = GetComponentInChildren(); - } + anim = GetComponentInChildren(); + } - //move the camera white awsd or with mouse in the border - private void MoveScreen() + //move the camera white awsd or with mouse in the border + private void MoveScreen() { - if ( - Input.GetKey ("w") || - ( Input.mousePosition.y >= (Screen.height - panBoardThickness) && + if ( + Input.GetKey("w") || + (Input.mousePosition.y >= (Screen.height - panBoardThickness) && Input.mousePosition.y <= Screen.height) - || Input.GetKey(KeyCode.UpArrow) - ) + || Input.GetKey(KeyCode.UpArrow) + ) { - GoForward (); - } - if ( Input.GetKey ("s") || - ( Input.mousePosition.y <= panBoardThickness && - Input.mousePosition.y >= 0f ) || - Input.GetKey(KeyCode.DownArrow) - ) + GoForward(); + } + if (Input.GetKey("s") || + (Input.mousePosition.y <= panBoardThickness && + Input.mousePosition.y >= 0f) || + Input.GetKey(KeyCode.DownArrow) + ) { - GoBack (); - } - if ( - Input.GetKey ("d") || - ( Input.mousePosition.x >= Screen.width - panBoardThickness && Input.mousePosition.x <= Screen.width) || - Input.GetKey(KeyCode.RightArrow) - ) + GoBack(); + } + if ( + Input.GetKey("d") || + (Input.mousePosition.x >= Screen.width - panBoardThickness && Input.mousePosition.x <= Screen.width) || + Input.GetKey(KeyCode.RightArrow) + ) { - GoRight (); - } - if ( - Input.GetKey ("a") || - (Input.mousePosition.x <= panBoardThickness && Input.mousePosition.x >= 0f) || - Input.GetKey(KeyCode.LeftArrow) - ) + GoRight(); + } + if ( + Input.GetKey("a") || + (Input.mousePosition.x <= panBoardThickness && Input.mousePosition.x >= 0f) || + Input.GetKey(KeyCode.LeftArrow) + ) { - GoLeft (); - } - } + GoLeft(); + } + } - //Transform mouse scroll into zoom and defines min and max distances - private void ZoomScroll() + //Transform mouse scroll into zoom and defines min and max distances + private void ZoomScroll() { - float scroll = LimitScrollSensibility( Input.GetAxis("Mouse ScrollWheel") ); + float scroll = LimitScrollSensibility(Input.GetAxis("Mouse ScrollWheel")); - if ( transform.position.y > minY - epsilon && transform.position.y < maxY + epsilon ) + if (transform.position.y > minY - epsilon && transform.position.y < maxY + epsilon) ZoomMoviment(scroll); - } + } private float LimitScrollSensibility(float scroll) { return Mathf.Clamp(scroll, (-1f) * scrollMaxSensibility, scrollMaxSensibility); } - //Camera zoom moviment - private void ZoomMoviment(float scroll) + //Camera zoom moviment + private void ZoomMoviment(float scroll) { - Vector3 triedPosition = transform.position; - triedPosition.y -= scroll * scrollSpeed * 200 * Time.deltaTime; - - if ( triedPosition.y > minY - epsilon && triedPosition.y < maxY + epsilon ) - { - ZoomVerticalMoviment(triedPosition); - ZoomHorizontalMoviment(scroll); - return; - } - if ( triedPosition.y <= minY - epsilon ) + if (!Camera.main.orthographic) { - float triedMoviment = Mathf.Abs(transform.position.y - triedPosition.y ); - float maxDisplacement = Mathf.Abs(transform.position.y - (minY - epsilon)); - float movimentRation = maxDisplacement / triedMoviment; - triedPosition.y = minY; - ZoomVerticalMoviment( triedPosition ); - ZoomHorizontalMoviment( scroll * movimentRation ); - return; + Vector3 triedPosition = transform.position; + triedPosition.y -= scroll * scrollSpeed * 200 * Time.deltaTime; + + if (triedPosition.y > minY - epsilon && triedPosition.y < maxY + epsilon) + { + ZoomVerticalMoviment(triedPosition); + ZoomHorizontalMoviment(scroll); + return; + } + if (triedPosition.y <= minY - epsilon) + { + float triedMoviment = Mathf.Abs(transform.position.y - triedPosition.y); + float maxDisplacement = Mathf.Abs(transform.position.y - (minY - epsilon)); + float movimentRation = maxDisplacement / triedMoviment; + triedPosition.y = minY; + ZoomVerticalMoviment(triedPosition); + ZoomHorizontalMoviment(scroll * movimentRation); + return; + } + if (triedPosition.y >= maxY + epsilon) + { + float triedMoviment = Mathf.Abs(transform.position.y - triedPosition.y); + float maxDisplacement = Mathf.Abs(transform.position.y - (maxY + epsilon)); + float movimentRation = maxDisplacement / triedMoviment; + triedPosition.y = maxY; + ZoomVerticalMoviment(triedPosition); + ZoomHorizontalMoviment(scroll * movimentRation); + return; + } } - if (triedPosition.y >= maxY + epsilon) + else { - float triedMoviment = Mathf.Abs( transform.position.y - triedPosition.y ); - float maxDisplacement = Mathf.Abs( transform.position.y - (maxY + epsilon) ); - float movimentRation = maxDisplacement / triedMoviment; - triedPosition.y = maxY; - ZoomVerticalMoviment( triedPosition ); - ZoomHorizontalMoviment(scroll * movimentRation); - return; + float fieldOfView = Camera.main.orthographicSize; + if (scroll == 0) + return; + if (fieldOfView - scroll > minSize && fieldOfView - scroll < maxSize) + { + fieldOfView = fieldOfView - scroll * 5f * scrollSpeed; + } + Camera.main.orthographicSize = fieldOfView; } - } + } private void ZoomVerticalMoviment(Vector3 pos) { transform.position = pos; } - private void ZoomHorizontalMoviment(float scroll) + private void ZoomHorizontalMoviment(float scroll) { - Vector3 pos = transform.position; - transform.Translate (Vector3.forward * scroll * scrollSpeed * 200 * Time.deltaTime, Space.Self); - } + Vector3 pos = transform.position; + transform.Translate(Vector3.forward * scroll * scrollSpeed * 200 * Time.deltaTime, Space.Self); + } - private void LimitPosition() + private void LimitPosition() { SetPos(); SetCameraEdgesForTheHeigh(); ClampCameraPosition(); - transform.position = new Vector3 (posX, posY, posZ); - } + transform.position = new Vector3(posX, posY, posZ); + } private void SetPos() { @@ -182,37 +202,37 @@ private void ClampCameraPosition() posZ = Mathf.Clamp(posZ, minZ, maxZ); } - private void GoForward () + private void GoForward() { - transform.Translate ( Vector3.forward * panSpeed * Time.deltaTime, Space.Self ); - } + transform.Translate(Vector3.forward * panSpeed * Time.deltaTime, Space.Self); + } - private void GoBack () + private void GoBack() { - transform.Translate ( Vector3.back * panSpeed * Time.deltaTime, Space.Self ); - } + transform.Translate(Vector3.back * panSpeed * Time.deltaTime, Space.Self); + } - private void GoLeft () + private void GoLeft() { - transform.Translate ( Vector3.left * panSpeed * Time.deltaTime, Space.Self ); - } + transform.Translate(Vector3.left * panSpeed * Time.deltaTime, Space.Self); + } - private void GoRight () + private void GoRight() { - transform.Translate ( Vector3.right * panSpeed * Time.deltaTime, Space.Self ); - } + transform.Translate(Vector3.right * panSpeed * Time.deltaTime, Space.Self); + } - /// - /// Function to shake the camera. It's animation-based, then it's not dependent of camera's transform - /// - /// The speed of the animation playing - /// Which percentage of the animation should play - public void ShakeBySpeed (float speed, float percentageOfAnimationToShow) - { - //float t0 = Time.time; - anim.SetFloat("speed", speed); - StartCoroutine(Shake(percentageOfAnimationToShow)); - /* + /// + /// Function to shake the camera. It's animation-based, then it's not dependent of camera's transform + /// + /// The speed of the animation playing + /// Which percentage of the animation should play + public void ShakeBySpeed(float speed, float percentageOfAnimationToShow) + { + //float t0 = Time.time; + anim.SetFloat("speed", speed); + StartCoroutine(Shake(percentageOfAnimationToShow)); + /* float a = 0.1f; float w = 1f; float phi = 0f; @@ -220,12 +240,12 @@ public void ShakeBySpeed (float speed, float percentageOfAnimationToShow) { anim.SetFloat("speed", a * Mathf.Cos(w * (Time.time - t0))); }*/ - } - - IEnumerator Shake(float t) - { - anim.SetBool("shake", true); - yield return new WaitForSeconds(t); - anim.SetBool("shake", false); - } + } + + IEnumerator Shake(float t) + { + anim.SetBool("shake", true); + yield return new WaitForSeconds(t); + anim.SetBool("shake", false); + } } diff --git a/Assets/scripts/ShaderScripts/PrePassCamera.cs b/Assets/scripts/ShaderScripts/PrePassCamera.cs index fd5e8ce7..ebc494fb 100644 --- a/Assets/scripts/ShaderScripts/PrePassCamera.cs +++ b/Assets/scripts/ShaderScripts/PrePassCamera.cs @@ -4,7 +4,8 @@ [ExecuteInEditMode] [RequireComponent(typeof(Camera))] -public class PrePassCamera : MonoBehaviour { +public class PrePassCamera : MonoBehaviour +{ private static RenderTexture PrePass; //Texture where the solid color is stored private static RenderTexture BlurTexture; //Texture where the blur is stored @@ -13,7 +14,7 @@ public class PrePassCamera : MonoBehaviour { private void OnEnable() { - PrePass = new RenderTexture(Screen.width, Screen.height, 24); + PrePass = new RenderTexture(Screen.width, Screen.height, 24); BlurTexture = new RenderTexture(Screen.width >> 1, Screen.height >> 1, 0); //Downing the resolution for the blur Camera _camera = GetComponent(); @@ -36,7 +37,7 @@ private void OnRenderImage(RenderTexture source, RenderTexture destination) Graphics.Blit(source, BlurTexture); //Time to apply the blur. First, the blurTexture is merged with what the camera is seeing - for (int i = 0 ; i < 10; i++) + for (int i = 0; i < 10; i++) { RenderTexture rt = RenderTexture.GetTemporary(BlurTexture.width, BlurTexture.height); //Temporary texture to apply iterative blur Graphics.Blit(BlurTexture, rt, _blurMaterial); //Step 1 of iterative blur, the temporary texture receives the blur texture, but blurred(by the blur shader) @@ -45,4 +46,22 @@ private void OnRenderImage(RenderTexture source, RenderTexture destination) } //After the loop, the blur texture is very blurred } + + #region Main camera tracking and following + /// + /// Start is called on the frame when a script is enabled just before + /// any of the Update methods is called the first time. + /// + void Start() + { + gameObject.GetComponent().orthographic = Camera.main.orthographic; + } + /// + /// Update is called every frame, if the MonoBehaviour is enabled. + /// + void Update() + { + gameObject.GetComponent().orthographicSize = Camera.main.orthographicSize; + } + #endregion }