/// <summary>
        /// 初始化图层数据
        /// </summary>
        public void initGraphData()
        {
            nodesInWidth   = 200;
            nodesInDepth   = 200;
            nodeSize       = 2.5F;
            gridDefineSize = new Vector2(nodesInWidth, nodesInDepth) * nodeSize;
            gridSize       = gridDefineSize;
            gridCenter     = Matrix.MultiplyPoint3x4(new Vector3((nodesInWidth / 2 * nodeSize), 0, (nodesInDepth / 2 * nodeSize)));

            //默认为绿色
            nodeColorOfConnection                       = new Color(0, 1, 0, 0.5f);
            graphicCollision                            = new GraphicCollisionHandle();
            graphicCollision.collisionCheck             = true;
            graphicCollision.maskOfCollisionCheck.value = LayerMask.GetMask("TransparentFX");
            graphicCollision.heightCheck                = true;
            graphicCollision.maskOfHeightCheck.value    = LayerMask.GetMask("Default");
        }
        /// <summary>
        /// 处理图形冲突
        /// </summary>
        public void HandingGraphicCollision()
        {
            if (graphicCollision == null)
            {
                graphicCollision = new GraphicCollisionHandle();
            }
            graphicCollision.Initialize(Matrix);

            for (int depth = 0; depth < nodesInDepth; depth++)
            {
                for (int width = 0; width < nodesInWidth; width++)
                {
                    var node = nodes[depth * nodesInWidth + width];
                    HandingCollisonOfSingleNode(node, width, depth);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 绘制冲突检查的属性, 像障碍物和高度检查
        /// </summary>
        public void DrawCollisionCheckAttribute(GridNavGraph graphObj, ref bool changeFlag)
        {
            if (graphObj.graphicCollision == null)
            {
                return;
            }
            GraphicCollisionHandle graphicCollision = graphObj.graphicCollision;

            #region  碰撞检查

            bool checkFlag = graphicCollision.collisionCheck;
            graphicCollision.collisionCheck = GUILayout.Toggle(graphicCollision.collisionCheck, "Collision Check");
            if (checkFlag != graphicCollision.collisionCheck)
            {
                changeFlag = true;
            }

            EditorGUI.BeginDisabledGroup(!graphicCollision.collisionCheck);

            //射线高度
            float tmpData = graphicCollision.height;
            graphicCollision.height = EditorGUILayout.FloatField(new GUIContent("Ray Length", "Is the length of the ray"), graphicCollision.height);
            if (tmpData != graphicCollision.height)
            {
                changeFlag = true;
            }

            ////检测节点时的向上偏移的值
            //tmpData = graphicCollision.upwardOffsetOfNode;
            //graphicCollision.upwardOffsetOfNode = EditorGUILayout.FloatField(new GUIContent("UpwardOffset", "The value of the upward offset when the node is detected"), graphicCollision.upwardOffsetOfNode);
            //if (tmpData != graphicCollision.upwardOffsetOfNode) changeFlag = true;

            //检查的层
            int selectMask = graphicCollision.maskOfCollisionCheck.value;
            graphicCollision.maskOfCollisionCheck.value = EditorGUILayout.MaskField("Mask", selectMask, AStarPathEditor.GetLayerMaskField(true));
            if (selectMask != graphicCollision.maskOfCollisionCheck.value)
            {
                changeFlag = true;
            }

            EditorGUI.EndDisabledGroup();

            #endregion

            #region  高度检查

            checkFlag = graphicCollision.heightCheck;
            graphicCollision.heightCheck = GUILayout.Toggle(graphicCollision.heightCheck, "Height Check");
            if (checkFlag != graphicCollision.heightCheck)
            {
                changeFlag = true;
            }

            EditorGUI.BeginDisabledGroup(!graphicCollision.heightCheck);

            //射线高度
            tmpData = graphicCollision.rayOfLaunchHeight;
            graphicCollision.rayOfLaunchHeight = EditorGUILayout.FloatField(new GUIContent("Height", "Is the length of the ray"), graphicCollision.rayOfLaunchHeight);
            if (tmpData != graphicCollision.rayOfLaunchHeight)
            {
                changeFlag = true;
            }

            //检查的层
            selectMask = graphicCollision.maskOfHeightCheck.value;
            graphicCollision.maskOfHeightCheck.value = EditorGUILayout.MaskField("Mask", selectMask, AStarPathEditor.GetLayerMaskField());
            if (selectMask != graphicCollision.maskOfHeightCheck.value)
            {
                changeFlag = true;
            }

            EditorGUI.EndDisabledGroup();

            #endregion
        }