コード例 #1
0
        /// <summary>Destroy the Unity Object at the given key and remove it from the dictionary,
        /// optionally destroying the associated GameObject (if there is one).</summary>
        public static void Destroy <T, U>(this IDictionary <T, U> collection, T key, bool destroyGameObject = true)
            where U : UnityEngine.Object
        {
            UnityEngine.Object o = collection.GetOrNull(key);

            if (!o)
            {
                Debug.LogWarning("Key not found in IDictionary.Destroy()");
                return;
            }

            collection.Remove(key);
            if (destroyGameObject)
            {
                o.DestroyGameObject();
            }
            else
            {
                UnityEngine.Object.Destroy(o);
            }
        }