[MOD]Ambidexterity Module (Shield Module Branch)

Show off your mod creations or just a work in progress.
Post Reply
l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

odd, let me check this. Maybe I grabbed an old rar.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

After checking into it, it is what I was worried about. The particle system does not want to import into the Daggerfall Unity stand alone.

Can someone who knows more about this, explain why I can't use the built in particle system to setup and run particles in Daggerfall using c# scripting?

Do I need to make them as prefabs in the editor, like snow and rain particles, and package them that way and attach the prefab to a creating object?

I'll post the newest version, with particles disabled for now.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by TheLacus »

There are no issues with particle systems; in fact I'm using one for the loading screen mod.

You can load a prefab with a particle system with Mod.GetAsset() or handle it in any way supported by Unity.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

Odd. So, this is the particle code I created that works in the editor without issue or a prefab setup.

However, when imported into the mod, it doesn't work, even though it does in the builder with just this code.

Code: Select all

using UnityEngine;
namespace ParticleConstructorClass
{
    public class ParticleConstructor : MonoBehaviour
    {
            ParticleSystem system;
            Texture2D particleTex;
            Light lightPrefab;
            GameObject storedParticleSystem;

            //PARTICLE SYSTEM SETUP: Sets up the first/beta particle system.\\
            public void setupParticleSystem(Vector3 SystemRotation, ParticleSystem.ColorOverLifetimeModule ColorModule, GradientColorKey[] ColorGradient, GradientAlphaKey[] AlphaGradient, ParticleSystemRenderMode RenderMode, float StretchVelocity)
            {
                Gradient gradient = new Gradient();
                storedParticleSystem = new GameObject("Particle System");
                system = storedParticleSystem.AddComponent<ParticleSystem>();
                // Create a textured stretched Particle System.
                storedParticleSystem.transform.Rotate(SystemRotation); // Rotate so the system emits upwards.
                ParticleSystem.ColorOverLifetimeModule colorModule = ColorModule;
                gradient.SetKeys(ColorGradient, AlphaGradient);
                colorModule.color = gradient;
                storedParticleSystem.GetComponent<ParticleSystemRenderer>().renderMode = RenderMode;
                storedParticleSystem.GetComponent<ParticleSystemRenderer>().velocityScale = StretchVelocity;
            }

            public void setupMaterials(string ShaderName, Mesh ParticleMesh, bool MaterialEmissions, Color EmissionColor, Color MaterialColor, Texture2D ParticleTexture = null)
            {
                Material particleMaterial = new Material(Shader.Find(ShaderName));

                if(ParticleTexture != null)
                    particleMaterial.mainTexture = ParticleTexture;

                storedParticleSystem.GetComponent<ParticleSystemRenderer>().mesh = ParticleMesh;
                storedParticleSystem.GetComponent<ParticleSystemRenderer>().material = particleMaterial;

                if (MaterialEmissions)
                {
                    storedParticleSystem.GetComponent<Renderer>().material.EnableKeyword("_EMISSION");
                    storedParticleSystem.GetComponent<Renderer>().material.SetColor("_EMISSION", EmissionColor);
                }

                storedParticleSystem.GetComponent<Renderer>().material.SetColor("_Color", MaterialColor);
            }

            public void setupMainSystem(Color StartParticleColor, ParticleSystemEmitterVelocityMode EmitterVelocityMode, float ParticleDuration, float ParticleSize, float GravityMod, bool loop)
            {
                //sets up particle system main module.
                var mainModule = system.main;
                mainModule.startColor = StartParticleColor;
                mainModule.emitterVelocityMode = EmitterVelocityMode;
                mainModule.duration = ParticleDuration;
                mainModule.startSize = ParticleSize;
                mainModule.gravityModifier = GravityMod;
                mainModule.loop = loop;
            }

