Пример #1
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character instance = this.character.GetCharacter(target);

            if (instance == null)
            {
                return(true);
            }

            CharacterAnimator animator = instance.GetCharacterAnimator();

            if (animator == null)
            {
                return(true);
            }

            switch (this.part)
            {
            case Section.Head: animator.useSmartHeadIK = this.enable; break;

            case Section.Hands: animator.useHandIK = this.enable; break;

            case Section.Feet: animator.useFootIK = this.enable; break;
            }

            return(true);
        }
        // INITIALIZERS: --------------------------------------------------------------------------

        protected void OnEnable()
        {
            this.characterAnimator = (CharacterAnimator)this.target;

            string    iconModelPath = Path.Combine(CharacterEditor.CHARACTER_ICONS_PATH, "CharacterAnimModel.png");
            Texture2D iconModel     = AssetDatabase.LoadAssetAtPath <Texture2D>(iconModelPath);

            this.sectionModel = new CharacterEditor.Section("Character Model", iconModel, this.Repaint);

            string    iconIKPath = Path.Combine(CharacterEditor.CHARACTER_ICONS_PATH, "CharacterAnimIK.png");
            Texture2D iconIK     = AssetDatabase.LoadAssetAtPath <Texture2D>(iconIKPath);

            this.sectionIK = new CharacterEditor.Section("Inverse Kinematics", iconIK, this.Repaint);

            string    iconRagdollPath = Path.Combine(CharacterEditor.CHARACTER_ICONS_PATH, "CharacterAnimRagdoll.png");
            Texture2D iconRagdoll     = AssetDatabase.LoadAssetAtPath <Texture2D>(iconRagdollPath);

            this.sectionRagdoll = new CharacterEditor.Section("Ragdoll", iconRagdoll, this.Repaint);

            this.spAnimator     = serializedObject.FindProperty("animator");
            this.spDefaultState = serializedObject.FindProperty("defaultState");

            this.spUseFootIK      = serializedObject.FindProperty("useFootIK");
            this.spUseHandIK      = serializedObject.FindProperty("useHandIK");
            this.spUseSmartHeadIK = serializedObject.FindProperty("useSmartHeadIK");

            this.spRagdollMass   = serializedObject.FindProperty("ragdollMass");
            this.spStableTimeout = serializedObject.FindProperty("stableTimeout");
            this.spStandFaceUp   = serializedObject.FindProperty("standFaceUp");
            this.spStandFaceDown = serializedObject.FindProperty("standFaceDown");
        }
Пример #3
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public CharacterRagdoll(Character character)
        {
            this.character    = character;
            this.charAnimator = this.character.GetCharacterAnimator();

            this.Initialize(true);
        }
Пример #4
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character charTarget = this.character.GetCharacter(target);

            if (charTarget != null && this.prefabModel != null)
            {
                RuntimeAnimatorController runtimeController = null;

                CharacterAnimator targetCharAnim = charTarget.GetComponent <CharacterAnimator>();
                if (targetCharAnim.animator != null)
                {
                    runtimeController = targetCharAnim.animator.runtimeAnimatorController;
                    Destroy(targetCharAnim.animator.gameObject);
                }

                GameObject instance = Instantiate <GameObject>(this.prefabModel, charTarget.transform);
                instance.name = this.prefabModel.name;

                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = Quaternion.identity;

                Animator instanceAnimator = instance.GetComponent <Animator>();
                if (instanceAnimator != null)
                {
                    targetCharAnim.animator = instanceAnimator;
                    targetCharAnim.ResetControllerTopology(runtimeController);
                }
            }

            return(true);
        }
Пример #5
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public CharacterAnimation(CharacterAnimator characterAnimator, CharacterState defaultState)
        {
            this.characterAnimator = characterAnimator;
            this.SetupTopology(defaultState == null
                ? null
                : defaultState.GetRuntimeAnimatorController()
                               );
        }
