Пример #1
0
    // Use this for initialization
    void Start()
    {
        INSTANCE    = this;
        m_state     = MonkeyState.IdlePre;
        m_animation = GetComponentInChildren <Animation>();

        m_lastKnownIdle = "";
        m_audio         = GetComponent <AudioSource>();
    }
Пример #2
0
 public void CheckStateChange()
 {
     if (newState != null)
     {
         currentState.ExitState();
         currentState = newState;
         currentState.EnterState();
     }
 }
Пример #3
0
    public void Update(float t)
    {
        if (currentState == null)
        {
            return;
        }

        newState = currentState.UpdateState(t);
        CheckStateChange();
    }
Пример #4
0
    public void ReceiveMessage(MonkeyState.Messages message)
    {
        if (currentState == null)
        {
            return;
        }

        newState = currentState.ReceiveMessage(message);
        CheckStateChange();
    }
Пример #5
0
 public StateMachine(Monkey apa)
 {
     this.actor   = apa;
     currentState = null;
 }
Пример #6
0
    private void setState(MonkeyState para_state)
    {
        currState = para_state;

        if(para_state == MonkeyState.IDLE)
        {
            transform.GetComponent<SpriteRenderer>().color = Color.white;
            currMonkeySpeed = monkeyWalkSpeed;
            idle_timeOfLastFaceSwitch = Time.time;
            currAlertCount = 0;
        }
        else if(para_state == MonkeyState.ALERTED)
        {
            currAlertCount++;
        }
        else if(para_state == MonkeyState.CHASING)
        {
            if(currAlertCount == 1)
            {
                triggerSoundAtCamera("MonkeyAngry");
                transform.GetComponent<SpriteRenderer>().color = Color.red;
            }
        }else if(para_state == MonkeyState.COUNTER){

        }else if(para_state == MonkeyState.STEALING_PACKAGE)
        {
            GameObject.Find("GlobObj").GetComponent<AcPackageDeliveryScenario>().handleMonkeyPackageSteal(transform.gameObject.name);
        }
        else if(para_state == MonkeyState.ESCAPING_WITH_PACKAGE)
        {
            // Select end point of monkey. The monkey should drop off the package about mid way.
            triggerSoundAtCamera("MonkeyLaugh");

            currMonkeySpeed = monkeyRunSpeed;

            GameObject stolenItem = GameObject.Find(stolenPackageName);
            Transform itemHolder = transform.FindChild("WorldPivot").FindChild("ItemHolder");
            itemHolder.parent = null;
            stolenItem.transform.position = new Vector3(itemHolder.position.x,itemHolder.position.y,itemHolder.position.z);
            itemHolder.parent = transform.FindChild("WorldPivot");
            stolenItem.transform.parent = itemHolder;

            List<NavNode> escapeNodes = null;
            escapeNodes = worldNavGraph.getChildNodesAtHopDistance(worldNavGraph.getNode(terrainHandle.getNavNodeIDForCell(getCellForItem(transform.gameObject.name))),
                                                                 8,
                                                                 new HashSet<int>() {worldNavGraph.getTypeIDByName("MonkeySpawn")},
                                                                 new HashSet<int>() {worldNavGraph.getNode(terrainHandle.getNavNodeIDForCell(getCellForItem("MainAvatar"))).getNodeID()});

            if((escapeNodes == null)||(escapeNodes.Count > 0))
            {
                // Try again, this time allow passing through the player.

                escapeNodes = worldNavGraph.getChildNodesAtHopDistance(worldNavGraph.getNode(terrainHandle.getNavNodeIDForCell(getCellForItem(transform.gameObject.name))),
                                                                       8,
                                                                       new HashSet<int>() {worldNavGraph.getTypeIDByName("MonkeySpawn")},
                                                                       null);

                if((escapeNodes == null)||(escapeNodes.Count > 0))
                {
                    // Select random location on the map.

                    List<int> freeSpaceNodeIDs = worldNavGraph.getNodesOfType(worldNavGraph.getTypeIDByName("FreeSpace"));
                    escapeNodes = new List<NavNode>();
                    escapeNodes.Add(worldNavGraph.getNode(freeSpaceNodeIDs[Random.Range(0,freeSpaceNodeIDs.Count)]));
                }
            }

            // Select escape node out of potential escapes.
            NavNode chosenEscapeNode = escapeNodes[Random.Range(0,escapeNodes.Count)];

            List<NavNode> escapepath = worldNavGraph.searchForPath(terrainHandle.getNavNodeIDForCell(getCellForItem(transform.gameObject.name)),
                                       							   chosenEscapeNode.getNodeID());

            escapeNode = escapepath[escapepath.Count-1];

            // Select package drop off from the escape path.
            dropOffNode = escapepath[ (int) (escapepath.Count/2f) ];

            //List<NavNode> pathToDropOff = worldNavGraph.searchForPath(terrainHandle.getNavNodeIDForCell(getCellForItem(transform.gameObject.name)),
            //                                                          dropOffNode.getNodeID());

            initCharacterMovement(getCellForItem(((WorldNode) dropOffNode).getWorldPt()),false,false);
        }
        else if(para_state == MonkeyState.RETREATING)
        {
            Transform stolenItem = transform.FindChild("WorldPivot").FindChild("ItemHolder").FindChild(stolenPackageName);
            stolenItem.parent = null;
            stolenItem.position = new Vector3(transform.position.x,transform.position.y,transform.position.z + 0.1f);
            if(stolenItem.collider != null)
            {
                stolenItem.collider.enabled = true;
            }

            initCharacterMovement(getCellForItem(((WorldNode) escapeNode).getWorldPt()),false,true);

            GameObject.Find("GlobObj").GetComponent<AcPackageDeliveryScenario>().respondToEvent(transform.name,"MonkeyDroppedItem",stolenPackageName);
        }
        else if(para_state == MonkeyState.EATING_BANANA)
        {
            triggerSoundAtCamera("Eat");
            transform.GetComponent<SpriteRenderer>().color = Color.green;

            cnm.faceDirection("S");
            GameObject monkeyFoodGObj = transform.FindChild("Food").gameObject;
            //Color monkeyFoodColor = monkeyFoodGObj.GetComponent<SpriteRenderer>().color;

            CustomAnimationManager aniMang = monkeyFoodGObj.AddComponent<CustomAnimationManager>();
            List<List<AniCommandPrep>> batchLists = new List<List<AniCommandPrep>>();
            List<AniCommandPrep> batch1 = new List<AniCommandPrep>();
            batch1.Add(new AniCommandPrep("GrowOrShrink",1,new List<System.Object>() { new float[3] { 0,0,0 }, 0.05f }));
            //batch1.Add(new AniCommandPrep("ColorTransition",1,new List<System.Object>() { new float[4] {monkeyFoodColor.r,monkeyFoodColor.g,monkeyFoodColor.b,monkeyFoodColor.a}, 2f }));
            batchLists.Add(batch1);
            aniMang.registerListener("Monkey",this);
            aniMang.init("EatingAni",batchLists);
        }
    }
