/// <summary>
        /// Sets the value of the specified variable
        /// </summary>
        /// <param name="name">The name of the variable to be set</param>
        /// <param name="newValue">The value to assign to the variable</param>
        public void SetValue(string name, System.Object newValue)
        {
            SceneVariable foundVariable = GetVariable(name);

            if (foundVariable == null)
            {
                throw new KeyNotFoundException("Variable " + name + " doesn't exist");
            }

            System.Object oldValue = foundVariable.GetValue();

            if (oldValue.Equals(newValue))
            {
                return;
            }

            foundVariable.SetValue(newValue);

            OnVariableChanged.SafeInvoke(this, new EventArgs <string>()
            {
                Value = name
            });
        }
示例#2
0
 public static void RaiseVariableChanged(string variableName)
 {
     OnVariableChanged?.Invoke(variableName);
 }
示例#3
0
        /// <summary>
        /// グローバル変数をセットする
        /// </summary>
        /// <param name="name">グローバル変数名</param>
        /// <param name="value">値</param>
        /// <param name="zone"ゾーン名</param>
        /// <returns>is changed</returns>
        public static bool SetVariable(
            string name,
            object value,
            string zone = null)
        {
            var result = false;

            lock (ExpressionLocker)
            {
                var variable = default(TimelineVariable);
                if (Variables.ContainsKey(name))
                {
                    variable = Variables[name];
                }
                else
                {
                    variable        = new TimelineVariable(name);
                    Variables[name] = variable;
                    result          = true;
                }

                switch (value)
                {
                case bool b:
                    if (!(variable.Value is bool current) ||
                        current != b)
                    {
                        variable.Value      = b;
                        variable.Expiration = DateTime.MaxValue;
                        result = true;
                    }
                    break;

                case int i:
                    if (variable.Counter != i)
                    {
                        variable.Counter    = i;
                        variable.Expiration = DateTime.MaxValue;
                        result = true;
                    }
                    break;

                default:
                    if (!ObjectComparer.Equals(value, variable.Value))
                    {
                        variable.Value      = value;
                        variable.Expiration = DateTime.MaxValue;
                        result = true;
                    }
                    break;
                }

                variable.Zone = zone ?? string.Empty;
            }

            if (result)
            {
                OnVariableChanged?.Invoke(new EventArgs());
            }

            return(result);
        }
        /// <summary>
        /// グローバル変数をセットする
        /// </summary>
        /// <param name="name">グローバル変数名</param>
        /// <param name="value">値</param>
        /// <param name="zone"ゾーン名</param>
        /// <returns>is changed</returns>
        public static bool SetVariable(
            string name,
            object value,
            string zone = null)
        {
            var result   = false;
            var variable = default(TimelineVariable);

            lock (ExpressionLocker)
            {
                if (Variables.ContainsKey(name))
                {
                    variable = Variables[name];
                }
                else
                {
                    variable        = new TimelineVariable(name);
                    Variables[name] = variable;
                    result          = true;
                }

                switch (value)
                {
                case bool b:
                    if (!(variable.Value is bool current1) ||
                        current1 != b)
                    {
                        variable.Value      = b;
                        variable.Expiration = DateTime.MaxValue;
                        result = true;
                    }
                    break;

                case string s:
                    if (s.TryParse0xString2Int(out int i2))
                    {
                        if (!(variable.Value is int current2) ||
                            current2 != i2)
                        {
                            variable.Value      = i2;
                            variable.Expiration = DateTime.MaxValue;
                            result = true;
                        }
                    }
                    else
                    {
                        goto default;
                    }
                    break;

                default:
                    if (!ObjectComparer.Equals(value, variable.Value))
                    {
                        variable.Value      = value;
                        variable.Expiration = DateTime.MaxValue;
                        result = true;
                    }
                    break;
                }

                variable.Zone = zone ?? string.Empty;
            }

            if (result)
            {
                OnVariableChanged?.Invoke(new EventArgs());

                if (ReferedTriggerRecompileDelegates.ContainsKey(variable.Name))
                {
                    lock (variable)
                    {
                        ReferedTriggerRecompileDelegates[variable.Name]?.Invoke();
                    }
                }
            }

            return(result);
        }
示例#5
0
 public static void SetVariable(Variable var, TokenType value)
 {
     variables[var] = value;
     OnVariableChanged?.Invoke(null, new VariableEventArgs(var, value));
 }