/// <summary>
        /// 创建一个单位
        /// </summary>
        /// <param name="id">唯一id</param>
        /// <param name="type">类型</param>
        /// <param name="assetid">资源id</param>
        /// <param name="onCreated">加载完回调</param>
        /// <param name="isSync">是否是同步加载</param>
        /// <returns></returns>
        public T CreateUnit <T>(long id, UnitType type, string assetid,
                                Action <UnitEntityBase> bandAct,
                                Action <UnitEntityBase> onCreated,
                                bool isSync = false)
            where T : UnitEntityBase, new()
        {
            UnitEntityBase unit;

            if (TryGetUnitByGuid(id, type, out unit))
            {
#if UNITY_EDITOR
                Debug.LogError("已创建了此角色id:");
#endif
                return(unit as T);
            }

            unit = GetUnit <T>();
            bandAct?.Invoke(unit);
            unit.m_type = type;
            if (type == UnitType.MainUnit)
            {
                mainUnit = unit;
            }

            activeUnits[type].Add(id, unit);
            unit.Init(id, assetid, onCreated, isSync);

            return(unit as T);
        }
 public bool TryGetUnitByGuid(long guid, out UnitEntityBase unit)
 {
     foreach (var item in activeUnits.Values)
     {
         if (item.ContainsKey(guid))
         {
             unit = item[guid];
             return(true);
         }
     }
     unit = null;
     return(false);
 }
        public bool TryGetUnitByGuid(long guid, UnitType type, out UnitEntityBase unit)
        {
            var unitDic = activeUnits[type];

            if (unitDic.ContainsKey(guid))
            {
                unit = unitDic[guid];
                return(true);
            }

            unit = null;
            return(false);
        }
        public bool TryGetUnitByGuid(long guid, UnitType type, out UnitEntityBase unit)
        {
            //var unitDic = m_dicActiveUnit[type];

            //if (unitDic.ContainsKey(guid))
            //{
            //    unit = unitDic[guid];
            //    return true;
            //}

            unit = null;
            return(false);
        }
 public bool TryGetUnitByGuid(long guid, out UnitEntityBase unit)
 {
     //foreach (var item in activeUnits.Values)
     //{
     //    if (item.ContainsKey(guid))
     //    {
     //        unit = item[guid];
     //        return true;
     //    }
     //}
     unit = null;
     return(false);
 }
        public T CreateUnit <T>(UnitType type, string assetid, Action <UnitEntityBase> onCreated,
                                Action <UnitEntityBase> bandAction, bool isSync = false) where T : UnitEntityBase, new()
        {
            UnitEntityBase unit;

            unit = GetUnit <T>();
            bandAction?.Invoke(unit);
            unit.m_type = type;

            if (type == UnitType.MainUnit)
            {
                mainUnit = unit;
            }

            activeUnits[type].Add(unit);
            //unit.Init(id, assetid, onCreated, isSync);

            return(unit as T);
        }
        //从池中获取一个指定类型的对象
        internal static T GetComponent <T>(UnitEntityBase role) where T : UnitComponentBase, new()
        {
            Type type = typeof(T);

            if (!s_pool.ContainsKey(type))
            {
                s_pool.Add(type, new Stack <UnitComponentBase>());
            }
            T com;

            if (s_pool[type].Count > 0)
            {
                com = s_pool[type].Pop() as T;
            }
            else
            {
                com = new T();
            }
            com.ResetRole(role);
            com.m_isRecover = false;

            return(com);
        }
        public void RecoverUnit(UnitEntityBase obj)
        {
            Type type = obj.GetType();

            m_dicPool[type].Push(obj);
        }
 public void RemoveUnit(UnitEntityBase obj)
 {
 }
        //public YuTransforem

        private void ResetRole(UnitEntityBase role)
        {
            m_role = role;
        }
 private void AddUnitToActiveUnitDic(UnitEntityBase a)
 {
 }