示例#1
0
    Vector2 TeleporterPos(string n, string t)
    {
        List <string> maploc = new List <string>();
        TextAsset     te     = ed.jsonMaps.Find(x => x.name == n);

        s_map m = JsonUtility.FromJson <s_map>(te.text);

        s_map.s_tileobj til = m.tilesdata.Find(x => x.TYPENAME == "teleport_object" && x.name == t);
        if (til != null)
        {
            return(new Vector2(til.pos_x, til.pos_y));
        }
        return(new Vector2(0, 0));
    }
示例#2
0
    public override void GetTileDat(ref s_map mapfil)
    {
        Tile[]     tiles    = new Tile[(int)mapsizeToKeep.x * (int)mapsizeToKeep.y];
        Tile[]     colTiles = new Tile[(int)mapsizeToKeep.x * (int)mapsizeToKeep.y];
        Vector2Int vec      = new Vector2Int(0, 0);

        for (int x = 0; x < mapsizeToKeep.x; x++)
        {
            for (int y = 0; y < mapsizeToKeep.y; y++)
            {
                Tile coltil = colmp.GetTile <Tile>(new Vector3Int(x, y, 0));
                if (coltil != null)
                {
                    colTiles[(int)(x + (mapsizeToKeep.x * y))] = coltil;
                    if (colTiles[(int)(x + (mapsizeToKeep.x * y))] != null)
                    {
                        string          tileName = coltil.name;
                        s_map.s_tileobj tilo     = new s_map.s_tileobj(new Vector2(x * 20, y * 20), null);
                        tilo.name = tileName;

                        mapfil.tilesdata.Add(tilo);
                    }
                }

                Tile til = tm.GetTile <Tile>(new Vector3Int(x, y, 0));
                if (til != null)
                {
                    mapfil.graphicTiles.Add(
                        new s_map.s_block(til.sprite.name,
                                          new Vector2(x * 20, y * 20)));
                }

                Tile tilmid = tm2.GetTile <Tile>(new Vector3Int(x, y, 0));
                if (tilmid != null)
                {
                    mapfil.graphicTilesMiddle.Add(
                        new s_map.s_block(tilmid.sprite.name,
                                          new Vector2(x * 20, y * 20)));
                }

                Tile tiltop = tm3.GetTile <Tile>(new Vector3Int(x, y, 0));
                if (tiltop != null)
                {
                    mapfil.graphicTilesTop.Add(
                        new s_map.s_block(tiltop.sprite.name,
                                          new Vector2(x * 20, y * 20)));
                }
            }
        }
    }
    List <string> PositionsOnMap(string n)
    {
        List <string> maploc = new List <string>();
        TextAsset     te     = mapdat.jsonMaps.Find(x => x.name == n);

        s_map m = JsonUtility.FromJson <s_map>(te.text);

        for (int i = 0; i < m.tilesdata.Count; i++)
        {
            //print((s_map.s_mapteleport)mapdat.tilesdata[i]);
            switch (m.tilesdata[i].TYPENAME)
            {
            case "teleport_object":
                maploc.Add(m.tilesdata[i].name);
                break;
            }
        }
        return(maploc);
    }
示例#4
0
    void WriteCode()
    {
        s_map  map = ed.mapDat;
        string str = "";

        EditorGUILayout.Space();
        int ind = 0;

        foreach (ev_details d in map.Map_Script)
        {
            bool findLabel = FindLabel(ind);
            if (findLabel)
            {
                ev_label l = map.map_script_labels.Find(x => x.index == ind);
                EditorGUILayout.LabelField(l.name + ": \n");
            }
            ind++;
            EditorGUILayout.LabelField(ind + ". " + str + "\n");
        }
    }
