void Start()
 {
     mouse = GameObject.Find("Game").GetComponent <Mouse>();
     gui   = GameObject.Find("Game").GetComponent <GUISetup>();
     StartCoroutine("AutoAttack");
 }
Exemple #2
0
        private void OnGUI()
        {
            TryInit();

            #region Main setup
            //var debugFlags = DebugDisplayRegistry.DebugFlags;
            var enumType = (Type)null;//debugFlags.maskType;
            if (enumType == null || !enumType.IsEnum)
            {
                return;
            }

            enumInfos.Init(enumType);
            activeFlags.Count   = enumInfos.Count;
            expandedFlags.Count = enumInfos.Count;

            if (styleSetup == null)
            {
                styleSetup = new GUISetup();
            }
            #endregion Main setup

            #region Draw setup
            var bgMargin   = 2;
            var lineMargin = 4;
            #endregion Draw setup

            var maskHasChanged = false;
            var itemCount      = 0;
            for (int e = 0; e < enumInfos.Count; e++)
            {
                var value = enumInfos[e].value;
                //if (IsExpanded(value, ref debugFlags))
                //    itemCount += 1;
            }

            var titleRect = GUIDraw.BackgroundAuto(2, lineMargin, bgMargin, styleSetup.background);
            {
                titleRect = titleRect.TruncateX(titleRect.height)
                            .TruncateX(-titleRect.height)
                            .Inflate(-titleRect.height / 8);
                GUIDraw.Background(titleRect, 2, styleSetup.itemBG[0]);
                titleRect = titleRect.TruncateX(titleRect.height / 2);
                GUI.Label(titleRect, enumInfos.Type.Name, styleSetup.titleText);
            }

            var winRect = GUIDraw.BackgroundAuto(itemCount, lineMargin, bgMargin, styleSetup.background);
            {
                var lineRect = winRect;
                lineRect.height /= itemCount;
                for (int e = 0; e < enumInfos.Count; e++)
                {
                    var value       = enumInfos[e].value;
                    var parentCount = 0; //debugFlags.CountParent(value);
                    var hasChildren = 0; //debugFlags.HasChildren(value);
                    //if (IsExpanded(value, ref debugFlags))
                    {
                        var line     = lineRect;
                        var lockSize = 0.8f;

                        {
                            var lockRect = line.nh(line.height * (1.0f + lockSize));
                            GUIDraw.Background(lockRect, 0, styleSetup.itemBG[0]);
                            lockRect = lockRect.TruncateX(lockRect.height);
                            GUIDraw.Background(lockRect.Inflate(-2), 0, styleSetup.actives[0]);
                        }

                        //On-Off square
                        var activeRect = GUIDraw.Square(GUIDraw.Square(ref line, 2), 0, styleSetup.actives[activeFlags[e] ? 1 : 0]);
                        if (Event.current.type == EventType.MouseUp && activeRect.Contains(Event.current.mousePosition))
                        {
                            maskHasChanged = true;
                            activeFlags[e] = !activeFlags[e];
                            Repaint();
                        }

                        //Parent offsets
                        line = line.TruncateX(line.height * ((float)parentCount + lockSize));

                        line = GUIDraw.Background(line, 2, styleSetup.itemBG[0]);

                        if (Event.current.type == EventType.MouseUp && line.Contains(Event.current.mousePosition))
                        {
                            expandedFlags[e] = !expandedFlags[e];
                            Repaint();
                        }

                        //Does this option has children
                        //GUIDraw.Square(ref line, 0, hasChildren ? styleSetup.actives[0] : null);

                        line = line.TruncateX(line.height / 2);
                        GUI.Label(line, enumInfos[e].name, styleSetup.itemText);

                        lineRect = lineRect.NextLine();
                    }
                }
            }

            //todo var manager = !EditorApplication.isPlaying ? null : TickableRegistry.GetManager<DebugDisplayManager>();
            //todo if (manager != null)
            //todo {
            //todo     if (maskHasChanged)
            //todo     {
            //todo         for (int e = 0; e < enumInfos.Count; e++)
            //todo         {
            //todo             debugFlags.SetStatus(enumInfos[e].value, activeFlags[e]);
            //todo         }
            //todo         DebugDisplayManager.DebugFlags = debugFlags;
            //todo         manager.Build();
            //todo     }
            //todo }
            return;


            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            {
                /*
                 #region Draw setup
                 * var margin2 = Vector2.one * 2;
                 * var margin4 = Vector2.one * 4;
                 * var windowRect = EditorGUILayout.GetControlRect(GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * enumInfos.Count + margin4.y * 2));
                 * var lineRect = windowRect;
                 * {
                 *  lineRect.x += margin4.x;
                 *  lineRect.width -= margin4.x * 2;
                 *  lineRect.height = EditorGUIUtility.singleLineHeight;
                 *  lineRect.y = windowRect.height - (lineRect.height + margin4.y);
                 * }
                 * var boxRect = lineRect;
                 * {
                 *  boxRect.width = lineRect.height - margin2.y * 2;
                 *  boxRect.height = lineRect.height - margin2.x * 2;
                 *  boxRect.x += margin2.x;
                 *  boxRect.y += margin2.y;
                 * }
                 * var textRect = lineRect;
                 * {
                 *  textRect.x += boxRect.width + margin2.x * 2;
                 *  textRect.width -= boxRect.width + margin2.x * 3;
                 *  textRect.height = EditorGUIUtility.singleLineHeight;
                 * }
                 #endregion Draw setup
                 *
                 #region Draw background
                 * GUI.Box(windowRect, GUIContent.none, styleSetup.background);
                 #endregion Draw background
                 *
                 #region Draw lines
                 *
                 * for (int i = enumInfos.Count - 1; i >= 0; i--)
                 * {
                 *  var indent = manager != null ? manager.CountParents(i) : 0;
                 *  var oldX = lineRect.x;
                 *  var oldWidth = lineRect.width;
                 *  {
                 *      lineRect.x += indent * lineRect.height;
                 *      lineRect.width -= indent * lineRect.height;
                 *      boxRect.x += indent * lineRect.height;
                 *      textRect.x += indent * lineRect.height;
                 *
                 *      GUI.Box(lineRect, GUIContent.none, styleSetup.m_item_background[Mathf.Min(indent, styleSetup.m_item_background.Count)]);
                 *      GUI.Box(boxRect, GUIContent.none, styleSetup.m_active[i % 2]);
                 *      GUI.Label(textRect, enumInfos[i].name, styleSetup.m_item_text);
                 *  }
                 *  lineRect.x = oldX;
                 *  lineRect.width = oldWidth;
                 *  lineRect.y -= lineRect.height;
                 *  boxRect.x = oldX + margin2.x;
                 *  boxRect.y -= lineRect.height;
                 *  textRect.x = oldX + boxRect.width + margin2.x * 2;
                 *  textRect.y -= lineRect.height;
                 * }
                 *
                 #endregion Draw lines
                 */
            }
            EditorGUILayout.EndScrollView();
            //m_enum_data.Sort((a, b) =>
            //{
            //    if (a.value == DebugDisplayType.OVERRIDE_DEACTIVATE_ALL)
            //        return -1;
            //    if (b.value == DebugDisplayType.OVERRIDE_DEACTIVATE_ALL)
            //        return 1;
            //    return String.Compare(a.name, b.name);
            //});

            return;

            /*
             *
             *
             * //DEBUG DISPLAY -----------------------------------------------------------------------
             *
             * //var colors = new Color[enumValues.Length];
             * //colors[(int)DebugType.Raycast]      = new Color(1, 1, 1, 1);
             * //colors[(int)DebugType.Navigation]   = new Color(1, 1, 1, 1);
             * //colors[(int)DebugType.Effects]      = new Color(1, 1, 1, 1);
             * //colors[(int)DebugType.Electricity]  = new Color(1, 1, 1, 1);
             * //colors[(int)DebugType.Robots]       = new Color(1, 1, 1, 1);
             * //colors[(int)DebugType.Ash]          = new Color(1, 1, 1, 1);
             * //colors[(int)DebugType.Physic]       = new Color(1, 1, 1, 1);
             *
             * m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, false, true);
             *
             * GUILayout.BeginHorizontal();
             * var backupColor = GUI.color;
             * GUI.color = new Color(0.8f, 1.0f, 0.8f, 1.0f);
             * EditorGUILayout.LabelField(new GUIContent("A", "On All Objects"), GUILayout.Width(12));
             *
             * GUI.color = new Color(0.8f, 1.0f, 0.8f, 1.0f);
             * EditorGUILayout.LabelField(new GUIContent("S", "On Selected Objects"), GUILayout.Width(12));
             *
             * GUI.color = backupColor;
             * EditorGUILayout.Space();
             * GUILayout.Label("Duration", GUILayout.Width(60));
             * var oldDuration = 0; //TODO DebugDisplay.Duration;
             * var newDuration = EditorGUILayout.FloatField(GUIContent.none, oldDuration, GUILayout.Width(30));
             * if (newDuration != oldDuration)
             * {
             *  //TODO DebugDisplay.Duration = newDuration;
             * }
             * GUILayout.EndHorizontal();
             *
             * bool valueChanged = false;
             * foreach (var d in m_enum_data)
             * {
             *  var debugType = d.value;
             *
             *  GUILayout.BeginHorizontal();
             *
             *  var oldValue = false;
             *  var newValue = false;
             *
             *  //oldValue = DebugDisplay.IsUnselectedActive(debugType);
             *  //GUI.color = new Color(0.8f, 0.8f, 0.8f, 1.0f);
             *  //newValue = EditorGUILayout.Toggle(oldValue, GUILayout.Width(12));
             *  //if (oldValue != newValue)
             *  //{
             *  //    valueChanged = true;
             *  //    DebugDisplay.SetActive(debugType, false, newValue);
             *  //}
             *
             *  oldValue = DebugDisplay.IsActive(debugType);
             *  GUI.color = new Color(0.8f, 1.0f, 0.8f, 1.0f);
             *  newValue = EditorGUILayout.Toggle(oldValue, GUILayout.Width(12));
             *  GUI.color =  backupColor;
             *
             *  if (oldValue != newValue)
             *  {
             *      valueChanged = true;
             *      DebugDisplay.SetActive(debugType, newValue);
             *  }
             *
             *  GUILayout.Label(d.name);
             *
             *  GUILayout.EndHorizontal();
             * }
             *
             * if (valueChanged)
             * {
             *  SceneView.RepaintAll();
             * }
             *
             * GUILayout.EndScrollView();
             */
        }