コード例 #1
0
        public override void OnInspectorGUI()
        {
            AgentProperties myTarget = (AgentProperties)target;

            if (myTarget == null)
            {
                return;
            }

            float currentLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 130;

            UITools.Line();
            generalTab = EditorGUILayout.Foldout(generalTab, generalTabContent);
            if (generalTab)
            {
                Rect rect = EditorGUILayout.GetControlRect(false, 100);
                //GUI.Box(rect, string.Empty);

                #region nice drawing
                float   rectHeight        = rect.height * 0.7f;
                float   rectheightHalf    = rectHeight * 0.5f;
                float   rectheightQuarter = rectheightHalf * 0.5f;
                Vector2 rectCenter        = rect.center;

                float agentWidth = (radius.floatValue / height.floatValue) * rectHeight * 0.8f;

                Vector2 leftBottom  = new Vector2(rectCenter.x + agentWidth + rectheightQuarter, rectCenter.y + rectheightHalf);
                Vector2 rightBotton = new Vector2(rectCenter.x - agentWidth - rectheightQuarter, rectCenter.y + rectheightHalf);

                Handles.color = Color.black;

                float   slope       = maxSlope.floatValue;
                Vector2 slopeVector = new Vector2(
                    (float)Math.Cos(slope * Math.PI / 180) * (rectHeight * 0.9f),
                    (float)Math.Sin(slope * Math.PI / 180) * (rectHeight * 0.9f));

                slopeVector = new Vector2(-slopeVector.x, slopeVector.y);


                GUI.Label(new Rect((leftBottom - (slopeVector * 0.15f)) - (new Vector2(0, 15)), new Vector2(100, 20)), string.Format("Slope {0}", maxSlope.floatValue));


                float stepHeight = (maxStepHeight.floatValue / height.floatValue) * rectHeight;

                Handles.DrawAAPolyLine(
                    3,
                    leftBottom - slopeVector,
                    leftBottom,
                    rightBotton,
                    rightBotton - new Vector2(0, stepHeight),
                    rightBotton - new Vector2(50, stepHeight));

                GUI.Label(new Rect(rightBotton - new Vector2(50, stepHeight + 20), new Vector2(100, 20)), string.Format("Step {0}", maxStepHeight.floatValue));

                //Vector2 leftStart = rectCenter - new Vector2(rectheightQuarter, rectheightQuarter);
                //Vector2 leftUp = leftStart + new Vector2(0, rectheightHalf);

                Color hColor = Handles.color;
                Handles.color = Color.black;

                Color niceColor = new Color(135f / 255f, 206f / 255f, 250f / 255f, 1f);

                Handles.color = niceColor;
                Handles.DrawSolidDisc(new Vector2(rectCenter.x, rectCenter.y - rectheightHalf), new Vector3(0f, -1f, 0.5f), agentWidth);
                Handles.DrawSolidDisc(new Vector2(rectCenter.x, rectCenter.y + rectheightHalf), new Vector3(0f, 1f, 0.5f), agentWidth);
                EditorGUI.DrawRect(new Rect(
                                       rectCenter.x - agentWidth,
                                       rectCenter.y - rectheightHalf,
                                       agentWidth + agentWidth,
                                       rectheightHalf * 2), niceColor);

                Vector2 rectCenterSlightlyOffseted = new Vector2(rectCenter.x - 0.5f, rectCenter.y);

                textFieldStyles.normal.textColor = Color.red;
                GUI.Label(new Rect(rectCenter.x + agentWidth, rectCenter.y, 100, 20), string.Format("Radius {0}", radius.floatValue), textFieldStyles);

                textFieldStyles.normal.textColor = Color.blue;
                GUI.Label(new Rect(rectCenter.x + agentWidth, rectCenter.y - rectheightHalf, 100, 20), string.Format("Height {0}", height.floatValue), textFieldStyles);

                //outlines
                Handles.color = Color.black;
                Handles.DrawWireDisc(new Vector2(rectCenterSlightlyOffseted.x, rectCenterSlightlyOffseted.y - rectheightHalf), new Vector3(0f, 1f, 0.5f), agentWidth);
                Handles.DrawWireDisc(new Vector2(rectCenterSlightlyOffseted.x, rectCenterSlightlyOffseted.y - rectheightHalf), new Vector3(0f, -1f, 0.5f), agentWidth);
                Handles.DrawWireDisc(new Vector2(rectCenterSlightlyOffseted.x, rectCenterSlightlyOffseted.y + rectheightHalf), new Vector3(0f, 1f, 0.5f), agentWidth);

                Handles.DrawLine(
                    new Vector2(rectCenterSlightlyOffseted.x - agentWidth, rectCenterSlightlyOffseted.y - rectheightHalf),
                    new Vector2(rectCenterSlightlyOffseted.x - agentWidth, rectCenterSlightlyOffseted.y + rectheightHalf));

                Handles.DrawLine(
                    new Vector2(rectCenterSlightlyOffseted.x + agentWidth, rectCenterSlightlyOffseted.y - rectheightHalf),
                    new Vector2(rectCenterSlightlyOffseted.x + agentWidth, rectCenterSlightlyOffseted.y + rectheightHalf));


                Handles.color = Color.red;
                Handles.DrawWireDisc(rectCenterSlightlyOffseted, new Vector3(0f, 1f, 0.5f), agentWidth);
                Handles.DrawWireDisc(rectCenterSlightlyOffseted + Vector2.up, new Vector3(0f, 1f, 0.5f), agentWidth);
                Handles.DrawWireDisc(rectCenterSlightlyOffseted + Vector2.down, new Vector3(0f, 1f, 0.5f), agentWidth);

                Handles.color = hColor;
                #endregion

                EditorGUILayout.PropertyField(radius, radiusContent);
                EditorGUILayout.PropertyField(height, heightContent);
                EditorGUILayout.PropertyField(maxSlope, maxSlopeContent);
                EditorGUILayout.PropertyField(maxStepHeight, maxStepHeightContent);
                EditorGUILayout.PropertyField(includedLayers, includedLayersContent);
                EditorGUILayout.PropertyField(ignoredTags, ignoredTagsContent, true);
                if (ignoredTags.arraySize > 0)
                {
                    EditorGUILayout.PropertyField(checkHierarchyTag, checkHierarchyTagContent);
                }

                if (maxStepHeight.floatValue > height.floatValue)
                {
                    maxStepHeight.floatValue = height.floatValue;
                }

                if (canCrouch.boolValue && maxStepHeight.floatValue > crouchHeight.floatValue)
                {
                    maxStepHeight.floatValue = crouchHeight.floatValue;
                }

                if (radius.floatValue < 0.001f)
                {
                    radius.floatValue = 0.001f;
                }

                if (height.floatValue < 0.001f)
                {
                    height.floatValue = 0.001f;
                }

                if (maxStepHeight.floatValue < 0.001f)
                {
                    maxStepHeight.floatValue = 0.001f;
                }

                if (includedLayers.intValue == 0)    //big warning in case no layers sellected
                {
                    rect = EditorGUILayout.GetControlRect(false, 30);
                    Color gColor = GUI.color;
                    GUI.color = Color.red;
                    GUI.Box(rect, new GUIContent("No layers sellected", "Sellect at least something in included Layers"));
                    GUI.color = gColor;
                }

                if (maxStepHeight.floatValue < (PathFinder.gridSize / myTarget.voxelsPerChunk))    //big warning in case no layers sellected
                {
                    rect = EditorGUILayout.GetControlRect(false, 30);
                    Color gColor = GUI.color;
                    GUI.color = Color.yellow;
                    GUI.Box(rect, new GUIContent("Step height is very low", "Agent probably will have incorrect navmesh generation if it that low. Recomend at least greater than voxel size"));
                    GUI.color = gColor;
                }
            }

            UITools.Line();

            voxelTab = EditorGUILayout.Foldout(voxelTab, voxelTabContent);

            if (voxelTab)
            {
                EditorGUILayout.PropertyField(voxelsPerChunk, voxelsPerChunkContent);

                float foxelSize = PathFinder.gridSize / myTarget.voxelsPerChunk;
                EditorGUILayout.LabelField("Voxel Size", foxelSize.ToString());

                EditorGUILayout.LabelField("Voxel Per Radius", ((int)(myTarget.radius / foxelSize)).ToString());

                GUILayout.BeginHorizontal();
                setThisMuch = EditorGUILayout.IntField(setThisMuch, GUILayout.MaxWidth(100));
                if (GUILayout.Button("Set this much"))
                {
                    voxelsPerChunk.intValue = Mathf.CeilToInt(PathFinder.gridSize / (myTarget.radius / setThisMuch));
                }

                if (voxelsPerChunk.intValue < setThisMuch)
                {
                    voxelsPerChunk.intValue = voxelsPerChunk.intValue + 1;
                }

                GUILayout.EndHorizontal();

                if (voxelsPerChunk.intValue < 10)
                {
                    voxelsPerChunk.intValue = 10;
                }

                if ((int)(myTarget.radius / foxelSize) <= 0)    //big warning in case no layers sellected
                {
                    Rect  rect   = EditorGUILayout.GetControlRect(false, 30);
                    Color gColor = GUI.color;
                    GUI.color = Color.red;
                    GUI.Box(rect, new GUIContent("Voxel per radius is 0", "Increase amount of voxels per radius. Recomend at least 2"));
                    GUI.color = gColor;
                }
            }

            UITools.Line();

            movementTab = EditorGUILayout.Foldout(movementTab, movementTabContent);
            if (movementTab)
            {
                EditorGUILayout.PropertyField(doNavMesh, doNavMeshContent);
                if (doNavMesh.boolValue)
                {
                    EditorGUILayout.PropertyField(walkMod, walkModContent);
                    EditorGUILayout.PropertyField(canCrouch, canCrouchContent);

                    if (canCrouch.boolValue)
                    {
                        EditorGUILayout.PropertyField(crouchHeight, crouchHeightContent);
                        EditorGUILayout.PropertyField(crouchMod, crouchModContent);

                        if (crouchHeight.floatValue < 0)
                        {
                            crouchHeight.floatValue = 0;
                        }

                        if (crouchHeight.floatValue > height.floatValue)
                        {
                            crouchHeight.floatValue = height.floatValue;
                        }
                    }

                    EditorGUILayout.PropertyField(canJump, canJumpContent);

                    if (canJump.boolValue)
                    {
                        EditorGUILayout.PropertyField(JumpDown, JumpDownContent);
                        EditorGUILayout.PropertyField(jumpDownMod, jumpDownModContent);
                        EditorGUILayout.PropertyField(JumpUp, JumpUpContent);
                        EditorGUILayout.PropertyField(jumpUpMod, jumpUpModContent);
                    }
                }
            }

            UITools.Line();
            coverTab = EditorGUILayout.Foldout(coverTab, coverTabContent);
            if (coverTab)
            {
                EditorGUILayout.PropertyField(canCover, canCoverContent);
                if (canCover.boolValue)
                {
                    EditorGUILayout.PropertyField(fullCover, fullCoverContent);
                    if (fullCover.floatValue < 0)
                    {
                        fullCover.floatValue = 0;
                    }

                    EditorGUILayout.PropertyField(canHalfCover, canHalfCoverContent);

                    if (canHalfCover.boolValue)
                    {
                        EditorGUILayout.PropertyField(halfCover, halfCoverContent);

                        halfCover.floatValue = SomeMath.Clamp(0, fullCover.floatValue, halfCover.floatValue);

                        if (fullCover.floatValue < halfCover.floatValue)
                        {
                            fullCover.floatValue = halfCover.floatValue;
                        }
                    }

                    EditorGUILayout.PropertyField(coverExtraSamples, coverExtraSamplesContent);
                    if (coverExtraSamples.intValue < 0)
                    {
                        coverExtraSamples.intValue = 0;
                    }
                }
            }

            UITools.Line();

            battleGridTab = EditorGUILayout.Foldout(battleGridTab, battleGridTabContent);
            if (battleGridTab)
            {
                EditorGUILayout.PropertyField(battleGrid, battleGridContent);
                if (battleGrid.boolValue)
                {
                    EditorGUILayout.PropertyField(battleGridDensity, battleGridDensityContent);
                }
            }

            UITools.Line();

            otherTab = EditorGUILayout.Foldout(otherTab, otherTabContent);
            if (otherTab)
            {
                EditorGUILayout.PropertyField(offsetMultiplier, offsetMultiplierContent);
            }

            EditorGUIUtility.labelWidth = currentLabelWidth;
            serializedObject.ApplyModifiedProperties();
        }
