using Sirenix.OdinInspector; using System.Collections; using System.Collections.Generic; using UnityEngine; //using UnityEngine.InputSystem.UI; using UnityEngine.Rendering; namespace Beyond { public class GUIScroll : MonoBehaviour { // Start is called before the first frame update public enum PanelEnum {QUESTS, INVENTORY, SKILLS, STATS, SCROLLS, CUTSCENE }; public UVInputModule m_uvInputModule; // public InputSystemUIInputModule m_inputSystemUIInputModule; public Animator m_scrollAnimator; public Canvas m_canvas; public Camera m_GUICamera; public Camera m_ScrollCamera; public Renderer m_scrollRenderer; public bool m_burnIn = false; public bool m_isOpen = false; public float m_burnInDelay = 1f; public float m_moveInTime = 1f; public float m_burnInTime = 1f; public float m_burnThreshold; [Tooltip("Motion curve for first move in")] public AnimationCurve m_MotionCurve; public AnimationCurve m_BurnInCurve; public Vector3 m_startPositionShift = new Vector3(-3f, 0f, 0f); private Vector3 m_startPosition; private Vector3 m_endPosition; private Transform m_scrollTransform; private Material m_scrollMat; private Volume m_volume; public VolumeProfile m_volumeProfile; private VolumeProfile m_defaultProfile; public PanelEnum m_activePanel = PanelEnum.CUTSCENE; public GameObject[] m_panels; void ActivateObjects(bool activate) { m_canvas.gameObject.SetActive(activate); m_GUICamera.gameObject.SetActive(activate); m_ScrollCamera.gameObject.SetActive(activate); m_volume.profile = activate ? m_volumeProfile : m_defaultProfile; } IEnumerator OpenAndBurnIn() { BlockUI(true); ActivateObjects(true); float time = 0f; while (time < m_moveInTime) { time += Time.deltaTime; float val = m_MotionCurve.Evaluate(time / m_moveInTime); m_scrollTransform.position = m_startPosition - m_startPositionShift * val; yield return null; } m_scrollAnimator.SetBool("Open", true); yield return new WaitForSeconds(m_burnInDelay); time = 0f; while (time < m_burnInTime) { time += Time.deltaTime; float val = m_BurnInCurve.Evaluate(time / m_burnInTime); SetBurnInTh(val); yield return null; } yield return true; } IEnumerator CloseAndBurnOut() { float time = 0f; while (time < m_burnInTime) { time += Time.deltaTime; float val = m_BurnInCurve.Evaluate(1.0f - time / m_burnInTime); SetBurnInTh(val); yield return null; } m_scrollAnimator.SetBool("Open", false); time = 0f; yield return new WaitForSeconds(m_burnInDelay); while (time < m_moveInTime) { time += Time.deltaTime; float val = m_MotionCurve.Evaluate(1.0f - time / m_moveInTime); m_scrollTransform.position = m_startPosition - m_startPositionShift * val; yield return null; } BlockUI(false); ActivateObjects(false); yield return true; } IEnumerator SwitchPanelCoroutine(PanelEnum panel) { float time = 0f; while (time < m_burnInTime) { time += Time.deltaTime; float val = m_BurnInCurve.Evaluate(1.0f - time / m_burnInTime); SetBurnInTh(val); yield return null; } m_panels[(int)m_activePanel].SetActive(false); m_panels[(int)panel].SetActive(true); time = 0f; while (time < m_burnInTime) { time += Time.deltaTime; float val = m_BurnInCurve.Evaluate(time / m_burnInTime); SetBurnInTh(val); yield return null; } m_activePanel = (PanelEnum)panel; yield return null; } public void SwitchPanel(int panel) { if (panel == (int)m_activePanel) return; StartCoroutine(SwitchPanelCoroutine((PanelEnum)panel)); } void SetBurnInTh(float burnTh) { m_scrollMat.SetFloat("_Threshold", burnTh); } void Awake() { if (!m_scrollAnimator) { m_scrollAnimator = transform.GetComponentInChildren(); } m_scrollAnimator.SetBool("Open", false); m_scrollTransform = m_scrollAnimator.transform.parent; if (m_scrollRenderer == null) { m_scrollMat = m_scrollAnimator.transform.GetComponentInChildren().material; } else { m_scrollMat = m_scrollRenderer.material; } } [Button] public void OpenCloseScroll(bool open) { if (open) StartCoroutine(OpenAndBurnIn()); else StartCoroutine(CloseAndBurnOut()); } void BlockUI(bool block) { HideUI.SetActive(!block); m_uvInputModule.enabled = block; // m_inputSystemUIInputModule.enabled = !block; } void Start() { m_endPosition = m_scrollTransform.position; m_startPosition = m_endPosition + m_startPositionShift; m_scrollTransform.position = m_startPosition; m_volume = GameObject.FindObjectOfType(); m_defaultProfile = m_volume.profile; //OpenCloseScroll(true); ActivateObjects(false); } // Update is called once per frame void Update() { } } }