using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChatPanelManager : MonoBehaviour { public RectTransform transformPosition; public RectTransform transformedPosition; public RectTransform canvasPosition; public RectTransform imagePosition; public Vector2 standerdImageSize; public List OtherPanels; public Camera mainCamera; private static bool isLerp = false; public static bool isOpenPanel = false; public float speed = 5.0f; private static bool isFirstTime = true; private bool wait = false; void Update() { if(Input.GetKeyDown(KeyCode.Tab)) { Switch(); } if (isLerp) { if (isOpenPanel) { canvasPosition.anchoredPosition3D = Vector3.Lerp(canvasPosition.anchoredPosition3D, transformedPosition.anchoredPosition3D, speed * Time.deltaTime); canvasPosition.localRotation = Quaternion.Lerp(canvasPosition.localRotation, transformedPosition.localRotation, speed * Time.deltaTime); canvasPosition.localScale = Vector3.Lerp(canvasPosition.localScale, transformedPosition.localScale, speed * Time.deltaTime); if(Vector3.Distance(canvasPosition.anchoredPosition3D,transformedPosition.anchoredPosition3D) < 0.1f) { isLerp = false; canvasPosition.GetComponent().renderMode = RenderMode.ScreenSpaceOverlay; //canvasPosition.GetComponent().worldCamera = null; imagePosition.sizeDelta = standerdImageSize; foreach (var panel in OtherPanels) { panel.SetActive(false); } } } else { if (isFirstTime) { canvasPosition.GetComponent().renderMode = RenderMode.WorldSpace; canvasPosition.GetComponent().worldCamera = mainCamera; canvasPosition.anchoredPosition3D = transformedPosition.anchoredPosition3D; canvasPosition.localRotation = transformedPosition.localRotation; canvasPosition.localScale = transformedPosition.localScale; foreach (var panel in OtherPanels) { panel.SetActive(true); } isFirstTime = false; wait = true; StartCoroutine(SkipForAFrame()); } if (!wait) { canvasPosition.anchoredPosition3D = Vector3.Lerp(canvasPosition.anchoredPosition3D, transformPosition.anchoredPosition3D, speed * Time.deltaTime); canvasPosition.localRotation = Quaternion.Lerp(canvasPosition.localRotation, transformPosition.localRotation, speed * Time.deltaTime); canvasPosition.localScale = Vector3.Lerp(canvasPosition.localScale, transformPosition.localScale, speed * Time.deltaTime); if(Vector3.Distance(canvasPosition.anchoredPosition3D, transformedPosition.anchoredPosition3D)<0.1f) { isLerp = false; } } } } } IEnumerator SkipForAFrame() { yield return new WaitForSeconds(0.15f); wait = false; } public static void Switch() { isLerp = true; isOpenPanel = !isOpenPanel; isFirstTime = true; } }