コード例 #1
0
        private static object CopyClass(ScriptableObject owner, object original)
        {
            Type   type = original.GetType();
            object copy = Activator.CreateInstance(type, true);

            foreach (FieldInfo info in TypeUtility.GetFields(type))
            {
                if (info.IsLiteral)
                {
                    continue;
                }

                info.SetValue(copy, CopyObject(owner, info.GetValue(original)));
            }

            return(copy);
        }
コード例 #2
0
        /// <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 ComponentMonoBehaviour)
                {
                    ComponentMonoBehaviour component = value as ComponentMonoBehaviour;

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

            DestroyImmediate(this, true);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        private static ScriptableComponent CopyComponent(ScriptableObject owner, ScriptableComponent original)
        {
            Type type = original.GetType();
            ScriptableComponent copy = original.Instantiate();

            foreach (FieldInfo info in TypeUtility.GetFields(type))
            {
                if (info.IsLiteral)
                {
                    continue;
                }

                info.SetValue(copy, CopyObject(copy, info.GetValue(original)));
            }

            copy.Owner = owner;

            return(copy);
        }