public static void CellTester(Vector3 origin, AgentProperties properties)
        {
            Graph graph;

            if (TryGetGraph(ToChunkPosition(origin), properties, out graph) == false || graph.canBeUsed == false)
            {
                return;
            }

            Cell    cell;
            bool    outsideCell;
            Vector3 closestPosToCell;

            graph.GetClosestCell(origin, out cell, out outsideCell, out closestPosToCell);

            foreach (var pair in cell.dataContentPairs)
            {
                Debuger_K.AddLine(pair.Key, Color.magenta);

                if (pair.Value == null)
                {
                    continue;
                }

                Cell connection = pair.Value.connection;
                Debuger_K.AddLabel(pair.Key.centerV3, connection.Contains(pair.Key));
            }
        }
 public static void RemoveGraph(AgentProperties properties, bool createNewGraphAfter = true, params Bounds[] bounds)
 {
     for (int i = 0; i < bounds.Length; i++)
     {
         RemoveGraph(bounds[i], properties, createNewGraphAfter);
     }
 }
        public static void QueueGraph(Bounds bounds, AgentProperties properties)
        {
            XZPosInt min = ToChunkPosition(bounds.min);
            XZPosInt max = ToChunkPosition(bounds.max);

            QueueGraph(min.x, min.z, properties, max.x - min.x + 1, max.z - min.z + 1);
        }
        public static SerializedNavmesh Serialize(AgentProperties properties)
        {
            NavmeshLayserSerializer serializer = new NavmeshLayserSerializer(_chunkData, _chunkRange, properties);
            SerializedNavmesh       result     = serializer.Serialize();

            result.pathFinderVersion = VERSION;
            return(result);
        }
示例#5
0
 public GeneralXZData(XZPosInt chunkPos, AgentProperties properties)
 {
     this.gridPosition = chunkPos;
     this.properties   = properties;
     if (properties == null)
     {
         throw new NullReferenceException("Agent properties can't be null when creating GeneralXZData");
     }
 }
        public static void RemoveGraph(Bounds bounds, AgentProperties properties, bool createNewGraphAfter = true)
        {
            float    offset   = properties.radius * properties.offsetMultiplier;
            Vector3  v3Offset = new Vector3(offset, 0, offset);
            XZPosInt min      = ToChunkPosition(bounds.min - v3Offset);
            XZPosInt max      = ToChunkPosition(bounds.max + v3Offset);

            VectorInt.Vector2Int size = new VectorInt.Vector2Int(Math.Max(1, max.x - min.x + 1), Math.Max(1, max.z - min.z + 1));
            RemoveGraph(min.x, min.z, properties, size.x, size.y, createNewGraphAfter);
        }
 public static void RemoveGraph(int x, int z, AgentProperties properties, int sizeX = 1, int sizeZ = 1, bool createNewGraphAfter = true)
 {
     for (int _x = 0; _x < sizeX; _x++)
     {
         for (int _z = 0; _z < sizeZ; _z++)
         {
             RemoveGraph(new XZPosInt(x + _x, z + _z), properties, createNewGraphAfter);
         }
     }
 }
        //generic version
        public static void Raycast(Vector3 origin, Vector3 direction, AgentProperties properties, out RaycastHitNavMesh hit,
                                   float length = 1000f, bool triggeredByPassabilityChange = true, bool triggeredByAreaChange = true, int maxIterations = 100)
        {
            //try get cell at target position
            Cell cell;
            bool outsideCell;

            if (TryGetCell(origin, properties, out cell, out outsideCell) == false || outsideCell)
            {
                hit = new RaycastHitNavMesh(origin, false);
                return;
            }

            Raycast(origin, direction, properties, out hit, length, triggeredByPassabilityChange, triggeredByAreaChange, maxIterations, cell.passability, cell.area, cell);
        }
        //try get Cell
        public static bool TryGetCell(Vector3 pos, AgentProperties properties, out Cell cell, out bool outsideCell, out Vector3 closestPoint)
        {
            Graph graph;

            if (TryGetGraph(ToChunkPosition(pos), properties, out graph))
            {
                graph.GetClosestCell(pos, out cell, out outsideCell, out closestPoint);
                return(true);
            }
            else
            {
                cell         = null;
                outsideCell  = false;
                closestPoint = Vector3.zero;
                return(false);
            }
        }
        //queue graph creation
        //functions to order navmesh at some space
        public static void QueueGraph(int x, int z, AgentProperties properties, int sizeX = 1, int sizeZ = 1)
        {
            Init();
            if (sizeX == 0 | sizeZ == 0)
            {
                Debug.LogWarning("you trying to create navmesh with zero size. are you mad?");
                return;
            }
            Graph graph;

            for (int _x = 0; _x < sizeX; _x++)
            {
                for (int _z = 0; _z < sizeZ; _z++)
                {
                    GetGraph(x + _x, z + _z, properties, out graph);
                }
            }
        }
        //remove graph
        //function to remove graph at some space
        //IMPORTANT: if bool createNewGraphAfter == true then pathfinder are also add this graph to generation queue after it was removed
        public static void RemoveGraph(XZPosInt pos, AgentProperties properties, bool createNewGraphAfter = true)
        {
            Init();

            if (_acceptingWork == false)
            {
                return;
            }

            lock (_allTemplatesDestructive) {
                if (_allTemplatesDestructive.Exists(x => x.Match(pos, properties)))
                {
                    return; //already in progress
                }
            }
            Graph graph;

            if (TryGetGraph(pos, properties, out graph))
            {
                TemplateChunkDisconnection template = new TemplateChunkDisconnection(graph);

                _allTemplatesDestructive.Add(template);

                template.SetCallBack(() => {
#if UNITY_EDITOR
                    Debuger_K.UpdateSceneImportantThings();
                    Debuger_K.ClearChunksDebug(pos.x, pos.z, properties);
#endif
                    lock (_chunkData) {
                        _chunkData.Remove(new GeneralXZData(pos, properties));
                    }
                    _allTemplatesDestructive.Remove(template);
                    if (createNewGraphAfter)
                    {
                        QueueNavMeshTemplateToPopulation(pos, properties);
                    }
                });

                _disconnectionQueue.Enqueue(template);
            }
        }
        //give me Graph
        public static bool GetGraph(XZPosInt pos, AgentProperties properties, out Graph graph)
        {
            Init();

            lock (_chunkData) {
                GeneralXZData key = new GeneralXZData(pos, properties);

                if (_chunkData.TryGetValue(key, out graph))
                {
                    return(true);
                }
                else
                {
                    if (AreTemplateInProcess(pos, properties) == false)
                    {
                        QueueNavMeshTemplateToPopulation(pos, properties);
                    }
                    return(false);
                }
            }
        }
        private static void QueueNavMeshTemplateToPopulation(XZPosInt pos, AgentProperties properties)
        {
            if (_acceptingWork == false)
            {
                return;
            }

            //Debug.Log("queue 1 " + pos);
            NavMeshTemplateRecast template = new NavMeshTemplateRecast(_chunkRange, pos, properties);

            Action <Graph> callBack = (Graph graph) => {
                //Debug.Log("callback 1 " + pos);
                QueueFinishGraphInMainThread(graph);
            };

            template.SetCallBack(callBack);
            _allTemplatesCreative[new GeneralXZData(pos, properties)] = template;

            lock (_navMeshTemplateQueue)
                _navMeshTemplateQueue.Enqueue(template);
        }
