public override bool ProcessEvents(Event aEvent, AntAIWorkbench aWorkbench)
        {
            switch (aEvent.type)
            {
            case EventType.MouseDown:
                if (aEvent.button == 0)
                {
                    if (rect.Contains(aEvent.mousePosition))
                    {
                        isDragged    = true;
                        GUI.changed  = true;
                        isSelected   = true;
                        currentStyle = (_goal.isDefault)
                                                                ? _activeDefaultStyle
                                                                : selectedStyle;
                    }
                    else
                    {
                        GUI.changed  = true;
                        isSelected   = false;
                        currentStyle = (_goal.isDefault)
                                                                ? _defaultStyle
                                                                : normalStyle;
                    }
                }

                if (aEvent.button == 1 && isSelected &&
                    rect.Contains(aEvent.mousePosition))
                {
                    ProcessContextMenu();
                    aEvent.Use();
                }
                break;

            case EventType.MouseUp:
                if (isDragged && aWorkbench.IsAlignToGrid)
                {
                    var dx = Mathf.Floor((rect.x - aWorkbench.Offset.x) / 20.0f);
                    var dy = Mathf.Floor((rect.y - aWorkbench.Offset.y) / 20.0f);
                    rect.x = aWorkbench.Offset.x + dx * 20.0f;
                    rect.y = aWorkbench.Offset.y + dy * 20.0f;
                    aWorkbench.Repaint();
                    _goal.position = rect.position;
                    EditorUtility.SetDirty(_scenario);
                }
                isDragged = false;
                break;

            case EventType.MouseDrag:
                if (aEvent.button == 0 && isDragged)
                {
                    Drag(aEvent.delta);
                    aEvent.Use();
                    return(true);
                }
                break;
            }
            return(false);
        }
 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();
     if (GUILayout.Button("Open AI Workbench", GUILayout.MinHeight(40.0f)))
     {
         AntAIWorkbench.OpenScenario(target.name);
     }
 }
        public virtual bool ProcessEvents(Event aEvent, AntAIWorkbench aWorkbench)
        {
            switch (aEvent.type)
            {
            case EventType.MouseDown:
                if (aEvent.button == 0)
                {
                    if (rect.Contains(aEvent.mousePosition))
                    {
                        isDragged    = true;
                        GUI.changed  = true;
                        isSelected   = true;
                        currentStyle = selectedStyle;
                    }
                    else
                    {
                        GUI.changed  = true;
                        isSelected   = false;
                        currentStyle = normalStyle;
                    }
                }

                if (aEvent.button == 1 && isSelected &&
                    rect.Contains(aEvent.mousePosition))
                {
                    ProcessContextMenu();
                    aEvent.Use();
                }
                break;

            case EventType.MouseUp:
                if (isDragged && aWorkbench.IsAlignToGrid)
                {
                    var dx = Mathf.Floor((rect.x - aWorkbench.Offset.x) / 20.0f);
                    var dy = Mathf.Floor((rect.y - aWorkbench.Offset.y) / 20.0f);
                    rect.x = aWorkbench.Offset.x + dx * 20.0f;
                    rect.y = aWorkbench.Offset.y + dy * 20.0f;
                    aWorkbench.Repaint();
                }
                isDragged = false;
                break;

            case EventType.MouseDrag:
                if (aEvent.button == 0 && isDragged)
                {
                    Drag(aEvent.delta);
                    aEvent.Use();
                    return(true);
                }
                break;
            }
            return(false);
        }
