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) { 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) { variable.SetValue(value); variable.ValueChanged(); } }
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(); } }
private static void DeserializeObject(Task task, object obj, Dictionary <string, object> dict, IVariableSource variableSource, List <UnityEngine.Object> unityObjects) { if (dict == null) { return; } FieldInfo[] allFields = TaskUtility.GetAllFields(obj.GetType()); for (int i = 0; i < allFields.Length; i++) { object obj2; if (dict.TryGetValue(allFields[i].FieldType + "," + allFields[i].Name, out obj2) || dict.TryGetValue(allFields[i].Name, out obj2)) { if (typeof(IList).IsAssignableFrom(allFields[i].FieldType)) { IList list = obj2 as IList; if (list != null) { Type type; if (allFields[i].FieldType.IsArray) { type = allFields[i].FieldType.GetElementType(); } else { Type type2 = allFields[i].FieldType; while (!type2.IsGenericType) { type2 = type2.BaseType; } type = type2.GetGenericArguments()[0]; } bool flag = type.Equals(typeof(Task)) || type.IsSubclassOf(typeof(Task)); if (flag) { if (JSONDeserializationDeprecated.taskIDs != null) { List <int> list2 = new List <int>(); for (int j = 0; j < list.Count; j++) { list2.Add(Convert.ToInt32(list[j])); } JSONDeserializationDeprecated.taskIDs.Add(new JSONDeserializationDeprecated.TaskField(task, allFields[i]), list2); } } else if (allFields[i].FieldType.IsArray) { Array array = Array.CreateInstance(type, list.Count); for (int k = 0; k < list.Count; k++) { array.SetValue(JSONDeserializationDeprecated.ValueToObject(task, type, list[k], variableSource, unityObjects), k); } allFields[i].SetValue(obj, array); } else { IList list3; if (allFields[i].FieldType.IsGenericType) { list3 = (TaskUtility.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type })) as IList); } else { list3 = (TaskUtility.CreateInstance(allFields[i].FieldType) as IList); } for (int l = 0; l < list.Count; l++) { list3.Add(JSONDeserializationDeprecated.ValueToObject(task, type, list[l], variableSource, unityObjects)); } allFields[i].SetValue(obj, list3); } } } else { Type fieldType = allFields[i].FieldType; if (fieldType.Equals(typeof(Task)) || fieldType.IsSubclassOf(typeof(Task))) { if (TaskUtility.HasAttribute(allFields[i], typeof(InspectTaskAttribute))) { Dictionary <string, object> dictionary = obj2 as Dictionary <string, object>; Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(dictionary["ObjectType"] as string); if (typeWithinAssembly != null) { Task task2 = TaskUtility.CreateInstance(typeWithinAssembly) as Task; JSONDeserializationDeprecated.DeserializeObject(task2, task2, dictionary, variableSource, unityObjects); allFields[i].SetValue(task, task2); } } else if (JSONDeserializationDeprecated.taskIDs != null) { List <int> list4 = new List <int>(); list4.Add(Convert.ToInt32(obj2)); JSONDeserializationDeprecated.taskIDs.Add(new JSONDeserializationDeprecated.TaskField(task, allFields[i]), list4); } } else { allFields[i].SetValue(obj, JSONDeserializationDeprecated.ValueToObject(task, fieldType, obj2, variableSource, unityObjects)); } } } else if (typeof(SharedVariable).IsAssignableFrom(allFields[i].FieldType) && !allFields[i].FieldType.IsAbstract) { if (dict.TryGetValue(allFields[i].FieldType + "," + allFields[i].Name, out obj2)) { SharedVariable sharedVariable = TaskUtility.CreateInstance(allFields[i].FieldType) as SharedVariable; sharedVariable.SetValue(JSONDeserializationDeprecated.ValueToObject(task, allFields[i].FieldType, obj2, variableSource, unityObjects)); allFields[i].SetValue(obj, sharedVariable); } else { SharedVariable value = TaskUtility.CreateInstance(allFields[i].FieldType) as SharedVariable; allFields[i].SetValue(obj, value); } } } }