Exemplo n.º 1
0
    protected new void Update()
    {
        //PHYSICS RELATED STUFF
        base.Update();

        if (SpriteObj != null)
        {
            SpriteObj.transform.position = new Vector2(transform.position.x, transform.position.y + Z_offset);
        }

        if (control)
        {
            if (AI)
            {
                ArtificialIntelleginceControl();

                Collider2D col = IfTouchingGetCol <PDII_character>(collision);
                if (col != null)
                {
                    PDII_character ob = col.GetComponent <PDII_character>();

                    switch (CONTACT_TYPE)
                    {
                    case ON_CONTACT.IMMOBILIZE:
                        if (ob != null)
                        {
                            if (ob.control)
                            {
                                ob.StartCoroutine(ob.Unconsious());
                            }
                        }
                        break;

                    case ON_CONTACT.TELEPORT:

                        if (ob != null)
                        {
                            if (!ob.AI)
                            {
                                s_map.s_tileobj to = s_levelloader.LevEd.mapDat.tilesdata.Find(x => x.name == teleportLoc);
                                if (to != null)
                                {
                                    ob.gameObject.transform.position = new Vector3(to.pos_x, to.pos_y);
                                }
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                PlayerControl();
            }
        }
    }
Exemplo n.º 2
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.º 3
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)));
                }
            }
        }
    }
Exemplo n.º 4
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));
    }