Beispiel #4
0
        public override void Draw()
        {
            rect.height = (_items.Count > 0)
                                ? LINE_HEIGHT * _items.Count
                                : LINE_HEIGHT;
            rect.height += 52.0f;
            GUI.Box(rect, "", currentStyle);

            // Title
            GUI.Label(new Rect(rect.x + 12.0f, rect.y + 12.0f, rect.y + 12.0f, rect.width - 24.0f), title, _titleStyle);

            content.x      = rect.x + 7.0f;
            content.y      = rect.y + 30.0f;
            content.width  = rect.width - 14.0f;
            content.height = rect.height - 50.0f;
            GUI.Box(content, "", _bodyStyle);

#if UNITY_2019_3_OR_NEWER
            content.y += 3.0f;
#else
            content.y += 1.0f;
#endif

            content.height = (_items.Count > 0)
                                ? LINE_HEIGHT * _items.Count
                                : LINE_HEIGHT;

            var c = GUI.color;
            GUILayout.BeginArea(content);
            {
                EditorGUIUtility.labelWidth = 80.0f;
                if (_items.Count > 0)
                {
                    GUILayout.BeginVertical();
                    {
                        for (int i = 0, n = _items.Count; i < n; i++)
                        {
#if UNITY_2019_3_OR_NEWER
                            GUILayout.BeginHorizontal();
#else
                            GUILayout.BeginHorizontal("Icon.ClipSelected");
#endif
                            {
                                GUILayout.Space(4.0f);
                                GUI.color = c * ((_items[i].value)
                                                                        ? new Color(0.5f, 1.0f, 0.5f) // green
                                                                        : new Color(1.0f, 0.5f, 0.5f) // red
                                                 );

                                GUILayout.Button(AntAIWorkbench.BoolToStr(_items[i].value), _badgeStyle, GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f));
                                GUI.color = c;

                                if (_items[i].isChanged)
                                {
#if UNITY_2019_3_OR_NEWER
                                    GUILayout.Label(string.Concat("▶ ", _items[i].name), _boldLabelStyle);
#else
                                    GUILayout.Label(string.Concat("▶ ", _items[i].name));
#endif
                                    GUILayout.FlexibleSpace();
                                    GUILayout.BeginVertical();
                                    {
                                        GUILayout.Space(2.0f);
                                        GUILayout.Label((_items[i].value) ? "YES" : "NO", GUI.skin.FindStyle("AssetLabel"));
                                    }
                                    GUILayout.EndVertical();
                                }
                                else
                                {
#if UNITY_2019_3_OR_NEWER
                                    GUILayout.Label(_items[i].name, _labelStyle);
#else
                                    GUILayout.Label(_items[i].name);
#endif
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndVertical();
                }
                else
                {
                    GUILayout.Label("<No Coditions>", EditorStyles.centeredGreyMiniLabel);
                }
            }
            GUILayout.EndArea();
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (Application.isPlaying)
            {
                var c = GUI.color;

                // 1. Show our active goal.
                // ------------------------
#if UNITY_2018_3_OR_NEWER
                _isGoal = EditorGUILayout.BeginFoldoutHeaderGroup(_isGoal, "Goal");
#else
                _isGoal = EditorGUILayout.Foldout(_isGoal, "Goal");
#endif
                if (_isGoal)
                {
                    for (int i = 0; i < AntAIPlanner.MAX_ATOMS; i++)
                    {
                        if (_self.Goal.GetMask(i))
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                GUILayout.Space(4.0f);
                                GUI.color = c * ((_self.Goal.GetValue(i))
                                                                        ? new Color(0.5f, 1.0f, 0.5f) // green
                                                                        : new Color(1.0f, 0.5f, 0.5f) // red
                                                 );
                                GUILayout.Button(AntAIWorkbench.BoolToStr(_self.Goal.GetValue(i)), "CN CountBadge", GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f));
                                EditorGUILayout.LabelField(_self.planner.atoms[i]);
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
#if UNITY_2018_3_OR_NEWER
                EditorGUILayout.EndFoldoutHeaderGroup();
#endif
                GUI.color = c;

                // 2. Show current world state.
                // ----------------------------
#if UNITY_2018_3_OR_NEWER
                _isWorldState = EditorGUILayout.BeginFoldoutHeaderGroup(_isWorldState, "World State");
#else
                _isWorldState = EditorGUILayout.Foldout(_isWorldState, "World State");
#endif
                if (_isWorldState)
                {
                    for (int i = 0; i < AntAIPlanner.MAX_ATOMS; i++)
                    {
                        if (_self.worldState.GetMask(i))
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                GUILayout.Space(4.0f);
                                GUI.color = c * ((_self.worldState.GetValue(i))
                                                                        ? new Color(0.5f, 1.0f, 0.5f) // green
                                                                        : new Color(1.0f, 0.5f, 0.5f) // red
                                                 );
                                GUILayout.Button(AntAIWorkbench.BoolToStr(_self.worldState.GetValue(i)), "CN CountBadge", GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f));
                                EditorGUILayout.LabelField(string.Concat(_self.planner.atoms[i]));
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
#if UNITY_2018_3_OR_NEWER
                EditorGUILayout.EndFoldoutHeaderGroup();
#endif
                GUI.color = c;

                // 3. Show current plan.
                // ---------------------
                // GUI.color = c * ((_self.currentPlan.isSuccess)
                //  ? new Color(0.5f, 1.0f, 0.5f) // green
                //  : new Color(1.0f, 0.5f, 0.5f) // red
                // );

                var planSuccess = (_self.currentPlan.isSuccess)
                                        ? "Plan (Status: Success)"
                                        : "Plan (Status: Failed)";

#if UNITY_2018_3_OR_NEWER
                _isPlan = EditorGUILayout.BeginFoldoutHeaderGroup(_isPlan, planSuccess);
#else
                _isPlan = EditorGUILayout.Foldout(_isPlan, planSuccess);
#endif
                if (_isPlan)
                {
                    string value = string.Empty;
                    for (int i = 0; i < _self.currentPlan.Count; i++)
                    {
                        if (_self.worldState.GetMask(i))
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                GUILayout.Space(4.0f);
                                value = string.Concat((i + 1).ToString(), ". ", _self.currentPlan[i]);
                                if (i == 0)
                                {
                                    EditorGUILayout.LabelField(value, EditorStyles.boldLabel);
                                }
                                else
                                {
                                    EditorGUILayout.LabelField(value);
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
#if UNITY_2018_3_OR_NEWER
                EditorGUILayout.EndFoldoutHeaderGroup();
#endif
                GUI.color = c;
            }
        }
        private void DrawConditionList(string aLabel, ref AntAIScenarioItem[] aConditions, ConditionKind aConditionKind)
        {
            GUILayout.BeginVertical();
            {
                var c = GUI.color;
                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(aLabel, EditorStyles.boldLabel);
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("", "OL Plus"))
                    {
                        var menu = new GenericMenu();
                        for (int i = 0, n = _scenario.conditions.list.Length; i < n; i++)
                        {
                            switch (aConditionKind)
                            {
                            case ConditionKind.Pre:
                                menu.AddItem(new GUIContent(_scenario.conditions.list[i].name), false, OnAddPreCondition, _scenario.conditions.list[i].name);
                                break;

                            case ConditionKind.Post:
                                menu.AddItem(new GUIContent(_scenario.conditions.list[i].name), false, OnAddPostCondition, _scenario.conditions.list[i].name);
                                break;
                            }
                        }
                        menu.ShowAsContext();
                    }
                }
                GUILayout.EndHorizontal();

                if (aConditions.Length == 0)
                {
                    GUILayout.Label("<Empty>", EditorStyles.centeredGreyMiniLabel);
                }
                else
                {
                    int delIndex = -1;
                    for (int i = 0, n = aConditions.Length; i < n; i++)
                    {
#if UNITY_2019_3_OR_NEWER
                        GUILayout.BeginHorizontal();
#else
                        GUILayout.BeginHorizontal("Icon.ClipSelected");
#endif
                        {
                            GUILayout.Space(4.0f);
                            GUI.color = c * ((aConditions[i].value)
                                                                ? new Color(0.5f, 1.0f, 0.5f) // green
                                                                : new Color(1.0f, 0.5f, 0.5f) // red
                                             );

                            if (GUILayout.Button(AntAIWorkbench.BoolToStr(aConditions[i].value), _badgeStyle, GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f)))
                            {
                                aConditions[i].value = !aConditions[i].value;
                            }

#if UNITY_2019_3_OR_NEWER
                            GUILayout.Label(_scenario.conditions.GetName(aConditions[i].id), _labelStyle);
#else
                            GUILayout.Label(_scenario.conditions.GetName(aConditions[i].id));
#endif
                            GUI.color = c;
                            if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(18.0f), GUILayout.MaxHeight(18.0f)))
                            {
                                delIndex = i;
                            }
                        }
                        GUILayout.EndHorizontal();
                    }

                    if (delIndex > -1)
                    {
                        AntArray.RemoveAt(ref aConditions, delIndex);
                    }
                }
            }
            GUILayout.EndVertical();
        }
        public override void Draw()
        {
            if (_scenario == null)
            {
                return;
            }

            rect.height = (_worldState.list.Length > 0)
                                ? LINE_HEIGHT * _worldState.list.Length
                                : LINE_HEIGHT;
            rect.height += 52.0f;
            GUI.Box(rect, "", currentStyle);

            // Title
            GUI.Label(new Rect(rect.x + 12.0f, rect.y + 12.0f, rect.y + 12.0f, rect.width - 24.0f), title, _titleStyle);

            content.x      = rect.x + 7.0f;
            content.y      = rect.y + 30.0f;
            content.width  = rect.width - 14.0f;
            content.height = rect.height - 50.0f;
            GUI.Box(content, "", _bodyStyle);

            var r = new Rect(rect.x + rect.width - 25.0f, rect.y + 11.0f, 20.0f, 44.0f);

            EditorGUI.BeginChangeCheck();
            GUILayout.BeginArea(r);
            if (GUILayout.Button("", "OL Plus", GUILayout.MaxWidth(16.0f), GUILayout.MaxHeight(16.0f)))
            {
                var menu = new GenericMenu();
                for (int i = 0, n = _scenario.conditions.list.Length; i < n; i++)
                {
                    menu.AddItem(new GUIContent(_scenario.conditions.list[i].name), false, AddConditionHandler, _scenario.conditions.list[i].name);
                }

                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Add All"), false, AddAllConditionsHandler, "Add All");
                menu.ShowAsContext();
            }
            GUILayout.EndArea();

#if UNITY_2019_3_OR_NEWER
            content.y += 3.0f;
#else
            content.y += 1.0f;
#endif

            content.height = (_worldState.list.Length > 0)
                                ? LINE_HEIGHT * _worldState.list.Length
                                : LINE_HEIGHT;

            var c = GUI.color;
            GUILayout.BeginArea(content);
            {
                EditorGUIUtility.labelWidth = 80.0f;
                if (_worldState.list.Length > 0)
                {
                    int delIndex = -1;
                    GUILayout.BeginVertical();
                    {
                        for (int i = 0, n = _worldState.list.Length; i < n; i++)
                        {
#if UNITY_2019_3_OR_NEWER
                            GUILayout.BeginHorizontal();
#else
                            GUILayout.BeginHorizontal("Icon.ClipSelected");
#endif
                            {
                                GUILayout.Space(4.0f);
                                GUI.color = c * ((_worldState.list[i].value)
                                                                        ? new Color(0.5f, 1.0f, 0.5f) // Green
                                                                        : new Color(1.0f, 0.5f, 0.5f) // Red
                                                 );

                                if (GUILayout.Button(AntAIWorkbench.BoolToStr(_worldState.list[i].value), _badgeStyle, GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f)))
                                {
                                    _worldState.list[i].value = !_worldState.list[i].value;
                                }

#if UNITY_2019_3_OR_NEWER
                                GUILayout.Label(_scenario.conditions.GetName(_worldState.list[i].id), _labelStyle);
#else
                                GUILayout.Label(_scenario.conditions.GetName(_worldState.list[i].id));
#endif
                                GUI.color = c;
                                if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(18.0f), GUILayout.MaxHeight(18.0f)))
                                {
                                    delIndex = i;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndVertical();

                    if (delIndex > -1)
                    {
                        AntArray.RemoveAt(ref _worldState.list, delIndex);
                    }
                }
                else
                {
                    GUILayout.Label("<No Coditions>", EditorStyles.centeredGreyMiniLabel);
                }
            }
            GUILayout.EndArea();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(_scenario);
            }
        }