public static void CreateFireworkHead(Vector3 position) { GameObject gameObject = new GameObject("Firework " + Time.time); gameObject.transform.position = position; // PARTICLESYSTEM. GPUParticleSystem system = gameObject.AddComponent <GPUParticleSystem>(); GPUParticleDescriptor descriptor = new GPUParticleDescriptor(); descriptor.EmittFrequency = 500.0f; descriptor.Lifetime = 1.0f; descriptor.InheritVelocity = false; GPUParticleDescriptor.LifetimePoints colorPoints = new GPUParticleDescriptor.LifetimePoints(); colorPoints.Add(new Vector4(0, 1, 0, 0)); colorPoints.Add(new Vector4(1, 1, 0, 0.1f)); colorPoints.Add(new Vector4(0, 1, 0, 0.2f)); colorPoints.Add(new Vector4(1, 0, 0, 0.3f)); colorPoints.Add(new Vector4(0, 1, 0, 0.4f)); colorPoints.Add(new Vector4(0, 0, 1, 0.5f)); colorPoints.Add(new Vector4(1, 0, 1, 0.6f)); colorPoints.Add(new Vector4(0, 1, 1, 0.7f)); colorPoints.Add(new Vector4(0, 1, 0, 0.8f)); colorPoints.Add(new Vector4(1, 1, 1, 0.9f)); colorPoints.Add(new Vector4(1, 1, 0, 1)); descriptor.ColorOverLifetime = colorPoints; GPUParticleDescriptor.LifetimePoints haloPoints = new GPUParticleDescriptor.LifetimePoints(); haloPoints.Add(new Vector4(1, 0, 0, 0)); haloPoints.Add(new Vector4(0, 1, 0, 0.333f)); haloPoints.Add(new Vector4(0, 0, 1, 0.666f)); haloPoints.Add(new Vector4(0.5f, 0, 0.5f, 1)); descriptor.HaloOverLifetime = haloPoints; GPUParticleDescriptor.LifetimePoints scalePoints = new GPUParticleDescriptor.LifetimePoints(); scalePoints.Add(new Vector4(0.01f, 0.01f, 0, 0)); scalePoints.Add(new Vector4(0.01f, 0.01f, 0, 1)); descriptor.ScaleOverLifetime = scalePoints; GPUParticleDescriptor.LifetimePoints opacityPoints = new GPUParticleDescriptor.LifetimePoints(); opacityPoints.Add(new Vector4(1.0f, 0, 0, 0)); opacityPoints.Add(new Vector4(1.0f, 0, 0, 0.8f)); opacityPoints.Add(new Vector4(0.0f, 0, 0, 1.0f)); descriptor.OpacityOverLifetime = opacityPoints; descriptor.EmittMesh = CreateMesh(PrimitiveType.Sphere); system.ParticleDescriptor = descriptor; // ATTRACTOR. gameObject.AddComponent <GPUParticleAttractor>().Power = -10.0f; // LIFETIME. gameObject.AddComponent <LifeTimer>().LifeTime = 5; }
public static GameObject CreateVatsugWand(float powerEndAttractor, float powerNormalAttractors, float pendulumSpeed, float reboundDistance, bool rightHand) { //The wand is the parent object to all the parts. GameObject WandGO = new GameObject("VatsugWand" + count++); //The rod //We set its transform. GameObject RodGO = new GameObject("Rod" + count++); RodGO.transform.parent = WandGO.transform; RodGO.transform.localScale += Vector3.up * 8; RodGO.transform.localScale *= 0.2f; RodGO.transform.position += Vector3.forward * 0.2f; TempVisuals(RodGO, PrimitiveType.Cylinder, Color.black); //The tip //We set its transform GameObject TipGO = new GameObject("Tip" + count++); TipGO.transform.parent = WandGO.transform; TipGO.transform.position += Vector3.up * 2; TipGO.transform.localScale *= 0.5f; TipGO.transform.position += Vector3.forward * 0.2f; TempVisuals(TipGO, PrimitiveType.Sphere, Color.red); WandGO.transform.localScale *= 0.1f; //++++++++++ WAND ++++++++++ GameObject endAttractor; GameObject emitter = new GameObject("VatsugEmitter" + count++); //We add the emitter to the tip. GPUParticleSystem particleEmitter = emitter.AddComponent <GPUParticleSystem>(); emitter.AddComponent <GPUParticleAttractor>().Power = 0.0f; TempVisuals(emitter, PrimitiveType.Sphere, Color.blue); emitter.GetComponent <Renderer>().enabled = false; emitter.transform.parent = TipGO.transform; emitter.transform.localScale = Vector3.one * 0.7f; emitter.transform.localPosition = new Vector3(1, 0, 0) * reboundDistance; GPUParticleDescriptor descriptor = new GPUParticleDescriptor(); descriptor.EmittFrequency = 500.0f; descriptor.Lifetime = 5.0f; descriptor.InheritVelocity = false; GPUParticleDescriptor.LifetimePoints colorPoints = new GPUParticleDescriptor.LifetimePoints(); colorPoints.Add(new Vector4(1, 0, 0, 0)); colorPoints.Add(new Vector4(1, 1, 0, 0.3f)); colorPoints.Add(new Vector4(0, 1, 0, 1.0f)); descriptor.ColorOverLifetime = colorPoints; GPUParticleDescriptor.LifetimePoints haloPoints = new GPUParticleDescriptor.LifetimePoints(); haloPoints.Add(new Vector4(0, 0, 1, 0)); haloPoints.Add(new Vector4(1, 0, 1, 1.0f)); descriptor.HaloOverLifetime = haloPoints; GPUParticleDescriptor.LifetimePoints scalePoints = new GPUParticleDescriptor.LifetimePoints(); scalePoints.Add(new Vector4(0.01f, 0.01f, 0, 0)); scalePoints.Add(new Vector4(0.01f, 0.01f, 0, 1)); descriptor.ScaleOverLifetime = scalePoints; GPUParticleDescriptor.LifetimePoints opacityPoints = new GPUParticleDescriptor.LifetimePoints(); opacityPoints.Add(new Vector4(1.0f, 0, 0, 0)); opacityPoints.Add(new Vector4(1.0f, 0, 0, 0.8f)); opacityPoints.Add(new Vector4(0.0f, 0, 0, 1.0f)); descriptor.OpacityOverLifetime = opacityPoints; descriptor.EmittMesh = TipGO.GetComponent <MeshFilter>().mesh; particleEmitter.ParticleDescriptor = descriptor; particleEmitter.Active = false; endAttractor = new GameObject(); endAttractor.AddComponent <GPUParticleAttractor>().Power = 0.0f; endAttractor.transform.parent = TipGO.transform; endAttractor.transform.localPosition = Vector3.up * 17.0f; WandGO.transform.Rotate(90, 0, 0); WandGO.transform.position += Vector3.forward * 0.2f; VatsugWand wand = TipGO.AddComponent <VatsugWand>(); wand.mEndAttractor = endAttractor; wand.mPowerEndAttractor = powerEndAttractor; wand.mPowerAttractors = powerNormalAttractors; wand.mReboundDistance = reboundDistance; wand.mParticleEmitter = emitter;// particleEmitter; wand.rightHand = rightHand; wand.pendulumSpeed = pendulumSpeed; GameObject hand = new GameObject(rightHand ? "Right" : "Left" + "hand"); WandGO.transform.parent = hand.transform; hand.AddComponent <MirrorHandMovement>(); return(WandGO); }
public static GameObject CreateAttractorWand(float power, bool rightHand) { //The wand is the parent object to all the parts. GameObject WandGO = new GameObject("AttractorWand" + count++); //The rod //We set its transform. GameObject RodGO = new GameObject("Rod" + count++); RodGO.transform.parent = WandGO.transform; RodGO.transform.localScale += Vector3.up * 8; RodGO.transform.localScale *= 0.2f; RodGO.transform.position += Vector3.forward * 0.2f; TempVisuals(RodGO, PrimitiveType.Cylinder, Color.black); //The tip //We set its transform GameObject TipGO = new GameObject("Tip" + count++); TipGO.transform.parent = WandGO.transform; TipGO.transform.position += Vector3.up * 2; TipGO.transform.localScale *= 0.5f; TipGO.transform.position += Vector3.forward * 0.2f; TempVisuals(TipGO, PrimitiveType.Sphere, Color.red); WandGO.transform.localScale *= 0.1f; //We add the emitter to the tip. GPUParticleSystem system = TipGO.AddComponent <GPUParticleSystem>(); Health.HEALTH_FACTOR = 1.0f; GPUParticleDescriptor descriptor = new GPUParticleDescriptor(); descriptor.EmittFrequency = 500.0f; descriptor.Lifetime = 5.0f; descriptor.InheritVelocity = false; GPUParticleDescriptor.LifetimePoints colorPoints = new GPUParticleDescriptor.LifetimePoints(); colorPoints.Add(new Vector4(0, 1, 0, 0)); colorPoints.Add(new Vector4(1, 1, 0, 0.1f)); colorPoints.Add(new Vector4(0, 1, 0, 0.2f)); colorPoints.Add(new Vector4(1, 0, 0, 0.3f)); colorPoints.Add(new Vector4(0, 1, 0, 0.4f)); colorPoints.Add(new Vector4(0, 0, 1, 0.5f)); colorPoints.Add(new Vector4(1, 0, 1, 0.6f)); colorPoints.Add(new Vector4(0, 1, 1, 0.7f)); colorPoints.Add(new Vector4(0, 1, 0, 0.8f)); colorPoints.Add(new Vector4(1, 1, 1, 0.9f)); colorPoints.Add(new Vector4(1, 1, 0, 1)); descriptor.ColorOverLifetime = colorPoints; GPUParticleDescriptor.LifetimePoints haloPoints = new GPUParticleDescriptor.LifetimePoints(); haloPoints.Add(new Vector4(1, 0, 0, 0)); haloPoints.Add(new Vector4(0, 1, 0, 0.333f)); haloPoints.Add(new Vector4(0, 0, 1, 0.666f)); haloPoints.Add(new Vector4(0.5f, 0, 0.5f, 1)); descriptor.HaloOverLifetime = haloPoints; GPUParticleDescriptor.LifetimePoints scalePoints = new GPUParticleDescriptor.LifetimePoints(); scalePoints.Add(new Vector4(0.005f, 0.005f, 0, 0)); scalePoints.Add(new Vector4(0.005f, 0.005f, 0, 1)); descriptor.ScaleOverLifetime = scalePoints; GPUParticleDescriptor.LifetimePoints opacityPoints = new GPUParticleDescriptor.LifetimePoints(); opacityPoints.Add(new Vector4(0.0f, 0, 0, 0)); opacityPoints.Add(new Vector4(1.0f, 0, 0, 0.1f)); opacityPoints.Add(new Vector4(1.0f, 0, 0, 0.8f)); opacityPoints.Add(new Vector4(0.0f, 0, 0, 1.0f)); descriptor.OpacityOverLifetime = opacityPoints; descriptor.EmittMesh = TipGO.GetComponent <MeshFilter>().mesh; system.ParticleDescriptor = descriptor; //We add an attractor to the tip. GPUParticleAttractor attractor = TipGO.AddComponent <GPUParticleAttractor>(); attractor.Power = 1; //We add vector field to the tip. GPUParticleVectorField vectorField = TipGO.AddComponent <GPUParticleVectorField>(); vectorField.Max = 0.3f; WandGO.transform.Rotate(90, 0, 0); AttractorWand wand = WandGO.AddComponent <AttractorWand>(); wand.power = power; wand.rightHand = rightHand; wand.system = system; wand.attractor = attractor; wand.vectorField = vectorField; GameObject hand = new GameObject(rightHand ? "Right" : "Left" + "hand"); WandGO.transform.parent = hand.transform; hand.AddComponent <MirrorHandMovement>().rightHand = rightHand; return(hand); }