コード例 #1
0
        public virtual void Fire(Vector3 position, Vector3 velocity, float gravity, IAmmoEffect effect, Transform ignoreRoot, LayerMask layers, IDamageSource damageSource = null)
        {
            m_Velocity     = velocity;
            this.gravity   = gravity;
            m_AmmoEffect   = effect;
            m_DamageSource = damageSource;
            m_IgnoreRoot   = ignoreRoot;
            m_Layers       = layers;

            localTransform.position = position;
            if (m_FollowCurve)
            {
                localTransform.LookAt(position + velocity);
            }

            // Reset distance
            m_Distance      = 0;
            m_PassedMinimum = false;

            // Reset pooling
            m_Release = false;
            m_Timeout = m_RecycleDelay;

            // Hide the mesh for the first frame
            if (m_MeshRenderer != null)
            {
                m_MeshRenderer.enabled = false;
            }

            // Store the starting position
            m_LerpToPosition = localTransform.position;

            // Update immediately
            FixedUpdate();
        }
コード例 #2
0
        public void ReadProperties(INeoDeserializer reader, NeoSerializedGameObject nsgo)
        {
            reader.TryReadValue(k_VelocityKey, out m_Velocity, m_Velocity);
            reader.TryReadValue(k_ReleaseKey, out m_Release, m_Release);
            reader.TryReadValue(k_DistanceKey, out m_Distance, m_Distance);

            int layerMask = m_Layers;

            if (reader.TryReadValue(k_LayersKey, out layerMask, layerMask))
            {
                m_Layers = layerMask;
            }

            Vector3 position;

            if (reader.TryReadValue(k_PositionKey, out position, Vector3.zero))
            {
                m_LerpFromPosition      = position;
                m_LerpToPosition        = position;
                localTransform.position = position;
            }

            IAmmoEffect serializedAmmoEffect;

            if (reader.TryReadComponentReference(k_AmmoEffectKey, out serializedAmmoEffect, nsgo))
            {
                m_AmmoEffect = serializedAmmoEffect;
            }
            IDamageSource serializedDamageSource;

            if (reader.TryReadComponentReference(k_DamageSourceKey, out serializedDamageSource, nsgo))
            {
                m_DamageSource = serializedDamageSource;
            }
        }
コード例 #3
0
        public override void NetShoot(IAmmoEffect effect, float delay, Vector3 startPosition, Vector3 rayDirection)
        {
            if (m_ProjectilePrefab != null)
            {
                IProjectile projectile = PoolManager.GetPooledObject <IProjectile>(m_ProjectilePrefab, false);
                InitialiseProjectile(projectile);

                Transform ignoreRoot = GetRootTransform();

                if (projectile is NetBallisticProjectile netProjectile)
                {
                    netProjectile.SetCatchup(delay, rayDirection * m_MuzzleSpeed, m_Gravity);
                }

                projectile.Fire(startPosition, rayDirection * m_MuzzleSpeed, m_Gravity, effect, ignoreRoot, m_Layers, firearm as IDamageSource);
                projectile.gameObject.SetActive(true);
            }
            base.NetShoot(effect, delay, startPosition, rayDirection);
        }
コード例 #4
0
        public override void NetShoot(IAmmoEffect effect, float timeDelay, Vector3 startPosition, Vector3 rayDirection)
        {
            // THIS IS A MODDED SHOOT COMMAND TO SUPPORT NETWORKTIME ROLLBACK
            // Just return if there is no effect
            if (effect == null)
            {
                return;
            }

            // Get root game object to prevent impacts with body
            Transform ignoreRoot = GetRootTransform();

            // could possibly lag comp the gun pos as well, but for not take the location of player shot.
            base.StartRayRollback(timeDelay);
            // Check for raycast hit
            Ray     ray = new Ray(startPosition, rayDirection);
            Vector3 hitPoint;
            bool    didHit = PhysicsExtensions.RaycastNonAllocSingle(ray, out m_Hit, m_MaxDistance, m_Layers, ignoreRoot, QueryTriggerInteraction.Ignore);

            if (didHit)
            {
                hitPoint = m_Hit.point;
            }
            else
            {
                hitPoint = startPosition + (rayDirection * m_MaxDistance);
            }

            if (didHit)
            {
                effect.Hit(m_Hit, ray.direction, m_Hit.distance, float.PositiveInfinity, firearm as IDamageSource);
            }

            base.StopRayRollback(timeDelay);
            // Draw the tracer line out to max distance
            if (m_TracerPrototype != null)
            {
                StartCoroutine(ShowTracer(hitPoint));
            }

            base.NetShoot(effect, timeDelay, startPosition, rayDirection);
        }
コード例 #5
0
 public virtual void NetShoot(IAmmoEffect effect, float delay, Vector3 position, Vector3 forward)
 {
     SendOnShootEvent();
 }
