Exemplo n.º 1
0
    public override List <s_map.s_tileobj> GetTiles(s_object[] tiles)
    {
        List <s_map.s_tileobj> t = new List <s_map.s_tileobj>();
        int nodeID = 0;

        foreach (s_object c in tiles)
        {
            s_map.s_tileobj til = new s_map.s_tileobj(c.ID);
            til.pos_x = (int)c.transform.position.x;
            til.pos_y = (int)c.transform.position.y;
            til.name  = c.name;

            switch (c.ID)
            {
            case "Node":
                o_nodeobj nod = c.GetComponent <o_nodeobj>();

                if (til.CustomTypes == null)
                {
                    til.CustomTypes = new List <s_map.s_customType>();
                }

                til.CustomTypes.Add(new s_map.s_customType("nodeID", nod.nodeID));
                foreach (o_nodeobj no in nod.nieghbours)
                {
                    if (no == null)
                    {
                        continue;
                    }
                    if (til.CustomTypes != null)
                    {
                        //print("node " + no.nodeID);
                        til.CustomTypes.Add(new s_map.s_customType("node", no.nodeID));
                    }
                    else
                    {
                        til.CustomTypes = new List <s_map.s_customType>();
                        //print("node " + no.nodeID);
                        til.CustomTypes.Add(new s_map.s_customType("node", no.nodeID));
                    }
                }
                t.Add(til);
                nodeID++;
                continue;

            default:
                t.Add(til);
                break;
            }
        }
        return(t);
    }
Exemplo n.º 2
0
    public List <s_map.s_tileobj> GetNodes()
    {
        if (nl == null)
        {
            nl = this;
        }
        s_object[]             tiles = GetTileObjects();
        List <s_map.s_tileobj> t     = new List <s_map.s_tileobj>();
        int nodeID = 0;

        foreach (s_object c in tiles)
        {
            s_map.s_tileobj til = new s_map.s_tileobj(c.ID);
            til.pos_x = (int)c.transform.position.x;
            til.pos_y = (int)c.transform.position.y;

            switch (c.ID)
            {
            case "Node":
                o_nodeobj nod = c.GetComponent <o_nodeobj>();
                if (nod.nieghbours != null)
                {
                    foreach (o_nodeobj no in nod.nieghbours)
                    {
                        if (no == null)
                        {
                            continue;
                        }
                        if (til.CustomTypes != null)
                        {
                            til.CustomTypes.Add(new s_map.s_customType("node", no.nodeID));
                        }
                    }
                }
                t.Add(til);
                nodeID++;
                continue;

            default:
                continue;
            }
        }
        return(t);
    }
Exemplo n.º 3
0
 public o_nodeobj GetNode(int id)
 {
     s_object[] objs = GetTileObjects();
     foreach (s_object obj in objs)
     {
         o_nodeobj nod = obj.GetComponent <o_nodeobj>();
         if (nod != null)
         {
             if (nod.nodeID == id)
             {
                 return(nod);
             }
         }
         else
         {
             continue;
         }
     }
     return(null);
 }
