예제 #1
0
        private T InternalCreateUnit <T>(T prefabComponent) where T : PUnit
        {
            if (prefabComponent == null)
            {
                Debug.LogErrorFormat("Cannot create unit of null {0}", nameof(prefabComponent));
                return(null);
            }

            var unitGO = PUnitPool.FetchCachedOrCreateUnit(prefabComponent.gameObject);

            if (unitGO == null)
            {
                Debug.LogErrorFormat("Unexpected error while creating {0}", nameof(unitGO));
                return(null);
            }

            var unitComponent = GetCacheableUnitComponent <T>(unitGO);

            if (unitComponent == null)
            {
                Debug.LogErrorFormat("Unexpected error while getting {0}", nameof(unitComponent));
                PUnitPool.DestroyUnit(unitGO);
                return(null);
            }

            unitComponent.OnInit();

            return(unitComponent);
        }
예제 #2
0
        private GameObject InternalCreateUnit(GameObject prefabGO)
        {
            if (prefabGO == null)
            {
                Debug.LogErrorFormat("Cannot create unit of null {0}", nameof(prefabGO));
                return(null);
            }

            var unitGO = PUnitPool.FetchCachedOrCreateUnit(prefabGO);

            if (unitGO == null)
            {
                return(null);
            }

            var unit = GetCacheableUnitComponent <PUnit>(unitGO);

            if (unit != null)
            {
                unit.OnInit();
            }

            return(unitGO);
        }