Beispiel #1
0
        void TriggerSound(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (_random == null)
            {
                _random = new vFisherYatesRandom();
            }
            isTrigger = true;
            GameObject audioObject = null;

            if (audioSource != null)
            {
                audioObject = Instantiate(audioSource.gameObject, animator.transform.position, Quaternion.identity) as GameObject;
            }
            else
            {
                audioObject = new GameObject("audioObject");
                audioObject.transform.position = animator.transform.position;
            }
            if (audioObject != null)
            {
                var source = audioObject.gameObject.GetComponent <AudioSource>();
                var clip   = sounds[_random.Next(sounds.Count)];
                source.PlayOneShot(clip);
            }
        }
Beispiel #2
0
        public override void Init()
        {
            base.Init();
            if (randomWaypoint == null)
            {
                randomWaypoint = new vFisherYatesRandom();
            }
            if (randomPatrolPoint == null)
            {
                randomPatrolPoint = new vFisherYatesRandom();
            }

            currentWaypoint    = -1;
            currentPatrolPoint = -1;
            fwd         = transform.forward;
            destination = transform.position;
            agent       = GetComponent <NavMeshAgent>();

            agentPath    = new NavMeshPath();
            sphereSensor = GetComponentInChildren <v_AISphereSensor>();
            if (sphereSensor)
            {
                sphereSensor.SetColliderRadius(maxDetectDistance);
                sphereSensor.tagsToDetect    = tagsToDetect;
                sphereSensor.passiveToDamage = passiveToDamage;
            }

            animator     = GetComponent <Animator>();
            meleeManager = GetComponent <vMeleeManager>();
            canAttack    = true;
            attackCount  = 0;
            sideMovement = GetRandonSide();
            destination  = transform.position;

            _rigidbody             = GetComponent <Rigidbody>();
            _rigidbody.useGravity  = true;
            _rigidbody.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezeRotation;
            agent.updatePosition   = false;
            agent.updateRotation   = false;
            agent.enabled          = false;
            _capsuleCollider       = GetComponent <CapsuleCollider>();

            // avoid collision detection with inside colliders
            Collider[] AllColliders = this.GetComponentsInChildren <Collider>();
            Collider   thisCollider = GetComponent <Collider>();

            for (int i = 0; i < AllColliders.Length; i++)
            {
                Physics.IgnoreCollision(thisCollider, AllColliders[i]);
            }

            healthSlider  = GetComponentInChildren <v_SpriteHealth>();
            head          = animator.GetBoneTransform(HumanBodyBones.Head);
            oldPosition   = transform.position;
            currentHealth = maxHealth;
            startPosition = transform.position;
        }
Beispiel #3
0
        public void Init()
        {
            if (randomWaypoint == null)
            {
                randomWaypoint = new vFisherYatesRandom();
            }
            if (randomPatrolPoint == null)
            {
                randomPatrolPoint = new vFisherYatesRandom();
            }
            currentWaypoint    = -1;
            currentPatrolPoint = -1;
            fwd                  = transform.forward;
            destination          = transform.position;
            agent                = GetComponent <UnityEngine.AI.NavMeshAgent>();
            agent.updateRotation = false;
            agentPath            = new UnityEngine.AI.NavMeshPath();
            sphereSensor         = GetComponentInChildren <v_AISphereSensor>();
            if (sphereSensor)
            {
                sphereSensor.SetColliderRadius(maxDetectDistance);
            }
            animator     = GetComponent <Animator>();
            meleeManager = GetComponent <vMeleeManager>();
            canAttack    = true;
            attackCount  = 0;
            sideMovement = GetRandonSide();
            destination  = transform.position;

            _rigidbody             = GetComponent <Rigidbody>();
            _rigidbody.useGravity  = false;
            _rigidbody.isKinematic = false;
            _rigidbody.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
            _capsuleCollider       = GetComponent <CapsuleCollider>();

            healthSlider  = GetComponentInChildren <v_SpriteHealth>();
            head          = animator.GetBoneTransform(HumanBodyBones.Head);
            oldPosition   = transform.position;
            currentHealth = maxHealth;

            method = OffMeshLinkMoveMethod.Grounded;

            // set up Actions
            jumpOverLayer = UnityEngine.AI.NavMesh.GetAreaFromName("JumpOver");
            stepUpLayer   = UnityEngine.AI.NavMesh.GetAreaFromName("StepUp");
            climbUpLayer  = UnityEngine.AI.NavMesh.GetAreaFromName("ClimbUp");
            useJumpOver   = ActionIsEnabled(AIActions.JumpOver);
            useStepUp     = ActionIsEnabled(AIActions.StepUp);
            useClimbUp    = ActionIsEnabled(AIActions.ClimbUp);
            startPosition = transform.position;
        }
        public void PlayRandomClip(FootStepObject footStepObject)
        {
            // if there are no clips to play return.
            if (audioClips == null || audioClips.Count == 0)
            {
                return;
            }

            // initialize variable if not already started
            if (randomSource == null)
            {
                randomSource = new vFisherYatesRandom();
            }

            // find a random clip and play it.
            GameObject audioObject = null;

            if (audioSource != null)
            {
                audioObject = Instantiate(audioSource.gameObject, footStepObject.sender.position, Quaternion.identity) as GameObject;
            }
            else
            {
                audioObject = new GameObject("audioObject");
                audioObject.transform.position = footStepObject.sender.position;
            }

            var source = audioObject.AddComponent <vAudioSurfaceControl>();

            if (audioMixerGroup != null)
            {
                source.outputAudioMixerGroup = audioMixerGroup;
            }
            int index = randomSource.Next(audioClips.Count);

            if (particleObject && footStepObject.ground && stepLayer.ContainsLayer(footStepObject.ground.gameObject.layer))
            {
                var obj = Instantiate(particleObject, footStepObject.sender.position, footStepObject.sender.rotation) as GameObject;
                obj.transform.SetParent(vObjectContainer.root, true);
            }
            if (useStepMark)
            {
                StepMark(footStepObject);
            }

            source.PlayOneShot(audioClips[index]);
        }