public void SetVariable(string name, SharedVariable sharedVariable) { this.CheckForSerialization(false); if (this.m_Variables == null) { this.m_Variables = new List <SharedVariable>(); } else if (this.m_SharedVariableIndex == null) { this.UpdateVariablesIndex(); } sharedVariable.name = name; int index; if (this.m_SharedVariableIndex != null && this.m_SharedVariableIndex.TryGetValue(name, out index)) { SharedVariable sharedVariable2 = this.m_Variables[index]; if (!sharedVariable2.GetType().Equals(typeof(SharedVariable)) && !sharedVariable2.GetType().Equals(sharedVariable.GetType())) { Debug.LogError(string.Format("Error: Unable to set SharedVariable {0} - the variable type {1} does not match the existing type {2}", name, sharedVariable2.GetType(), sharedVariable.GetType())); } else { sharedVariable2.SetValue(sharedVariable.GetValue()); } } else { this.m_Variables.Add(sharedVariable); this.UpdateVariablesIndex(); } }
public void SetVariableValue(string name, object value) { SharedVariable variable = this.GetVariable(name); if (variable != null) { if (value is SharedVariable) { SharedVariable sharedVariable = value as SharedVariable; if (!string.IsNullOrEmpty(sharedVariable.propertyMapping)) { variable.propertyMapping = sharedVariable.propertyMapping; variable.propertyMappingOwner = sharedVariable.propertyMappingOwner; variable.InitializePropertyMapping(this.m_BehaviorSource); } else { variable.SetValue(sharedVariable.GetValue()); } } else { variable.SetValue(value); } variable.ValueChanged(); } else if (value is SharedVariable) { SharedVariable sharedVariable2 = value as SharedVariable; SharedVariable sharedVariable3 = TaskUtility.CreateInstance(sharedVariable2.GetType()) as SharedVariable; sharedVariable3.name = sharedVariable2.name; sharedVariable3.isShared = sharedVariable2.isShared; sharedVariable3.isGlobal = sharedVariable2.isGlobal; if (!string.IsNullOrEmpty(sharedVariable2.propertyMapping)) { sharedVariable3.propertyMapping = sharedVariable2.propertyMapping; sharedVariable3.propertyMappingOwner = sharedVariable2.propertyMappingOwner; sharedVariable3.InitializePropertyMapping(this.m_BehaviorSource); } else { sharedVariable3.SetValue(sharedVariable2.GetValue()); } this.m_BehaviorSource.SetVariable(name, sharedVariable3); } else { Debug.LogError("Error: No variable exists with name " + name); } }
public void SetVariable(string name, SharedVariable sharedVariable) { if (this.m_Variables == null) { this.m_Variables = new List <SharedVariable>(); } else if (this.m_SharedVariableIndex == null) { this.UpdateVariablesIndex(); } sharedVariable.name = name; int index; if (this.m_SharedVariableIndex != null && this.m_SharedVariableIndex.TryGetValue(name, out index)) { SharedVariable sharedVariable2 = this.m_Variables[index]; if (!sharedVariable2.GetType().Equals(typeof(SharedVariable)) && !sharedVariable2.GetType().Equals(sharedVariable.GetType())) { Debug.LogError(string.Format("Error: Unable to set SharedVariable {0} - the variable type {1} does not match the existing type {2}", name, sharedVariable2.GetType(), sharedVariable.GetType())); } else if (!string.IsNullOrEmpty(sharedVariable.propertyMapping)) { sharedVariable2.propertyMappingOwner = sharedVariable.propertyMappingOwner; sharedVariable2.propertyMapping = sharedVariable.propertyMapping; sharedVariable2.InitializePropertyMapping(this); } else { sharedVariable2.SetValue(sharedVariable.GetValue()); } } else { this.m_Variables.Add(sharedVariable); this.UpdateVariablesIndex(); } }