private static ParticleSystem InstantiateAndInherit(MuzzlePointComponent muzzlePoint, ParticleSystem prefab)
        {
            ParticleSystem system = Object.Instantiate <ParticleSystem>(prefab);

            UnityUtil.InheritAndEmplace(system.transform, muzzlePoint.Current);
            return(system);
        }
Beispiel #2
0
        public void SelfSwitchMuzzlePoint(PostShotEvent e, WeaponMultyMuzzleNode weaponNode)
        {
            MuzzlePointComponent muzzlePoint = weaponNode.muzzlePoint;

            muzzlePoint.CurrentIndex = (muzzlePoint.CurrentIndex + 1) % muzzlePoint.Points.Length;
            base.ScheduleEvent(new MuzzlePointSwitchEvent(muzzlePoint.CurrentIndex), weaponNode);
        }
 private void DrawHammerHitDecals(Vector3 shotDirection, PelletThrowingGraphicsNode weapon, SingleNode <DecalManagerComponent> decalManagerNode, DecalSettingsComponent settings)
 {
     if (settings.EnableDecals && (settings.MaxDecalsForHammer > 0))
     {
         DecalMeshBuilder              decalMeshBuilder       = decalManagerNode.component.DecalMeshBuilder;
         BulletHoleDecalManager        bulletHoleDecalManager = decalManagerNode.component.BulletHoleDecalManager;
         MuzzlePointComponent          muzzlePoint            = weapon.muzzlePoint;
         HammerDecalProjectorComponent hammerDecalProjector   = weapon.hammerDecalProjector;
         Vector3 barrelOriginWorld = new MuzzleVisualAccessor(muzzlePoint).GetBarrelOriginWorld();
         decalMeshBuilder.Clean();
         DecalProjection projection2 = new DecalProjection {
             HalfSize   = hammerDecalProjector.CombineHalfSize,
             Distantion = hammerDecalProjector.Distance,
             Ray        = new Ray(barrelOriginWorld - shotDirection, shotDirection)
         };
         DecalProjection decalProjection = projection2;
         if (decalMeshBuilder.CompleteProjectionByRaycast(decalProjection) && decalMeshBuilder.CollectPolygons(decalProjection))
         {
             Vector3     localDirection = muzzlePoint.Current.InverseTransformVector(shotDirection);
             Vector3[]   vectorArray    = PelletDirectionsCalculator.GetRandomDirections(weapon.hammerPelletCone, muzzlePoint.Current.rotation, localDirection);
             List <Mesh> list           = new List <Mesh>(vectorArray.Length);
             for (int i = 0; i < Math.Min(vectorArray.Length, settings.MaxDecalsForHammer); i++)
             {
                 Vector3 direction = vectorArray[i];
                 projection2 = new DecalProjection {
                     AtlasHTilesCount      = hammerDecalProjector.AtlasHTilesCount,
                     AtlasVTilesCount      = hammerDecalProjector.AtlasVTilesCount,
                     SurfaceAtlasPositions = hammerDecalProjector.SurfaceAtlasPositions,
                     HalfSize   = hammerDecalProjector.HalfSize,
                     Up         = hammerDecalProjector.Up,
                     Distantion = hammerDecalProjector.Distance,
                     Ray        = new Ray(barrelOriginWorld - shotDirection, direction)
                 };
                 DecalProjection projection3 = projection2;
                 if (decalMeshBuilder.CompleteProjectionByRaycast(projection3))
                 {
                     decalMeshBuilder.BuilldDecalFromCollectedPolygons(projection3);
                     Mesh mesh = null;
                     if (decalMeshBuilder.GetResultToMesh(ref mesh))
                     {
                         list.Add(mesh);
                     }
                 }
             }
             if (list.Count != 0)
             {
                 CombineInstance[] combine = new CombineInstance[list.Count];
                 for (int j = 0; j < list.Count; j++)
                 {
                     combine[j].mesh = list[j];
                 }
                 Mesh decalMesh = new Mesh();
                 decalMesh.CombineMeshes(combine, true, false);
                 decalMesh.RecalculateBounds();
                 bulletHoleDecalManager.AddDecal(decalMesh, hammerDecalProjector.Material, hammerDecalProjector.Color, hammerDecalProjector.LifeTime);
             }
         }
     }
 }
Beispiel #4
0
        public void PlayShotEffect(BaseShotEvent evt, DiscreteWeaponSoundEffectReadyNode node)
        {
            DiscreteWeaponShotEffectComponent discreteWeaponShotEffect = node.discreteWeaponShotEffect;
            MuzzlePointComponent muzzlePoint = node.muzzlePoint;

            discreteWeaponShotEffect.AudioSources[muzzlePoint.CurrentIndex].Stop();
            discreteWeaponShotEffect.AudioSources[muzzlePoint.CurrentIndex].Play();
        }