Пример #7
0
 void DoAnimations()
 {
     if (m_level == MonkeyLevel.Unspecified)
     {
         if (m_state == MonkeyState.IdlePre)
         {
             m_currentAnimation = "MONKEY_idle";
             if (!m_animation.IsPlaying(m_currentAnimation))
             {
                 m_animation.CrossFade(m_currentAnimation, 0.2f);
             }
         }
     }
     else if (m_level == MonkeyLevel.OneTwo)
     {
         if (m_state == MonkeyState.IdlePre)
         {
             m_currentAnimation = "MONKEY_1-2_idle";
             if (!m_animation.IsPlaying(m_currentAnimation))
             {
                 m_animation.CrossFade(m_currentAnimation, 0.2f);
             }
         }
         else if (m_state == MonkeyState.Animate)
         {
             m_currentAnimation = "MONKEY_1-2";
             if (!m_animation.IsPlaying("MONKEY_1-2") && !m_startedMainAnim)
             {
                 //Debug.Log("On attack start");
                 m_startedMainAnim = true;
                 m_animation["MONKEY_1-2"].speed = 1.0f;
                 m_animation.CrossFade("MONKEY_1-2");
             }
             else if (!m_animation.IsPlaying("MONKEY_1-2"))
             {
                 m_startedMainAnim = false;
                 m_state           = MonkeyState.IdlePost;
                 this.gameObject.SetActiveRecursively(false);
                 //Debug.Log("On attack complete");
             }
         }
         if (m_state == MonkeyState.IdlePost)
         {
             m_currentAnimation = "MONKEY_idle";
             if (!m_animation.IsPlaying(m_currentAnimation))
             {
                 m_animation.CrossFade(m_currentAnimation, 0.2f);
             }
         }
     }
     else if (m_level == MonkeyLevel.OneEight)
     {
         if (m_state == MonkeyState.IdlePre)
         {
             m_currentAnimation = "MONKEY_idle";
             if (!m_animation.IsPlaying(m_currentAnimation))
             {
                 m_animation.CrossFade(m_currentAnimation, 0.2f);
             }
         }
         else if (m_state == MonkeyState.Animate)
         {
             m_currentAnimation = "MONKEY_idle-to-attack";
             if (!m_animation.IsPlaying("MONKEY_idle-to-attack") && !m_startedMainAnim)
             {
                 //Debug.Log("On attack start");
                 m_startedMainAnim = true;
                 m_animation["MONKEY_idle-to-attack"].speed = 1.0f;
                 m_animation.CrossFade("MONKEY_idle-to-attack");
             }
             else if (!m_animation.IsPlaying("MONKEY_idle-to-attack"))
             {
                 m_startedMainAnim = false;
                 m_state           = MonkeyState.IdlePost;
                 this.gameObject.SetActiveRecursively(false);
                 //Debug.Log("On attack complete");
             }
         }
         if (m_state == MonkeyState.IdlePost)
         {
             m_currentAnimation = "MONKEY_idle";
             if (!m_animation.IsPlaying(m_currentAnimation))
             {
                 m_animation.CrossFade(m_currentAnimation, 0.2f);
             }
         }
     }
 }
