private static void registerCustomizedProperty(AgentMeta meta, string propName, string typeName, string valueStr, bool isStatic) { typeName = typeName.Replace("::", "."); uint nameId = Utils.MakeVariableId(propName); IProperty prop = meta.GetProperty(nameId); ICustomizedProperty newProp = AgentMeta.CreateCustomizedProperty(typeName, nameId, propName, valueStr); if (prop != null && newProp != null) { object newValue = newProp.GetValueObject(null); object value = prop.GetValueObject(null); if (newValue != null && value != null && newValue.GetType() == value.GetType()) { return; } string errorInfo = string.Format("The type of '{0}' has been modified to {1}, which would bring the unpredictable consequences.", propName, typeName); Debug.LogWarning(errorInfo); Debug.Check(false, errorInfo); } if (isStatic) { meta.RegisterStaticCustomizedProperty(nameId, newProp); } else { meta.RegisterCustomizedProperty(nameId, newProp); } Type type = AgentMeta.GetTypeFromName(typeName); if (Utils.IsArrayType(type)) { // Get item type, i.e. vector<int> int kStartIndex = "vector<".Length; typeName = typeName.Substring(kStartIndex, typeName.Length - kStartIndex - 1); // item type ICustomizedProperty arrayItemProp = AgentMeta.CreateCustomizedArrayItemProperty(typeName, nameId, propName); nameId = Utils.MakeVariableId(propName + "[]"); if (isStatic) { meta.RegisterStaticCustomizedProperty(nameId, arrayItemProp); } else { meta.RegisterCustomizedProperty(nameId, arrayItemProp); } } }
public Dictionary <uint, IInstantiatedVariable> InstantiateCustomizedProperties() { Dictionary <uint, IInstantiatedVariable> vars = new Dictionary <uint, IInstantiatedVariable>(); //instance customzied properties { var e = this._customizedProperties.Keys.GetEnumerator(); while (e.MoveNext()) { uint id = e.Current; ICustomizedProperty pCustomProperty = this._customizedProperties[id]; vars[id] = pCustomProperty.Instantiate(); } } if (_customizedStaticVars == null) { _customizedStaticVars = new Dictionary <uint, IInstantiatedVariable>(); var e = this._customizedStaticProperties.Keys.GetEnumerator(); while (e.MoveNext()) { uint id = e.Current; ICustomizedProperty pCustomProperty = this._customizedStaticProperties[id]; this._customizedStaticVars[id] = pCustomProperty.Instantiate(); } } //static customzied properties { var e = this._customizedStaticVars.Keys.GetEnumerator(); while (e.MoveNext()) { uint id = e.Current; IInstantiatedVariable pVar = this._customizedStaticVars[id]; vars[id] = pVar; } } return(vars); }
private static void registerCustomizedProperty(AgentMeta meta, string propName, string typeName, string valueStr, bool isStatic) { typeName = typeName.Replace("::", "."); uint nameId = Utils.MakeVariableId(propName); ICustomizedProperty prop = AgentMeta.CreateCustomizedProperty(typeName, nameId, propName, valueStr); if (isStatic) { meta.RegisterStaticCustomizedProperty(nameId, prop); } else { meta.RegisterCustomizedProperty(nameId, prop); } Type type = AgentMeta.GetTypeFromName(typeName); if (Utils.IsArrayType(type)) { // Get item type, i.e. vector<int> int kStartIndex = "vector<".Length; typeName = typeName.Substring(kStartIndex, typeName.Length - kStartIndex - 1); // item type ICustomizedProperty arrayItemProp = AgentMeta.CreateCustomizedArrayItemProperty(typeName, nameId, propName); nameId = Utils.MakeVariableId(propName + "[]"); if (isStatic) { meta.RegisterStaticCustomizedProperty(nameId, arrayItemProp); } else { meta.RegisterCustomizedProperty(nameId, arrayItemProp); } } }
public void RegisterStaticCustomizedProperty(uint propId, ICustomizedProperty property) { _customizedStaticProperties[propId] = property; }