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

127 行
4.7 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChatPanelManager : MonoBehaviour
{
public RectTransform transformPosition;
public RectTransform transformedPosition;
public RectTransform canvasPosition;
public RectTransform imagePosition;
public List<GameObject> OtherPanels;
public Camera mainCamera;
public Button 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.enabled = true;
canvasPosition.sizeDelta = new Vector2(UnityEngine.Screen.width,UnityEngine.Screen.height);
transformedPosition.sizeDelta = new Vector2(UnityEngine.Screen.width,UnityEngine.Screen.height);
transformPosition.sizeDelta = new Vector2(UnityEngine.Screen.width,UnityEngine.Screen.height);
Vector3 transformedScale = transformedPosition.localScale;
transformedPosition.localScale = new Vector3(
transformedScale.x * 1920 / UnityEngine.Screen.height,
transformedScale.y * 1920 / UnityEngine.Screen.height,
z:transformedScale.z
);
}
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;
imagePosition.sizeDelta = new Vector2(UnityEngine.Screen.width,UnityEngine.Screen.height);
imagePosition.offsetMin = new Vector2(0, 0);
imagePosition.offsetMax = new Vector2(0, 0);
foreach (var panel in OtherPanels)
{
panel.SetActive(false);
}
}
button.enabled = 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;
button.enabled = true;
StartCoroutine(SkipForAWhile());
}
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 SkipForAWhile()
{
yield return new WaitForSeconds(0.15f);
wait = false;
}
public static void Switch()
{
isLerp = true;
isOpenPanel = !isOpenPanel;
isFirstTime = true;
}
public void SwitchB()
{
Switch();
}
}