Пример #6
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public CharacterAnimation(CharacterAnimator characterAnimator, CharacterState defaultState = null)
        {
            this.characterAnimator = characterAnimator;
            this.runtimeController = defaultState != null
                ? defaultState.GetRuntimeAnimatorController()
                : characterAnimator.animator.runtimeAnimatorController;

            this.Setup();
        }
Пример #7
0
        protected void CharacterAwake()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            this.animator = GetComponent <CharacterAnimator>();
            this.characterLocomotion.Setup(this);

            this.ragdoll = new CharacterRagdoll(this);
        }
Пример #8
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character charTarget = this.character.GetCharacter(target);

            if (this.clip != null && charTarget != null && charTarget.GetCharacterAnimator() != null)
            {
                this.characterAnimator = charTarget.GetCharacterAnimator();
                this.characterAnimator.PlayGesture(this.clip, this.speed.GetValue(target), this.avatarMask);
            }

            return(!this.waitTillComplete);
        }
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character charTarget = this.character.GetCharacter(target);

            if (charTarget != null && charTarget.GetCharacterAnimator() != null)
            {
                CharacterAnimator characterAnimator = charTarget.GetCharacterAnimator();
                characterAnimator.StopGesture(this.transition);
            }

            return(true);
        }
Пример #10
0
            public TargetTransform(Transform transform = null)
            {
                this.transform = transform;

                if (transform != null)
                {
                    CharacterAnimator charAnimator = transform.GetComponent <CharacterAnimator>();
                    if (charAnimator != null)
                    {
                        this.transform = charAnimator.GetHeadTransform();
                    }
                }
            }
Пример #11
0
        protected void CharacterAwake()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            this.animator = GetComponent <CharacterAnimator>();
            this.characterLocomotion.Setup(this);

            if (this.animator != null && this.animator.autoInitializeRagdoll)
            {
                this.InitializeRagdoll();
            }
        }
Пример #12
0
            public TrackInfo(Character character)
            {
                this.character         = character;
                this.characterAnimator = this.character.GetCharacterAnimator();

                if (this.characterAnimator != null)
                {
                    this.headTransform = this.characterAnimator.GetHeadTransform();
                }

                this.currentTrackState = TrackState.NOT_TRACKING;
                this.currentPosition   = Vector3.zero;
                this.currentWeight     = 0.0f;
                this.changedTime       = Time.time;
            }
Пример #13
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public void Setup(Character character)
        {
            this.character         = character;
            this.characterAnimator = this.character.GetCharacterAnimator();
            this.animator          = this.characterAnimator.animator;
            if (this.animator == null || !this.animator.isHuman)
            {
                return;
            }

            Transform handLTransform = this.animator.GetBoneTransform(HumanBodyBones.LeftHand);
            Transform handRTransform = this.animator.GetBoneTransform(HumanBodyBones.RightHand);

            this.handL = new Hand(handLTransform, AvatarIKGoal.LeftHand);
            this.handR = new Hand(handRTransform, AvatarIKGoal.RightHand);
        }
Пример #14
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character  charTarget = this.character.GetCharacter(target);
            GameObject prefab     = this.prefabModel.GetGameObject(target);

            if (charTarget != null && prefab != null)
            {
                CharacterAnimator targetCharAnim = charTarget.GetComponent <CharacterAnimator>();
                if (targetCharAnim.animator != null)
                {
                    targetCharAnim.ChangeModel(prefab);
                }
            }

            return(true);
        }
Пример #15
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public void Setup(Character character)
        {
            this.character         = character;
            this.characterAnimator = this.character.GetCharacterAnimator();
            this.animator          = this.characterAnimator.animator;
            this.controller        = gameObject.GetComponentInParent <CharacterController>();
            if (this.animator == null || !this.animator.isHuman || this.controller == null)
            {
                return;
            }

            Transform handLTransform = this.animator.GetBoneTransform(HumanBodyBones.LeftHand);
            Transform handRTransform = this.animator.GetBoneTransform(HumanBodyBones.RightHand);

            this.handL = new Hand(handLTransform, AvatarIKGoal.LeftHand);
            this.handR = new Hand(handRTransform, AvatarIKGoal.RightHand);
        }