示例#14
0
        public static void Create()
        {
            string path = EditorUtility.SaveFilePanel("Create Agent Properties",
                                                      "Assets/" + PathFinderSettings.PROJECT_FOLDER + PathFinderSettings.PROPERTIES_FOLDER,
                                                      "AgentName Properties.asset",
                                                      "asset");

            if (path == "")
            {
                return;
            }

            path = FileUtil.GetProjectRelativePath(path);

            AgentProperties ap = CreateInstance <AgentProperties>();

            ap.includedLayers.value = 1;

            AssetDatabase.CreateAsset(ap, path);
            AssetDatabase.SaveAssets();
        }
        public static bool TryGetGraphFrom(XZPosInt pos, Directions direction, AgentProperties properties, out Graph graph)
        {
            switch (direction)
            {
            case Directions.xPlus:
                return(TryGetGraph(pos.x + 1, pos.z, properties, out graph));

            case Directions.xMinus:
                return(TryGetGraph(pos.x - 1, pos.z, properties, out graph));

            case Directions.zPlus:
                return(TryGetGraph(pos.x, pos.z + 1, properties, out graph));

            case Directions.zMinus:
                return(TryGetGraph(pos.x, pos.z - 1, properties, out graph));

            default:
                Debug.LogError("defaul direction are not exist");
                graph = null;
                return(false);
            }
        }
        //targeted by area and passability
        public static void Raycast(Vector3 origin, Vector3 direction, AgentProperties properties, out RaycastHitNavMesh hit,
                                   Area expectedArea, Passability expectedPassability,
                                   float length = 1000f, int maxIterations = 100)
        {
            //try get cell at target position
            Cell cell;
            bool outsideCell;

            if (TryGetCell(origin, properties, out cell, out outsideCell) == false || outsideCell)
            {
                hit = new RaycastHitNavMesh(origin, false);
                return;
            }

            //cell we found are not with expected area or passability
            if (cell.area != expectedArea | cell.passability != expectedPassability)
            {
                hit = new RaycastHitNavMesh(origin, true);
                return;
            }

            Raycast(origin, direction, properties, out hit, length, true, true, maxIterations, expectedPassability, expectedArea, cell);
        }
 public NavMeshTemplateDestruction(XZPosInt pos, AgentProperties properties, bool queueNewGraphAfter) : this(new GeneralXZData(pos, properties), properties)
 {
 }
 public bool Match(XZPosInt gridPosition, AgentProperties properties)
 {
     return(this.gridPosition == gridPosition && this.properties == properties);
 }
 public WorkTemplate(XZPosInt gridPosition, AgentProperties properties)
 {
     this.stop         = false;
     this.gridPosition = gridPosition;
     this.properties   = properties;
 }
        public static bool TryGetCell(Vector3 pos, AgentProperties properties, out Cell cell, out bool outsideCell)
        {
            Vector3 closestPoint;

            return(TryGetCell(pos, properties, out cell, out outsideCell, out closestPoint));
        }
 public NavMeshTemplateCreation(Dictionary <XZPosInt, YRangeInt> chunkRange, AreaPassabilityHashData hashData, XZPosInt gridPosition, AgentProperties properties)
 {
     this.gridPosition = gridPosition;
     this.hashData     = hashData;
     this.properties   = properties;
     this.chunkRange   = chunkRange;
 }