Exemplo n.º 5
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.º 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);
    }
    public override IEnumerator EventPlay()
    {
        switch ((EVENT_TYPES)current_ev.eventType)
        {
        default:
            yield return(StartCoroutine(base.EventPlay()));

            break;

        case EVENT_TYPES.CAMERA_MOVEMENT:

            GameObject ca = GameObject.Find("Main Camera");
            ca.GetComponent <s_camera>().focus = false;
            ca.GetComponent <s_camera>().ResetSpeedProg();
            ca.GetComponent <s_camera>().lerping = true;

            float spe = current_ev.float0;     //SPEED
            float s   = 0;

            s_object obje = null;

            if (current_ev.string0 != "o_player")
            {
                if (GameObject.Find(current_ev.string0) != null)
                {
                    obje = GameObject.Find(current_ev.string0).GetComponent <s_object>();
                }
            }
            else
            {
                if (host != null)
                {
                    obje = host;
                }
                else
                {
                    obje = player;
                }
            }

            Vector2 pos = new Vector2(0, 0);
            if (obje != null)
            {
                pos = obje.transform.position;
            }

            if (obje != null)
            {
                ca.GetComponent <s_camera>().targetPos = obje.transform.position;
            }
            else
            {
                ca.GetComponent <s_camera>().targetPos = new Vector2(current_ev.pos.x, current_ev.pos.y);
            }

            if (current_ev.boolean)
            {
                float dista = Vector2.Distance(ca.transform.position, new Vector3(pos.x, pos.y));

                while (Vector2.Distance(ca.transform.position, new Vector3(pos.x, pos.y))
                       > dista * 0.05f)
                {
                    // s += spe * Time.deltaTime * travSpeed;
                    // ca.transform.position = Vector3.Lerp(ca.transform.position, new Vector3(pos.x, pos.y, -15), s);
                    yield return(new WaitForSeconds(Time.deltaTime));
                }
                if (current_ev.boolean1)
                {
                    ca.GetComponent <s_camera>().focus = true;
                    // ca.GetComponent<s_camera>(). = obje.GetComponent<o_character>();
                }
            }
            else
            {
                float dista = Vector2.Distance(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y));
                while (Vector2.Distance(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y))
                       > dista * 0.05f)
                {
                    // s += spe * Time.deltaTime * travSpeed;
                    // ca.transform.position = Vector2.Lerp(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y, -15), s);
                    //ca.transform.position = new Vector3(ca.transform.position.x, ca.transform.position.y, -15);
                    yield return(new WaitForSeconds(Time.deltaTime));
                }
            }
            ca.GetComponent <s_camera>().lerping = false;
            break;

        case EVENT_TYPES.MOVEMNET:

            float       timer     = 1.02f;
            o_character charaMove = null;

            s_map.s_tileobj to = s_levelloader.LevEd.mapDat.tilesdata.Find(
                x => x.TYPENAME == "teleport_object" &&
                x.name == current_ev.string1);

            if (current_ev.string0 == "o_player")
            {
                if (host == null)
                {
                    charaMove = player;
                }
                else
                {
                    charaMove = host;
                }
            }
            else
            {
                charaMove = GameObject.Find(current_ev.string0).GetComponent <o_character>();
            }

            Vector2 newpos = charaMove.transform.position;

            if (current_ev.boolean)
            {
                newpos = new Vector2(to.pos_x, to.pos_y);
                charaMove.transform.position = new Vector3(newpos.x, newpos.y, 0);
                break;
            }

            float   dist = Vector2.Distance(charaMove.transform.position, newpos);
            Vector2 dir  = (newpos - new Vector2(charaMove.transform.position.x, charaMove.transform.position.y)).normalized;
            print(newpos);

            while (Vector2.Distance(charaMove.transform.position, newpos)
                   > dist * 0.01f)
            {
                charaMove.transform.position += (Vector3)(dir * current_ev.float0 * current_ev.float1) * 0.007f;
                yield return(new WaitForSeconds(Time.deltaTime));
            }
            break;

        case EVENT_TYPES.CHANGE_MAP:

            dialogueChoices.Clear();
            if (player != null)
            {
                player.direction        = new Vector2(0, 0);
                player.rbody2d.velocity = Vector2.zero;
                player.control          = false;
                player.SetAnimation("idle_d", false);
                player.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
            }
            if (host != null)
            {
                host.direction        = new Vector2(0, 0);
                host.rbody2d.velocity = Vector2.zero;
                host.control          = false;
                host.SetAnimation("idle_d", false);
                host.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
            }

            float t2 = 0;
            while (fade.color != Color.black)
            {
                t2        += Time.deltaTime;
                fade.color = Color.Lerp(Color.clear, Color.black, t2);
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (host == null)
            {
                s_levelloader.LevEd.TriggerSpawn(current_ev.string0, current_ev.string1, player);
            }
            else
            {
                s_levelloader.LevEd.TriggerSpawn(current_ev.string0, current_ev.string1, host);
            }

            t2 = 0;
            while (fade.color != Color.clear)
            {
                t2        += Time.deltaTime;
                fade.color = Color.Lerp(Color.black, Color.clear, t2);
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            if (player != null)
            {
                player.control = true;
            }
            if (host != null)
            {
                host.control = true;
            }

            pointer     = -1;
            doingEvents = false;
            break;

        case EVENT_TYPES.DEPOSSES:

            if (host != null)
            {
                host.OnDeposess();
                host = null;
            }
            break;

        case EVENT_TYPES.ADD_CHOICE_OPTION:
            s_dialogue_choice dialo = new s_dialogue_choice(current_ev.string0, FindLabel(current_ev.string1));

            if (dialogueChoices != null)
            {
                dialogueChoices.Add(dialo);
            }
            else
            {
                dialogueChoices = new List <s_dialogue_choice>();
                dialogueChoices.Add(dialo);
            }
            break;

        case EVENT_TYPES.CHECK_FLAG:

            int integr = s_globals.GetGlobalFlag(current_ev.string0);

            int labelNum = FindLabel(current_ev.string1);

            if (labelNum == int.MinValue)
            {
                labelNum = current_ev.int1 - 1;
            }

            switch ((LOGIC_TYPE)current_ev.logic)
            {
            default:
                yield return(StartCoroutine(base.EventPlay()));

                break;

            case LOGIC_TYPE.CHECK_CHARACTER:
                if (host != null)
                {
                    if (host.ID == current_ev.string0) //Check if it is equal to the value
                    {
                        pointer = labelNum;            //Label to jump to
                    }
                }
                break;

            case LOGIC_TYPE.CHECK_CHARACTER_NOT:
                if (host != null)
                {
                    if (host.ID != current_ev.string0)
                    {
                        pointer = labelNum;           //Label to jump to
                    }
                }
                else
                {
                    pointer = labelNum;
                }
                break;


                /*
                 * case LOGIC_TYPE.CHECK_UTILITY_RETURN_NUM:
                 *
                 * //This checks utilities after the INITIALIZE function
                 * if (GetComponent<s_utility>().eventState == current_ev.int0)
                 * {
                 *  pointer = current_ev.int1 - 1;   //Label to jump to
                 * }
                 * else
                 * {
                 *  pointer = current_ev.int2 - 1;
                 * }
                 * break;
                 */
            }
            break;

        case EVENT_TYPES.CHOICE:
            int choice = 0, finalchoice = -1;
            print(choice);

            while (finalchoice == -1)
            {
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    choice--;
                }

                if (Input.GetKeyDown(KeyCode.DownArrow))
                {
                    choice++;
                }

                choice = Mathf.Clamp(choice, 0, dialogueChoices.Count - 1);

                if (Input.GetKeyDown(KeyCode.Z))
                {
                    print("Chosen");
                    finalchoice = choice;
                }
                Dialogue.text  = "Arrow keys to scroll, Z to select" + "\n";
                Dialogue.text += current_ev.string0 + "\n";
                for (int i = 0; i < dialogueChoices.Count - 1; i++)
                {
                    if (choice == i)
                    {
                        Dialogue.text += "-> ";
                    }

                    Dialogue.text += dialogueChoices[i].option + "\n";
                }
                print(choice);
                yield return(new WaitForSeconds(Time.deltaTime));
            }
            Dialogue.text = "";
            pointer       = dialogueChoices[finalchoice].flagTojump - 1;
            break;

        case EVENT_TYPES.CLEAR_CHOICES:
            dialogueChoices.Clear();
            break;

        case EVENT_TYPES.RUN_CHARACTER_SCRIPT:


            if (current_ev.string0 == "o_player")
            {
                o_character ch = null;
                if (host == null)
                {
                    ch = player.GetComponent <o_character>();
                }
                else
                {
                    ch = host.GetComponent <o_character>();
                }

                if (ch.rbody2d != null)
                {
                    ch.rbody2d.velocity = Vector2.zero;
                }
                ch.control         = current_ev.boolean;
                ch.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
            }
            else
            {
                GameObject obj = GameObject.Find(current_ev.string0);
                if (obj != null)
                {
                    o_character ch = obj.GetComponent <o_character>();
                    if (ch != null)
                    {
                        if (ch.rbody2d != null)
                        {
                            ch.rbody2d.velocity = Vector2.zero;
                        }
                        ch.control         = current_ev.boolean;
                        ch.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE;
                    }
                }
            }
            break;
        }
    }
