コード例 #1
0
        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();
            }
        }
コード例 #2
0
ファイル: Behavior.cs プロジェクト: Qn880914/GameReborn
        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);
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        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);
        }