示例#22
0
        public override void OnInspectorGUI()
        {
            AgentProperties myTarget = (AgentProperties)target;

            if (myTarget == null)
            {
                return;
            }

            float currentLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 160f;

            var serializedObject       = new SerializedObject(myTarget);
            var tagsProperty           = serializedObject.FindProperty("ignoredTags");
            var includedLayersProperty = serializedObject.FindProperty("includedLayers");

            serializedObject.Update();

            myTarget.voxelsPerChunk = EditorGUILayout.IntField(new GUIContent("Voxel per chunk side", "amount of voxel per chunk side. voxel size are chunk size / this number"), myTarget.voxelsPerChunk);
            if (myTarget.voxelsPerChunk < 10)
            {
                myTarget.voxelsPerChunk = 10;
            }

            float foxelSize = PathFinder.gridSize / myTarget.voxelsPerChunk;

            EditorGUILayout.LabelField("Voxel Size", (foxelSize).ToString());

            myTarget.radius = EditorGUILayout.FloatField(new GUIContent("Radius", "agent radius in world space"), myTarget.radius);

            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"))
            {
                myTarget.voxelsPerChunk = Mathf.CeilToInt(PathFinder.gridSize / (myTarget.radius / setThisMuch));
            }
            GUILayout.EndHorizontal();

            GUILayout.Box(string.Empty, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
            myTarget.height   = EditorGUILayout.FloatField(new GUIContent("Height", "agent height in world space"), myTarget.height);
            myTarget.maxSlope = EditorGUILayout.FloatField(new GUIContent("Max slope", "maximum slope in degree"), myTarget.maxSlope);
            myTarget.maxSlope = Mathf.Clamp(myTarget.maxSlope, 0f, 89f);

            myTarget.maxStepHeight = EditorGUILayout.FloatField(new GUIContent("Step height", "maximum step peight in world space. describe how much height difference agent can handle while moving up and down"), myTarget.maxStepHeight);
            if (myTarget.maxStepHeight < 0f)
            {
                myTarget.maxStepHeight = 0f;
            }

            myTarget.offsetMultiplier = EditorGUILayout.Slider(new GUIContent("Offset multiplier", "In order chunk to be more precise pathfinder must  take into account nearby obstacles outside chunk. This value will tell how much area it should take into account. 1 = agent radius"), myTarget.offsetMultiplier, 0, 2);

            EditorGUILayout.PropertyField(tagsProperty, true);
            EditorGUILayout.PropertyField(includedLayersProperty, true);
            serializedObject.ApplyModifiedProperties();


            GUILayout.Box(string.Empty, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });

            myTarget.doNavMesh = EditorGUILayout.Toggle(new GUIContent("Do NavMesh", "do NavMesh at all. (maybe you just need grid or covers?)"), myTarget.doNavMesh);
            if (myTarget.doNavMesh)
            {
                myTarget.walkMod   = EditorGUILayout.FloatField(new GUIContent("Walk mod", "generic move cost modifyer. (maybe you need one?) 1f == move cost equal to distance of movement"), myTarget.walkMod);
                myTarget.canCrouch = EditorGUILayout.Toggle(new GUIContent("Can crouch", "If true then Pathfinder will add aditional area where agent can crouch"), myTarget.canCrouch);

                if (myTarget.canCrouch)
                {
                    myTarget.crouchHeight = EditorGUILayout.FloatField(new GUIContent("Crouch height", "lowest limit where crouch start in world units (upper obliviously is agent height)"), myTarget.crouchHeight);
                    myTarget.crouchMod    = EditorGUILayout.FloatField(new GUIContent("Crouch mod", "crouch move cost modifyer,  1f == move cost equal to distance of movement"), myTarget.crouchMod);

                    if (myTarget.crouchHeight <0 | myTarget.crouchHeight> myTarget.height)
                    {
                        myTarget.crouchHeight = myTarget.height * 0.5f;
                    }
                }

                myTarget.canJump = EditorGUILayout.Toggle(new GUIContent("Can jump", "If true then Pathfinder will add aditional info about jump spots"), myTarget.canJump);

                if (myTarget.canJump)
                {
                    myTarget.JumpDown    = EditorGUILayout.FloatField(new GUIContent("Jump down", "Max distance to jump down"), myTarget.JumpDown);
                    myTarget.jumpDownMod = EditorGUILayout.FloatField(new GUIContent("Jump down mod", "Cost modifyer to jump down"), myTarget.jumpDownMod);
                    myTarget.JumpUp      = EditorGUILayout.FloatField(new GUIContent("Jump up", "Max distance to jump up"), myTarget.JumpUp);
                    myTarget.jumpUpMod   = EditorGUILayout.FloatField(new GUIContent("Jump up mod", "Cost modifyer to jump up"), myTarget.jumpUpMod);
                }
            }

            GUILayout.Box(string.Empty, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
            myTarget.canCover = EditorGUILayout.Toggle(new GUIContent("Do Cover", "If true then Pathfinder will add aditional info about covers"), myTarget.canCover);

            if (myTarget.canCover)
            {
                myTarget.coverExtraSamples = EditorGUILayout.IntField(new GUIContent("Extra samples", "Cover on diagonal can be funky. Here you can add some extra samples into it"), myTarget.coverExtraSamples);

                if (myTarget.coverExtraSamples < 0)
                {
                    myTarget.coverExtraSamples = 0;
                }

                myTarget.fullCover    = EditorGUILayout.FloatField(new GUIContent("Cover full", "How much height are considered as cover"), myTarget.fullCover);
                myTarget.canHalfCover = EditorGUILayout.Toggle(new GUIContent("Can half cover", "should we add half covers?"), myTarget.canHalfCover);

                //if half cover too low
                if (myTarget.canHalfCover)
                {
                    myTarget.halfCover = EditorGUILayout.FloatField(new GUIContent("Cover half", "How much height are considered as half cover"), myTarget.halfCover);

                    if (myTarget.halfCover < 0)
                    {
                        myTarget.halfCover = 0;
                    }
                }

                //if full covet too low
                if (myTarget.canHalfCover)
                {
                    if (myTarget.fullCover < myTarget.halfCover)
                    {
                        myTarget.fullCover = myTarget.halfCover;
                    }
                }
                else
                {
                    if (myTarget.fullCover < 0)
                    {
                        myTarget.fullCover = 0;
                    }
                }
            }

            GUILayout.Box(string.Empty, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });
            myTarget.battleGrid = EditorGUILayout.Toggle(new GUIContent("Do Battle grid", "If true then Pathfinder will add battle grid"), myTarget.battleGrid);

            if (myTarget.battleGrid)
            {
                myTarget.battleGridDensity = EditorGUILayout.IntField(new GUIContent("Battle grid density", "Size of space in battle grid in voxels. every this much voxel we sample data"), myTarget.battleGridDensity);
            }
            GUILayout.Box(string.Empty, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });

            EditorGUIUtility.labelWidth = currentLabelWidth;

            if (GUI.changed)
            {
                EditorUtility.SetDirty(myTarget);
            }
        }
