コード例 #1
0
    private void Update()
    {
        if (_spriterAnimator == null)
        {
            _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
            _animationList   = _spriterAnimator.GetAnimations().ToList();
        }

        if (_collisionState.OnSolidGround)
        {
            if (Time.time - _timer > 1.0f)
            {
                _controller.SetButtonPressTime(Buttons.MoveRight);
                _walkingMovementRequest.RequestMovement(Buttons.MoveRight);
                if (_currentIndex != _previousIndex)
                {
                    Play(_currentIndex);
                    _previousIndex = _currentIndex;
                }
            }
        }
        else
        {
            _timer = Time.time;
        }
    }
コード例 #2
0
    private void Update()
    {
        // Check if the deployed animation has already played.
        if (!_deployed)
        {
            if (_spriterAnimator == null)
            {
                _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
                _animationList   = _spriterAnimator.GetAnimations().ToList();
            }

            // Initially get the sniper's position relative to the camera view
            _GOpos = Camera.main.WorldToViewportPoint(transform.position);

            // KEEP CHECKING IF THE SNIPER IS WITHIN THE SCREEN TO ENSURE THE PLAYER SEES THE DEPLOY ANIMATION
            if (_GOpos.x > 0.1f && _GOpos.x < 0.9f && _GOpos.y > 0.1 && _GOpos.y < 0.9F)
            {
                StartCoroutine(DeployDelay());
                _deployed = true;
            }
        }
        else
        {
            if (_currentIndex != _previousIndex)
            {
                Play(_currentIndex);
                _previousIndex = _currentIndex;
            }
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        // Weird skip assign workaround. Don't remove this or Alah will punish you
        if (uAnimator == null)
        {
            uAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
        }

        //Debug.Log("uAnimator.Time = " + uAnimator.Time);
        if (GameManager.IsPaused == false)
        {
            if (GameManager.IsGameStarted == true)
            {
                ProcessInput();
            }
            Transition();
            AttackAndRetreat();
            TransitionBack();
            Idle();
        }
        else
        {
        }

        // Debug.Log("State: " + _state);
        // TestSwapAssets();
    }
コード例 #4
0
 public UnityAnimator GetAnimator()
 {
     if (animator == null)
     {
         animator = GetComponent <SpriterDotNetBehaviour>().Animator;
     }
     return(animator);
 }
コード例 #5
0
 // Update is called once per frame
 void Update()
 {
     // Weird skip assign workaround
     if (uAnimator == null)
     {
         uAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
     }
 }
コード例 #6
0
ファイル: Controller.cs プロジェクト: razluta/SpriterDotNet
    private static string GetAnimation(UnityAnimator animator, int offset)
    {
        List <string> animations = animator.GetAnimations().ToList();
        int           index      = animations.IndexOf(animator.CurrentAnimation.Name);

        index += offset;
        if (index >= animations.Count)
        {
            index = 0;
        }
        if (index < 0)
        {
            index = animations.Count - 1;
        }
        return(animations[index]);
    }
コード例 #7
0
ファイル: Controller.cs プロジェクト: razluta/SpriterDotNet
    void Update()
    {
        if (animator == null)
        {
            animator = FindObjectOfType <SpriterDotNetBehaviour>().Animator;
            animator.EventTriggered += e => Debug.Log("Event Triggered. Source: " + animator.CurrentAnimation.Name + ". Value: " + e);
        }

        if (GetAxisDownPositive("Vertical"))
        {
            PushCharacterMap();
        }
        if (GetAxisDownNegative("Vertical"))
        {
            animator.SpriteProvider.PopCharMap();
        }
        if (Input.GetButtonDown("Jump"))
        {
            ReverseAnimation();
        }
        if (GetAxisDownPositive("Horizontal"))
        {
            Transition(1);
        }
        if (GetAxisDownNegative("Horizontal"))
        {
            Transition(-1);
        }
        if (Input.GetButtonDown("Fire1"))
        {
            SwitchAnimation(1);
        }
        if (Input.GetButtonDown("Fire2"))
        {
            SwitchAnimation(-1);
        }
        if (Input.GetButtonDown("Cancel"))
        {
            PushCharacterMap();
        }

        float speed = Math.Sign(Input.GetAxis("Mouse ScrollWheel")) * DeltaSpeed;

        ChangeAnimationSpeed(speed);

        animator.Speed = AnimatorSpeed;
    }
コード例 #8
0
        protected UnityAnimator toAnimator(GameObject obj, AnimatorController controller, UnityScene unityScene)
        {
            var path = AssetDatabase.GetAssetPath(controller);

            if ("" == path)
            {
                return(null);
            }


            if (true == unityScene.animatorObj.ContainsKey(path))
            {
                return(unityScene.animatorObj[path]);
            }

            UnityAnimator animator = new UnityAnimator();

            unityScene.animatorObj.Add(path, animator);

            Dictionary <string, CurveData> boneObj = new Dictionary <string, CurveData>();

            Export.foramtCurveData(boneObj, obj.transform, "");

            AnimationClip[] clips  = controller.animationClips;
            int             length = clips.Length;

            for (int i = 0; i < length; i++)
            {
                var clip = clips[i];
                // animDatas[i] = Export.clipToAnimationData(clips[i],boneObj);
                var refName = Export.getAnimationPath(clip);
                var name    = Export.getAnimationName(clip);

                if (false == unityScene.animationDataObj.ContainsKey(refName))
                {
                    var data = Export.clipToAnimationData(clip, boneObj);
                    unityScene.animationDataObj.Add(refName, data);
                }

                animator.animObjs.Add(name, refName.Replace("assets/", ""));
            }



            return(animator);
        }
コード例 #9
0
    private void Update()
    {
        if (_animator == null)
        {
            _animator = GetComponent <SpriterDotNetUnity.SpriterDotNetBehaviour>().Animator;
            _animator.Play(GetAnimation(1));
        }

        if (_canMove)
        {
            if (Time.time - _timer > _landingDuration && _timer != 0.0f)
            {
                _animator.Play(GetAnimation(2));
                GetComponent <AudioSource>().Play();
                _timer = 0.0f;
            }

            _offset = _movingRight ? _GOBox.bounds.max.x : _GOBox.bounds.min.x;

            _origin = _GOBox.bounds.center;
            _hit    = Physics2D.Raycast(new Vector2(_offset, _origin.y), _direction, _distance);
            Debug.DrawRay(new Vector2(_offset, _origin.y), new Vector3(_direction.x * _distance, _direction.y * _distance, 0.0f), Color.green);

            if (Mathf.Abs(_body.velocity.x) <= 1.0f)
            {
                _movingRight   = _movingRight ? false : true;
                _walkingSpeed *= -1.0f;
                _direction.x  *= -1.0f;
            }

            if (_hit.collider == null)
            {
                _movingRight   = _movingRight ? false : true;
                _walkingSpeed *= -1.0f;
                _direction.x  *= -1.0f;
            }



            else
            {
                _body.MoveRotation(0.0f);
            }
        }
    }
コード例 #10
0
    private void Update()
    {
        // Keep looking for the animator component unit it is found.
        if (_animator == null)
        {
            _animator = GetComponent <SpriterDotNetBehaviour>().Animator;
            if (_activated)
            {
                Activate();
            }
        }

        // If a player has reached a new checkpoint, reset the old checkpoint to a ready state (not a checked state)
        if (_activated && _GM.SOSaveHandler.CheckpointID != ID)
        {
            _activated = false;
            _animator.Play(GetAnimation(-1));
        }
    }
コード例 #11
0
    // Update is called once per frame
    void HandleAnimation()
    {
        if (spriteObject == null)
        {
            foreach (Transform child in transform)
            {
                if (child.name == "Ember")
                {
                    spriteObject = child.gameObject;
                    break;
                }
            }
        }

        if (animator == null && spriteObject != null)
        {
            animator = spriteObject.GetComponent <SpriterDotNetBehaviour>().Animator;
            animator.EventTriggered += AudioTriggers;
        }
    }
コード例 #12
0
    //public PlayerStateMachineAction stateMachineAction;

    // Use this for initialization
    void Start()
    {
        // Physics
        body = GetComponent <Rigidbody2D>();
        floorContactCounter = 0;
        freeze = false;
        // End physics

        // Graphisms
        toRight  = true;
        animator = GetComponent <SpriterDotNetBehaviour>().Animator;
        // End graphisms

        // Gameplay
        jumpCounter = 0;
        canJump     = true;
        stateMachineMouvementH.SStart();
        stateMachineMouvementH.SetPlayer(this);

        stateMachineMouvementV.SStart();
        stateMachineMouvementV.SetPlayer(this);
        // End gameplay
    }
コード例 #13
0
    bool HandleAnimation()
    {
        if (spriteObject == null)
        {
            foreach (Transform child in transform)
            {
                if (child.name == "Ember")
                {
                    spriteObject = child.gameObject;
                    break;
                }
            }
        }

        if (animator == null && spriteObject != null)
        {
            animator = spriteObject.GetComponent <SpriterDotNetBehaviour>().Animator;
            animator.AnimationFinished += HandleAnimationTransitions;
        }

        //determine statue state
        if (!PauseManager.Instance.Paused && animator.CurrentAnimation.Name == "Statue" &&
            (
                //NOTE: carbon input really needs an "any key"
                //any face button
                GamePad.GetState().Pressed(CButton.A) || GamePad.GetState().Pressed(CButton.B) || GamePad.GetState().Pressed(CButton.X) || GamePad.GetState().Pressed(CButton.Y) ||                 //only pressed this loop
                //any axis
                Mathf.Abs(GamePad.GetAxis(CAxis.LX)) >= deadZone || Mathf.Abs(GamePad.GetAxis(CAxis.LY)) >= deadZone || Mathf.Abs(GamePad.GetAxis(CAxis.RX)) >= deadZone || Mathf.Abs(GamePad.GetAxis(CAxis.RY)) >= deadZone
            )
            )
        {
            animator.Play("Statue to Idle");
            return(false);
        }

        if (animator.CurrentAnimation.Name == "Statue to Idle")
        {
            return(false);
        }

        //switch from regular animations to transition animations
        if (animator.CurrentAnimation.Name == "Straight Jump Rising" && rigidBody.velocity.y <= 0)
        {
            animator.Play("Straight Jump Crest");
        }

        if (animator.CurrentAnimation.Name == "Straight Jump Falling" && rigidBody.velocity.y >= 0)
        {
            animator.Play("Straight Jump Landing");
        }

        if (animator.CurrentAnimation.Name == "Rolling Jump" && grounded)
        {
            animator.Play("Straight Jump Landing");             //deliberately reuse this
        }

        //start looking up
        if (animator.CurrentAnimation.Name == "Idle" && verticalInput < 0 && Mathf.Abs(rigidBody.velocity.x) < 0.0001f)
        {
            animator.Play("Idle to Lookup");
        }

        //stop looking up
        if (animator.CurrentAnimation.Name == "Lookup" && verticalInput >= 0)
        {
            animator.Play("Lookup to Idle");
        }

        //BUGFIX: bouncing off of a wall
        if (!grounded && !wallHugged && animator.CurrentAnimation.Name == "Wall Slide")
        {
            animator.Play("Rolling Jump");
        }

        //if ever simply falling (or attacking)
        if (!grounded && !wallHugged && rigidBody.velocity.y < 0 && animator.CurrentAnimation.Name != "Straight Jump Crest" && animator.CurrentAnimation.Name != "Straight Jump Turn" && animator.CurrentAnimation.Name != "Rolling Jump Turn" && animator.CurrentAnimation.Name != "Rolling Jump" && animator.CurrentAnimation.Name != "Airborn Upward Slash" && animator.CurrentAnimation.Name != "Airborn Downward Slash" && animator.CurrentAnimation.Name != "Airborn Forward Slash")
        {
            animator.Play("Straight Jump Falling");
        }

        //hit a wall
        if (animator.CurrentAnimation.Name != "Brace on Wall" && animator.CurrentAnimation.Name != "Wall Slide" && animator.CurrentAnimation.Name != "Wall Kick" && wallHugged && !grounded)
        {
            animator.Play("Brace on Wall");
        }

        //reach the bottom of a wall-slide (or hit the ground when turning)
        if ((animator.CurrentAnimation.Name == "Brace on Wall" || animator.CurrentAnimation.Name == "Wall Slide" || animator.CurrentAnimation.Name == "Straight Jump Turn" || animator.CurrentAnimation.Name == "Rolling Jump Turn") && grounded)
        {
            animator.Play("Straight Jump Landing");
        }

        //if bouncing
        if (animator.CurrentAnimation.Name == "Straight Jump Landing" && !grounded && rigidBody.velocity.y > 0f)
        {
            animator.Play("Begin Rolling Jump");
        }

        //handle bounding box
        if (
            animator.CurrentAnimation.Name == "Crouch" ||
            animator.CurrentAnimation.Name == "Idle to Crouch" ||
            animator.CurrentAnimation.Name == "Rolling Jump" ||
            animator.CurrentAnimation.Name == "Begin Rolling Jump" ||
            (rigidBody.velocity.y > 0 && animator.CurrentAnimation.Name == "Straight Jump Landing") ||
            animator.CurrentAnimation.Name == "Brace on Wall" ||
            animator.CurrentAnimation.Name == "Wall Slide" ||
            animator.CurrentAnimation.Name == "Wall Kick"
            )
        {
            //half box
            if (currentBoxCollider != GetComponents <BoxCollider2D>()[1])
            {
                currentBoxCollider.enabled = false;
                currentBoxCollider         = GetComponents <BoxCollider2D>()[1];
                currentBoxCollider.enabled = true;
            }
        }
        else
        {
            //full box
            if (currentBoxCollider != GetComponents <BoxCollider2D>()[0])
            {
                currentBoxCollider.enabled = false;
                currentBoxCollider         = GetComponents <BoxCollider2D>()[0];
                currentBoxCollider.enabled = true;
            }
        }

        //peek with the camera
        CameraController camController = Object.FindObjectOfType <CameraController>();

        if (camController.GetPeek() == Vector2.zero)
        {
            if (animator.CurrentAnimation.Name == "Lookup")
            {
                camController.SetPeek(new Vector2(0f, 4f));
            }
            if (animator.CurrentAnimation.Name == "Crouch")
            {
                camController.SetPeek(new Vector2(0f, -4f));
            }
        }
        if (camController.GetPeek() != Vector2.zero)
        {
            if (animator.CurrentAnimation.Name != "Lookup" && animator.CurrentAnimation.Name != "Crouch")
            {
                camController.ResetPeek();
            }
        }

        return(true);
    }
コード例 #14
0
    private void Update()
    {
        if (_spriterAnimator == null)
        {
            _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
            _animationList   = _spriterAnimator.GetAnimations().ToList();
        }

        _grounded = _collisionState.OnSolidGround;

        _currentIndex  = _shotgunGO.isActiveAndEnabled ? 0 : 23; // Check if the shotgun or the machine gun is active
        _currentIndex += !_grounded ? 0 : 6;                     // Check if the player is falling or is on the ground.

        // If the player is on the ground, check if the player is standing still or running.
        if (_currentIndex == 6 || _currentIndex == 29)
        {
            _currentIndex += _controller.GetButtonPress(Buttons.MoveLeft) || _controller.GetButtonPress(Buttons.MoveRight) ? 6 : 0;
        }

        if (_controller.GetButtonPress(Buttons.AimDown) || _controller.GetButtonPress(Buttons.AimLeft) ||
            _controller.GetButtonPress(Buttons.AimRight) || _controller.GetButtonPress(Buttons.AimUp) || _controller.GetButtonPress(Buttons.Shoot))
        {
            switch (_controller.AimDirection)
            {
            case 0:
            case 180:
                _currentIndex += 3; break;

            case 45:
            case 135:
                _currentIndex += 2; break;

            case 90:
                _currentIndex += 1; break;

            case 270:
                _currentIndex += 5; break;

            case 225:
            case 315:
                _currentIndex += 4; break;

            default:
                _currentIndex += 3; break;
            }
        }

        if (_grounded)
        {
            if (_controller.GetButtonPress(Buttons.MoveLeft) && _controller.GetButtonPress(Buttons.AimRight) ||
                _controller.GetButtonPress(Buttons.MoveRight) && _controller.GetButtonPress(Buttons.AimLeft))
            {
                _currentIndex += 5;
            }
        }

        if (_currentIndex != _previousIndex)
        {
            Play(_currentIndex);
            _previousIndex = _currentIndex;
        }
    }
コード例 #15
0
    void Update()
    {
        if (Ember == null)
        {
            foreach (Transform child in transform)
            {
                if (child.name == "Ember")
                {
                    Ember = child.gameObject; break;
                }
            }
        }

        if (anim == null)
        {
            anim = Ember.GetComponent <SpriterDotNetBehaviour>().Animator;
            //This event is fired whenever an animation ends.
            anim.AnimationFinished += animationTransitions;
        }

        if (Input.anyKeyDown)
        {
            //Advance the animation.
            if (anim.CurrentAnimation.Name == "Statue")
            {
                anim.Play("Statue to Idle");
            }
            else if (anim.CurrentAnimation.Name == "Idle")
            {
                switch (mode)
                {
                case animationMode.move:
                    anim.Play("Idle to Walk");
                    mode = animationMode.straightJump;
                    break;

                case animationMode.straightJump:
                    anim.Play("Begin Straight Jump");
                    mode = animationMode.rollingJump;
                    break;

                case animationMode.rollingJump:
                    anim.Play("Begin Rolling Jump");
                    mode = animationMode.lookUp;
                    break;

                case animationMode.lookUp:
                    if (!slash)
                    {
                        anim.Play("Grounded Forward Slash");
                        slash = true;
                    }
                    else
                    {
                        slash = false;
                        anim.Play("Idle to Lookup");
                        mode = animationMode.lookDown;
                    }
                    break;

                case animationMode.lookDown:
                    anim.Play("Idle to Crouch");
                    mode = animationMode.move;
                    break;
                }
            }
            else if (anim.CurrentAnimation.Name == "Walk")
            {
                anim.Play("Run");
            }
            else if (anim.CurrentAnimation.Name == "Run")
            {
                anim.Play("Idle");
            }
            else if (anim.CurrentAnimation.Name == "Straight Jump Rising")
            {
                if (!slash)
                {
                    anim.Play("Airborn Upward Slash");
                    slash = true;
                }
                else
                {
                    anim.Play("Straight Jump Crest");
                    slash = false;
                }
            }
            else if (anim.CurrentAnimation.Name == "Straight Jump Falling" ||
                     anim.CurrentAnimation.Name == "Rolling Jump")
            {
                if (!slash)
                {
                    if (anim.CurrentAnimation.Name == "Straight Jump Falling")
                    {
                        anim.Play("Airborn Forward Slash");
                    }
                    else
                    {
                        anim.Play("Airborn Downward Slash");
                    }
                    slash = true;
                }
                else
                {
                    anim.Play("Straight Jump Landing");
                    slash = false;
                }
            }
            else if (anim.CurrentAnimation.Name == "Crouch")
            {
                anim.Play("Crouch to Idle");
            }
            else if (anim.CurrentAnimation.Name == "Lookup")
            {
                if (!slash)
                {
                    anim.Play("Grounded Upward Slash");
                    slash = true;
                }
                else
                {
                    anim.Play("Lookup to Idle");
                    slash = false;
                }
            }
        }
    }
コード例 #16
0
 // Use this for initialization
 void Start()
 {
     uAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
     Screen.SetResolution(1200, 786, true);
 }
コード例 #17
0
 void Awake()
 {
     _animator            = new UnityAnimator(GetComponent <Animator>());
     _skinnedMeshRenderer = GetComponentInChildren <SkinnedMeshRenderer>();
     _handAnimation       = new HandAnimation(_animator, _skinnedMeshRenderer);
 }