Beispiel #5
0
        public void Init(MuzzlePointComponent muzzlePoint)
        {
            GameObject gameObject = Instantiate <GameObject>(this.effectPrefab);

            UnityUtil.InheritAndEmplace(gameObject.transform, muzzlePoint.Current);
            this.Instance = gameObject.GetComponent <StreamEffectBehaviour>();
            CustomRenderQueue.SetQueue(gameObject, 0xc4e);
        }
Beispiel #6
0
        public void Init(NodeAddedEvent evt, SoleTracerGraphicsInitNode node)
        {
            MuzzlePointComponent        muzzlePoint        = node.muzzlePoint;
            SoleTracerGraphicsComponent soleTracerGraphics = node.soleTracerGraphics;

            soleTracerGraphics.Tracer = Object.Instantiate <ParticleSystem>(soleTracerGraphics.Tracer);
            UnityUtil.InheritAndEmplace(soleTracerGraphics.Tracer.transform, muzzlePoint.Current);
            node.Entity.AddComponent <SoleTracerGraphicsReadyComponent>();
        }
        public void Init(NodeAddedEvent evt, PelletThrowingGraphicsInitNode node)
        {
            MuzzlePointComponent            muzzlePoint            = node.muzzlePoint;
            PelletThrowingGraphicsComponent pelletThrowingGraphics = node.pelletThrowingGraphics;

            pelletThrowingGraphics.Trails = InstantiateAndInherit(muzzlePoint, pelletThrowingGraphics.Trails);
            pelletThrowingGraphics.Hits   = InstantiateAndInherit(muzzlePoint, pelletThrowingGraphics.Hits);
            CustomRenderQueue.SetQueue(pelletThrowingGraphics.gameObject, 0xc4e);
            node.Entity.AddComponent <PelletThrowingGraphicsReadyComponent>();
        }
Beispiel #8
0
        private void CollectPelletTargets(TargetingData targetingData, DirectionData directionData, TargetCollectorNode targetCollectorNode)
        {
            MuzzlePointComponent muzzlePoint = targetCollectorNode.muzzlePoint;
            Vector3 dir            = directionData.Dir;
            Vector3 localDirection = muzzlePoint.Current.InverseTransformVector(dir);

            Vector3[] vectorArray = PelletDirectionsCalculator.GetRandomDirections(targetCollectorNode.hammerPelletCone, muzzlePoint.Current.rotation, localDirection);
            for (int i = 0; i < vectorArray.Length; i++)
            {
                directionData.Dir = vectorArray[i];
                targetCollectorNode.hammerTargetCollector.Collect(targetingData.FullDistance, directionData, 0);
            }
            directionData.Dir = dir;
        }
        private static unsafe void InstantiatePelletsByBaseEvent(Vector3 shotDirection, PelletThrowingGraphicsNode weapon)
        {
            MuzzlePointComponent            muzzlePoint            = weapon.muzzlePoint;
            PelletThrowingGraphicsComponent pelletThrowingGraphics = weapon.pelletThrowingGraphics;
            float radiusOfMinDamage = weapon.damageWeakeningByDistance.RadiusOfMinDamage;
            float constant          = pelletThrowingGraphics.Trails.main.startSpeed.constant;
            float num3 = radiusOfMinDamage / constant;

            ParticleSystem.EmitParams params2 = new ParticleSystem.EmitParams {
                position   = pelletThrowingGraphics.Trails.transform.position,
                startColor = pelletThrowingGraphics.Trails.main.startColor.color,
                startSize  = pelletThrowingGraphics.Trails.main.startSizeMultiplier
            };
            ParticleSystem.EmitParams emitParams = params2;
            params2 = new ParticleSystem.EmitParams {
                startColor = pelletThrowingGraphics.Hits.main.startColor.color,
                startSize  = pelletThrowingGraphics.Hits.main.startSizeMultiplier
            };
            ParticleSystem.EmitParams params3 = params2;
            Vector3 localDirection            = muzzlePoint.Current.InverseTransformVector(shotDirection);

            foreach (Vector3 vector2 in PelletDirectionsCalculator.GetRandomDirections(weapon.hammerPelletCone, muzzlePoint.Current.rotation, localDirection))
            {
                RaycastHit hit;
                ParticleSystem.MainModule     main       = pelletThrowingGraphics.Trails.main;
                ParticleSystem.MinMaxGradient startColor = main.startColor;
                if (startColor.mode == ParticleSystemGradientMode.RandomColor)
                {
                    emitParams.startColor = pelletThrowingGraphics.Trails.main.startColor.Evaluate(Random.Range((float)0f, (float)1f));
                }
                emitParams.randomSeed = (uint)(Random.value * 4.294967E+09f);
                emitParams.velocity   = vector2 * constant;
                if (!Physics.Raycast(pelletThrowingGraphics.Trails.transform.position, vector2, out hit, radiusOfMinDamage, LayerMasks.GUN_TARGETING_WITH_DEAD_UNITS))
                {
                    emitParams.startLifetime = num3;
                }
                else
                {
                    emitParams.startLifetime = Vector3.Distance(pelletThrowingGraphics.Trails.transform.position, hit.point) / constant;
                    params3.startLifetime    = Random.Range(pelletThrowingGraphics.SparklesMinLifetime, pelletThrowingGraphics.SparklesMaxLifetime);
                    params3.randomSeed       = (uint)(Random.value * 4.294967E+09f);
                    params3.position         = hit.point;
                    params3.velocity         = Random.onUnitSphere;
                    ParticleSystem.EmitParams *paramsPtr1 = &params3;
                    paramsPtr1.velocity *= Mathf.Sign(Vector3.Dot(params3.velocity, hit.normal)) * pelletThrowingGraphics.HitReflectVeolcity;
                    pelletThrowingGraphics.Hits.Emit(params3, 1);
                }
                pelletThrowingGraphics.Trails.Emit(emitParams, 1);
            }
        }