示例#23
0
 public GeneralXZData(int x, int z, AgentProperties properties)
 {
     this.chunkPos   = new XZPosInt(x, z);
     this.properties = properties;
 }
示例#24
0
 public GeneralXZData(XZPosInt chunkPos, AgentProperties properties)
 {
     this.chunkPos   = chunkPos;
     this.properties = properties;
 }
示例#25
0
 public NavMeshTemplateRecast(Dictionary <XZPosInt, YRangeInt> chunkRange, XZPosInt gridPosition, AgentProperties properties) : base(gridPosition, properties)
 {
     this.chunkRange = chunkRange;
 }
示例#26
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();
        }
示例#27
0
 public GeneralXZData(int x, int z, AgentProperties properties) : this(new XZPosInt(x, z), properties)
 {
 }
 public static void QueueGraph(XZPosInt pos, AgentProperties properties)
 {
     QueueGraph(pos.x, pos.z, properties);
 }
 public static void QueueGraph(XZPosInt pos, VectorInt.Vector2Int size, AgentProperties properties)
 {
     QueueGraph(pos.x, pos.z, properties, size.x, size.y);
 }
 public static bool TryGetGraph(int x, int z, AgentProperties properties, out Graph graph)
 {
     return(TryGetGraph(new XZPosInt(x, z), properties, out graph));
 }