public void SetVariable(string name, SharedVariable sharedVariable) { this.CheckForSerialization(false); if (this.mVariables == null) { this.mVariables = new List <SharedVariable>(); } else { if (this.mSharedVariableIndex == null) { this.UpdateVariablesIndex(); } } sharedVariable.Name = name; int index; if (this.mSharedVariableIndex != null && this.mSharedVariableIndex.TryGetValue(name, out index)) { SharedVariable sharedVariable2 = this.mVariables[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.mVariables.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.mBehaviorSource); } else { variable.SetValue(sharedVariable.GetValue()); } } else { variable.SetValue(value); } variable.ValueChanged(); } else if (value is SharedVariable) { SharedVariable sharedVariable = value as SharedVariable; SharedVariable instance = TaskUtility.CreateInstance(sharedVariable.GetType()) as SharedVariable; instance.Name = sharedVariable.Name; instance.IsShared = sharedVariable.IsShared; instance.IsGlobal = sharedVariable.IsGlobal; if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping)) { instance.PropertyMapping = sharedVariable.PropertyMapping; instance.PropertyMappingOwner = sharedVariable.PropertyMappingOwner; instance.InitializePropertyMapping(this.mBehaviorSource); } else { instance.SetValue(sharedVariable.GetValue()); } this.mBehaviorSource.SetVariable(name, instance); } else { Debug.LogError((object)("Error: No variable exists with name " + name)); } }
/// <summary> /// 设置指定名字的共享变量 /// </summary> /// <param name="name"></param> /// <param name="sharedVariable"></param> public void SetVariable(string name, SharedVariable sharedVariable) { if (this.mVariables == null) { this.mVariables = new List <SharedVariable>(); } else if (this.mSharedVariableIndex == null) { this.UpdateVariablesIndex(); } sharedVariable.Name = name; int index; if (this.mSharedVariableIndex != null && this.mSharedVariableIndex.TryGetValue(name, out index)) { SharedVariable sharedVariable2 = this.mVariables[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.mVariables.Add(sharedVariable); this.UpdateVariablesIndex(); } }
// Token: 0x06000170 RID: 368 RVA: 0x0000DB70 File Offset: 0x0000BD70 private static SharedVariable DeserializeSharedVariable(Dictionary <string, object> dict, IVariableSource variableSource, bool fromSource, List <UnityEngine.Object> unityObjects) { if (dict == null) { return(null); } SharedVariable sharedVariable = null; object obj; if (!fromSource && variableSource != null && dict.TryGetValue("Name", out obj)) { object value; dict.TryGetValue("IsGlobal", out value); if (!dict.TryGetValue("IsGlobal", out value) || !Convert.ToBoolean(value)) { sharedVariable = variableSource.GetVariable(obj as string); } else { if (JSONDeserializationDeprecated.globalVariables == null) { JSONDeserializationDeprecated.globalVariables = GlobalVariables.Instance; } if (JSONDeserializationDeprecated.globalVariables != null) { sharedVariable = JSONDeserializationDeprecated.globalVariables.GetVariable(obj as string); } } } Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(dict["Type"] as string); if (typeWithinAssembly == null) { return(null); } bool flag = true; if (sharedVariable == null || !(flag = sharedVariable.GetType().Equals(typeWithinAssembly))) { sharedVariable = (TaskUtility.CreateInstance(typeWithinAssembly) as SharedVariable); sharedVariable.Name = (dict["Name"] as string); object obj2; if (dict.TryGetValue("IsShared", out obj2)) { sharedVariable.IsShared = Convert.ToBoolean(obj2); } if (dict.TryGetValue("IsGlobal", out obj2)) { sharedVariable.IsGlobal = Convert.ToBoolean(obj2); } if (dict.TryGetValue("NetworkSync", out obj2)) { sharedVariable.NetworkSync = Convert.ToBoolean(obj2); } if (!sharedVariable.IsGlobal && dict.TryGetValue("PropertyMapping", out obj2)) { sharedVariable.PropertyMapping = (obj2 as string); if (dict.TryGetValue("PropertyMappingOwner", out obj2)) { sharedVariable.PropertyMappingOwner = (JSONDeserializationDeprecated.IndexToUnityObject(Convert.ToInt32(obj2), unityObjects) as GameObject); } sharedVariable.InitializePropertyMapping(variableSource as BehaviorSource); } if (!flag) { sharedVariable.IsShared = true; } JSONDeserializationDeprecated.DeserializeObject(null, sharedVariable, dict, variableSource, unityObjects); } return(sharedVariable); }