public override Expression Compile( Expression context, ParameterInfo parameter, Type sourceType) { StateAttribute attribute = parameter.GetCustomAttribute <StateAttribute>(); ConstantExpression key = Expression.Constant(attribute.Key); ConstantExpression defaultIfNotExists = Expression.Constant(attribute.DefaultIfNotExists); MemberExpression contextData = attribute.IsScoped ? Expression.Property(context, ScopedContextData) : Expression.Property(context, ContextData); MethodInfo resolveContextData = attribute.IsScoped ? _resolveScopedContextData.MakeGenericMethod( parameter.ParameterType) : _resolveContextData.MakeGenericMethod( parameter.ParameterType); return(Expression.Call( resolveContextData, contextData, key, defaultIfNotExists)); }
public NodeMenuItem[] AddNodeMenuItems(NodeMachineModel model, Vector2 mousePosition, NodeMachineEditor editor) { HashSet <Type> types = LoadStateTypes(model); HashSet <NodeMenuItem> menuItems = new HashSet <NodeMenuItem>(); int stateCount = 0; foreach (Type type in types) { foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { StateAttribute methodStateInfo = method.GetCustomAttribute <StateAttribute>(); if (methodStateInfo != null) { if (!methodStateInfo.Visible) { continue; } stateCount++; bool runOnEncounter = methodStateInfo.RunOnEncounter; menuItems.Add(new NodeMenuItem("States/" + type.ToString() + "/" + method.Name, () => { StateNode node = new StateNode(type, method.Name, model, mousePosition); node.runOnEncounter = runOnEncounter; editor.AddNode(node); }, false, false)); } } } if (stateCount == 0) { menuItems.Add(new NodeMenuItem("States", null, false, true)); } return(menuItems.ToArray()); }
public void OnAfterDeserialize() { stateType = Type.GetType(stateTypeName); SetValid(stateType != null); if (stateType != null) { if (stateType.BaseType != typeof(State)) { SetValid(false); } else { MethodInfo method = stateType.GetMethod(stateMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method == null) { SetValid(false); } else { StateAttribute stateInfo = method.GetCustomAttribute <StateAttribute>(); if (stateInfo == null) { SetValid(false); } else { runOnEncounter = stateInfo.RunOnEncounter; } } } } }
private bool AddState( string a_DisplayName, Vector2 a_Position, StateAttribute a_Attribute, AllowedTransitionType a_AllowedTransitions = AllowedTransitionType.All, int a_MaxTransitions = -1) { var newState = this.AddChildAsset <DSMState> (); newState.Init(this, a_DisplayName, a_Position, a_Attribute, a_AllowedTransitions, a_MaxTransitions); m_States.Add(newState); return(true); }
public StateSettings(GameState state) { InitializeComponent(); State = state; StateAttribute attributes = (StateAttribute)Attribute.GetCustomAttribute(state.GetType(), typeof(StateAttribute)); StateMetaInfo meta = (StateMetaInfo)Attribute.GetCustomAttribute(state.GetType(), typeof(StateMetaInfo)); label2.Text = string.Format("Developed by {0}", attributes.Author); if (meta != null && meta.Version != null) { label2.Text += "\nVersion: " + meta.Version + "\nLast Updated: " + meta.DateUpdated; } }
public void Init( DSMObject a_Parent, string a_DisplayName, Vector2 a_Position, StateAttribute a_Attribute, AllowedTransitionType a_AllowedTransitions = AllowedTransitionType.All, int a_MaxTransitions = -1) { m_Parent = a_Parent; name = a_DisplayName; m_DisplayName = a_DisplayName; position = a_Position; m_Attribute = a_Attribute; m_AllowedTransitionTypes = a_AllowedTransitions; m_MaxTransitions = a_MaxTransitions; }