using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ChatPanelManager : MonoBehaviour { public Transform startTransform; public Transform targetTransform; public Transform panelTransform; public RectTransform canvasTransform; public List OtherPanels; public Camera mainCamera; public GameObject button; private static bool isLerp = false; public static bool isOpenPanel = false; public float speed = 5.0f; private static bool isFirstTime = true; private bool wait = false; private void Start() { button.SetActive(true); canvasTransform.sizeDelta = new Vector2(UnityEngine.Screen.width,UnityEngine.Screen.height); var scale = 1920 * targetTransform.localScale.x / Screen.height; targetTransform.localScale = new Vector3(scale, scale, scale); } void Update() { if (isLerp) { if (isOpenPanel) { panelTransform.position = Vector3.Lerp(panelTransform.position, targetTransform.position, speed * Time.deltaTime); panelTransform.rotation = Quaternion.Lerp(panelTransform.rotation, targetTransform.rotation, speed * Time.deltaTime); panelTransform.localScale = Vector3.Lerp(panelTransform.localScale, targetTransform.localScale, speed * Time.deltaTime); if(Vector3.Distance(panelTransform.position,targetTransform.position) < 0.01f) { isLerp = false; canvasTransform.GetComponent().renderMode = RenderMode.ScreenSpaceOverlay; panelTransform.position = targetTransform.position; panelTransform.rotation = targetTransform.rotation; panelTransform.localScale = targetTransform.localScale; foreach (var panel in OtherPanels) { panel.SetActive(false); } } button.SetActive(false); } else { if (isFirstTime) { canvasTransform.GetComponent().renderMode = RenderMode.WorldSpace; canvasTransform.GetComponent().worldCamera = mainCamera; canvasTransform.anchoredPosition3D = Vector3.zero; canvasTransform.localRotation = Quaternion.Euler(0,0,0); canvasTransform.localScale = new Vector3(1, 1, 1); panelTransform.position = targetTransform.position; panelTransform.rotation = targetTransform.rotation; panelTransform.localScale = targetTransform.localScale; foreach (var panel in OtherPanels) { panel.SetActive(true); } isFirstTime = false; wait = true; button.SetActive(true); StartCoroutine(SkipForAWhile()); } if (!wait) { panelTransform.position = Vector3.Lerp(panelTransform.position, startTransform.position, speed * Time.deltaTime); panelTransform.rotation = Quaternion.Lerp(panelTransform.rotation, startTransform.rotation, speed * Time.deltaTime); panelTransform.localScale = Vector3.Lerp(panelTransform.localScale, startTransform.localScale, speed * Time.deltaTime); if(Vector3.Distance(panelTransform.position, startTransform.position)<0.01f) { panelTransform.position = startTransform.position; panelTransform.rotation = startTransform.rotation; panelTransform.localScale = startTransform.localScale; isLerp = false; } } } } } IEnumerator SkipForAWhile() { yield return new WaitForSeconds(0.15f); wait = false; } public static void Switch() { isLerp = true; isOpenPanel = !isOpenPanel; isFirstTime = true; } public void OpenPanel() { Switch(); } }