示例#1
0
        public GameObject Spawn(string sname, Transform par = null, System.Action <GameObject> initializeProperties = null, ISpawner optionalSpawnPoint = null)
        {
            //var cache = (from o in _registeredPrefabs where o.ItemName == sname select o).FirstOrDefault();
            PrefabCacheOptions cache = null;
            var e = _registeredPrefabs.GetEnumerator();

            while (e.MoveNext())
            {
                if (e.Current.ItemName == sname)
                {
                    cache = e.Current;
                    break;
                }
            }
            if (cache == null)
            {
                return(null);
            }

            var pos = (par != null) ? par.position : Vector3.zero;
            var rot = (par != null) ? par.rotation : Quaternion.identity;
            var obj = cache.Spawn(pos, rot, par, initializeProperties);

            this.SignalSpawned(obj, optionalSpawnPoint);
            return(obj.gameObject);
        }
示例#2
0
        public PrefabCacheOptions Register(GameObject prefab, string sname, int cacheSize = 0, int resizeBuffer = 1, int limitAmount = 1)
        {
            if (object.ReferenceEquals(prefab, null))
            {
                throw new System.ArgumentNullException("prefab");
            }
            if (_prefabToCache.ContainsKey(prefab))
            {
                throw new System.ArgumentException("Already manages prefab.", "prefab");
            }

            var options = new PrefabCacheOptions(prefab)
            {
                ItemName     = sname,
                CacheSize    = cacheSize,
                ResizeBuffer = resizeBuffer,
                LimitAmount  = limitAmount
            };

            _registeredPrefabs.Add(options);
            _prefabToCache[prefab] = options;
            return(options);
        }