Пример #16
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character characterTarget = this.character.GetCharacter(target);

            if (characterTarget == null)
            {
                return(true);
            }

            CharacterAnimator animator = characterTarget.GetCharacterAnimator();

            if (animator == null)
            {
                return(true);
            }

            CharacterAttachments attachments = animator.GetCharacterAttachments();

            if (attachments == null)
            {
                return(true);
            }

            switch (this.action)
            {
            case Action.Attach:
                attachments.Attach(
                    this.bone,
                    this.instance.GetGameObject(target),
                    this.position,
                    Quaternion.Euler(this.rotation),
                    this.space
                    ); break;

            case Action.Detach:
                attachments.Detach(this.bone);
                break;

            case Action.Remove:
                attachments.Remove(this.bone);
                break;
            }

            return(true);
        }
Пример #17
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public void Setup(Character character)
        {
            this.character         = character;
            this.characterAnimator = this.character.GetCharacterAnimator();
            this.animator          = this.characterAnimator.animator;
            this.controller        = gameObject.GetComponentInParent <CharacterController>();
            if (this.animator == null || !this.animator.isHuman || this.controller == null)
            {
                return;
            }

            Transform lFoot = this.animator.GetBoneTransform(HumanBodyBones.LeftFoot);
            Transform rFoot = this.animator.GetBoneTransform(HumanBodyBones.RightFoot);

            this.leftFoot  = new Foot(lFoot, AvatarIKGoal.LeftFoot, IK_L_FOOT);
            this.rightFoot = new Foot(rFoot, AvatarIKGoal.RightFoot, IK_R_FOOT);

            this.defaultOffset = transform.localPosition.y;
        }
Пример #18
0
        // EXECUTABLE: ----------------------------------------------------------------------------

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character characterTarget = this.character.GetCharacter(target);

            if (characterTarget == null)
            {
                return(true);
            }

            CharacterAnimator animator = characterTarget.GetCharacterAnimator();

            if (animator == null)
            {
                return(true);
            }

            CharacterHandIK handIK = animator.GetCharacterHandIK();

            if (handIK == null)
            {
                return(true);
            }

            switch (this.action)
            {
            case Action.Reach:
                handIK.Reach(
                    this.hand,
                    this.reachTarget.GetTransform(target),
                    this.duration
                    );
                break;

            case Action.LetGo:
                handIK.LetGo(this.hand, this.duration);
                break;
            }

            return(true);
        }
Пример #19
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character instance = this.character.GetCharacter(target);

            if (instance == null)
            {
                return(true);
            }

            CharacterAnimator animator = instance.GetCharacterAnimator();

            if (animator == null)
            {
                return(true);
            }

            bool value = this.visible.GetValue(target);

            animator.SetVisibility(value);

            return(true);
        }