            public void setupLight(Color LightColor, float ParticleLightRation, float LightIntensity, float Range)
            {
                //setup lights for sparks.
                GameObject lightGameObject = new GameObject("The Light");
                var lights = system.lights;
                lightPrefab = lightGameObject.AddComponent<Light>();
                // Add the light component
                lights.enabled = true;
                lightPrefab.color = LightColor;
                lights.ratio = ParticleLightRation;
                lights.intensityMultiplier = LightIntensity;
                lights.rangeMultiplier = Range;
                lights.light = lightPrefab;
            }

            public void setupEmitter(ParticleSystemShapeType SystemShape, Vector3 SystemScale)
            {
                var shape = system.shape;
                shape.enabled = true;
                shape.shapeType = SystemShape;
                shape.scale = SystemScale;
                //sets up the emession burst at 0 seconds to add sparks to first particle emmission.
            }

            public void setupParticleBursts(float BurstTiming, ParticleSystem.MinMaxCurve ParticleAmounts)
            {
                var em = system.emission;
                em.enabled = true;
                em.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(BurstTiming, ParticleAmounts) });
            }

        public void setupTrails(string ShaderName,float ParticleTrailRatio, float TrailLifeTime, float TrailWidth, GradientColorKey[] ColorGradient, GradientAlphaKey[] AlphaGradient)
            {
                Gradient gradient = new Gradient();

                var trails = system.trails;
                storedParticleSystem.GetComponent<ParticleSystemRenderer>().trailMaterial = new Material(Shader.Find(ShaderName));
                trails.enabled = true;
                trails.ratio = ParticleTrailRatio;
                trails.lifetime = TrailLifeTime;
                trails.widthOverTrail = TrailWidth;
                //trails.inheritParticleColor = true;
                gradient.SetKeys(ColorGradient, AlphaGradient);
                trails.colorOverLifetime = gradient;
            }

            public ParticleSystem ReturnConstructedParticle()
            {
                Debug.Log("Returning System: " + system.ToString());
                return system;
            }
    }
}
There's the particle constructor script.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

Then I use this script to construct a particle system using previous constructor and store it for later use.

Code: Select all

using ParticleConstructorClass;
using UnityEngine;
namespace ParticleConstructorClass
{
    public class ParticleSystemContainer : MonoBehaviour
    {
        public ParticleSystem sparkParticles(float ParticleSize = .0025f, float ParticleLife = .3f, float ParticleGravity = 1.5f, float MinSparks = 5, float MaxSparks = 10)
        {
            ParticleSystem system;
            //Uses particle constructor to create unique particle system object\\
            //Sets up all the objects to be used to construct the particle system object.
            var go = new GameObject("Particle System");
            system = go.AddComponent<ParticleSystem>();
            ParticleSystem.ColorOverLifetimeModule colorModule1 = system.colorOverLifetime;
            var Sparks = new GameObject("Sparks");
            ParticleConstructor SparkParticles = new ParticleConstructor();
            SparkParticles = Sparks.AddComponent<ParticleConstructor>();
            //begins using class objects to setup particle system.
            SparkParticles.setupParticleSystem(new Vector3(45, 45, 0), colorModule1, new GradientColorKey[] { new GradientColorKey(Color.yellow, 0.01f), new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.red, .0225f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, .1f) }, ParticleSystemRenderMode.Mesh, .05f);
            SparkParticles.setupMainSystem(Color.white, ParticleSystemEmitterVelocityMode.Transform, ParticleLife, ParticleSize, ParticleGravity, false);
            SparkParticles.setupMaterials("Particles/Standard Surface", Resources.GetBuiltinResource<Mesh>("Sphere.fbx"), true, Color.white, Color.yellow);
            SparkParticles.setupLight(Color.yellow, 1f, 10f, 1f);
            SparkParticles.setupEmitter(ParticleSystemShapeType.Cone, new Vector3(.1f, .05f, .05f));
            SparkParticles.setupParticleBursts(0, new ParticleSystem.MinMaxCurve(MinSparks, MaxSparks));
            SparkParticles.setupTrails("Legacy Shaders/Particles/Alpha Blended Premultiply", .75f, .0035f, 1.25f, new GradientColorKey[] { new GradientColorKey(Color.yellow, 0.015f), new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.red, .04f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, .1f) });
            //assigns constructed particle system to a enpty particle system object.
            return SparkParticles.ReturnConstructedParticle();
        }
    }
}
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

