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 static IInstanceMember ParseProperty(string value) { try { if (string.IsNullOrEmpty(value)) { return(null); } List <string> tokens = StringUtils.SplitTokens(value); string typeName = ""; if (tokens[0] == "const") { // const Int32 0 Debug.Check(tokens.Count == 3); const int kConstLength = 5; string strRemaining = value.Substring(kConstLength + 1); int p = StringUtils.FirstToken(strRemaining, ' ', ref typeName); typeName = typeName.Replace("::", "."); string strVale = strRemaining.Substring(p + 1); // const return(AgentMeta.CreateInstanceConst(typeName, strVale)); } else { string propStr = ""; string indexPropStr = ""; if (tokens[0] == "static") { // static float Self.AgentNodeTest::s_float_type_0 // static float Self.AgentNodeTest::s_float_type_0[int Self.AgentNodeTest::par_int_type_2] Debug.Check(tokens.Count == 3 || tokens.Count == 4); typeName = tokens[1]; propStr = tokens[2]; if (tokens.Count == 4) // array index { indexPropStr = tokens[3]; } } else { // float Self.AgentNodeTest::par_float_type_1 // float Self.AgentNodeTest::par_float_type_1[int Self.AgentNodeTest::par_int_type_2] Debug.Check(tokens.Count == 2 || tokens.Count == 3); typeName = tokens[0]; propStr = tokens[1]; if (tokens.Count == 3) // array index { indexPropStr = tokens[2]; } } string arrayItem = ""; IInstanceMember indexMember = null; if (!string.IsNullOrEmpty(indexPropStr)) { arrayItem = "[]"; indexMember = ParseProperty <int>(indexPropStr); } typeName = typeName.Replace("::", "."); propStr = propStr.Replace("::", "."); string[] props = propStr.Split('.'); Debug.Check(props.Length >= 3); string instantceName = props[0]; string propName = props[props.Length - 1]; string className = props[1]; for (int i = 2; i < props.Length - 1; ++i) { className += "." + props[i]; } uint classId = Utils.MakeVariableId(className); AgentMeta meta = AgentMeta.GetMeta(classId); Debug.Check(meta != null, "please add the exported 'AgentProperties.cs' and 'customizedtypes.cs' into the project!"); uint propId = Utils.MakeVariableId(propName + arrayItem); // property IProperty p = meta.GetProperty(propId); if (p != null) { return(p.CreateInstance(instantceName, indexMember)); } // local var return(AgentMeta.CreateInstanceProperty(typeName, instantceName, indexMember, propId)); } } catch (System.Exception e) { Debug.Check(false, e.Message); } return(null); }