示例#1
0
 public override void ClearTarget()
 {
     base.ClearTarget();
     healthController  = null;
     meleeFighter      = null;
     character         = null;
     combateController = null;
 }
示例#2
0
        void Start()
        {
            // store the Animator component
            animator    = GetComponent <Animator>();
            _parentRigb = GetComponent <Rigidbody>();
            iChar       = GetComponent <vICharacter>();

            if (iChar != null)
            {
                iChar.onActiveRagdoll.AddListener(ActivateRagdoll);
            }

            if (!collisionSource)
            {
                var _collisionPrefab = new GameObject("ragdollAudioSource");
                _collisionPrefab.transform.SetParent(gameObject.transform);
                collisionSource = _collisionPrefab.AddComponent <AudioSource>();
            }

            // 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
            CreateRagdollContainer();

            // find all the transforms in the character, assuming that this script is attached to the root
            if (characterHips)
            {
                Component[] components = characterHips.GetComponentsInChildren(typeof(Transform));
                bodyParts.Add(new BodyPart(characterHips));
                // for each of the transforms, create a BodyPart instance and store the transform
                foreach (Component c in components)
                {
                    if (!ignoreTags.Contains(c.tag) && c)
                    {
                        var t = c as Transform;
                        if (t != transform && t.GetComponent <Rigidbody>())
                        {
                            BodyPart bodyPart = new BodyPart(t);

                            if (bodyPart.rigidbody != null)
                            {
                                bodyPart.rigidbody.isKinematic = true;
                                c.tag = gameObject.tag;
                            }
                            bodyParts.Add(bodyPart);
                        }
                    }
                }
                setKinematic(true);
                setCollider(true);
            }
        }
示例#3
0
 public override void InitTarget(Transform target)
 {
     base.InitTarget(target);
     if (target)
     {
         healthController     = target.GetComponent <vIHealthController>();
         _hadHealthController = this.healthController != null;
         meleeFighter         = target.GetComponent <vIMeleeFighter>();
         character            = target.GetComponent <vICharacter>();
         combateController    = target.GetComponent <vIControlAICombat>();
     }
 }
示例#4
0
        void Start()
        {
            if (!sensor)
            {
                var sensorObj = new GameObject("HeadTrackSensor");
                sensor = sensorObj.AddComponent <vHeadTrackSensor>();
            }

            vchar            = GetComponent <vICharacter>();
            sensor.headTrack = this;
            animator         = GetComponentInParent <Animator>();
            head             = animator.GetBoneTransform(HumanBodyBones.Head);
            spine1           = animator.GetBoneTransform(HumanBodyBones.Spine);
            spine2           = animator.GetBoneTransform(HumanBodyBones.Chest);
            spines           = new List <Transform>();
            spines.Add(spine1);
            spines.Add(spine2);
            neck = animator.GetBoneTransform(HumanBodyBones.Neck);

            if (neck == null)
            {
                Debug.LogWarning("Invector Headtrack Warning - Check your Character Avatar to see if a Neck Bone was assign correctly.");
            }
            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();
        }
示例#5
0
        void Start()
        {
            if (!sensor)
            {
                var sensorObj = new GameObject("HeadTrackSensor");
                sensor = sensorObj.AddComponent <vHeadTrackSensor>();
            }

            // updates the headtrack using the late update of the tpinput so we don't need to create another one
            var tpInput = GetComponent <vThirdPersonInput>();

            if (tpInput)
            {
                tpInput.onLateUpdate -= UpdateHeadTrack;
                tpInput.onLateUpdate += UpdateHeadTrack;
            }

            vchar            = GetComponent <vICharacter>();
            sensor.headTrack = this;
            animator         = GetComponentInChildren <Animator>();
            if (animator)
            {
                animatorStateInfos = new vAnimatorStateInfos(animator);
                animatorStateInfos.RegisterListener();
            }

            if (autoFindBones)
            {
                head = animator.GetBoneTransform(HumanBodyBones.Head);
                if (head)
                {
                    forwardReference = new GameObject("FWRF").transform;
                    forwardReference.SetParent(head);
                    forwardReference.transform.localPosition = Vector3.zero;
                    forwardReference.transform.rotation      = transform.rotation;
                    var hips = animator.GetBoneTransform(HumanBodyBones.Hips);
                    if (hips)
                    {
                        var target = head;
                        for (int i = 0; i < 4; i++)
                        {
                            if (target.parent && target.parent.gameObject != hips.gameObject)
                            {
                                spine.Add(target.parent);
                                target = target.parent;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            cameraMain = Camera.main;
            if (head)
            {
                headHeight = Vector3.Distance(transform.position, head.position);
                sensor.transform.position = head.transform.position;
            }
            else
            {
                headHeight = 1f;
                sensor.transform.position = transform.position;
            }
            if (spine.Count == 0)
            {
                Debug.Log("Headtrack Spines missing");
            }
            var layer = LayerMask.NameToLayer("HeadTrack");

            sensor.transform.parent = transform;
            sensor.gameObject.layer = layer;
            sensor.gameObject.tag   = transform.tag;
            spine.Reverse();
            GetLookPoint();
        }