Exemplo n.º 1
0
    void PutPosToTempPoly(Vector3 pos)
    {
        float repeatDistance = builder.repeatDistance;

        bool repeat = false;

        foreach (var poly in builder.polys)
        {
            if (!poly)
            {
                continue;
            }
            foreach (var pos2 in poly.vertices)
            {
                if (Vector3.Distance(pos, pos2) < repeatDistance)
                {
                    pos    = pos2;
                    repeat = true;
                    break;
                }
            }
        }

        if (!repeat && tempPoly)
        {
            foreach (var pos2 in tempPoly.vertices)
            {
                if (Vector3.Distance(pos, pos2) < repeatDistance)
                {
                    pos    = pos2;
                    repeat = true;
                    break;
                }
            }
        }

        if (tempPoly && tempPoly.vertices.Count > 0)
        {
            if (Vector3.Distance(pos, tempPoly.vertices[tempPoly.vertices.Count - 1]) < repeatDistance ||
                Vector3.Distance(pos, tempPoly.vertices[0]) < repeatDistance)
            {
                return;
            }
        }

        if (!tempPoly)
        {
            tempPoly = new GameObject(builder.polys.Count.ToString()).AddComponent <NavMeshPoly>();
            tempPoly.transform.SetParent(builder.transform);
            tempPoly.transform.localPosition = Vector3.zero;
            tempPoly.transform.localRotation = Quaternion.identity;
            tempPoly.transform.localScale    = Vector3.one;
            GameObjectUtility.SetStaticEditorFlags(tempPoly.gameObject, StaticEditorFlags.NavigationStatic);
        }
        tempPoly.vertices.Add(pos);
        tempPoly.Refresh();
        MarkSceneDirty();
    }
Exemplo n.º 2
0
 void OnSceneGUI()
 {
     if (Event.current.alt)
     {
         if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
         {
             Vector3 pickPos;
             if (PickWalkablePos(out pickPos))
             {
                 // 存储到临时面
                 //Debug.LogWarning("Pick hit: " + pickPos);
                 PutPosToTempPoly(pickPos);
             }
             else
             {
                 Debug.LogWarning("Invalid pick");
             }
             //Event.current.Use();
         }
     }
     else
     {
         // 存档
         if (tempPoly)
         {
             if (tempPoly.vertices.Count > 2)
             {
                 tempPoly.Refresh();
                 builder.polys.Add(tempPoly);
             }
             else
             {
                 GameObject.DestroyImmediate(tempPoly.gameObject);
             }
             tempPoly = null;
         }
     }
 }