public Property(CMemberBase pMemberBase, bool bIsConst) { m_memberBase = pMemberBase; m_variableId = 0; m_bValidDefaultValue = false; m_bIsConst = bIsConst; }
public Property(CMemberBase pMemberBase, bool bIsConst) { m_memberBase = pMemberBase; m_variableId = 0; m_bValidDefaultValue = false; m_bIsConst = bIsConst; if (this.m_memberBase != null) { this.m_pt = this.m_memberBase.GetParentType(); Debug.Check(this.m_pt == ParentType.PT_INVALID); } else { this.m_pt = ParentType.PT_PAR; } }
private static void RegisterType(Type type, bool bIsAgentType) { Attribute[] attributes = (Attribute[])type.GetCustomAttributes(typeof(behaviac.TypeMetaInfoAttribute), false); //agent type must have behaviac.AgentTypeAttribute if (!bIsAgentType || attributes.Length > 0) { behaviac.TypeMetaInfoAttribute cda = attributes.Length > 0 ? (behaviac.TypeMetaInfoAttribute)attributes[0] : null; Agent.CTagObjectDescriptor objectDesc = Agent.GetDescriptorByName(type.FullName); if (Utils.IsAgentType(type.BaseType)) { Agent.CTagObjectDescriptor baseObjectDesc = Agent.GetDescriptorByName(type.BaseType.FullName); objectDesc.m_parent = baseObjectDesc; } objectDesc.type = type; objectDesc.displayName = ((cda == null || string.IsNullOrEmpty(cda.DisplayName)) ? type.FullName : cda.DisplayName); objectDesc.desc = ((cda == null || string.IsNullOrEmpty(cda.Description)) ? objectDesc.displayName : cda.Description); if (Utils.IsEnumType(type)) { return; } BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; FieldInfo[] fields = type.GetFields(bindingFlags); foreach (FieldInfo f in fields) { //for agent type, only register members with MemberDescAttribute bool bToRegister = false; behaviac.MemberMetaInfoAttribute memberDesc = null; if (bIsAgentType) { Attribute[] attributes1 = (Attribute[])f.GetCustomAttributes(typeof(behaviac.MemberMetaInfoAttribute), false); if (attributes1.Length > 0) { memberDesc = (behaviac.MemberMetaInfoAttribute)attributes1[0]; bToRegister = true; } } else { bToRegister = true; } if (bToRegister) { CMemberBase m = new CMemberBase(f, memberDesc); CMemberBase pMember = objectDesc.ms_members.Find(delegate(CMemberBase m1) { return m1.GetId() == m.GetId(); }); Debug.Check(pMember == null, "RegisterMetas is called more than once!"); objectDesc.ms_members.Add(m); if ((Utils.IsCustomClassType(f.FieldType) || Utils.IsEnumType(f.FieldType)) && !Agent.IsTypeRegisterd(f.FieldType.FullName)) { RegisterType(f.FieldType, false); } } } if (bIsAgentType) { MethodInfo[] methods = type.GetMethods(bindingFlags); foreach (MethodInfo m in methods) { Attribute[] attributes2 = (Attribute[])m.GetCustomAttributes(typeof(behaviac.MethodMetaInfoAttribute), false); if (attributes2.Length > 0) { behaviac.MethodMetaInfoAttribute methodDesc = (behaviac.MethodMetaInfoAttribute)attributes2[0]; CMethodBase method = new CMethodBase(m, methodDesc, null); objectDesc.ms_methods.Add(method); ParameterInfo[] parameters = m.GetParameters(); foreach (ParameterInfo para in parameters) { if ((Utils.IsCustomClassType(para.ParameterType) || Utils.IsEnumType(para.ParameterType)) && !Agent.IsTypeRegisterd(para.ParameterType.FullName)) { RegisterType(para.ParameterType, false); } } if ((Utils.IsCustomClassType(m.ReturnType) || Utils.IsEnumType(m.ReturnType)) && !Agent.IsTypeRegisterd(m.ReturnType.FullName)) { RegisterType(m.ReturnType, false); } } }//end of foreach Type[] delegates = type.GetNestedTypes(bindingFlags); foreach (Type d in delegates) { Attribute[] attributes0 = (Attribute[])d.GetCustomAttributes(typeof(behaviac.EventMetaInfoAttribute), false); if (attributes0.Length > 0) { behaviac.EventMetaInfoAttribute eventDesc = (behaviac.EventMetaInfoAttribute)attributes0[0]; MethodInfo m = d.GetMethod("Invoke"); CNamedEvent method = new CNamedEvent(m, eventDesc, d.Name); objectDesc.ms_methods.Add(method); } } }//if (bIsAgentType) } }
public override object GetObject(Agent pAgent, bool bMemberGet, CMemberBase pMember, uint varId) { if (this.state_stack != null && this.state_stack.Count > 0) { for (int i = this.state_stack.Count - 1; i >= 0; --i) { AgentState t = this.state_stack[i]; object result = t.GetObject(pAgent, false, pMember, varId); if (result != null) { return result; } } } object result1 = base.GetObject(pAgent, bMemberGet, pMember, varId); return result1; }
public override void SetObject(bool bMemberSet, Agent pAgent, bool bLocal, CMemberBase pMember, string variableName, object value, uint varId) { //if (variableName == "DirtyRooms") //{ // Debug.Check(true); //} // not in planning if (pAgent.PlanningTop == -1 && !bLocal) { base.SetObject(bMemberSet, pAgent, bLocal, pMember, variableName, value, varId); return; } if (this.state_stack != null && this.state_stack.Count > 0) { int stackIndex = 0; if (bLocal) { //top stackIndex = this.state_stack.Count - 1; } else { //bottom stackIndex = pAgent.PlanningTop; } AgentState t = this.state_stack[stackIndex]; //if there are something in the state stack, it is used for planning, so, don't really set member t.SetObject(false, pAgent, bLocal, null, variableName, value, varId); } else { base.SetObject(bMemberSet, pAgent, bLocal, pMember, variableName, value, varId); } }
public IVariable(CMemberBase pMember, Property property_) { m_property = property_; m_pMember = pMember; m_instantiated = 1; Debug.Check(this.m_property != null); this.m_name = this.m_property.GetVariableName(); this.m_id = this.m_property.GetVariableId(); #if !BEHAVIAC_RELEASE m_changed = true; #endif }
public IVariable(CMemberBase pMember, string variableName, uint id) { m_id = id; m_name = variableName; m_property = null; m_pMember = pMember; m_instantiated = 1; #if !BEHAVIAC_RELEASE m_changed = true; #endif }
public static Property Create(string value, CMemberBase pMemberBase, bool bConst) { Property p = new Property(pMemberBase, bConst); //a const must have default value Debug.Check(!bConst || !string.IsNullOrEmpty(value)); if (!string.IsNullOrEmpty(value)) { if (p.SetDefaultValue(value)) { // } else { //a const must have a valid default value Debug.Check(!bConst); } } return p; }
public void Set(Agent pAgent, CMemberBase pMember, string variableName, object value, uint varId) { Debug.Check(!string.IsNullOrEmpty(variableName)); if (varId == 0) { varId = Utils.MakeVariableId(variableName); } IVariable pVar = null; if (!this.m_variables.ContainsKey(varId)) { if (pMember == null) { if (pAgent != null) { pMember = pAgent.FindMember(variableName); } else { pMember = Agent.FindMemberBase(variableName); } } pVar = new IVariable(pMember, variableName, varId); behaviac.Debug.Check(pVar != null); m_variables[varId] = pVar; } else { pVar = this.m_variables[varId]; } pVar.SetValue(value, pAgent); }
public void SetFromString(Agent pAgent, CMemberBase pMember, string valueString) { if (!string.IsNullOrEmpty(valueString)) { object value = StringUtils.FromString(pMember.MemberType, valueString, false); if (!(Details.Equal(this.m_value, value))) { this.m_value = value; #if !BEHAVIAC_RELEASE this.m_changed = true; #endif if (!Object.ReferenceEquals(pAgent, null)) { //const CMemberBase* pMember = pAgent.FindMember(variableName); if (pMember != null) { pMember.Set(pAgent, value); } } } } }
private void RegisterMember(Type type, Agent.CTagObjectDescriptor objectDesc, Type memberType, CMemberBase m) { CMemberBase pMember = objectDesc.ms_members.Find(delegate(CMemberBase m1) { return m1.GetId() == m.GetId(); }); if (pMember == null) { objectDesc.ms_members.Add(m); if ((Utils.IsCustomClassType(memberType) || Utils.IsEnumType(memberType)) && !Agent.IsTypeRegisterd(memberType.FullName)) { RegisterType(memberType, false); } } else { //string msg = string.Format("{0}.{1} duplated", type.FullName, pMember.Name); //Debug.LogWarning(msg); } }