Exemplo n.º 1
0
        // ----------------------------------------------------------------------------------------------------
        #endregion

        #region Spawning Methods
        // ----------------------------------------------------------------------------------------------------
        /// <summary>
        /// Spawns a new instance.
        /// </summary>
        public GameObject Spawn(Vector3 position, Quaternion rotation, Vector3 scale)
        {
            // Fetch next available instance
            FeatherPoolInstance poolInstance = NextAvailableInstance;

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

            // Signal if implementing
            poolInstance.InvokeOnSpawning();

            // Set Transform
            poolInstance.SetPosition(position);
            poolInstance.SetRotation(rotation);
            poolInstance.SetScale(scale);

            // Signal if implementing
            poolInstance.InvokeResettable();

            // Signal if implementing
            poolInstance.InvokeOnSpawned();

            // Activate instance
            poolInstance.SetActive();

            // Return instance
            return(poolInstance.PrefabInstance);
        }
Exemplo n.º 2
0
        // ----------------------------------------------------------------------------------------------------
        #endregion

        #region Despawn Methods
        // ----------------------------------------------------------------------------------------------------
        /// <summary>
        /// Despawns and returns an instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        public void Despawn(FeatherPoolInstance instance)
        {
            // Check if object already despwned
            if (!this.activeInstances.Contains(instance))
            {
                return;
            }

            // Remove instance from active instances and makes it available
            this.activeInstances.Remove(instance);
            this.availableInstances.Push(instance);

            // Signal if implementing
            instance.InvokeOnDespawning();

            // Reset Object
            instance.PrefabInstance.SetActive(false);
            instance.PrefabInstance.transform.SetParent(this.transform);
            instance.ResetTransform();

            // Signal if implementing
            instance.InvokeOnDespawning();

#if UNITY_EDITOR
            UpdateProgressBar();
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tries the get a FeatherPoolInstance containing the GameObject.
        /// </summary>
        /// <param name="pooledObject">The game object.</param>
        /// <returns>FeatherPoolInstance.</returns>
        private FeatherPoolInstance TryGetInstance(GameObject pooledObject)
        {
            FeatherPoolInstance instance = null;

            this.instanceDictionary.TryGetValue(pooledObject.GetInstanceID(), out instance);
            return(instance);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tries the get a FeatherPoolInstance containing the GameObject.
        /// </summary>
        /// <param name="pooledObjectID">The game object.</param>
        /// <returns>FeatherPoolInstance.</returns>
        private FeatherPoolInstance TryGetInstance(int pooledObjectID)
        {
            FeatherPoolInstance instance = null;

            this.instanceDictionary.TryGetValue(pooledObjectID, out instance);
            return(instance);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines whether the specified game object is available.
        /// </summary>
        /// <param name="pooledObject">The game object.</param>
        /// <returns><c>true</c> if the specified game object is available; otherwise, <c>false</c>.</returns>
        public bool IsAvailable(GameObject pooledObject)
        {
            FeatherPoolInstance instance = TryGetInstance(pooledObject);

            if (instance != null)
            {
                return(this.availableInstances.Contains(instance));
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines whether the specified game object is active.
        /// </summary>
        /// <param name="pooledObjectID">The game object.</param>
        /// <returns><c>true</c> if the specified game object is active; otherwise, <c>false</c>.</returns>
        public bool IsActive(int pooledObjectID)
        {
            FeatherPoolInstance instance = TryGetInstance(pooledObjectID);

            if (instance != null)
            {
                return(this.activeInstances.Contains(instance));
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Despawns and returns an instance.
        /// </summary>
        /// <param name="pooledObject">The gameObject.</param>
        public void Despawn(GameObject pooledObject)
        {
            FeatherPoolInstance instance = TryGetInstance(pooledObject);

            if (instance != null)
            {
                this.Despawn(instance);
            }
            else
            {
                Debug.LogError("[FeatherPool] Tried despawning object <b>" + gameObject.name + "</b>, but object not part of this pool.");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Adds a new instance.
        /// </summary>
        /// <param name="newInstance">The new instance.</param>
        private void AddNewInstance(GameObject newInstance)
        {
            Transform instanceTransform = newInstance.transform;

            instanceTransform.name = PrefabObject.name;
            instanceTransform.SetParent(this.transform);
            newInstance.SetActive(false);

            FeatherPoolInstance newItemInstance = new FeatherPoolInstance(newInstance);

            availableInstances.Push(newItemInstance);

            instanceDictionary.Add(newInstance.GetInstanceID(), newItemInstance);
        }