Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DestroyAll
        /// # Destroy all destroyable objects given baseName (optional)
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void DestroyAll(bool byBaseName, string baseName)
        {
            foreach (Object destroyable in GameObject.FindObjectsOfType(typeof(GenericDestroyable)))
            {
                GenericDestroyable actualDestroyable = destroyable as GenericDestroyable;

                bool validDestroyable = true;

                if (byBaseName && (actualDestroyable.GetBaseName() != baseName))
                {
                    //Debug.Log ("Invalid base name: " + actualDestroyable.GetBaseName () + ", need to be " + baseName);
                    validDestroyable = false;
                }

                if (validDestroyable)
                {
                    Object.DestroyImmediate(actualDestroyable.gameObject, true);
                }
            }
        }
Beispiel #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DestroyLast
        /// # Destroy last object in scene given seed and basename (optional)
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void DestroyLast(string seed, bool byBaseName, string baseName)
        {
            int maxIndex = -1;

            GenericDestroyable destroyableToDelete = null;

            foreach (Object destroyable in GameObject.FindObjectsOfType(typeof(GenericDestroyable)))
            {
                GenericDestroyable actualDestroyable = destroyable as GenericDestroyable;

                bool validDestroyable = true;

                if (actualDestroyable.GetSeed() != seed)
                {
                    validDestroyable = false;
                }

                if (byBaseName && (actualDestroyable.GetBaseName() != baseName))
                {
                    validDestroyable = false;
                }

                if (validDestroyable)
                {
                    if (actualDestroyable.GetIndex() > maxIndex)
                    {
                        maxIndex            = actualDestroyable.GetIndex();
                        destroyableToDelete = actualDestroyable;
                    }
                }
            }

            if (destroyableToDelete)
            {
                Object.DestroyImmediate(destroyableToDelete.gameObject, true);
            }
        }