public void StartRun()
        {
            _portrait.CrossFade("Run");

            _moveStatus = MoveStatus.Run;

            _isGround  = true;
            _jumpCount = 0;
        }
Пример #2
0
    private void ChangeStatus(Status nextStatus)
    {
        switch (nextStatus)
        {
        case Status.Normal:
            if (nextStatus != status)
            {
                portrait.CrossFade("Idle Normal", 0.3f);
            }
            break;

        case Status.Smile:
            smileTime = 0.0f;

            if (nextStatus != status)
            {
                portrait.CrossFade("Idle Smile", 0.3f);
            }
            break;

        case Status.Angry:
            if (nextStatus != status)
            {
                portrait.CrossFade("Idle Angry", 0.3f);
            }
            break;

        case Status.Embarrassed:
            portrait.Play("Embarrass", 0, apAnimPlayUnit.BLEND_METHOD.Interpolation, apAnimPlayManager.PLAY_OPTION.StopAllLayers, true);
            embarrassedTime = 0.0f;
            break;

        case Status.SetAngry:
            portrait.Play("Angry", 0, apAnimPlayUnit.BLEND_METHOD.Interpolation, apAnimPlayManager.PLAY_OPTION.StopAllLayers, true);
            setAngryTime = 0.0f;
            break;
        }
        status = nextStatus;
    }
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (portrait.IsPlaying("Idle"))
         {
             portrait.StopAll(0.3f);
         }
         else
         {
             portrait.CrossFade("Idle", 0.3f);
         }
     }
 }
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (!isPlaying)
         {
             portrait.CrossFade("Idle", 0.3f);
             isPlaying = true;
         }
         else
         {
             portrait.StopAll(0.3f);
             isPlaying = false;
         }
     }
 }
    void Update()
    {
        //Calculate Touch
        isTouched = false;
        Vector2 touchPosScreen = Vector2.zero;


        if (Input.GetMouseButton(0))
        {
            isTouched      = true;
            touchPosScreen = Input.mousePosition;
        }
        else if (Input.touchCount == 1)
        {
            TouchPhase touchPhase = Input.GetTouch(0).phase;
            if (touchPhase == TouchPhase.Began ||
                touchPhase == TouchPhase.Moved ||
                touchPhase == TouchPhase.Stationary)
            {
                isTouched      = true;
                touchPosScreen = Input.GetTouch(0).position;
            }
        }


        if (isTouched)
        {
            touchPos = targetCamera.ScreenToWorldPoint(new Vector3(touchPosScreen.x, touchPosScreen.y, portrait.transform.position.z));
        }
        else
        {
            isTouchDown = true;
        }


        // Touch Event
        if (isTouched != isTouchedPrevFrame)
        {
            isTouchHead = false;
            isTouchBody = false;

            if (isTouched)
            {
                Ray          touchRay = targetCamera.ScreenPointToRay(new Vector3(touchPosScreen.x, touchPosScreen.y, 1000.0f));
                RaycastHit[] hits     = Physics.RaycastAll(touchRay);
                if (hits != null && hits.Length > 0)
                {
                    for (int i = 0; i < hits.Length; i++)
                    {
                        if (hits[i].collider == bodyArea)
                        {
                            isTouchBody = true;
                            break;
                        }
                        if (hits[i].collider == headArea)
                        {
                            isTouchHead = true;
                            break;
                        }
                    }
                }

                if (isTouchHead)
                {
                    if (isTouchDown)
                    {
                        // Smile!
                        if (!portrait.IsPlaying("Smile"))
                        {
                            portrait.CrossFade("Smile", 0.2f);
                            portrait.CrossFadeQueued("Idle");
                        }
                    }
                }
                else if (isTouchBody)
                {
                    if (isTouchDown)
                    {
                        // Angry
                        if (!portrait.IsPlaying("Angry"))
                        {
                            portrait.Play("Angry");
                            portrait.CrossFadeQueued("Idle", 0.2f);
                        }
                    }
                }
            }
            else
            {
                //Reset "Eye" Timer
                isEyeReturn   = true;
                eyeReturnTime = 0.0f;
            }
        }


        //Eye/Head Control
        if (isTouched)
        {
            Vector2 head2Touch = new Vector2(touchPos.x - headCenter.position.x, touchPos.y - headCenter.position.y);
            Vector2 eyeParam   = new Vector2(Mathf.Clamp(head2Touch.x / eyeAreaMaxSize.x, -1, 1),
                                             Mathf.Clamp(head2Touch.y / eyeAreaMaxSize.y, -1, 1));

            Vector2 headParam = new Vector2(Mathf.Clamp(head2Touch.x / headAreaMaxSize.x, -1, 1),
                                            Mathf.Clamp(head2Touch.y / headAreaMaxSize.y, -1, 1));

            portrait.SetControlParamVector2(controlParamName_EyeDirection, eyeParam);
            portrait.SetControlParamVector2(controlParamName_HeadDirection, headParam);

            lastEyeParam  = eyeParam;
            lastHeadParam = headParam;

            if (!touchParticle.isPlaying)
            {
                touchParticle.Play();
            }

            handGroup.position        = new Vector3(touchPos.x, touchPos.y, handGroup.position.z);
            handMesh_Released.enabled = false;
            handMesh_Pressed.enabled  = true;
        }
        else
        {
            if (touchParticle.isPlaying)
            {
                touchParticle.Stop();
            }

            if (Input.mousePresent)
            {
                Vector2 mousePosW = targetCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, portrait.transform.position.z));

                handGroup.position        = new Vector3(mousePosW.x, mousePosW.y, handGroup.position.z);
                handMesh_Released.enabled = true;
                handMesh_Pressed.enabled  = false;
            }
            else
            {
                handMesh_Released.enabled = false;
                handMesh_Pressed.enabled  = false;
            }

            if (isEyeReturn)
            {
                eyeReturnTime += Time.deltaTime;
                if (eyeReturnTime < eyeReturnTimeLength)
                {
                    apControlParam controlParam_Eye  = portrait.GetControlParam(controlParamName_EyeDirection);
                    apControlParam controlParam_Head = portrait.GetControlParam(controlParamName_HeadDirection);

                    float itp = 1.0f - (eyeReturnTime / eyeReturnTimeLength);

                    portrait.SetControlParamVector2(controlParamName_EyeDirection, lastEyeParam * itp + controlParam_Eye.Vector2ValueWithoutEditing * (1 - itp));
                    portrait.SetControlParamVector2(controlParamName_HeadDirection, lastHeadParam * itp + controlParam_Head.Vector2ValueWithoutEditing * (1 - itp));
                }
                else
                {
                    isEyeReturn   = false;
                    eyeReturnTime = 0.0f;
                }
            }
        }

        isTouchedPrevFrame = isTouched;
        if (isTouchDown && isTouched)
        {
            isTouchDown = false;
        }
    }
    void Update()
    {
        if (motion == Motion.Attack)
        {
            //Attack
            //...Wait
        }
        else
        {
            //Idle or Run

            int inputX = 0;
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                inputX += -1;
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                inputX += 1;
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                motion = Motion.Attack;
                portrait.CrossFade("Attack", 0.1f);
            }

            if (motion != Motion.Attack)
            {
                if (inputX == 0)
                {
                    // Stop
                    curVelocity = Vector2.zero;

                    if (motion == Motion.Run)
                    {
                        //Run -> Idle
                        portrait.CrossFade("Idle");
                        motion = Motion.Idle;
                    }
                }
                else
                {
                    // Move
                    curVelocity.x += inputX * moveAcc.x * Time.deltaTime;                     //Move Left / Right
                    curVelocity.x  = Mathf.Clamp(curVelocity.x, -moveVelocity.x, moveVelocity.x);

                    if (motion == Motion.Idle)
                    {
                        //Idle -> Run
                        portrait.CrossFade("Run");
                        motion = Motion.Run;
                    }
                }

                bool isXFlip = false;
                if (curVelocity.x < -0.3f && portrait.transform.localScale.x < 0.0f)
                {
                    //Turn To Left
                    isXFlip = true;
                }
                else if (curVelocity.x > 0.3f && portrait.transform.localScale.x > 0.0f)
                {
                    //Turn To Right
                    isXFlip = true;
                }

                if (isXFlip)
                {
                    Vector3 curScale = portrait.transform.localScale;
                    curScale.x *= -1;

                    portrait.transform.localScale = curScale;
                }

                Vector3 nextPos = portrait.transform.position + curVelocity * Time.deltaTime;
                if (nextPos.x < limitPos_L.position.x && curVelocity.x < 0.0f)
                {
                    nextPos.x = limitPos_L.position.x;
                }
                else if (nextPos.x > limitPos_R.position.x && curVelocity.x > 0.0f)
                {
                    nextPos.x = limitPos_R.position.x;
                }
                portrait.transform.position = nextPos;
            }
        }


        //카메라를 움직이자
        Vector3 cameraPos = targetCamera.transform.position;
        float   deltaXCamera2Character = (portrait.transform.position.x - cameraPos.x);

        if (Mathf.Abs(deltaXCamera2Character) > maxDistToCharacter)
        {
            //카메라가 한계점에 도달했다.
            if (deltaXCamera2Character < 0.0f)
            {
                cameraPos.x = portrait.transform.position.x + maxDistToCharacter;
            }
            else
            {
                cameraPos.x = portrait.transform.position.x - maxDistToCharacter;
            }
        }
        else
        {
            cameraPos.x = cameraPos.x * 0.98f + portrait.transform.position.x * 0.02f;
        }

        float itpSize = Mathf.Clamp01((Mathf.Abs(deltaXCamera2Character) / maxDistToCharacter));

        targetCamera.transform.position = cameraPos;
        float nextOrthoSize = nearSize * (1.0f - itpSize) + farSize * itpSize;

        targetCamera.orthographicSize = targetCamera.orthographicSize * 0.9f + nextOrthoSize * 0.1f;
    }