// Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // get the index of the waiting line
        npc.index_of_waiting_line = npc.waiting_point.Get_My_Index(Owner.GetComponent <HHK_Role_Tags> ());
        // set the destination
        npc.agent.SetDestination(npc.waiting_point.Get_My_Position(Owner.GetComponent <HHK_Role_Tags> ()));
        switch (moveType)
        {
        case HHK_FSM_Walking_NPC_Variables.MOVETYPE.Run:
            // play animation.
            npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.motion);
            npc.agent.speed = npc.speed_run;
            break;

        case HHK_FSM_Walking_NPC_Variables.MOVETYPE.Walk:
            // play animation.
            npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.motion);
            npc.agent.speed = npc.speed_walk;
            break;

        default:
            // play animation.
            npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.idle);
            npc.agent.speed = 0;
            break;
        }

        timeout = 0.5f;
    }
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // if not ready and I am not in this spot, switch to the in spot state
        if (!npc.spot.Is_Ready())
        {
            if (!npc.spot.Is_In_This_Place(Owner.GetComponent <HHK_Role_Tags> ()))
            {
                Fsm.Event(lookingSpot);
                return;
            }
        }

        // if at the right position, switch to the in spot state
        if ((npc.agent.destination - npc.transform.position).magnitude <= npc.destance_for_stop_limit)
        {
            Fsm.Event(inSpot);
            return;
        }
    }
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }

        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        if (npc.role_controller.Is_Current_State(HHK_Role_Controller.AnimName.idle))
        {
            // if has a next place need to go
            if (npc.spot.next_place)
            {
                npc.place = npc.spot.next_place;
                Fsm.Event(walkingToPlace);
                return;
            }
            else
            {
                Fsm.Event(lookingPlace);
                return;
            }
        }
    }
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // *** move to walking spot
        // set the destination
        npc.agent.SetDestination(npc.spot.transform.position);
        switch (moveType)
        {
        case HHK_FSM_Walking_NPC_Variables.MOVETYPE.Run:
            // play animation.
            npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.motion);
            npc.agent.speed = npc.speed_run;
            break;

        case HHK_FSM_Walking_NPC_Variables.MOVETYPE.Walk:
            // play animation.
            npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.motion);
            npc.agent.speed = npc.speed_walk;
            break;

        default:
            // play animation.
            npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.idle);
            npc.agent.speed = 0;
            break;
        }

        timeout = 0.5f;
    }
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // play animation via spot
        npc.role_controller.CrossFade(npc.spot.actionNameExit);
        timeout = .5f;
    }
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // play animatino
        npc.role_controller.Play_Boring();

        timeout = 0.5f;
    }
Beispiel #7
0
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // set the time for using
        time_to_leave = Random.Range(npc.spot.mixTime, npc.spot.maxTime);
        // stop
        // agent.Stop();
        // play animation via spot
        npc.role_controller.CrossFade(npc.spot.actionName);

        timeout = 0.5f;
    }
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        if (npc.role_controller.Is_Current_State(HHK_Role_Controller.AnimName.idle))
        {
            Fsm.Event(walkingToWaitingPoint);
            return;
        }
    }
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // if at the right position, switch to the in waiting line
        if ((npc.agent.destination - npc.transform.position).magnitude <= npc.destance_for_stop_limit)
        {
            Fsm.Event(inWaitingLine);
            return;
        }
    }
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        waitingTime = Random.Range(0, npc.waittingBoringTime);

        // ramdomly direction
        newDir   = Random.insideUnitSphere;
        newDir.y = 0;
        newDir.Normalize();

        // play animation
        npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.idle);

        timeout = 0.5f;
    }
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }

        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // check, if reach the place, switch to looking for wp 2 state
        // and stop
        if (npc.place.Is_In_This_Place(Owner.GetComponent <HHK_Role_Tags> ()))
        {
            // send event looking spot
            Fsm.Event(lookingSpot);
        }
    }
Beispiel #12
0
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }

        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // rotataion
        npc.transform.rotation = Quaternion.Lerp(npc.transform.rotation, npc.spot.transform.rotation,
                                                 npc.agent.angularSpeed * Time.deltaTime);

        // count down
        time_to_leave -= Time.deltaTime;
        if (time_to_leave <= 0.0f)
        {
            Fsm.Event(afterSpot);
            return;
        }
    }
