コード例 #1
0
        private void ShootTrajectoryCast(CharacterShooter shooter, float deviation, CharacterShooter.ShotType shotType)
        {
            TrajectoryRenderer.TrajectoryResult result = this.GetTrajectoryResult(shooter);

            if (result.hit.collider)
            {
                Vector3 pointA = result.hit.point;
                Vector3 pointB = result.hit.point;

                if (result.points.Length > 2)
                {
                    pointA = result.points[result.count - 2];
                    pointB = result.points[result.count - 1];
                }

                Vector3    direction = (pointA - pointB).normalized;
                Quaternion rotation  = Quaternion.FromToRotation(Vector3.forward, direction);
                GameObject other     = result.hit.collider.gameObject;


                this.ExecuteShootActions(
                    other,
                    result.hit.point,
                    rotation
                    );

                IgniterOnReceiveShot igniter = other.GetComponent <IgniterOnReceiveShot>();
                if (igniter)
                {
                    igniter.OnRecevieShot(shooter, shotType);
                }

                if (!Mathf.Approximately(this.pushForce, 0f) && result.hit.rigidbody && direction != Vector3.zero)
                {
                    result.hit.rigidbody.AddForceAtPosition(
                        -direction * this.pushForce,
                        result.hit.point,
                        ForceMode.Impulse
                        );
                }

                if (this.prefabImpactEffect)
                {
                    GameObject impact = PoolManager.Instance.Pick(this.prefabImpactEffect);
                    impact.transform.SetPositionAndRotation(result.hit.point, rotation);
                }

                this.shootTrail.position1 = shooter.muzzle.GetPosition();
                this.shootTrail.position2 = result.hit.point;
            }

            if (this.shootTrail.useShootingTrail)
            {
                ShootingTrailRenderer.Create(this.shootTrail, result);
            }
        }
コード例 #2
0
        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            CharacterShooter shooterValue = this.shooter.GetComponent <CharacterShooter>(target);

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

            switch (this.targetType)
            {
            case TargetType.Target:
                IgniterOnReceiveShot igniterTarget = this.target.GetComponent <IgniterOnReceiveShot>(target);
                if (igniterTarget != null)
                {
                    igniterTarget.OnRecevieShot(shooterValue, this.shotType);
                }
                break;

            case TargetType.AreaOfEffect:
                Vector3 pos = this.position.GetPosition(target);
                float   rad = this.radius.GetValue(target);
                QueryTriggerInteraction query = QueryTriggerInteraction.Collide;
                Collider[] colliders          = Physics.OverlapSphere(pos, rad, -1, query);

                for (int i = 0; i < colliders.Length; ++i)
                {
                    IgniterOnReceiveShot colliderIgniter = colliders[i].gameObject.GetComponent <IgniterOnReceiveShot>();
                    if (colliderIgniter != null)
                    {
                        colliderIgniter.OnRecevieShot(shooterValue, this.shotType);
                    }
                }

                break;
            }

            return(true);
        }
コード例 #3
0
        private void ShootGenericCast(CharacterShooter shooter, float deviation,
                                      CharacterShooter.ShotType shotType, CastType castType)
        {
            ShootData shootData = this.GetShootData(shooter);

            Vector3 shootPositionRaycast = shootData.originRaycast;
            Vector3 shootPositionWeapon  = shootData.originWeapon;
            Vector3 shootPositionTarget  = shootData.destination;

            if (deviation > 0f)
            {
                shootPositionTarget += this.CalculateError(
                    shooter.gameObject,
                    shootPositionRaycast,
                    shootPositionTarget,
                    deviation
                    );
            }

            Vector3 direction = (shootPositionTarget - shootPositionRaycast).normalized;

            int hitCounter = 0;

            switch ((((int)castType) & 2) >> 1)
            {
            case 0:     // Raycast
                hitCounter = Physics.RaycastNonAlloc(
                    shootPositionRaycast, direction, this.bufferCastHits,
                    this.distance, this.layerMask, this.triggersMask
                    );
                break;

            case 1:     // SphereCast
                hitCounter = Physics.SphereCastNonAlloc(
                    shootPositionRaycast, this.radius, direction, this.bufferCastHits,
                    this.distance, this.layerMask, this.triggersMask
                    );
                break;
            }

            int maxCount = Mathf.Min(hitCounter, this.bufferCastHits.Length);

            Array.Sort(this.bufferCastHits, 0, maxCount, SHOT_COMPARE);

            for (int i = 0; hitCounter > 0 && i < maxCount; ++i)
            {
                if (this.bufferCastHits[i].collider.gameObject.Equals(shooter.gameObject))
                {
                    continue;
                }

                Vector3    rotationDirection = (shootPositionWeapon - this.bufferCastHits[i].point).normalized;
                Quaternion rotation          = Quaternion.FromToRotation(Vector3.forward, rotationDirection);

                GameObject other = this.bufferCastHits[i].collider.gameObject;
                this.ExecuteShootActions(other, this.bufferCastHits[i].point, rotation);

                IgniterOnReceiveShot igniter = other.GetComponent <IgniterOnReceiveShot>();
                if (igniter)
                {
                    igniter.OnRecevieShot(shooter, shotType);
                }

                if (!Mathf.Approximately(this.pushForce, 0f) && this.bufferCastHits[i].rigidbody)
                {
                    this.bufferCastHits[i].rigidbody.AddForceAtPosition(
                        -rotationDirection * this.pushForce,
                        this.bufferCastHits[i].point,
                        ForceMode.Impulse
                        );
                }

                shootPositionTarget = this.bufferCastHits[i].point;

                if (this.prefabImpactEffect)
                {
                    GameObject impact = PoolManager.Instance.Pick(this.prefabImpactEffect);
                    impact.transform.SetPositionAndRotation(this.bufferCastHits[i].point, rotation);
                }

                if ((((int)castType) & 1) == 0)
                {
                    break;
                }
            }

            if (this.shootTrail.useShootingTrail)
            {
                this.shootTrail.position1 = shootPositionWeapon;
                this.shootTrail.position2 = shootPositionTarget;
                ShootingTrailRenderer.Create(this.shootTrail);
            }
        }