92 lines
2.3 KiB
C#
92 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AbstractPopUI : MonoBehaviour
|
|
{
|
|
private Camera mainCamera;
|
|
public RectTransform rectTransform;
|
|
[Header("偏移")]
|
|
public Vector3 offset = Vector3.zero;
|
|
//[Header("缩放")]
|
|
//public Vector3 scale = Vector3.zero;
|
|
|
|
private IDevice device;
|
|
private void Start()
|
|
{
|
|
mainCamera = Camera.main; // 获取主摄像机
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
// 使UI始终朝向摄像机
|
|
Vector3 directionToCamera = mainCamera.transform.position - transform.position;
|
|
Quaternion rotation = Quaternion.LookRotation(directionToCamera, mainCamera.transform.up);
|
|
Vector3 quaternion = new Vector3(0, rotation.eulerAngles.y +180, 0);
|
|
transform.rotation = Quaternion.Euler(quaternion);
|
|
|
|
}
|
|
public void Open(IDevice device,bool open)
|
|
{
|
|
if (open)
|
|
{
|
|
Open(device);
|
|
}
|
|
else
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
public void Open(ContainerEntity container, Transform transform, bool open)
|
|
{
|
|
if (open)
|
|
{
|
|
Open(container, transform);
|
|
}
|
|
else
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
public virtual void Open(IDevice device)
|
|
{
|
|
List<AbstractPopUI> popUIs = ApplicationBoot.Instance.GetBeans<AbstractPopUI>();
|
|
foreach(var item in popUIs)
|
|
{
|
|
item.Close();
|
|
}
|
|
this.device = device;
|
|
if (rectTransform == null)
|
|
{
|
|
rectTransform = transform.GetComponentInParent<RectTransform>();
|
|
}
|
|
}
|
|
public virtual void Open(ContainerEntity container,Transform transform)
|
|
{
|
|
List<AbstractPopUI> popUIs = ApplicationBoot.Instance.GetBeans<AbstractPopUI>();
|
|
foreach (var item in popUIs)
|
|
{
|
|
item.Close();
|
|
}
|
|
if (rectTransform == null)
|
|
{
|
|
rectTransform = transform.GetComponentInParent<RectTransform>();
|
|
}
|
|
}
|
|
public void Close()
|
|
{
|
|
gameObject.SetActive(false);
|
|
if (device != null)
|
|
{
|
|
device.DataChange -= DataChanageHandle;
|
|
}
|
|
|
|
}
|
|
public virtual void DataChanageHandle(object data,object other)
|
|
{
|
|
|
|
}
|
|
|
|
}
|