Exemplo n.º 4
0
    public override void SetTileMap(s_map mapdat)
    {
        pathNodes.Clear();
        debugNodes.Clear();

        s_map mp = mapdat;
        List <s_map.s_block>   tile    = mp.graphicTiles;
        List <s_map.s_block>   tileMid = mp.graphicTilesMiddle;
        List <s_map.s_block>   tileTop = mp.graphicTilesTop;
        List <s_map.s_tileobj> coll    = mp.tilesdata;

        // base.SetTileMap(mapdat);

        /*
         */
        foreach (s_map.s_block b in tile)
        {
            tm.SetTile(new Vector3Int((int)b.position.x / 20, (int)b.position.y / 20, 0), tilesNew.Find(ti => ti.name == b.sprite));
        }
        foreach (s_map.s_block b in tileMid)
        {
            tm2.SetTile(new Vector3Int((int)b.position.x / 20, (int)b.position.y / 20, 0), tilesNew.Find(ti => ti.name == b.sprite));
        }
        foreach (s_map.s_block b in tileTop)
        {
            tm3.SetTile(new Vector3Int((int)b.position.x / 20, (int)b.position.y / 20, 0), tilesNew.Find(ti => ti.name == b.sprite));
        }

        int nodeID = 0;

        for (int i = 0; i < coll.Count; i++)
        {
            s_map.s_tileobj b        = coll[i];
            string          tilename = "";
            COLLISION_T     tileType = (COLLISION_T)b.enumthing;
            Tile            t        = null;
            s_pathNode      nod2     = new s_pathNode();
            GameObject      go       = null;

            if (InEditor)
            {
                switch (b.TYPENAME)
                {
                case "teleport_object":
                case "keyObj":
                    go = Instantiate(
                        FindOBJ(b.TYPENAME),
                        new Vector3(b.pos_x, b.pos_y),
                        Quaternion.identity);
                    if (go != null)
                    {
                        go.transform.SetParent(tilesObj.transform);
                        go.name = b.name;
                    }
                    break;

                case "Node":
                    go = Instantiate(FindOBJ(b.TYPENAME),
                                     new Vector3(b.pos_x, b.pos_y),
                                     Quaternion.identity);
                    if (go != null)
                    {
                        go.transform.SetParent(tilesObj.transform);
                        go.name = b.name;
                    }

                    o_nodeobj nod = go.GetComponent <o_nodeobj>();

                    nod.nodeID             = nodeID;
                    nod.name               = "Node_" + nod.nodeID;
                    nod.transform.position = new Vector3(b.pos_x, b.pos_y);
                    nod.transform.SetParent(tilesObj.transform);
                    debugNodes.Add(nod);

                    /*
                     * o_nodeobj nod = go.GetComponent<o_nodeobj>();
                     * nod.nodeID = nodeID;
                     * nod.name = "Node_" + nod.nodeID;
                     * debugNodes.Add(nod);
                     */

                    nod2          = new s_pathNode();
                    nod2.position = new Vector2(b.pos_x, b.pos_y);
                    if (b.CustomTypes.Find(x => x.name == "nodeID").name == "")
                    {
                        nod2.id = nodeID;
                    }
                    else
                    {
                        nod2.id = b.CustomTypes.Find(x => x.name == "nodeID").type;
                    }
                    pathNodes.Add(nod2);
                    nodeID++;
                    break;
                }

                /*
                 * switch (tileType)
                 * {
                 *  case COLLISION_T.WALL:
                 *      if (b.TYPENAME == "teleport_object")
                 *          continue;
                 *      colmp.SetTile(new Vector3Int(b.pos_x / 20, b.pos_y / 20, 0), collisionTile);
                 *      break;
                 * }
                 */
            }
            else
            {
                switch (b.TYPENAME)
                {
                case "teleport_object":
                    continue;

                case "keyObj":
                    SpawnObject <o_generic>("keyObj", new Vector2(b.pos_x, b.pos_y), Quaternion.identity);
                    continue;

                case "Node":
                    nod2          = new s_pathNode();
                    nod2.position = new Vector2(b.pos_x, b.pos_y);
                    nod2.id       = nodeID;
                    pathNodes.Add(nod2);
                    nodeID++;
                    break;
                }
            }
            tilename = b.name;
            if (tilename != "")
            {
                colmp.SetTile(new Vector3Int(b.pos_x / 20, b.pos_y / 20, 0), collisionList.Find(ti => ti.name == tilename));
            }
            else
            {
                colmp.SetTile(new Vector3Int(b.pos_x / 20, b.pos_y / 20, 0), t);
            }
        }

        for (int i = 0; i < pathNodes.Count; i++)
        {
            s_pathNode        p             = pathNodes[i];
            List <s_pathNode> nbrs          = new List <s_pathNode>();
            List <int>        GetNeighbours = new List <int>();

            s_map.s_tileobj t = coll[p.id];

            //Gets all the neighbours
            foreach (s_map.s_customType no in t.CustomTypes)
            {
                //Find all the custom values with "node" which resemble the neighbours
                if (no.name == "node")
                {
                    s_pathNode path = pathNodes.Find(x => x.id == no.type);
                    nbrs.Add(path);
                }
            }
            if (InEditor)
            {
                o_nodeobj currentNode = debugNodes.Find(x => x.nodeID == p.id);
                foreach (s_pathNode n in nbrs)
                {
                    o_nodeobj nod = debugNodes.Find(x => x.nodeID == n.id);
                    if (nod != null)
                    {
                        currentNode.nieghbours.Add(nod);
                        GetNeighbours.Add(n.id);

                        //nod.nieghbours.Add(currentNode);
                        if (!currentNode.nieghbours.Find(x => nod))
                        {
                        }
                    }
                }
                foreach (s_pathNode n in nbrs)
                {
                    GetNeighbours.Add(n.id);
                }
                p            = new s_pathNode(p.id, new Vector2(p.position.x, p.position.y), GetNeighbours);
                pathNodes[i] = p;
            }
            else
            {
                foreach (s_pathNode n in nbrs)
                {
                    GetNeighbours.Add(n.id);
                }
                p            = new s_pathNode(p.id, new Vector2(p.position.x, p.position.y), GetNeighbours);
                pathNodes[i] = p;
            }
        }
        pathfind = GetComponent <s_pathfind>();
        pathfind.SetNodes(ref pathNodes);
    }
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        GameObject obj = Selection.activeGameObject;

        if (obj != null)
        {
            o_nodeobj anim = obj.GetComponent <o_nodeobj>();
            if (anim != null)
            {
                anim.nodeID = EditorGUILayout.IntField(anim.nodeID);
                EditorGUILayout.LabelField("Node neighbours");
                for (int i = 0; i < anim.nieghbours.Count; i++)
                {
                    o_nodeobj nod = anim.nieghbours[i];
                    if (nod == null)
                    {
                        continue;
                    }
                    if (GUILayout.Button(nod.ID + " " + nod.nodeID))
                    {
                        nod.nieghbours.Remove(anim);
                        anim.nieghbours.Remove(nod);
                    }
                }
                EditorGUILayout.LabelField("Nodes in map");
                if (nodes == null)
                {
                    s_ninjaloader nin = GameObject.Find("General").GetComponent <s_ninjaloader>();
                    s_ninjaloader.nl = nin;
                    nodes            = nin.GetNodes();
                }
                else
                {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        s_map.s_tileobj nod = nodes[i];
                        if (nod.TYPENAME != "Node")
                        {
                            continue;
                        }
                        if (i == anim.nodeID)
                        {
                            continue;
                        }
                        if (anim.nieghbours != null)
                        {
                            if (anim.nieghbours.Find(x => x.nodeID == i))
                            {
                                continue;
                            }
                        }
                        if (GUILayout.Button(i + ""))
                        {
                            o_nodeobj nud = s_ninjaloader.nl.GetNode(i);
                            anim.nieghbours.Add(nud);
                            nud.nieghbours.Add(anim);
                        }
                    }
                }
            }
        }
        Repaint();
    }