コード例 #2
0
        public void DrawAreaEditor()
        {
            settings.drawAreaEditor = EditorGUILayout.Foldout(settings.drawAreaEditor, "Area Editor");

            if (!settings.drawAreaEditor)
            {
                return;
            }

            if (GUILayout.Button("Add Area"))
            {
                settings.AddArea();
            }

            for (int i = 0; i < settings.areaLibrary.Count; i++)
            {
                bool remove = false;
                Area area   = settings.areaLibrary[i];

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(area.id.ToString(), GUILayout.MaxWidth(10f));
                if (area.id == 0 || area.id == 1)  //cant choose name to default areas to avoit confussion
                {
                    EditorGUILayout.LabelField(new GUIContent(area.name, "area name"), GUILayout.MaxWidth(80));
                }
                else
                {
                    area.name = EditorGUILayout.TextField(area.name, GUILayout.MaxWidth(80));
                }

                area.color = EditorGUILayout.ColorField(GUIContent.none, area.color, false, false, false, GUILayout.MaxWidth(12f));

                EditorGUILayout.LabelField(new GUIContent("Cost", "move cost"), GUILayout.MaxWidth(30));

                if (area.id == 1)
                {
                    EditorGUILayout.LabelField("max", GUILayout.MaxWidth(30f));
                }
                else
                {
                    area.cost = EditorGUILayout.FloatField(area.cost, GUILayout.MaxWidth(30f));
                }


                EditorGUILayout.LabelField(new GUIContent("Priority", "z-fighting cure. if one layer on another than this number matter"), GUILayout.MaxWidth(45f));

                if (area.id == 1)
                {
                    EditorGUILayout.LabelField(new GUIContent("-1", "clear area it always should be -1"), GUILayout.MaxWidth(30f));
                }
                else
                {
                    area.overridePriority = EditorGUILayout.IntField(area.overridePriority, GUILayout.MaxWidth(30f));
                    if (area.overridePriority < 0)
                    {
                        area.overridePriority = 0;
                    }
                }

                if (area.id != 0 && area.id != 1)
                {
                    remove = GUILayout.Button("X", GUILayout.MaxWidth(18f));
                }

                EditorGUILayout.EndHorizontal();

                if (remove)
                {
                    settings.RemoveArea(i);
                    break;
                }
            }
            UITools.Line();
            settings.drawUnityAssociations = EditorGUILayout.Foldout(settings.drawUnityAssociations, "Tag Associations");

            if (settings.drawUnityAssociations)
            {
                settings.checkRootTag = EditorGUILayout.ToggleLeft("Use Root Tag", settings.checkRootTag);

                settings.CheckTagAssociations();

                TextAnchor curAnchor = GUI.skin.box.alignment;
                GUI.skin.box.alignment = TextAnchor.MiddleLeft;
                Color curColor = GUI.color;
                foreach (var pair in PathFinderSettings.tagAssociations)
                {
                    EditorGUILayout.BeginHorizontal();

                    GUILayout.Box(pair.Key, GUILayout.ExpandWidth(true), GUILayout.MaxWidth(EditorGUIUtility.labelWidth));
                    GUI.color = settings.areaLibrary[pair.Value.id].color;
                    GUILayout.Box(string.Empty, GUILayout.MaxWidth(15));
                    GUI.color = curColor;

                    EditorGUI.BeginChangeCheck();
                    int tempValue = EditorGUILayout.IntPopup(
                        pair.Value.id, PathFinder.settings.areaNames, PathFinder.settings.areaIDs);
                    if (EditorGUI.EndChangeCheck())
                    {
                        PathFinderSettings.tagAssociations[pair.Key] = settings.areaLibrary[tempValue];
                    }
                    EditorGUILayout.EndHorizontal();
                }
                GUI.color = curColor;
                GUI.skin.box.alignment = curAnchor;
            }
        }