Пример #1
0
        private static void Validate(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            UnityEngine.Object[] components = AssetDatabase.LoadAllAssetsAtPath(path);
            for (int i = components.Length - 1; i >= 0; i--)
            {
                ScriptableComponent component = components[i] as ScriptableComponent;
                if (component == null)
                {
                    continue;
                }

                tested.Clear();
                component.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;

                if (component.Owner == null || !component.Owner || !Referenced(component.Owner, component))
                {
                    Debug.Log("Destroying " + components[i].ToString() + " because it is orphant.");
                    component.Erase();
                    continue;
                }
            }
        }
        /// <summary>
        /// Called when the inspector is about to destroy this one.
        /// Loop in all the internal and destroy sub-components.
        /// </summary>
        public void Erase()
        {
            foreach (FieldInfo info in TypeUtility.GetFields(GetType()))
            {
                object value = info.GetValue(this);

                if (value is ScriptableComponent)
                {
                    ScriptableComponent component = value as ScriptableComponent;

                    if (component.Owner == Owner)
                    {
                        component.Erase();
                    }
                }
            }

            DestroyImmediate(this, true);
        }