using UnityEngine;

namespace WS
{
    ///<summary>视图</summary>
    public abstract class View : WSComponent
    {
        ///<summary>UIObj</summary>
        public GameObject UIGameObject;
        ///<summary>窗体类型</summary>
        public ViewGroup Group = ViewGroup.From;
        ///<summary>窗体显示位置类型</summary>
        public ViewShowModeType ShowModeType = ViewShowModeType.Screen;
        ///<summary>窗体状态</summary>
        public ViewShowType ShowType = ViewShowType.Close;
        ///<summary>动画</summary>
        public AnimationComponent AnimComponent;

        ///<summary>View对象被创建,UIGameObject被创建;还没有在Canvas渲染(作为数据、UI初始化操作)</summary>
        public abstract void LoadInit();

        ///<summary>设置显示位置</summary>
        public virtual void SetPosition() { }

        ///<summary>设置显示位置</summary>
        public virtual void SetPosition(Vector3 pos, Quaternion rot)
        {
#if PLATFORM_PICO
            if (ShowModeType != ViewShowModeType.Screen)
            {
                UIGameObject.transform.parent.position = pos;
                UIGameObject.transform.parent.rotation = rot;
                return;
            }
#endif
            UIGameObject.transform.localPosition = pos;
            UIGameObject.transform.localRotation = rot;
        }

        ///<summary>打开View(在Canvas上渲染、或者是UI动画播放完成)</summary>
        public virtual void OnOpen() { }

        public override void Dispose()
        {
            base.Dispose();
            UIGameObject = null;
            Group = ViewGroup.From;
            ShowType = ViewShowType.Close;
            ShowModeType = ViewShowModeType.Screen;
        }
    }
}