Пример #20
0
        // INITIALIZERS: --------------------------------------------------------------------------

        protected void OnEnable()
        {
            this.characterAnimator = (CharacterAnimator)this.target;

            string    iconAnimatorPath = Path.Combine(CharacterEditor.CHARACTER_ICONS_PATH, "CharacterAnimParams.png");
            Texture2D iconAnimator     = AssetDatabase.LoadAssetAtPath <Texture2D>(iconAnimatorPath);

            this.sectionAnimator = new CharacterEditor.Section("Animator Parameters", iconAnimator, this.Repaint);

            string    iconModelPath = Path.Combine(CharacterEditor.CHARACTER_ICONS_PATH, "CharacterAnimModel.png");
            Texture2D iconModel     = AssetDatabase.LoadAssetAtPath <Texture2D>(iconModelPath);

            this.sectionModel = new CharacterEditor.Section("Character Model", iconModel, this.Repaint);

            string    iconIKPath = Path.Combine(CharacterEditor.CHARACTER_ICONS_PATH, "CharacterAnimIK.png");
            Texture2D iconIK     = AssetDatabase.LoadAssetAtPath <Texture2D>(iconIKPath);

            this.sectionIK = new CharacterEditor.Section("Inverse Kinematics", iconIK, this.Repaint);

            this.spMoveForwardSpeed = serializedObject.FindProperty("moveForwardSpeed");
            this.spMoveSidesSpeed   = serializedObject.FindProperty("moveSidesSpeed");
            this.spMovementSpeed    = serializedObject.FindProperty("movementSpeed");
            this.spTargetLock       = serializedObject.FindProperty("targetLock");
            this.spVerticalSpeed    = serializedObject.FindProperty("verticalSpeed");
            this.spIsGrounded       = serializedObject.FindProperty("isGrounded");
            this.spJump             = serializedObject.FindProperty("jump");
            this.spFallForce        = serializedObject.FindProperty("fallForce");
            this.spNormalX          = serializedObject.FindProperty("normalX");
            this.spNormalY          = serializedObject.FindProperty("normalY");
            this.spNormalZ          = serializedObject.FindProperty("normalZ");

            this.spAnimator = serializedObject.FindProperty("animator");

            this.spUseFootIK      = serializedObject.FindProperty("useFootIK");
            this.spUseHandIK      = serializedObject.FindProperty("useHandIK");
            this.spUseSmartHeadIK = serializedObject.FindProperty("useSmartHeadIK");
        }
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character _character = this.character.GetCharacter(target);

            if (_character == null)
            {
                return(true);
            }

            CharacterAnimator _animator = _character.GetCharacterAnimator();

            if (_animator == null)
            {
                return(true);
            }

            if (this.state == null)
            {
                return(true);
            }
            _animator.ResetControllerTopology(this.state.GetRuntimeAnimatorController());

            return(true);
        }
Пример #22
0
        // INITIALIZERS: --------------------------------------------------------------------------

        public CharacterAnimation(CharacterAnimator characterAnimator)
        {
            this.characterAnimator = characterAnimator;
            this.SetupTopology();
        }
Пример #23
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            Character characterTarget = this.character.GetCharacter(target);

            if (characterTarget == null)
            {
                return(true);
            }

            CharacterLocomotion locomotion    = characterTarget.characterLocomotion;
            CharacterAnimator   animator      = characterTarget.GetCharacterAnimator();
            Vector3             moveDirection = Vector3.zero;

            switch (this.direction)
            {
            case Direction.CharacterMovement:
                moveDirection = locomotion.GetMovementDirection();
                break;

            case Direction.TowardsTarget:
                Transform targetTransform = this.target.GetTransform(target);
                if (targetTransform != null)
                {
                    moveDirection = targetTransform.position - characterTarget.transform.position;
                    moveDirection.Scale(PLANE);
                }
                break;

            case Direction.TowardsPosition:
                Vector3 targetPosition = this.position.GetPosition(target);
                moveDirection = targetPosition - characterTarget.transform.position;
                moveDirection.Scale(PLANE);
                break;
            }

            Vector3 charDirection = Vector3.Scale(
                characterTarget.transform.TransformDirection(Vector3.forward),
                PLANE
                );

            float         angle = Vector3.SignedAngle(moveDirection, charDirection, Vector3.up);
            AnimationClip clip  = null;

            if (angle <= 45f && angle >= -45f)
            {
                clip = this.dashClipForward;
            }
            else if (angle < 135f && angle > 45f)
            {
                clip = this.dashClipLeft;
            }
            else if (angle > -135f && angle < -45f)
            {
                clip = dashClipRight;
            }
            else
            {
                clip = this.dashClipBackward;
            }

            if (clip != null && animator != null)
            {
                animator.CrossFadeGesture(clip, 1f, null, 0.05f, 0.5f);
            }

            characterTarget.Dash(
                moveDirection.normalized,
                this.impulse.GetValue(target),
                this.duration.GetValue(target),
                this.drag
                );

            return(true);
        }
Пример #24
0
 protected void CharacterAwake()
 {
     this.characterAnimator = GetComponent <CharacterAnimator>();
     this.characterLocomotion.Setup(this);
 }