Beispiel #1
0
    protected virtual void SpawnElement(IObjectDescription objectDescription)
    {
        ObjectSelectionElement element = Instantiate(elementPrefab);

        element.transform.SetParent(layoutParent);

        element.Initialize(this, objectDescription);
    }
Beispiel #2
0
 /// <summary>
 /// Add a description for a given class name (or ID)
 /// </summary>
 /// <param name="clsName"></param>
 /// <param name="description"></param>
 internal void AddDescription(string clsName, IObjectDescription description)
 {
     lock (m_descriptions)
     {
         if (m_descriptions.ContainsKey(clsName))
         {
             this.Log().Warn("Description already registered for class '{0}'", clsName);
         }
         else
         {
             m_descriptions[clsName] = description;
         }
     }
 }
    public void Initialize(IObjectSelectionPanel owner, IObjectDescription obj)
    {
        Owner  = owner;
        Object = obj;

        if (obj != null)
        {
            titleTextElement.text       = obj.Name;
            descriptionTextElement.text = obj.Description;
        }
        else
        {
            titleTextElement.text       = "None";
            descriptionTextElement.text = string.Empty;
        }
    }
Beispiel #4
0
        protected virtual object CreateObject(IObjectDescription objectDescription, IDictionary items, params object[] args)
        {
            var ctx = new ObjectBuilderContext(this.ObjectService, this, objectDescription, items);

            this.OnObjectCreating(ctx);
            var instance = ctx.ObjectInstance;

            if (instance != null)
            {
                return(instance);
            }
            this.CreateObjectInternal(ctx, args);

            this.OnObjectCreated(ctx);
            instance = ctx.ObjectInstance;
            return(instance);
        }
Beispiel #5
0
 public ObjectBuilderContext(IObjectService objectService, IObjectBuilder objectBuilder, IObjectDescription objectDescription, IDictionary items = null) : base(items)
 {
     this.ObjectService     = objectService;
     this.ObjectBuilder     = objectBuilder;
     this.ObjectDescription = objectDescription;
 }
Beispiel #6
0
            public ConfigurationValue(string name, ConfigurationValueType type, object defaultValue, IObjectDescription description, List <IObjectDescription> options = null, UserObjectType subType = UserObjectType.None)
            {
                DisplayName         = name;
                Type                = type;
                Description         = description.Description;
                DetailedDescription = description.DetailedDescription;
                Options             = options;
                Subtype             = subType;
                object verifiedDefault;

                if (!Validate(defaultValue, out verifiedDefault))
                {
                    throw new ArgumentException("Default value is not acceptable for this type.");
                }
                DefaultValue = verifiedDefault;
            }
 public ConfigurationValue(string name, ConfigurationValueType type, object defaultValue, IObjectDescription description, List<IObjectDescription> options = null, UserObjectType subType = UserObjectType.None)
 {
     DisplayName = name;
     Type = type;
     Description = description.Description;
     DetailedDescription = description.DetailedDescription;
     Options = options;
     Subtype = subType;
     object verifiedDefault;
     if (!Validate(defaultValue, out verifiedDefault))
         throw new ArgumentException("Default value is not acceptable for this type.");
     DefaultValue = verifiedDefault;
 }
Beispiel #8
0
    public void SelectObject(IObjectDescription obj)
    {
        Callback(obj);

        Destroy(gameObject);
    }
Beispiel #9
0
 void IObjectContainer.Init(IObjectDescription objectDescription, IObjectBuilder objectBuilder)
 {
     this.Init(objectDescription, objectBuilder);
 }
Beispiel #10
0
 protected virtual void Init(IObjectDescription objectDescription, IObjectBuilder objectBuilder)
 {
     this.ObjectDescription = objectDescription;
     this.ObjectBuilder     = objectBuilder;
 }
Beispiel #11
0
        public static object BuildObject(IObjectService objectService, IObjectDescription description, IDictionary items, params object[] args)
        {
            if (description == null)
            {
                return(null);
            }
            var objectType = description.ObjectType;

            if (objectType.IsInterface)
            {
                throw new Exception("无法创建接口的实例");
            }
            object instance = null;

            if (args != null && args.Length > 0)
            {
                instance = TypeHelper.CreateObject(objectType, null, true, args);
            }
            if (instance == null)
            {
                var parameters = description.ConstructorParameters;
                if (parameters != null)
                {
                    var length = parameters.Length;
                    if (length > 0)
                    {
                        var types  = new Type[length];
                        var values = new object[length];
                        for (var i = 0; i < parameters.Length; i++)
                        {
                            var parameter = parameters[i];
                            types[i]  = parameter.Type;
                            values[i] = GetValueFromValueDescription(parameter, objectService);
                        }
                        instance = TypeHelper.CreateObject(objectType, null, true, types, values);
                    }
                }
            }
            if (instance == null)
            {
                instance = TypeHelper.CreateObject(objectType, null, true);
            }
            //尝试进行属性注入
            var properties = description.Properties;

            if (instance != null && properties != null && properties.Length > 0)
            {
                foreach (var property in properties)
                {
                    var name  = property.Name;
                    var value = GetValueFromValueDescription(property, objectService);
                    if (value == null && property.ValueRequired)
                    {
                        throw new Exception($"value of {description.ObjectType}.{property.Name} cannot be resolved.");
                    }
                    if (instance is IPropertyDescriptor descriptor)
                    {
                        descriptor.SetValue(name, value);
                    }
                    else
                    {
                        TypeHelper.SetPropertyValue(instance, name, value);
                    }
                }
            }
            return(instance);
        }