Beispiel #13
0
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        npc.spot = npc.place.Any_Available_Spot();

        // find a available spot
        if (npc.spot)
        {
            // join the spot first
            npc.spot.Join_From_The_Waiting_Line(Owner.GetComponent <HHK_Role_Tags> ());
            Fsm.Event(walkingToSpot);
        }
        // go to the waiting point
        // if there is no any waiting point, go back to the looking for wp 1 state
        else
        {
            if (npc.place.waittingPoint)
            {
                // get the waiting point;
                npc.waiting_point = npc.place.waittingPoint;
                // join the line, and get the index of the line,
                // otherwise, looking for the next wp 1
                if (!npc.waiting_point.Join_To_This_Place(Owner.GetComponent <HHK_Role_Tags> ()))
                {
                    Fsm.Event(lookingPlace);
                    return;
                }
                Fsm.Event(walkingToWaitingPoint);
                return;
            }
            // switch to walking
            else
            {
                Fsm.Event(lookingPlace);
                return;
            }
        }
    }
Beispiel #14
0
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables>();

        // find all the wp1
        HHK_Way_Point_Level_1[] wp1s = HHK_Way_Point_Level_1.FindAllPlace();
        if (npc.place == null || wp1s.Length <= 1)
        {
            npc.place = wp1s[Random.Range(0, wp1s.Length)];
        }
        else
        {
            // no same place again
            HHK_Way_Point_Level_1 wp = wp1s[Random.Range(0, wp1s.Length)];
            while (wp == npc.place)
            {
                wp = wp1s[Random.Range(0, wp1s.Length)];
            }
            npc.place = wp;
        }
        // send event
        Fsm.Event(walkingToPlace);
    }
Beispiel #15
0
    // Code that runs on entering the state.
    public override void OnEnter()
    {
        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // play animation via spot
        npc.role_controller.CrossFade(HHK_Role_Controller.AnimName.die);

        HHK_Role_Tags tag = Owner.GetComponent <HHK_Role_Tags>();

        // force to leave the area
        if (npc.waiting_point)
        {
            npc.waiting_point.Leave_From_This_Place(tag);
        }
        if (npc.spot)
        {
            npc.spot.Leave_From_This_Place(tag);
        }

        npc.agent.Stop();

        // send a message
        MessageSystem.Send(MessageSystem.NPC_Die, npc);
    }
    // Code that runs every frame.
    public override void OnUpdate()
    {
        timeout -= Time.deltaTime;
        if (timeout >= 0.0f)
        {
            return;
        }

        HHK_FSM_Walking_NPC_Variables npc = Owner.GetComponent <HHK_FSM_Walking_NPC_Variables> ();

        // rotataion
        //npc.transform.forward = Vector3.Lerp(npc.transform.forward, newDir,
        //                                     npc.agent.angularSpeed * Time.deltaTime);
        // npc.transform.rotation = Quaternion.Lerp (npc.transform.rotation, npc.waiting_point.transform.rotation,
        //                                     npc.agent.angularSpeed * Time.deltaTime);

        waitingTime -= Time.deltaTime;
        if (waitingTime <= 0.0f)
        {
            Fsm.Event(boring);
        }

        // keep checking any availabe spot
        if (npc.index_of_waiting_line == 0)
        {
            npc.spot = npc.place.Any_Available_Spot();
            if (npc.spot)
            {
                // leave this please
                npc.waiting_point.Leave_From_This_Place(Owner.GetComponent <HHK_Role_Tags> ());
                // join the spot first
                npc.spot.Join_From_The_Waiting_Line(Owner.GetComponent <HHK_Role_Tags> ());
                // to spot
                Fsm.Event(walkingToSpot);
                return;
            }
        }

        // keep checking the new waiting index of the line, move to the new position
        if (npc.index_of_waiting_line != npc.waiting_point.Get_My_Index(Owner.GetComponent <HHK_Role_Tags> ()))
        {
            // waiting ,until the prev moved
            HHK_Role_Tags prevTag
                = npc.waiting_point.At_Index(npc.waiting_point.Get_My_Index(Owner.GetComponent <HHK_Role_Tags> ()) - 1);

            // I am the first one
            if (prevTag == null)
            {
                // go to the waitting line
                Fsm.Event(walkingToWaitingPoint);
                return;
            }

            HHK_FSM_Walking_NPC_Variables prev = prevTag.GetComponent <HHK_FSM_Walking_NPC_Variables> ();
            // prev moved
            if (prev.index_of_waiting_line == prev.waiting_point.Get_My_Index(prev.GetComponent <HHK_Role_Tags> ()))
            {
                // go to the waitting line
                Fsm.Event(walkingToWaitingPoint);
                return;
            }
        }
    }