Пример #8
0
 public void DoAnimation()
 {
     m_state = MonkeyState.Animate;
     PlayAudio(Loud);
 }
    void DoAnimations()
    {
        if( m_level == MonkeyLevel.Unspecified )
        {
            if( m_state == MonkeyState.IdlePre )
            {
                m_currentAnimation = "MONKEY_idle";
                if (!m_animation.IsPlaying(m_currentAnimation))
                {
                    m_animation.CrossFade(m_currentAnimation, 0.2f);
                }
            }
        }
        else if( m_level == MonkeyLevel.OneTwo )
        {
            if( m_state == MonkeyState.IdlePre )
            {
                m_currentAnimation = "MONKEY_1-2_idle";
                if (!m_animation.IsPlaying(m_currentAnimation))
                {
                    m_animation.CrossFade(m_currentAnimation, 0.2f);
                }
            }
            else if( m_state == MonkeyState.Animate )
            {
                m_currentAnimation = "MONKEY_1-2";
                if (!m_animation.IsPlaying("MONKEY_1-2") && !m_startedMainAnim)
                {
                    //Debug.Log("On attack start");
                    m_startedMainAnim = true;
                    m_animation["MONKEY_1-2"].speed = 1.0f;
                    m_animation.CrossFade("MONKEY_1-2");
                }
                else if (!m_animation.IsPlaying("MONKEY_1-2"))
                {
                    m_startedMainAnim = false;
                    m_state = MonkeyState.IdlePost;
                    this.gameObject.SetActiveRecursively(false);
                    //Debug.Log("On attack complete");
                }
            }
            if( m_state == MonkeyState.IdlePost )
            {
                m_currentAnimation = "MONKEY_idle";
                if (!m_animation.IsPlaying(m_currentAnimation))
                {
                    m_animation.CrossFade(m_currentAnimation, 0.2f);
                }
            }

        }
        else if( m_level == MonkeyLevel.OneEight )
        {
            if( m_state == MonkeyState.IdlePre )
            {
                m_currentAnimation = "MONKEY_idle";
                if (!m_animation.IsPlaying(m_currentAnimation))
                {
                    m_animation.CrossFade(m_currentAnimation, 0.2f);
                }
            }
            else if( m_state == MonkeyState.Animate )
            {
                m_currentAnimation = "MONKEY_idle-to-attack";
                if (!m_animation.IsPlaying("MONKEY_idle-to-attack") && !m_startedMainAnim)
                {
                    //Debug.Log("On attack start");
                    m_startedMainAnim = true;
                    m_animation["MONKEY_idle-to-attack"].speed = 1.0f;
                    m_animation.CrossFade("MONKEY_idle-to-attack");
                }
                else if (!m_animation.IsPlaying("MONKEY_idle-to-attack"))
                {
                    m_startedMainAnim = false;
                    m_state = MonkeyState.IdlePost;
                    this.gameObject.SetActiveRecursively(false);
                    //Debug.Log("On attack complete");
                }
            }
            if( m_state == MonkeyState.IdlePost )
            {
                m_currentAnimation = "MONKEY_idle";
                if (!m_animation.IsPlaying(m_currentAnimation))
                {
                    m_animation.CrossFade(m_currentAnimation, 0.2f);
                }
            }
        }
    }
 public void DoAnimation()
 {
     m_state = MonkeyState.Animate;
     PlayAudio(Loud);
 }
    // Use this for initialization
    void Start()
    {
        INSTANCE = this;
        m_state = MonkeyState.IdlePre;
        m_animation = GetComponentInChildren<Animation>();

        m_lastKnownIdle = "";
        m_audio = GetComponent<AudioSource>();
    }