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 GameObject panel; public GameObject dateAndTimePicker; private static bool isLerp = false; private 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; panel.SetActive(false); dateAndTimePicker.SetActive(false); } } else { if (isFirstTime) { canvasPosition.GetComponent().renderMode = RenderMode.WorldSpace; canvasPosition.GetComponent().worldCamera = Camera.main; canvasPosition.anchoredPosition3D = transformedPosition.anchoredPosition3D; canvasPosition.localRotation = transformedPosition.localRotation; canvasPosition.localScale = transformedPosition.localScale; panel.SetActive(true); dateAndTimePicker.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.1f); wait = false; } public static void Switch() { isLerp = true; isOpenPanel = !isOpenPanel; isFirstTime = true; } }