Beispiel #10
0
        public void Build(NodeAddedEvent evt, [Combine] DiscreteWeaponSoundEffectNode node, SingleNode <SoundListenerBattleStateComponent> soundListener)
        {
            DiscreteWeaponShotEffectComponent discreteWeaponShotEffect = node.discreteWeaponShotEffect;
            MuzzlePointComponent muzzlePoint = node.muzzlePoint;

            discreteWeaponShotEffect.AudioSources = new AudioSource[muzzlePoint.Points.Length];
            for (int i = 0; i < muzzlePoint.Points.Length; i++)
            {
                GameObject obj2 = Object.Instantiate <GameObject>(discreteWeaponShotEffect.Asset);
                discreteWeaponShotEffect.AudioSources[i] = obj2.GetComponent <AudioSource>();
                obj2.transform.parent = node.weaponSoundRoot.gameObject.transform;
                obj2.transform.SetPositionSafe(muzzlePoint.Points[i].position);
            }
            if (!node.Entity.HasComponent <DiscreteWeaponShotEffectReadyComponent>())
            {
                node.Entity.AddComponent <DiscreteWeaponShotEffectReadyComponent>();
            }
        }
        public void CreateMuzzlePoint(NodeAddedEvent e, SingleNode <WeaponVisualRootComponent> weaponVisualNode)
        {
            List <Transform> list = new List <Transform>();
            Transform        item = weaponVisualNode.component.transform;

            if (item.name == "muzzle_point")
            {
                list.Add(item);
            }
            IEnumerator enumerator = item.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    Transform current = (Transform)enumerator.Current;
                    if (current.name == "muzzle_point")
                    {
                        list.Add(current);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            MuzzlePointComponent component = new MuzzlePointComponent {
                Points = list.ToArray()
            };

            weaponVisualNode.Entity.AddComponent(component);
            weaponVisualNode.Entity.AddComponent <MuzzlePointInitializedComponent>();
        }
Beispiel #12
0
        public void RemoteSwitchMuzzlePoint(RemoteMuzzlePointSwitchEvent e, WeaponMultyMuzzleNode weaponNode)
        {
            MuzzlePointComponent muzzlePoint = weaponNode.muzzlePoint;

            muzzlePoint.CurrentIndex = e.Index % muzzlePoint.Points.Length;
        }
Beispiel #13
0
 public MuzzleLogicAccessor(MuzzlePointComponent muzzleComponent, WeaponInstanceComponent weaponInstanceComponent)
 {
     this.muzzleComponent = muzzleComponent;
     this.weaponTransform = weaponInstanceComponent.WeaponInstance.transform;
 }
Beispiel #14
0
 protected void DrawHitDecal(HitEvent evt, DecalManagerComponent decalManager, DynamicDecalProjectorComponent decalProjector, MuzzlePointComponent muzzlePoint)
 {
     if (evt.StaticHit != null)
     {
         Vector3 barrelOriginWorld = new MuzzleVisualAccessor(muzzlePoint).GetBarrelOriginWorld();
         this.DrawHitDecal(decalManager, decalProjector, barrelOriginWorld, (evt.StaticHit.Position - barrelOriginWorld).normalized);
     }
 }