コード例 #6
0
        public override void Shoot(float accuracy, IAmmoEffect effect)
        {
            // Just return if there is no effect
            if (effect == null)
            {
                return;
            }

            // Get root game object to prevent impacts with body
            Transform ignoreRoot = GetRootTransform();
            //if (firearm.wielder != null)
            //    ignoreRoot = firearm.wielder.gameObject.transform;

            // Get the forward vector
            Vector3 muzzlePosition = m_MuzzleTip.position;
            Vector3 startPosition  = muzzlePosition;
            Vector3 forwardVector  = m_MuzzleTip.forward;

            bool useCamera = false;

            if (firearm.wielder != null)
            {
                switch (m_UseCameraAim)
                {
                case UseCameraAim.HipAndAimDownSights:
                    useCamera = true;
                    break;

                case UseCameraAim.AimDownSightsOnly:
                    if (firearm.aimer != null)
                    {
                        useCamera = firearm.aimer.isAiming;
                    }
                    break;

                case UseCameraAim.HipFireOnly:
                    if (firearm.aimer != null)
                    {
                        useCamera = !firearm.aimer.isAiming;
                    }
                    else
                    {
                        useCamera = true;
                    }
                    break;
                }
            }
            if (useCamera)
            {
                Transform aimTransform = firearm.wielder.fpCamera.aimTransform;
                startPosition = aimTransform.position;
                forwardVector = aimTransform.forward;
            }

            // Get the direction (with accuracy offset)
            Vector3 rayDirection = forwardVector;
            float   spread       = Mathf.Lerp(m_MinimumSpread, m_MaximumSpread, 1f - accuracy);

            if (spread > Mathf.Epsilon)
            {
                Quaternion randomRot = UnityEngine.Random.rotationUniform;
                rayDirection = Quaternion.Slerp(Quaternion.identity, randomRot, spread / 360f) * forwardVector;
            }

            // Check for raycast hit
            Ray     ray = new Ray(startPosition, rayDirection);
            Vector3 hitPoint;
            bool    didHit = PhysicsExtensions.RaycastNonAllocSingle(ray, out m_Hit, m_MaxDistance, m_Layers, ignoreRoot, QueryTriggerInteraction.Ignore);

            if (didHit)
            {
                hitPoint = m_Hit.point;
            }
            else
            {
                hitPoint = startPosition + (rayDirection * m_MaxDistance);
            }

            // Double check hit from gun muzzle to prevent near scenery weirdness
            if (useCamera)
            {
                Vector3 newRayDirection = hitPoint - muzzlePosition;
                newRayDirection.Normalize();
                ray = new Ray(muzzlePosition, newRayDirection);
                if (PhysicsExtensions.RaycastNonAllocSingle(ray, out m_Hit, m_MaxDistance, m_Layers, ignoreRoot, QueryTriggerInteraction.Ignore))
                {
                    hitPoint = m_Hit.point;
                    effect.Hit(m_Hit, newRayDirection, m_Hit.distance, float.PositiveInfinity, firearm as IDamageSource);
                }
            }
            else
            {
                if (didHit)
                {
                    effect.Hit(m_Hit, ray.direction, m_Hit.distance, float.PositiveInfinity, firearm as IDamageSource);
                }
            }

            // Draw the tracer line out to max distance
            if (m_TracerPrototype != null)
            {
                StartCoroutine(ShowTracer(hitPoint));
            }

            SendNetShootEvent(startPosition, rayDirection);
            base.Shoot(accuracy, effect);
        }
コード例 #7
0
        public override void Shoot(float accuracy, IAmmoEffect effect)
        {
            if (m_ProjectilePrefab != null)
            {
                IProjectile projectile = PoolManager.GetPooledObject <IProjectile>(m_ProjectilePrefab, false);
                InitialiseProjectile(projectile);

                Transform ignoreRoot = GetRootTransform();
                //if (firearm.wielder != null)
                //    ignoreRoot = firearm.wielder.gameObject.transform;

                // Get the forward vector
                Vector3 muzzlePosition = m_MuzzleTip.position;
                Vector3 startPosition  = muzzlePosition;
                Vector3 forwardVector  = m_MuzzleTip.forward;

                bool useCamera = false;
                if (firearm.wielder != null)
                {
                    switch (m_UseCameraAim)
                    {
                    case UseCameraAim.HipAndAimDownSights:
                        useCamera = true;
                        break;

                    case UseCameraAim.AimDownSightsOnly:
                        if (firearm.aimer != null)
                        {
                            useCamera = firearm.aimer.isAiming;
                        }
                        break;

                    case UseCameraAim.HipFireOnly:
                        if (firearm.aimer != null)
                        {
                            useCamera = !firearm.aimer.isAiming;
                        }
                        else
                        {
                            useCamera = true;
                        }
                        break;
                    }
                }

                if (useCamera)
                {
                    Transform aimTransform = firearm.wielder.fpCamera.aimTransform;
                    startPosition = aimTransform.position;
                    forwardVector = aimTransform.forward;
                }

                // Get the direction (with accuracy offset)
                Vector3 rayDirection = forwardVector;
                float   spread       = Mathf.Lerp(m_MinimumSpread, m_MaximumSpread, 1f - accuracy);
                if (spread > Mathf.Epsilon)
                {
                    Quaternion randomRot = UnityEngine.Random.rotationUniform;
                    rayDirection = Quaternion.Slerp(Quaternion.identity, randomRot, spread / 360f) * forwardVector;
                }

                Ray     ray = new Ray(startPosition, rayDirection);
                Vector3 hitPoint;
                if (PhysicsExtensions.RaycastNonAllocSingle(ray, out m_Hit, k_MaxDistance, m_Layers, ignoreRoot, QueryTriggerInteraction.Ignore))
                {
                    hitPoint = m_Hit.point;
                }
                else
                {
                    hitPoint = startPosition + (rayDirection * k_MaxDistance);
                }

                if (useCamera)
                {
                    Vector3 newDirection = hitPoint - muzzlePosition;
                    newDirection.Normalize();
                    projectile.Fire(muzzlePosition, newDirection * m_MuzzleSpeed, m_Gravity, effect, firearm.wielder.gameObject.transform, m_Layers, firearm as IDamageSource);
                    SendNetShootEvent(muzzlePosition, newDirection);
                    projectile.gameObject.SetActive(true);
                }
                else
                {
                    projectile.Fire(startPosition, rayDirection * m_MuzzleSpeed, m_Gravity, effect, ignoreRoot, m_Layers, firearm as IDamageSource);
                    SendNetShootEvent(startPosition, rayDirection);
                    projectile.gameObject.SetActive(true);
                }
            }
            base.Shoot(accuracy, effect);
        }