Beispiel #1
0
        public static void CreateOnGameObject(GameObject _go, mg_GameObjectPool _managingPool)
        {
            Assert.NotNull(_managingPool, "Pooled objects must belong to a pool");
            mg_jr_Pooled mg_jr_Pooled2 = _go.AddComponent <mg_jr_Pooled>();

            mg_jr_Pooled2.ManagingPool            = _managingPool;
            mg_jr_Pooled2.IntentionallyDestroying = false;
        }
 protected void LoadPooledResource(string _resourcePath, mg_jr_ResourceList _assetTag, mg_ICreator <GameObject> _creator)
 {
     if (!m_pooledResources.ContainsKey(_assetTag))
     {
         LoadResource(_resourcePath, _assetTag);
         GameObject        gameObject         = new GameObject("mg_jr_Pool_" + _assetTag);
         mg_GameObjectPool mg_GameObjectPool2 = gameObject.AddComponent <mg_GameObjectPool>();
         mg_GameObjectPool2.Init(_creator);
         gameObject.transform.parent = ResourceContainer.transform;
         m_pooledResources.Add(_assetTag, mg_GameObjectPool2);
     }
     else
     {
         DisneyMobile.CoreUnitySystems.Logger.LogWarning(this, "LoadPooledResource: Attempting to register same resource twice");
     }
 }
        public GameObject GetPooledResource(mg_jr_ResourceList _assetTag)
        {
            GameObject gameObject = null;

            if (m_pooledResources.ContainsKey(_assetTag))
            {
                mg_GameObjectPool mg_GameObjectPool2 = m_pooledResources[_assetTag];
                gameObject = mg_GameObjectPool2.Fetch();
            }
            else
            {
                gameObject = GetInstancedResource(_assetTag);
            }
            if (gameObject == null)
            {
                gameObject = new GameObject("ErrorObject-MissingResource-" + _assetTag);
                DisneyMobile.CoreUnitySystems.Logger.LogWarning(this, "ErrorObject-MissingResource-" + _assetTag);
            }
            return(gameObject);
        }
        public void ReturnPooledResource(GameObject _instancedResource)
        {
            mg_jr_Pooled component = _instancedResource.GetComponent <mg_jr_Pooled>();

            if (component != null)
            {
                mg_GameObjectPool mg_GameObjectPool2 = null;
                foreach (mg_GameObjectPool value in m_pooledResources.Values)
                {
                    if (value == component.ManagingPool)
                    {
                        mg_GameObjectPool2 = value;
                        break;
                    }
                }
                Assert.NotNull(mg_GameObjectPool2, "Returning resource to a pool that doesn't exist.");
                mg_GameObjectPool2.Return(_instancedResource);
            }
            else
            {
                _instancedResource.transform.parent = null;
                Object.Destroy(_instancedResource);
            }
        }