您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
103 行
3.8 KiB
103 行
3.8 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 List<GameObject> 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<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
|
//canvasPosition.GetComponent<Canvas>().worldCamera = null;
|
|
imagePosition.sizeDelta = standerdImageSize;
|
|
foreach (var panel in OtherPanels)
|
|
{
|
|
panel.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (isFirstTime)
|
|
{
|
|
canvasPosition.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
|
|
canvasPosition.GetComponent<Canvas>().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;
|
|
}
|
|
|
|
|
|
}
|