Пример #1
0
        /// <summary>
        /// Adds a variable to the watchlist.
        /// If it's already added, it only updates the value.
        /// </summary>
        /// <param name="name">variable name</param>
        /// <param name="value">reported value</param>
        /// <param name="global">is global</param>
        public void AddToWatchlist(string name, System.Object value, bool global = false)
        {
            var newVar = new VariableWatch(name);

            newVar.global = global;
            newVar.ReportValue(value);
            foreach (VariableWatch v in watched)
            {
                if (v.Equals(newVar))
                {
                    if (value != null)
                    {
                        v.ReportValue(value);
                    }
                    return;
                }
            }
            watched.Add(newVar);
        }
Пример #2
0
        /// <summary>
        ///     Adds a variable to the watchlist.
        ///     If it's already added, it only updates the value.
        /// </summary>
        /// <param name="name">variable name</param>
        /// <param name="value">reported value</param>
        /// <param name="global">is global</param>
        public static void Add(string name, object value, bool global = false)
        {
            var newVar = new VariableWatch(name)
            {
                Global = global
            };

            newVar.ReportValue(value);
            foreach (var v in Watched)
            {
                if (v.Equals(newVar))
                {
                    if (value != null)
                    {
                        v.ReportValue(value);
                    }
                    return;
                }
            }
            Watched.Add(newVar);
        }
Пример #3
0
        /// <summary>
        /// Draws the main window.
        /// </summary>
        /// <param name="id"></param>
        private void DoMainWindow(int id)
        {
            var oldColor = GUI.backgroundColor;

            // Draw close button
            if (GUI.Button(new Rect(mainWindowRect.width - 38, 8, 30, 30),
                           "×", Elements.Buttons.Red))
            {
                Visible = false;
            }

            List <VariableWatch> toBeRemoved = new List <VariableWatch>();

            newVariableName = GUI.TextField(new Rect(68, 48, 248, 20), newVariableName, Elements.InputFields.ComponentField);
            if (GUI.Button(new Rect(4, 48, 60, 20), "Add", Elements.Buttons.Default) && Regex.Replace(newVariableName, @"\s+", "") != "")
            {
                newVariableName = Regex.Replace(newVariableName, @"\s+", "");
                AddToWatchlist(newVariableName, null, true);
                newVariableName = "";
            }

            GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f, 0.7f);
            scrollPosition      = GUI.BeginScrollView(
                new Rect(4, 72, 312, 400),
                scrollPosition,
                new Rect(0, 0, 296, 4 + (watched.Count * 24)));
            GUI.backgroundColor = oldColor;

            int i = 0;

            foreach (VariableWatch v in watched)
            {
                // Button for removing line
                if (GUI.Button(new Rect(4, 4 + i * 24, 20, 20), "×", Elements.Buttons.Red))
                {
                    toBeRemoved.Add(v);
                }

                // Color of labels
                GUI.backgroundColor = Color.black;

                // Variable name: button for global, label for local
                if (v.global)
                {
                    if (GUI.Button(new Rect(28, 4 + i * 24, 130, 20), v.GetName(), Elements.Buttons.Default))
                    {
                        editing          = true;
                        editingVariable  = v;
                        newVariableValue = v.GetEditString();
                        editWindowRect   = new Rect(
                            mainWindowRect.x + 24,
                            mainWindowRect.y + 60 + i * 24,
                            editWindowWidth,
                            editWindowHeight);
                    }
                }
                else
                {
                    GUI.Label(new Rect(28, 4 + i * 24, 130, 20), v.GetName(), Elements.InputFields.ComponentField);
                }

                // Label for variable value
                GUI.Label(new Rect(162, 4 + i * 24, 136, 20), v.GetValue(), Elements.InputFields.ComponentField);

                GUI.backgroundColor = oldColor;

                i++;
            }

            // Remove variables
            foreach (VariableWatch v in toBeRemoved)
            {
                watched.Remove(v);
            }

            GUI.EndScrollView();

            if (GUI.Button(new Rect(4, 476, 312, 20), "Clear Watchlist", Elements.Buttons.Red))
            {
                ClearWatchlist();
            }

            GUI.DragWindow(new Rect(0, 0, mainWindowRect.width, GUI.skin.window.padding.top));
        }