Ejemplo n.º 1
0
        public static EffectInfo CreateEffectObject(Transform parent)
        {
            var templateEffect = VehicleEffectsMod.FindEffect("Large Car Light Right2") as LightEffect;

            if (templateEffect != null)
            {
                GameObject obj = new GameObject(effectName);
                obj.transform.parent = parent;

                var ditchLightEffect = obj.AddComponent <LightEffect>();
                Util.CopyLight(templateEffect.GetComponent <Light>(), obj.AddComponent <Light>());
                Util.CopyLightEffect(templateEffect, ditchLightEffect);

                ditchLightEffect.m_batchedLight  = false;
                ditchLightEffect.m_positionIndex = -1;

                ditchLightEffect.m_offRange = new Vector2(1000, 1000);
                ditchLightEffect.m_position = Vector3.zero;

                return(ditchLightEffect);
            }
            else
            {
                Logging.Log("Could not find template for " + effectName);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates GameObject containing the particle system this effect needs.
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static EffectInfo CreateEffectObject(Transform parent)
        {
            ParticleEffect templateParticleEffect = VehicleEffectsMod.FindEffect("Factory Smoke Small") as ParticleEffect;

            if (gameObject != null)
            {
                Logging.LogWarning("Creating effect object for " + effectName + " but object already exists!");
            }

            if (templateParticleEffect != null)
            {
                gameObject = new GameObject(effectName);

                gameObject.transform.parent = parent;

                // Configure particle system
                CustomMovementParticleEffect dieselSmoke = gameObject.AddComponent <CustomMovementParticleEffect>();

                // Set custom properties
                dieselSmoke.m_canUseBezier    = false;
                dieselSmoke.m_canUseMeshData  = false;
                dieselSmoke.m_canUsePositions = true;

                dieselSmoke.m_maxVisibilityDistance = templateParticleEffect.m_maxVisibilityDistance;

                dieselSmoke.m_minSpawnAngle     = templateParticleEffect.m_minSpawnAngle;
                dieselSmoke.m_useSimulationTime = templateParticleEffect.m_useSimulationTime;

                dieselSmoke.m_velocityMultiplier   = 0.0f;
                dieselSmoke.m_spawnAreaRadius      = 0.25f;
                dieselSmoke.ParticleSystemOverride = templateParticleEffect.gameObject.GetComponent <ParticleSystem>();

                dieselSmoke.m_minMagnitude = 0.1f;
                dieselSmoke.m_magnitudeAccelerationMultiplier = 1.0f;
                dieselSmoke.m_magnitudeSpeedMultiplier        = 0;

                dieselSmoke.m_maxStartSpeed = templateParticleEffect.m_maxStartSpeed + 0.5f;
                dieselSmoke.m_minStartSpeed = templateParticleEffect.m_minStartSpeed + 0.5f;

                dieselSmoke.m_maxLifeTime = templateParticleEffect.m_maxLifeTime;
                dieselSmoke.m_minLifeTime = templateParticleEffect.m_minLifeTime;

                dieselSmoke.m_maxSpawnAngle = 20.0f;

                return(dieselSmoke);
            }
            else
            {
                Logging.LogError("Could not find default effects used for " + effectName + "!");
                return(null);
            }
        }
Ejemplo n.º 3
0
        public new void EmitParticles(InstanceID id, Matrix4x4 matrix, Vector4[] positions, Vector3 velocity, float particlesPerSquare, int probability, ref Vector3 min, ref Vector3 max)
        {
            // Fix for reloading from main menu
            if (m_particleSystemOverrideName != null && m_particleSystemOverride == null)
            {
                m_particleSystemOverride = VehicleEffectsMod.FindEffect(m_particleSystemOverrideName)?.GetComponent <ParticleSystem>();
            }
            if (m_particleSystemOverride != null && m_particleSystemOverride != m_particleSystem)
            {
                m_particleSystem = m_particleSystemOverride;
            }

            Randomizer randomizer = new Randomizer(id.RawData);
            var        module     = m_particleSystem.emission;

            particlesPerSquare *= module.rate.constant;
            int num = positions.Length;

            if (randomizer.Int32(100u) <= probability)
            {
                Vector3 worldPoint = matrix.MultiplyPoint(Vector3.zero);
                float   w          = m_spawnAreaRadius;

                float circleArea    = Mathf.Max(100f, 3.14159274f * w * w);
                int   particleCount = Mathf.FloorToInt(circleArea * particlesPerSquare + Random.value);
                for (int j = 0; j < particleCount; j++)
                {
                    ParticleSystem.EmitParams emitParams = default(ParticleSystem.EmitParams);
                    Vector3 position   = worldPoint;
                    float   startSpeed = this.m_minStartSpeed + (this.m_maxStartSpeed - this.m_minStartSpeed) * Random.value;

                    // Get random velocity vector witin a cone of 2 * m_maxSpawnAngle, in the direction of m_particleVector
                    float   d = 1f / Mathf.Tan(Mathf.Deg2Rad * m_maxSpawnAngle);
                    Vector3 a = Random.insideUnitCircle;
                    a.z = d;
                    Vector3 b = Random.insideUnitCircle * m_spawnAreaRadius;
                    b.z = 0f;

                    position                += matrix.MultiplyVector(b);
                    emitParams.position      = position;
                    emitParams.startColor    = m_particleSystem.startColor;
                    emitParams.velocity      = velocity + matrix.MultiplyVector(a) * startSpeed;
                    emitParams.startLifetime = this.m_minLifeTime + (this.m_maxLifeTime - this.m_minLifeTime) * UnityEngine.Random.value;
                    emitParams.startSize     = this.m_particleSystem.startSize;
                    this.m_particleSystem.Emit(emitParams, 1);
                }
                min = Vector3.Min(min, worldPoint - new Vector3(w, w, w));
                max = Vector3.Max(max, worldPoint + new Vector3(w, w, w));
            }
        }
Ejemplo n.º 4
0
        public static EffectInfo CreateEffectObject(Transform parent)
        {
            EngineSoundEffect defaultEngineSound = VehicleEffectsMod.FindEffect("Train Movement") as EngineSoundEffect;

            if (defaultEngineSound != null)
            {
                GameObject obj = new GameObject(effectName);
                obj.transform.parent = parent;

                EngineSoundEffect newSoundEffect = Util.CopyEngineSoundEffect(defaultEngineSound, obj.AddComponent <EngineSoundEffect>());
                newSoundEffect.name = effectName;



                // Create a copy of audioInfo
                AudioInfo audioInfo = UnityEngine.Object.Instantiate(defaultEngineSound.m_audioInfo) as AudioInfo;

                audioInfo.name     = effectName;
                audioInfo.m_volume = 0.8f;

                // Load new audio clip

                var clip = Util.LoadAudioClipFromModDir("Sounds/rolling-stock-moving.ogg");

                if (clip != null)
                {
                    audioInfo.m_clip = clip;
                }
                else
                {
                    return(null);
                }

                newSoundEffect.m_audioInfo = audioInfo;


                //defaultEngineSound.m_audioInfo = audioInfo;


                return(newSoundEffect);
            }
            else
            {
                Logging.LogError("Could not find default train sound effect!");
                return(null);
            }
        }
        public static EffectInfo CreateEffectObject(Transform parent)
        {
            MultiEffect defaultMultiEffect = VehicleEffectsMod.FindEffect("Aircraft Movement") as MultiEffect;

            if (defaultMultiEffect != null)
            {
                MultiEffect newMultiEffect = GameObject.Instantiate(defaultMultiEffect);
                newMultiEffect.name = effectName;

                newMultiEffect.m_effects[0].m_effect = PropAircraftSound.CreateEffectObject(parent);

                return(newMultiEffect);
            }
            else
            {
                Logging.LogError("Could not find default plane movement effect!");
                return(null);
            }
        }
Ejemplo n.º 6
0
        public static EffectInfo CreateEffectObject(Transform parent)
        {
            var obj = new GameObject(effectName);

            obj.transform.parent = parent;
            SoundEffect effect = obj.AddComponent <SoundEffect>();

            effect.m_position = Vector3.zero;

            // Create a copy of an audioInfo
            var       templateSound = VehicleEffectsMod.FindEffect("Train Movement") as SoundEffect;
            AudioInfo audioInfo     = UnityEngine.Object.Instantiate(templateSound.m_audioInfo) as AudioInfo;

            audioInfo.name         = effectName;
            audioInfo.m_fadeLength = 0.4f;
            audioInfo.m_loop       = true;
            audioInfo.m_pitch      = 1.4f;
            audioInfo.m_volume     = 0.7f;
            audioInfo.m_randomTime = false;

            // Load new audio clip

            var clip = Util.LoadAudioClipFromModDir("Sounds/train-whistle.ogg");

            if (clip != null)
            {
                audioInfo.m_clip = clip;
            }
            else
            {
                return(null);
            }

            effect.m_audioInfo = audioInfo;

            return(effect);
        }
Ejemplo n.º 7
0
        public bool ApplyPreview(VehicleEffectsDefinition definition, string packageName)
        {
            RevertPreview();

            m_parseErrors = new HashSet <string>();

            VehicleInfo vehicleInfo = ToolsModifierControl.toolController.m_editPrefabInfo as VehicleInfo;

            if (vehicleInfo != null)
            {
                // Find the VehicleInfo's currently in the scene and store them in a dictionary
                Dictionary <string, VehicleInfo> infoDict = new Dictionary <string, VehicleInfo>();
                infoDict.Add(vehicleInfo.name, vehicleInfo);

                if (vehicleInfo.m_trailers != null)
                {
                    foreach (var trailer in vehicleInfo.m_trailers)
                    {
                        if (!infoDict.ContainsKey(trailer.m_info.name))
                        {
                            infoDict.Add(trailer.m_info.name, trailer.m_info);
                        }
                    }
                }


                if (definition?.Vehicles == null || definition.Vehicles.Count == 0)
                {
                    m_parseErrors.Add("Previewer - vehicleEffectDef is null or empty.");
                }
                else
                {
                    m_isApplied = true;
                    foreach (var vehicleDef in definition.Vehicles)
                    {
                        // Check if the vehicle of this definition is in the scene and if so, apply it
                        VehicleInfo info;
                        if (infoDict.TryGetValue(vehicleDef.Name, out info))
                        {
                            VehicleEffectsMod.ParseVehicleDefinition(vehicleDef, packageName, ref m_changes, ref m_parseErrors, false, info);
                        }
                        else
                        {
                            m_parseErrors.Add("Prefab for " + vehicleDef.Name + " not found!");
                            m_parseErrors.Add(infoDict.Keys.Aggregate("List of prefabs:\n", (current, error) => current + error + "\n"));
                        }
                    }
                }
            }
            else
            {
                m_parseErrors.Add("No prefab found.");
            }



            if (m_parseErrors?.Count > 0)
            {
                var errorMessage = m_parseErrors.Aggregate("Error while parsing vehicle effect definition preview.\n" + "List of errors:\n", (current, error) => current + (error + '\n'));
                UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Vehicle Effects", errorMessage, false);
            }

            return(m_isApplied);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates GameObject containing the particle system this effect needs.
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static EffectInfo CreateEffectObject(Transform parent)
        {
            ParticleEffect         templateParticleEffect = VehicleEffectsMod.FindEffect("Factory Steam") as ParticleEffect;
            MovementParticleEffect templateMovementEffect = VehicleEffectsMod.FindEffect("Gravel Dust") as MovementParticleEffect;

            if (gameObject != null)
            {
                Logging.LogWarning("Creating effect object for " + effectName + " but object already exists!");
            }

            if (templateParticleEffect != null && templateMovementEffect != null)
            {
                // Load particle system from AssetBundle because we cannot access ParticleSystem modifiers from code.
                // The AssetBundle used contains a GameObject prefab with a ParticleSystem attached. The following modifiers are active:
                // Scale over time: scaling from ~7% to 100%.
                // Color over time: fade out near the end of the lifespan.
                // Velocity limit over time is active as well.

                Assembly asm        = Assembly.GetAssembly(typeof(VehicleEffectsMod));
                var      pluginInfo = PluginManager.instance.FindPluginInfo(asm);

                GameObject obj = null;

                try
                {
                    string      absUri = "file:///" + pluginInfo.modPath.Replace("\\", "/") + "/AssetBundles/particlesystems";
                    WWW         www    = new WWW(absUri);
                    AssetBundle bundle = www.assetBundle;


                    Logging.Log("Bundle loading " + ((bundle == null) ? "failed " + www.error : "succeeded"));
                    UnityEngine.Object a = bundle.LoadAsset("ParticleSystemSteam");
                    Logging.Log("Asset unpacking " + ((a == null) ? "failed " : "succeeded"));
                    obj = GameObject.Instantiate(a) as GameObject;
                    bundle.Unload(false);
                }
                catch (Exception e)
                {
                    Logging.Log("Exception trying to load bundle file!" + e.ToString());
                }

                if (obj != null)
                {
                    obj.name = effectName;
                }
                else
                {
                    obj = new GameObject(effectName);
                }

                obj.transform.parent = parent;

                // Configure particle system
                var particleSystem      = templateParticleEffect.GetComponent <ParticleSystem>();
                var particleRenderer    = templateParticleEffect.GetComponent <ParticleSystemRenderer>();
                var particleRendererMov = templateMovementEffect.GetComponent <ParticleSystemRenderer>();

                var psCopy = obj.GetComponent <ParticleSystem>() ?? obj.AddComponent <ParticleSystem>();
                psCopy.gravityModifier = 0.2f;
                psCopy.startSize       = 8;

                psCopy.time       = 0;
                psCopy.startSpeed = 10;

                psCopy.startRotation   = 6.283185f;
                psCopy.startLifetime   = 5;
                psCopy.startDelay      = 0;
                psCopy.startColor      = Color.white;
                psCopy.simulationSpace = ParticleSystemSimulationSpace.World;
                psCopy.randomSeed      = 0;
                psCopy.playOnAwake     = false;
                psCopy.playbackSpeed   = 0;
                psCopy.maxParticles    = 10000;
                psCopy.loop            = true;
                psCopy.hideFlags       = HideFlags.None;
                psCopy.enableEmission  = true;
                psCopy.emissionRate    = 10;


                var renderCopy = obj.GetComponent <ParticleSystemRenderer>();
                renderCopy.cameraVelocityScale = 0;
                renderCopy.lengthScale         = 2;
                renderCopy.maxParticleSize     = 20.0f;
                renderCopy.mesh                 = null;
                renderCopy.probeAnchor          = null;
                renderCopy.receiveShadows       = true;
                renderCopy.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.BlendProbes;
                renderCopy.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
                renderCopy.sharedMaterial       = particleRenderer.sharedMaterial;
                renderCopy.useLightProbes       = false;
                renderCopy.velocityScale        = 0;

                renderCopy.enabled             = true;
                renderCopy.hideFlags           = HideFlags.None;
                renderCopy.lightmapIndex       = -1;
                renderCopy.lightmapScaleOffset = new Vector4(1, 1, 0, 0);
                renderCopy.sortingLayerID      = 0;
                renderCopy.sortingLayerName    = "Default";
                renderCopy.sortingOrder        = 0;
                renderCopy.renderMode          = ParticleSystemRenderMode.Billboard;


                CustomMovementParticleEffect vehicleSteam = obj.AddComponent <CustomMovementParticleEffect>();

                // Set custom properties
                vehicleSteam.m_canUseBezier    = false;
                vehicleSteam.m_canUseMeshData  = false;
                vehicleSteam.m_canUsePositions = true;

                vehicleSteam.m_maxVisibilityDistance = 1800f;

                vehicleSteam.m_minSpawnAngle     = templateParticleEffect.m_minSpawnAngle;
                vehicleSteam.m_useSimulationTime = templateParticleEffect.m_useSimulationTime;


                vehicleSteam.m_velocityMultiplier = 1.0f;
                vehicleSteam.m_spawnAreaRadius    = 0.25f;

                vehicleSteam.m_minMagnitude = 0.2f;                     // Gives occasional puffs of smoke when standing still
                vehicleSteam.m_magnitudeAccelerationMultiplier = 10;
                vehicleSteam.m_magnitudeSpeedMultiplier        = 20;

                vehicleSteam.m_maxStartSpeed = 1.7f;
                vehicleSteam.m_minStartSpeed = 1.5f;

                vehicleSteam.m_maxLifeTime = 1.3f;
                vehicleSteam.m_minLifeTime = 1.1f;

                vehicleSteam.m_maxSpawnAngle = 4.0f;

                gameObject = obj;

                return(vehicleSteam);
            }
            else
            {
                Logging.LogError("Could not find default effects used for Vehicle Steam Effect!");
                return(null);
            }
        }