Exemplo n.º 8
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();
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        GameObject obj = Selection.activeGameObject;

        if (obj != null)
        {
            npc_guard anim = obj.GetComponent <npc_guard>();
            if (anim != null)
            {
                anim.ID      = EditorGUILayout.TextField(anim.ID);
                anim.faction = EditorGUILayout.TextField(anim.faction);
                EditorGUILayout.LabelField("Teleport location");
                anim.teleportLoc = EditorGUILayout.TextField(anim.teleportLoc);
                anim.marchPoint  = EditorGUILayout.IntField(anim.marchPoint);

                EditorGUILayout.LabelField("Pathfinding");
                if (anim.path != null)
                {
                    for (int i = 0; i < anim.path.Count; i++)
                    {
                        EditorGUILayout.LabelField(anim.path[i].id + "");
                    }
                }
                EditorGUILayout.LabelField("Path to follow");
                for (int i = 0; i < anim.marchDirection.Count; i++)
                {
                    int nod = anim.marchDirection[i];
                    if (GUILayout.Button("ID: " + nod))
                    {
                        anim.marchDirection.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 (GUILayout.Button(i + ""))
                        {
                            anim.marchDirection.Add(i);
                        }
                    }
                }
                EditorGUILayout.LabelField("Targets");
                if (anim.targets != null)
                {
                    for (int i = 0; i < anim.targets.Count; i++)
                    {
                        EditorGUILayout.LabelField(anim.targets[i].name + "");
                    }
                }
            }
        }
        Repaint();
    }