示例#5
0
    private void OnGUI()
    {
        int          x = 0, y = 0;
        List <s_map> maps = s_ninjaloader.LevEd.maps;

        for (int i = 0; i < maps.Count; i++)
        {
            s_map ma = maps[i];

            if (curmap == ma)
            {
                if (GUI.Button(new Rect(150, 50 * 1, 160, 50), "Back"))
                {
                    curmap = null;
                }
                if (GUI.Button(new Rect(160 * x, 50 * (y + 2), 160, 50), ma.name))
                {
                    s_ninjaloader.LevEd.current_area = i;
                    s_ninjaloader.LevEd.NewMap();
                    s_ninjaloader.LevEd.LoadMap(curmap);
                }
            }
            else
            {
                if (curmap == null)
                {
                    if (y == 10)
                    {
                        y = 0;
                        x++;
                    }
                    if (GUI.Button(new Rect(160 * x, 50 * (y + 3), 160, 50), ma.name))
                    {
                        curmap = ma;
                    }
                    y++;
                }
            }
        }
    }
示例#6
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);
    }
示例#7
0
    new void Update()
    {
        if (floatingNum > Mathf.PI * 2)
        {
            floatingNum = 0;
        }
        else
        {
            floatingNum += 0.04f;
        }

        rendererObj.transform.position = new Vector3(transform.position.x, transform.position.y + ((Mathf.Sin(floatingNum) * 25) * Time.deltaTime));
        Collider2D col = IfTouchingGetCol <o_character>(collision);

        if (col != null)
        {
            o_character p = col.GetComponent <o_character>();

            if (p != null)
            {
                switch (it)
                {
                case ITEM_TYPE.COLLECTIBLE:
                    /*
                     * npc_customer mask = p.GetComponent<npc_customer>();
                     * if (mask != null)
                     * {
                     *  if (mask.desiredItemName == name)
                     *  {
                     *      mask.satisfied = true;
                     *      DespawnObject();
                     *  }
                     * }
                     */
                    break;
                }
                if (!p.AI)
                {
                    switch (it)
                    {
                    case ITEM_TYPE.MONEY:
                        s_globals.Money += 1;
                        s_map mp = GameObject.Find("General").GetComponent <s_leveledit>().mapDat;
                        s_leveledit.LevEd.GetComponent <s_leveledit>().SetItemData(name, false);
                        mp.gemCount++;
                        s_save_item it = mp.itemdat.Find(x => x.ID == indexID);
                        it.iscollected = true;
                        s_soundmanager.sound.PlaySound(ref collectSound, false);
                        DespawnObject();
                        break;

                    case ITEM_TYPE.COLLECTIBLE:
                        s_soundmanager.sound.PlaySound(ref collectSound, false);
                        DespawnObject();
                        break;
                    }
                }
            }
            //DespawnObject();
        }
    }
    public override void OnInspectorGUI()
    {
        if (GameObject.Find("Main Camera") != null)
        {
            if (GameObject.Find("Main Camera").GetComponent <s_leveledit>() != null)
            {
                if (mapdat == null)
                {
                    mapdat = GameObject.Find("Main Camera").GetComponent <s_leveledit>().mapDat;
                }
                if (lev == null)
                {
                    lev = GameObject.Find("Main Camera").GetComponent <s_leveledit>();
                }
            }
        }

        base.OnInspectorGUI();

        tar = (o_generic)target;

        //EditorGUILayout.LabelField("Exeption character");
        //tar.character = EditorGUILayout.TextArea(tar.character);

        switch (tar.name)
        {
        case "BoundTile":
            if (GUILayout.Button("Re-search triggers"))
            {
                triggers = FindTriggers();
            }
            if (triggers == null)
            {
                triggers = FindTriggers();
            }
            else
            {
                List <u_boundary> bounds = FindBoundariesInTriggers();
                foreach (u_boundary b in bounds)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("    " + b.name);

                    GameObject bo = b.bounds.Find(x => tar.gameObject == x);
                    if (bo == null)
                    {
                        if (GUILayout.Button("Assign to boundary"))
                        {
                            b.bounds.Add(tar.gameObject);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Remove from boundary"))
                        {
                            b.bounds.Remove(bo);
                        }
                    }
                }
            }
            break;
        }

        EditorGUILayout.Space();
    }