Then I dump the prefabbed particle system into a empty particle system object and play it.

Code: Select all

            var SparkObject = new GameObject("SparkObject");
            ParticleSystemContainer SparkPrefab = new ParticleSystemContainer();
            SparkPrefab = SparkObject.AddComponent<ParticleSystemContainer>();
            SparkParticles = SparkPrefab.sparkParticles();
            
            SparkParticles.transform.position = attackerEntity.EntityBehaviour.transform.position + (attackerEntity.EntityBehaviour.transform.forward * .35f);        
            SparkParticles.Play();
            
            
This is all created via c# script and not prefabbed assets. Is that the issue? This runs in the editor, and will emit the spark particles on parrying an enemy, but not in the actual stand alone game, it causes the mod to crash at start up. And the output log isn't updating in my windows/user settings directory to see what is exactly going on.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

Got the log.

There is a null value that is not allowed some where in the material setup code. I think might be the texture.

Here's the error:
ArgumentNullException: Value cannot be null.
Parameter name: shader
at (wrapper managed-to-native) UnityEngine.Material.CreateWithShader(UnityEngine.Material,UnityEngine.Shader)
at UnityEngine.Material..ctor (UnityEngine.Shader shader) [0x00008] in <548b4fa0e7e04f27a1b7580930bfb7dc>:0
at ParticleConstructorClass.ParticleConstructor.setupMaterials (System.String ShaderName, UnityEngine.Mesh ParticleMesh, System.Boolean MaterialEmissions, UnityEngine.Color EmissionColor, UnityEngine.Color MaterialColor, UnityEngine.Texture2D ParticleTexture) [0x00006] in <f233e47184ae47ceb91934436e615592>:0
at ParticleConstructorClass.ParticleSystemContainer.sparkParticles (System.Single ParticleSize, System.Single ParticleLife, System.Single ParticleGravity, System.Single MinSparks, System.Single MaxSparks) [0x00129] in <f233e47184ae47ceb91934436e615592>:0
at AmbidexterityModule.AmbidexterityManager.Start () [0x00018] in <f233e47184ae47ceb91934436e615592>:0
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

resolved the issue. Dumb nooby mistake. I was compiling the code before the object was even setup on the launch code flow order.

Now, I need to fix the next issue. The particle isn't showing up, like it does in the editor. I take it, Daggerfall doesn't have all the built in unity shader textures and materials, and thus, I need to construct a prefab particle assets to import.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1409
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by l3lessed »

Okay, I recreated the particle system as a prefab. But, I can't figure out how to load it into the engine.

Code: Select all

            UnityEngine.Object prefabReference = Resources.Load(Application.dataPath + "/StreamingAssets/Particles/Spark_Particles.prefab");
            SparkPreb = Instantiate(prefabReference) as GameObject;
            sparkParticles = SparkPreb.AddComponent<ParticleSystem>();
Can we add prefabs using mods? Since it doesn't compile with the project, as a project prefab, I can't get it to attach/import it. am I missing the documentation?
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Legendoflight44
Posts: 9
Joined: Tue Oct 20, 2020 3:55 pm

Re: [MOD]Ambidexterity Module (Shield Module Branch)

Post by Legendoflight44 »

Sorry l3lessed in advance for this if anyone has trouble running the newest verion *so far* of Ambidexterity where it does not run What I did was extract the files added the ParticleConstructor.cs into the .json file because it was not even added also remove the lines that deal with particlesystemconstructor from AmbidexterityManager.cs because of an error where it's not found or defined remove them then build the mod and it should work, remember this is temporary until l3lessed can figure out the real problem with the particles

Post Reply