示例#1
0
    public static NodeCell AddNodeCell(GameObject start, GameObject end)
    {
        {
            NodeCell[] links = start.GetComponents <NodeCell>();
            for (int i = 0; i < links.Length; i++)
            {
                if ((links[i].start == start && links[i].end == end) || (links[i].start == end && links[i].end == start))
                {
                    links[i].lst.Clear();
                    return(links[i]);
                }
            }
        }
        {
            NodeCell[] links = end.GetComponents <NodeCell>();
            for (int i = 0; i < links.Length; i++)
            {
                if ((links[i].start == start && links[i].end == end) || (links[i].start == end && links[i].end == start))
                {
                    links[i].lst.Clear();
                    return(links[i]);
                }
            }
        }

        NodeCell cell = start.gameObject.AddComponent <NodeCell>();

        cell.start = start.transform;
        cell.end   = end.transform;
        return(cell);
    }
示例#2
0
    static void NodeLerp()
    {
        if (lerpLength <= 0)
        {
            Open();
        }
        if (Selection.gameObjects.Length == 2)
        {
            Transform start = null;
            Transform end   = null;
            {
                NodeLink[] links = Selection.gameObjects[0].GetComponents <NodeLink>();
                for (int i = 0; i < links.Length; i++)
                {
                    if (links[i].End == Selection.gameObjects[1].transform)
                    {
                        start = Selection.gameObjects[0].transform;
                        end   = Selection.gameObjects[1].transform;
                        GameObject.DestroyImmediate(links[i]);
                    }
                }
            }
            {
                NodeLink[] links = Selection.gameObjects[1].GetComponents <NodeLink>();
                for (int i = 0; i < links.Length; i++)
                {
                    if (links[i].End == Selection.gameObjects[0].transform)
                    {
                        start = Selection.gameObjects[1].transform;
                        end   = Selection.gameObjects[0].transform;
                        GameObject.DestroyImmediate(links[i]);
                    }
                }
            }
            float length = Vector3.Distance(Selection.gameObjects[0].transform.position, Selection.gameObjects[1].transform.position);
            if (length > lerpLength)
            {
                float floatCount = length / lerpLength;
                int   count      = Mathf.FloorToInt(length / lerpLength);
                //有小数的话数量加一
                if (floatCount > count)
                {
                    count += 1;
                }
                ////起始点结束点已经有,要差值的点数量-1
                //count -= 1;

                if (count > 0)
                {
                    if (start == null || end == null)
                    {
                        start = Selection.gameObjects[0].transform;
                        end   = Selection.gameObjects[1].transform;
                    }

                    Delete(start, end);

                    NodeCell nodeCell = AddNodeCell(start.gameObject, end.gameObject);

                    Transform pre = start;
                    for (int i = 1; i < count; i++)
                    {
                        pre = AddLerpObj(start.transform, pre, Vector3.Lerp(start.position, end.position, (float)i / (float)count));
                        nodeCell.lst.Add(pre);
                    }

                    AddLink(end.gameObject, pre);
                }
            }
            AStarHelpEditor.NodeAttachFloor();
            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
        }
    }
示例#3
0
    // Use this for initialization
    void Start()
    {
        // initialize the network
        nodes = new List<Node> ();
        nodesToFlip = new List<NodeCell> ();

        cells = new NodeCell[nWidth][];
        for (int i = 0; i<nWidth; i++) {
            cells[i] = new NodeCell[nHeight];
        }

        // init the nodes
        Index middle = new Index((int)(Mathf.Floor (nWidth / 2)), (int)Mathf.Floor (nHeight / 2));
        for (int i = 0; i<nWidth; i++) {
            for (int j = 0; j<nHeight; j++)
            {
                cells[i][j] = new NodeCell(i,j);
                // activate the middle node
                if(i == middle.x && j == middle.y && !cells[i][j].isActive)
                {
                    cells[i][j].isActive = true;
                }
            }
        }
        checkForActivation ();

        // initialize the Environment
        bckMusic = GameObject.Find("Sound");
        initItems ();
        enterAct (1);
        initHeads ();
        initEnds ();
    }