Exemplo n.º 10
0
    new void FixedUpdate()
    {
        //o_noise noise = s_nGlobal.GetNoise(transform.position);
        Collider2D pl = IfTouchingGetCol <c_plcharacter>(lineOfSight, "Player");

        lineOfSight.transform.position = transform.position + (Vector3)(direction * 60);
        LOSSpr.transform.position      = lineOfSight.transform.position;

        if (direction.x >= 0)
        {
            rendererObj.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
        }
        else
        {
            rendererObj.transform.rotation = Quaternion.Euler(new Vector3(0, -180, 0));
        }

        if (pl != null)
        {
            s_map.s_tileobj to = s_levelloader.LevEd.mapDat.tilesdata.Find(x => x.name == teleportLoc);
            if (to != null)
            {
                pl.GetComponent <c_plcharacter>().health--;
                pl.gameObject.transform.position = new Vector3(to.pos_x, to.pos_y);
            }
        }

        if (CheckTargetDistance(s_levelloader.LevEd.player, 450))
        {
            if (walkSoundTimer > 0)
            {
                walkSoundTimer -= Time.deltaTime;
            }
            else
            {
                s_soundmanager.sound.PlaySound(ref walksounds[UnityEngine.Random.Range(0, 5)], (450 / TargetDistance(s_levelloader.LevEd.player)) * 0.55f, false);
                walkSoundTimer = 0.4f;
            }
        }

        /*
         * if (pl != null)
         * {
         *  path.Clear();
         *  target = pl.GetComponent<o_character>();
         *
         *  GameObject go = GameObject.Find(teleportLoc);
         *  if (go != null)
         *  {
         *      pl.transform.position = go.transform.position;
         *  }
         *
         * }
         * switch (state)
         * {
         *  case AI_STATE.PATHFIND:
         *
         *      if (path != null)
         *      {
         *          if (path.Count > 0)
         *          {
         *              if (pl != null)
         *                  if (!Physics2D.Linecast(transform.position, target.transform.position, layerMsk))
         *                  {
         *                      path.Clear();
         *                  }
         *              PathWalk();
         *          }
         *          else
         *          {
         *              if (Physics2D.Linecast(transform.position, target.transform.position, layerMsk))
         *              {
         *
         *                  path.Clear();
         *                  backtrackSearchTimer = 2f;
         *                  //int minleng = s_ninjaloader.pathfind.PathFind(transform.position, s_ninjaloader.pathfind.FindPathNode(closestPathID).position).Count;
         *                  state = AI_STATE.BACKTRACK;
         *              }
         *              else
         *              {
         *                  direction = LookAtTarget(target);
         *                  lastSeenPos = target.transform.position;
         *                  if (CheckTargetDistance(target, 100))
         *                      CHARACTER_STATE = CHARACTER_STATES.STATE_IDLE;
         *                  else
         *                      CHARACTER_STATE = CHARACTER_STATES.STATE_MOVING;
         *
         *                  if (bulletShootTimer > 0)
         *                      bulletShootTimer -= Time.deltaTime;
         *                  else
         *                  {
         *                      ShootBullet(0.7f);
         *                      if (CHARACTER_STATE == CHARACTER_STATES.STATE_IDLE)
         *                          bulletShootTimer = startBulletShootTimer;
         *                      if (CHARACTER_STATE == CHARACTER_STATES.STATE_MOVING)
         *                          bulletShootTimer = startBulletShootTimer * 2;
         *                  }
         *              }
         *              if (pl == null)
         *              {
         *              }
         *          }
         *      }
         *      break;
         *
         *  case AI_STATE.IDLE:
         *
         *      WalkControl();
         *      PathWalk();
         *      if (pl != null)
         *      {
         *          path.Clear();
         *          target = pl.GetComponent<o_character>();
         *
         *          GameObject go = GameObject.Find(teleportLoc);
         *          if (go != null)
         *          {
         *              pl.transform.position = go.transform.position;
         *          }
         *
         *      }
         *
         *      break;
         *  case AI_STATE.BACKTRACK:
         *      if (backtrackSearchTimer > 0)
         *      {
         *          Tuple<List<s_pathNode>, float> nodes = s_ninjaloader.pathfind.PathFind(transform.position, target.transform.position);
         *
         *          if (path == null)
         *              path = new List<s_pathNode>();
         *
         *          if (nodes != null)
         *              if (nodes.Item1 != null)
         *                  path = nodes.Item1;
         *
         *          backtrackSearchTimer -= Time.deltaTime;
         *      }
         *      else
         *      {
         *          if (path.Count == 0)
         *          {
         *              path.Clear();
         *              ReturnToPatrol();
         *          }
         *      }
         *      PathWalk();
         *      if (pl != null)
         *      {
         *          path.Clear();
         *          state = AI_STATE.PATHFIND;
         *      }
         *      break;
         *
         * }
         */

        base.FixedUpdate();
    }