您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

99 行
3.7 KiB

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<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
//canvasPosition.GetComponent<Canvas>().worldCamera = null;
imagePosition.sizeDelta = standerdImageSize;
panel.SetActive(false);
dateAndTimePicker.SetActive(false);
}
}
else
{
if (isFirstTime)
{
canvasPosition.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
canvasPosition.GetComponent<Canvas>().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;
}
}