示例#1
0
        public GameObject Spawn(string name)
        {
            DevilObjectData data = GetDataByName(name);
            GameObject      go   = null;

            if (!_preloadedObjects.ContainsKey(name))
            {
                Log.Error(MessageGroup.Common, "This pool doesn't preload " + name + " objects.");
                return(null);
            }
            if (_preloadedObjects[name].Count > 0)
            {
                go = _preloadedObjects[name][0];
                _preloadedObjects[name].RemoveAt(0);
            }
            if (_instanceCount[name] >= data.MaximumInstances - 1 || go == null)
            {
                Log.Warning(MessageGroup.Common, "This game object ( " + name + " )reached maximum number of instances in that pool ( " + _poolName + ")");
                go = InstantiatePrefab(data.Prefab);
            }
            if (go == null)
            {
                Log.Error(MessageGroup.Common, "Something went wrong in spawn function and game object is null");
                return(null);
            }
            ++_instanceCount[name];
            go.SetActive(true);
            _spawnedObjects.Add(go, name);
            return(go);
        }
示例#2
0
        private void PreloadInstances(DevilObjectData data)
        {
            if (data == null)
            {
                Log.Error(MessageGroup.Common, "Given DevilObjectData with is null, in pool named: " + _poolName);
                return;
            }
            GameObject prefab = data.Prefab;

            if (prefab == null)
            {
                Log.Error(MessageGroup.Common, "Couldn't get prefab from DevilObjectData with that name ( " + data.PrefabName + " ) in pool named: " + _poolName);
                return;
            }
            int preloadedInstances = data.PreloadedInstances;

            if (!_preloadedObjects.ContainsKey(data.PrefabName))
            {
                _preloadedObjects.Add(data.PrefabName, new List <GameObject>());
            }
            if (_instanceCount.ContainsKey(data.PrefabName) == false)
            {
                _instanceCount.Add(data.PrefabName, 0);
            }
            for (int i = 0, c = preloadedInstances; i < c; ++i)
            {
                prefab = InstantiatePrefab(prefab);
                _preloadedObjects[data.PrefabName].Add(prefab);
            }
        }
示例#3
0
        private GameObject GetPrefabByName(string name)
        {
            DevilObjectData data = GetDataByName(name);

            if (data == null)
            {
                Log.Error(MessageGroup.Common, "Can't return prefab because data is null");
                return(null);
            }
            if (data.Prefab == null)
            {
                Log.Error(MessageGroup.Common, "Can't return prefab because prefab in data is null");
                return(null);
            }
            return(data.Prefab);
        }