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

119 行
4.4 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChatPanelManager : MonoBehaviour
{
public Transform startTransform;
public Transform targetTransform;
public Transform panelTransform;
public RectTransform canvasTransform;
public List<GameObject> OtherPanels;
public Camera mainCamera;
public GameObject 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.SetActive(true);
canvasTransform.sizeDelta = new Vector2(UnityEngine.Screen.width,UnityEngine.Screen.height);
var scale = 1920 * targetTransform.localScale.x / Screen.height;
targetTransform.localScale = new Vector3(scale, scale, scale);
}
void Update()
{
if (isLerp)
{
if (isOpenPanel)
{
panelTransform.position = Vector3.Lerp(panelTransform.position,
targetTransform.position, speed * Time.deltaTime);
panelTransform.rotation = Quaternion.Lerp(panelTransform.rotation,
targetTransform.rotation, speed * Time.deltaTime);
panelTransform.localScale = Vector3.Lerp(panelTransform.localScale, targetTransform.localScale,
speed * Time.deltaTime);
if(Vector3.Distance(panelTransform.position,targetTransform.position) < 0.01f)
{
isLerp = false;
canvasTransform.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
panelTransform.position = targetTransform.position;
panelTransform.rotation = targetTransform.rotation;
panelTransform.localScale = targetTransform.localScale;
foreach (var panel in OtherPanels)
{
panel.SetActive(false);
}
}
button.SetActive(false);
}
else
{
if (isFirstTime)
{
canvasTransform.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
canvasTransform.GetComponent<Canvas>().worldCamera = mainCamera;
canvasTransform.anchoredPosition3D = Vector3.zero;
canvasTransform.localRotation = Quaternion.Euler(0,0,0);
canvasTransform.localScale = new Vector3(1, 1, 1);
panelTransform.position = targetTransform.position;
panelTransform.rotation = targetTransform.rotation;
panelTransform.localScale = targetTransform.localScale;
foreach (var panel in OtherPanels)
{
panel.SetActive(true);
}
isFirstTime = false;
wait = true;
button.SetActive(true);
StartCoroutine(SkipForAWhile());
}
if (!wait)
{
panelTransform.position = Vector3.Lerp(panelTransform.position, startTransform.position, speed * Time.deltaTime);
panelTransform.rotation = Quaternion.Lerp(panelTransform.rotation, startTransform.rotation,
speed * Time.deltaTime);
panelTransform.localScale = Vector3.Lerp(panelTransform.localScale, startTransform.localScale,
speed * Time.deltaTime);
if(Vector3.Distance(panelTransform.position, startTransform.position)<0.01f)
{
panelTransform.position = startTransform.position;
panelTransform.rotation = startTransform.rotation;
panelTransform.localScale = startTransform.localScale;
isLerp = false;
}
}
}
}
}
IEnumerator SkipForAWhile()
{
yield return new WaitForSeconds(0.15f);
wait = false;
}
public static void Switch()
{
isLerp = true;
isOpenPanel = !isOpenPanel;
isFirstTime = true;
}
public void OpenPanel()
{
Switch();
}
}