protected virtual void SpawnElement(IObjectDescription objectDescription) { ObjectSelectionElement element = Instantiate(elementPrefab); element.transform.SetParent(layoutParent); element.Initialize(this, objectDescription); }
/// <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; } }
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); }
public ObjectBuilderContext(IObjectService objectService, IObjectBuilder objectBuilder, IObjectDescription objectDescription, IDictionary items = null) : base(items) { this.ObjectService = objectService; this.ObjectBuilder = objectBuilder; this.ObjectDescription = objectDescription; }
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; }
public void SelectObject(IObjectDescription obj) { Callback(obj); Destroy(gameObject); }
void IObjectContainer.Init(IObjectDescription objectDescription, IObjectBuilder objectBuilder) { this.Init(objectDescription, objectBuilder); }
protected virtual void Init(IObjectDescription objectDescription, IObjectBuilder objectBuilder) { this.ObjectDescription = objectDescription; this.ObjectBuilder = objectBuilder; }
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); }