Esempio n. 1
0
        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));
            }
        }
        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)
            {
                variable.SetValue(value);
                variable.ValueChanged();
            }
        }
Esempio n. 4
0
        public void SetVariableValue(string name, object value)
        {
            SharedVariable variable = this.GetVariable(name);

            if (variable != null)
            {
                variable.SetValue(value);
                variable.ValueChanged();
            }
            else
            {
                Debug.LogError("Error: No variable exists with name " + name);
            }
        }
Esempio n. 5
0
 static int SetValue(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         BehaviorDesigner.Runtime.SharedVariable obj = (BehaviorDesigner.Runtime.SharedVariable)ToLua.CheckObject <BehaviorDesigner.Runtime.SharedVariable>(L, 1);
         object arg0 = ToLua.ToVarObject(L, 2);
         obj.SetValue(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        /// <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: 0x06000171 RID: 369 RVA: 0x0000DD50 File Offset: 0x0000BF50
 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);
             }
         }
     }
 }
Esempio n. 8
0
        private static void DoVariablesFromICodeSync(IVariableSource variableSource, FsmVariable[] iCodeVariables)
        {
            if (variableSource == null)
            {
                return;
            }

            SharedVariable behaviorDesignerVariable = null;
            FsmVariable    iCodeVariable            = null;

            for (int i = 0; i < iCodeVariables.Length; ++i)
            {
                iCodeVariable = iCodeVariables[i];
                if ((behaviorDesignerVariable = variableSource.GetVariable(iCodeVariable.Name)) != null)
                {
                    // FsmInt
                    if (iCodeVariable is FsmInt)
                    {
                        if (behaviorDesignerVariable is SharedInt)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmInt).Value);
                        }
                        continue;
                    }

                    // FsmFloat
                    if (iCodeVariable is FsmFloat)
                    {
                        if (behaviorDesignerVariable is SharedFloat)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmFloat).Value);
                        }
                        continue;
                    }

                    // FsmBool
                    if (iCodeVariable is FsmBool)
                    {
                        if (behaviorDesignerVariable is SharedBool)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmBool).Value);
                        }
                        continue;
                    }

                    // FsmString
                    if (iCodeVariable is FsmString)
                    {
                        if (behaviorDesignerVariable is SharedString)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmString).Value);
                        }
                        continue;
                    }

                    // FsmColor
                    if (iCodeVariable is FsmColor)
                    {
                        if (behaviorDesignerVariable is SharedColor)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmColor).Value);
                        }
                        continue;
                    }

                    // FsmVector2
                    if (iCodeVariable is FsmVector2)
                    {
                        if (behaviorDesignerVariable is SharedVector2)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmVector2).Value);
                        }
                        continue;
                    }

                    // FsmVector3
                    if (iCodeVariable is FsmVector3)
                    {
                        if (behaviorDesignerVariable is SharedVector3)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmVector3).Value);
                        }
                        continue;
                    }

                    // FsmObject
                    if (iCodeVariable is FsmObject)
                    {
                        if (behaviorDesignerVariable is SharedGameObject || behaviorDesignerVariable is SharedObject)
                        {
                            behaviorDesignerVariable.SetValue((iCodeVariable as FsmObject).Value);
                        }
                        continue;
                    }
                }
            }
        }