Example #1
0
 public void OnReceiveAttack(vDamage damage, vIMeleeFighter attacker)
 {
     if (overrideReactionID)
     {
         damage.reaction_id = reactionID;
     }
     if (ragdoll && !ragdoll.iChar.isDead)
     {
         var _damage = new vDamage(damage);
         var value   = (float)_damage.damageValue;
         _damage.damageValue = (int)(value * damageMultiplier);
         ragdoll.gameObject.ApplyDamage(_damage, attacker);
     }
     else
     {
         if (!iChar)
         {
             iChar = GetComponentInParent <vCharacter>();
         }
         if (iChar)
         {
             var _damage = new vDamage(damage);
             var value   = (float)_damage.damageValue;
             _damage.damageValue = (int)(value * damageMultiplier);
             iChar.gameObject.ApplyDamage(_damage, attacker);
         }
     }
 }
Example #2
0
        void Start()
        {
            vCharacter character = GetComponent <vCharacter>();

            if (character)
            {
                character.onDead.AddListener(OnDeadHandle);
            }
        }
        void Start()
        {
            if (!sensor)
            {
                var sensorObj = new GameObject("HeadTrackSensor");
                sensor = sensorObj.AddComponent <vHeadTrackSensor>();
            }

            vchar            = GetComponent <vCharacter>();
            sensor.headTrack = this;
            animator         = GetComponentInParent <Animator>();
            head             = animator.GetBoneTransform(HumanBodyBones.Head);
            var spine1 = animator.GetBoneTransform(HumanBodyBones.Spine);
            var spine2 = animator.GetBoneTransform(HumanBodyBones.Chest);

            spines = new List <Transform>();
            spines.Add(spine1);
            spines.Add(spine2);
            var neck = animator.GetBoneTransform(HumanBodyBones.Neck);

            if (neck.parent != spine2)
            {
                spines.Add(neck.parent);
            }

            if (head)
            {
                headHeight = Vector3.Distance(transform.position, head.position);
                sensor.transform.position = head.transform.position;
            }
            else
            {
                sensor.transform.position = transform.position;
            }

            var layer = LayerMask.NameToLayer("HeadTrack");

            sensor.transform.parent = transform;
            sensor.gameObject.layer = layer;
            sensor.gameObject.tag   = transform.tag;
            tagsHash = new List <int>();

            for (int i = 0; i < animatorTags.Count; i++)
            {
                tagsHash.Add(Animator.StringToHash(animatorTags[i]));
            }
            GetLookPoint();
        }
Example #4
0
        void Start()
        {
            // store the Animator component
            animator = GetComponent <Animator>();
            iChar    = GetComponent <vCharacter>();

            if (iChar)
            {
                iChar.onReceiveDamage.AddListener(ActivateRagdoll);
            }

            // find character chest and hips
            characterChest = animator.GetBoneTransform(HumanBodyBones.Chest);
            characterHips  = animator.GetBoneTransform(HumanBodyBones.Hips);
            hipsParent     = characterHips.parent;
            // set all RigidBodies to kinematic so that they can be controlled with Mecanim
            // and there will be no glitches when transitioning to a ragdoll
            setKinematic(true);
            setCollider(true);
            _ragdollContainer           = new GameObject("RagdollContainer " + gameObject.name);
            _ragdollContainer.hideFlags = HideFlags.HideInHierarchy;
            // find all the transforms in the character, assuming that this script is attached to the root
            Component[] components = GetComponentsInChildren(typeof(Transform));

            // for each of the transforms, create a BodyPart instance and store the transform
            foreach (Component c in components)
            {
                if (!ignoreTags.Contains(c.tag))
                {
                    BodyPart bodyPart = new BodyPart();
                    bodyPart.transform = c as Transform;
                    if (c.GetComponent <Rigidbody>() != null)
                    {
                        c.tag = gameObject.tag;
                    }
                    bodyParts.Add(bodyPart);
                }
            }
        }
        /// <summary>
        /// Load all <see cref="vCharacterController.vActions.IActionController"/> and derivatives  in character gameObject to register to events <see cref="vCharacterController.vCharacter.onActionEnter"/>,<see cref="vCharacterController.vCharacter.onActionStay"/> and <see cref="vCharacterController.vCharacter.onActionExit"/>.
        /// </summary>
        /// <param name="character">Target <seealso cref="vCharacterController.vCharacter>"/></param>
        public static void LoadActionControllers(this vCharacterController.vCharacter character, bool debug = false)
        {
            var actionControllers = character.GetComponents <vCharacterController.vActions.IActionController>();

            for (int i = 0; i < actionControllers.Length; i++)
            {
                if (actionControllers[i].enabled)
                {
                    if (actionControllers[i] is vCharacterController.vActions.IActionListener)
                    {
                        var actionListener = actionControllers[i] as vCharacterController.vActions.IActionListener;

                        {
                            if (actionListener.useActionEnter)
                            {
                                character.onActionEnter.RemoveListener(actionListener.OnActionEnter);
                                character.onActionEnter.AddListener(actionListener.OnActionEnter);
                                if (debug)
                                {
                                    Debug.Log("Register Action Enter event to the " + actionListener.GetType().Name);
                                }
                            }

                            if (actionListener.useActionStay)
                            {
                                character.onActionStay.RemoveListener(actionListener.OnActionStay);
                                character.onActionStay.AddListener(actionListener.OnActionStay);
                                if (debug)
                                {
                                    Debug.Log("Register Action Stay event to the " + actionListener.GetType().Name);
                                }
                            }

                            if (actionListener.useActionExit)
                            {
                                character.onActionExit.RemoveListener(actionListener.OnActionExit);
                                character.onActionExit.AddListener(actionListener.OnActionExit);
                                if (debug)
                                {
                                    Debug.Log("Register action Exit event to the " + actionListener.GetType().Name);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (actionControllers[i] is vCharacterController.vActions.IActionEnterListener)
                        {
                            character.onActionEnter.RemoveListener((actionControllers[i] as vCharacterController.vActions.IActionEnterListener).OnActionEnter);
                            character.onActionEnter.AddListener((actionControllers[i] as vCharacterController.vActions.IActionEnterListener).OnActionEnter);
                            if (debug)
                            {
                                Debug.Log("Register Action Enter event to the " + actionControllers[i].GetType().Name);
                            }
                        }

                        if (actionControllers[i] is vCharacterController.vActions.IActionStayListener)
                        {
                            character.onActionStay.RemoveListener((actionControllers[i] as vCharacterController.vActions.IActionStayListener).OnActionStay);
                            character.onActionStay.AddListener((actionControllers[i] as vCharacterController.vActions.IActionStayListener).OnActionStay);
                            if (debug)
                            {
                                Debug.Log("Register Action Stay event to the " + actionControllers[i].GetType().Name);
                            }
                        }

                        if (actionControllers[i] is vCharacterController.vActions.IActionExitListener)
                        {
                            character.onActionExit.RemoveListener((actionControllers[i] as vCharacterController.vActions.IActionExitListener).OnActionExit);
                            character.onActionExit.AddListener((actionControllers[i] as vCharacterController.vActions.IActionExitListener).OnActionExit);
                            if (debug)
                            {
                                Debug.Log("Register Action Exit event to the " + actionControllers[i].GetType().Name);
                            }
                        }
                    }
                }
            }
        }
Example #6
0
 void Start()
 {
     _rigidbody = GetComponent <Rigidbody>();
     character  = GetComponent <vCharacter>();
     character.onReceiveDamage.AddListener(TakeDamage);
 }