public bool SetVariable(string name, object value) { FsmVariable variable = GetVariable(name); if (variable != null && variable.VariableType.IsAssignableFrom(value.GetType())) { variable.SetValue(value); return(true); } if (value != null) { variable = (FsmVariable)ScriptableObject.CreateInstance(FsmUtility.GetVariableType(value.GetType())); variable.hideFlags = HideFlags.HideInHierarchy; variable.Name = name; variable.SetValue(value); Variables = ArrayUtility.Add <FsmVariable> (Variables, variable); } return(false); }
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 override void Deserialize(NetworkReader reader) { string typeString = reader.ReadString(); Type type = TypeUtility.GetType(typeString); if (variable == null) { variable = ScriptableObject.CreateInstance(type) as FsmVariable; } if (type == typeof(FsmInt)) { variable.SetValue(reader.ReadInt32()); } else if (type == typeof(FsmString)) { variable.SetValue(reader.ReadString()); } else if (type == typeof(FsmFloat)) { variable.SetValue(reader.ReadSingle()); } else if (type == typeof(FsmColor)) { variable.SetValue(reader.ReadColor()); } else if (type == typeof(FsmVector2)) { variable.SetValue(reader.ReadVector2()); } else if (type == typeof(FsmVector3)) { variable.SetValue(reader.ReadVector3()); } }
private void Start() { if (behaviour.stateMachine != null) { if (!behaviour.stateMachine.IsInitialized) { bool isEnabled = behaviour.enabled; behaviour.EnableStateMachine(); behaviour.enabled = isEnabled; } for (int i = 0; i < setVariables.Count; i++) { FsmVariable variable = behaviour.stateMachine.GetVariable(setVariables[i].name); if (variable != null) { variable.SetValue(setVariables[i].GetValue()); } } } }