public static bool SetVariable(string name, object value) { FsmVariable variable = GlobalVariables.GetVariable(name); if (variable != null && variable.VariableType == value.GetType()) { variable.SetValue(value); return(true); } return(false); }
public void Init(Node node) { if (!initialized) { initialized = true; root = node.Root; FieldInfo[] fields = this.GetType().GetPublicFields(); for (int k = 0; k < fields.Length; k++) { if (typeof(FsmVariable).IsAssignableFrom(fields [k].FieldType)) { FsmVariable variable = (FsmVariable)fields [k].GetValue(this); if (variable != null && variable.IsShared) { FsmVariable fsmVariable = node.Root.GetVariable(variable.Name) ?? GlobalVariables.GetVariable(variable.Name); if (fsmVariable != null) { fields [k].SetValue(this, fsmVariable); // Debug.Log(this.GetType()+" "+variable.Name); } } } } } }