Пример #1
0
        public static void AssignConfigObject(ConfigFieldInfo field, ConfigNode value, ref IConfigNode result)
        {
            if (!field.ElementType.DerivesFrom(typeof(IConfigNode)))
            {
                throw new ArgumentException("Element type of field " + field.Name + " does not derive from IConfigNode");
            }

            if (result == null)
            {
                if (field.ElementType.DerivesFrom(typeof(Component)) && field.Parent is Component)
                {
                    result = (field.Parent as Component).gameObject.AddComponent(field.ElementType) as IConfigNode;
                }
                else if (field.ElementType.DerivesFrom(typeof(ScriptableObject)))
                {
                    result = ScriptableObject.CreateInstance(field.ElementType) as IConfigNode;
                }
                else
                {
                    try
                    {
                        result = (IConfigNode)Activator.CreateInstance(field.ElementType);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Error: Could not load field '" + field.Name + "' because an instance of " + field.ElementType.FullName + "could not be created: " + e.Message);
                        return;
                    }
                }
            }

            result.Load(value);
        }
Пример #2
0
        public object Clone()
        {
            IConfigNode obj = (IConfigNode)Activator.CreateInstance(this.GetType());

            ConfigNode node = new ConfigNode();

            SerializeToNode(node);
            obj.Load(node);

            return(obj);
        }