1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Game.UI
{
    public class UIItemWidget : MonoBehaviour
    {
        ResourceSet mResources;
        bool mHasDestroy = false;
        public bool hasDestroy { get { return mHasDestroy; } }

        public virtual ResourceSet resources
        {
            get
            {
                if (mResources == null)
                {
                    mResources = new ResourceSet();
                }
                return mResources;
            }
        }

        //public bool hasDestroy { get { return resources.hasDestroy; } }

        //protected virtual void Awake()
        //{
        //}
        protected virtual void OnDestroy()
        {
            if(mResources!=null)
                mResources.Destroy();
            mHasDestroy = true;
            //Debug.Log(ToString() + ".OnDestroy()");
        }
        public virtual void Destroy()
        {
            if (mResources != null)
                mResources.Destroy();
            mHasDestroy = true;
        }
        public void ClearInstanceAndResource()
        {
            if (mResources != null)
                mResources.ClearAllInstanceAndResource();
        }

        //protected void _RegResource( string _path , BaseLoadInfo resObj)
        //{
        //    resources._RegResource(_path ,resObj);
        //}

        //protected void _RegInstance(UnityEngine.Object instObj)
        //{
        //    resources._RegInstance(instObj);
        //}

        public void DeleteResource(ResourceSet.ResourceInfo resObj)
        {
            resources.DeleteResource(resObj);
        }

        public bool DeleteInstance(UnityEngine.Object instObj, bool immedia = false)
        {
            return resources.DeleteInstance(instObj,immedia);
        }

        /// <summary>
        /// 添加一个界面图集
        /// </summary>
        /// <param name="atlas">图集名</param>
        /// <param name="img">图素名</param>
        /// <param name="obj">控件对象</param>

        public ResourceSet.ResourceInfo AddResourceEx(string res)
        {
            return resources.AddResourceEx(res);
        }
        public UnityEngine.Object AddResource(string res)
        {
            return resources.AddResource(res);
        }
        public void AddResourceAsync(string res, ResourceSet.OnLoadResEnd onLoadEnd)
        {
            resources.AddResourceAsync(res, onLoadEnd);
        }
        public UnityEngine.Object AddInstance(string widgetName)
        {
            return resources.AddInstance(widgetName);
        }
        public BaseLoadInfo AddInstanceAsync(string widgetName, ResourceSet.OnObjectLoadEnd onLoadEnd)
        {
            return resources.AddInstanceAsync(widgetName, onLoadEnd);
        }
        public GameObject CreateGameObject(string name, Transform parent)
        {
            return resources.AddGameInstanceAsSubObject(name, parent);
        }
        public GameObject AddGameInstance(string name, Transform parent)
        {
            return resources.AddGameInstanceAsSubObject(name, parent);
        }
        public BaseLoadInfo AddGameInstanceAsync(string name, Transform parent, ResourceSet.OnGameObjectLoadEnd onLoadEnd)
        {
            return resources.AddGameInstanceAsSubObjectAsync(name, parent, onLoadEnd);
        }

        public void DestroyTrans(Transform tran,bool immedia=false)
        {
            if (null == tran)
            {
                return;
            }
            for (int i = tran.childCount - 1; i >= 0; i--)
            {
                DeleteInstance(tran.GetChild(i).gameObject,immedia);
            }
        }
    }
}

posted @ 2017-08-03 11:59  rexzhao  阅读(98)  评论(0编辑  收藏  举报