public PersistentKSPParticleEmitter( GameObject go, KSPParticleEmitter pe, KSPParticleEmitter templateKspParticleEmitter) { this.go = go; this.pe = pe; scale1DBase = templateKspParticleEmitter.shape1D; scale2DBase = templateKspParticleEmitter.shape2D; scale3DBase = templateKspParticleEmitter.shape3D; minEmissionBase = templateKspParticleEmitter.minEmission; maxEmissionBase = templateKspParticleEmitter.maxEmission; minEnergyBase = templateKspParticleEmitter.minEnergy; maxEnergyBase = templateKspParticleEmitter.maxEnergy; minSizeBase = templateKspParticleEmitter.minSize; maxSizeBase = templateKspParticleEmitter.maxSize; localVelocityBase = templateKspParticleEmitter.localVelocity; worldVelocityBase = templateKspParticleEmitter.worldVelocity; forceBase = templateKspParticleEmitter.force; PersistentEmitterManager.Add(this); }
/// <summary> /// The main initialisation. Here we create the subcomponents. /// </summary> private void Awake() { if (!GetComponent <KSPParticleEmitter>()) { // Shouldn't happen emitter = gameObject.AddComponent <KSPParticleEmitter>(); } else { emitter = GetComponent <KSPParticleEmitter>(); } emitter.useWorldSpace = false; emitter.emit = true; emitter.material = new Material(Shader.Find(shaderName)); emitter.doesAnimateColor = true; emitter.SetDirty(); emitter.particleRenderMode = ParticleSystemRenderMode.Mesh; var sh = emitter.ps.shape; sh.enabled = true; sh.shapeType = ParticleSystemShapeType.Mesh; var collision = emitter.ps.collision; collision.enabled = collideable; collision.type = ParticleSystemCollisionType.World; collision.bounce = bounce; collision.enableDynamicColliders = true; var lifeColor = emitter.ps.colorOverLifetime; lifeColor.enabled = lifetimeColors == null ? false : true; lifeColor.color = new ParticleSystem.MinMaxGradient(lifetimeColors[0], lifetimeColors[1]); }
public override void OnStart(PartModule.StartState state) { part.stagingIcon = "LIQUID_ENGINE"; base.OnStart(state); { if (state != StartState.Editor && state != StartState.None) { this.enabled = true; this.part.force_activate(); } else { this.enabled = false; } if (base.part.FindModelTransform("rotor").gameObject != null) { stator = base.part.FindModelTransform("stator").gameObject; rotor = base.part.FindModelTransform("rotor").gameObject; } EMITransform = base.part.FindModelTransform("EMI"); Emitter = EMITransform.gameObject.GetComponent <KSPParticleEmitter>(); Emitter.emit = false; } }
public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing <ModuleActiveRadiator>(); radiator.isEnabled = isDeployed && isCooling; radiator.enabled = isDeployed && isCooling; emitter = this.part.GetComponentInChildren <KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isDeployed && isCooling; emitter.enabled = isDeployed && isCooling; } UpdateStatus(); if (isOpenCycle) { this.Events["ToggleOpenCycle"].guiName = "Open Cycle Off"; } else { this.Events["ToggleOpenCycle"].guiName = "Open Cycle On"; } }
public void OnUpdate() { if (!_rescale) { return; } GetFieldInfos(); EffectBehaviour[] fxn = _part.GetComponents <EffectBehaviour>(); _rescale = fxn.Length != 0; foreach (EffectBehaviour fx in fxn) { if (fx is ModelMultiParticleFX) { List <KSPParticleEmitter> p = _mmpFxField.GetValue(fx) as List <KSPParticleEmitter>; if (p == null) { continue; } foreach (KSPParticleEmitter pe in p) { UpdateParticleEmitter(pe); } _rescale = false; } else if (fx is ModelParticleFX) { KSPParticleEmitter pe = _mpFxField.GetValue(fx) as KSPParticleEmitter; UpdateParticleEmitter(pe); _rescale = false; } } }
public PersistentKSPShurikenEmitter( GameObject go, ParticleSystem pe, ParticleSystemRenderer pr, KSPParticleEmitter templateKspParticleEmitter) { this.go = go; this.pe = pe; this.pr = pr; // TODO That s what we need to also save to emit manually with proper values // float emitterVelocityScale // Vector3 rndVelocity // bool rndRotation // float angularVelocity // float rndAngularVelocity //templateKspParticleEmitter.ve shape = templateKspParticleEmitter.shape; scale1DBase = shape1D = templateKspParticleEmitter.shape1D; scale2DBase = shape2D = templateKspParticleEmitter.shape2D; scale3DBase = shape3D = templateKspParticleEmitter.shape3D; minEmissionBase = minEmission = templateKspParticleEmitter.minEmission; maxEmissionBase = maxEmission = templateKspParticleEmitter.maxEmission; minEnergyBase = minEnergy = templateKspParticleEmitter.minEnergy; maxEnergyBase = maxEnergy = templateKspParticleEmitter.maxEnergy; minSizeBase = minSize = templateKspParticleEmitter.minSize; maxSizeBase = maxSize = templateKspParticleEmitter.maxSize; localVelocityBase = localVelocity = templateKspParticleEmitter.localVelocity; worldVelocityBase = worldVelocity = templateKspParticleEmitter.worldVelocity; forceBase = force = templateKspParticleEmitter.force; rndForce = templateKspParticleEmitter.rndForce; rndVelocity = templateKspParticleEmitter.rndVelocity; rndRotation = templateKspParticleEmitter.rndRotation; angularVelocity = templateKspParticleEmitter.angularVelocity; rndAngularVelocity = templateKspParticleEmitter.rndAngularVelocity; // Unity sure love its strange way of using struct (this actually works because each properties of the struct does magic) ParticleSystem.ForceOverLifetimeModule fol = pe.forceOverLifetime; fol.enabled = force.sqrMagnitude > 0 || rndForce.sqrMagnitude > 0; fol.x = new ParticleSystem.MinMaxCurve(forceBase.x, forceBase.x + rndForce.x); fol.y = new ParticleSystem.MinMaxCurve(forceBase.y, forceBase.y + rndForce.y); fol.z = new ParticleSystem.MinMaxCurve(forceBase.z, forceBase.z + rndForce.z); color = templateKspParticleEmitter.color; saturationMult = 1; brightnessMult = 1; alphaMult = 1; PersistentEmitterManager.Add(this); }
public void ShowParticleEffect(bool isVisible) { KSPParticleEmitter emitter = this.part.GetComponentInChildren <KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isVisible; emitter.enabled = isVisible; } }
public EmitterData(KSPParticleEmitter pe) { MinSize = pe.minSize; MaxSize = pe.maxSize; Shape1D = pe.shape1D; Shape2D = pe.shape2D; Shape3D = pe.shape3D; Force = pe.force; LocalVelocity = pe.localVelocity; }
public EmitterData(KSPParticleEmitter pe) { minSize = pe.minSize; maxSize = pe.maxSize; localVelocity = pe.localVelocity; shape1D = pe.shape1D; shape2D = pe.shape2D; shape3D = pe.shape3D; force = pe.force; }
private void Start() { PEmitter = gameObject.GetComponent <KSPParticleEmitter>(); PEmitter.emit = false; if (part != null) { //Debug.Log("Part " + Part.partName + "'s explosionPotential: " + Part.explosionPotential); } MaxDistance = PEmitter.minSize / 3; }
private void Start() { this.PEmitter = this.gameObject.GetComponent<KSPParticleEmitter>(); this.PEmitter.emit = false; if (this.Part != null) { Debug.Log("Part " + this.Part.partName + "'s explosionPotential: " + this.Part.explosionPotential); } this.MaxDistance = this.PEmitter.minSize / 3; }
private void Start() { this.PEmitter = this.gameObject.GetComponent <KSPParticleEmitter>(); this.PEmitter.emit = false; if (this.Part != null) { Debug.Log("Part " + this.Part.partName + "'s explosionPotential: " + this.Part.explosionPotential); } this.MaxDistance = this.PEmitter.minSize / 3; }
public override void OnStart(StartState state) { valveEffect = (KSPParticleEmitter)this.part.GetComponentInChildren <KSPParticleEmitter>(); if (allowStage) { Events["activateStaging"].guiActiveEditor = false; Events["deactivateStaging"].guiActiveEditor = true; } else { Invoke("disableStaging", 0.25f); } GameEvents.onVesselChange.Add(onVesselChange); if (valveEffect != null) { valveEffect.emit = isOpen; valveEffect.localVelocity.y = maxSpeedY * force / 100; } else { print("Launch effect not found"); } if (state != StartState.Editor) { // determine max amount of resources in parent part double totalResourceAmount = 0; foreach (PartResource resource in part.parent.Resources) { if (resource.resourceName == "ElectricCharge") { continue; } totalResourceAmount += resource.maxAmount; } // determine drain ratios foreach (PartResource resource in part.parent.Resources) { if (resource.resourceName == "ElectricCharge") { continue; } drainRatio.Add(resource.resourceName, (totalResourceAmount > 0 ? resource.maxAmount / totalResourceAmount : 0)); print("Valve: Adding ressource:" + resource.resourceName + " DR:" + resource.maxAmount / totalResourceAmount); } } }
public override void OnStart(PartModule.StartState state) { BladeProjector = base.part.FindModelTransform("BladeProjector"); swordEMI = base.part.FindModelTransform("swordEMI"); emt = swordEMI.gameObject.GetComponent("KSPParticleEmitter") as KSPParticleEmitter; if (state != StartState.Editor && state != StartState.None) { this.enabled = true; this.part.force_activate(); } if (HighLogic.LoadedSceneIsEditor) { emt.emit = false; } }
protected void setup_animation() { //animations animation_states.Clear(); foreach (var aname in Utils.ParseLine(AnimationNames, Utils.Whitespace)) { var animations = part.FindModelAnimators(aname); if (animations == null || animations.Length == 0) { this.Log("setup_animation: there's no '{}' animation in {}", aname, part.Title()); continue; } foreach (Animation anim in animations) { var animationState = anim[aname]; if (animationState == null) { continue; } animationState.speed = 0; animationState.enabled = true; animationState.wrapMode = WrapMode.ClampForever; anim.Blend(aname); animation_states.Add(animationState); } } Duration = animation_states.Aggregate(0f, (d, s) => Math.Max(d, s.length)); if (Duration.Equals(0)) { this.Log("setup_animation: animation length is zero!\n" + "Part: {}, AnimationNames: {}", part.Title(), AnimationNames); } //emitter emitter = part.FindModelComponents <KSPParticleEmitter>().FirstOrDefault(); if (emitter != null) { base_emission[0] = emitter.minEmission; base_emission[1] = emitter.maxEmission; } //initialize sound if (Sound != string.Empty) { Utils.createFXSound(part, fxSound, Sound, true, MaxDistance); fxSound.audio.volume = GameSettings.SHIP_VOLUME * MaxVolume; } }
void OnEnable() { if(!pe) { pe = gameObject.GetComponentInChildren<KSPParticleEmitter>(); } body = FlightGlobals.currentMainBody; if(!body) { gameObject.SetActive(false); return; } StartCoroutine(LifeRoutine()); }
void OnEnable() { if (!pe) { pe = gameObject.GetComponentInChildren <KSPParticleEmitter>(); } body = FlightGlobals.currentMainBody; if (!body) { gameObject.SetActive(false); return; } StartCoroutine(LifeRoutine()); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); Transform currentTransform = gameObject.transform; currentTransform = currentTransform.GetChild(0).GetChild(0); if (gameObjectPath != "") { string[] gameObjects = gameObjectPath.Split('/', '\\'); foreach (string objName in gameObjects) { for (int i = currentTransform.childCount - 1; i >= -1; i--) { if (i == -1) { Debug.LogErrorFormat("Could not find GameObject {0} in {1}.", objName, currentTransform.name); this.enabled = false; return; } if (currentTransform.GetChild(i).name == objName) { currentTransform = currentTransform.GetChild(i); break; } } } } GameObject targetObject = currentTransform.gameObject; emitter = targetObject.GetComponent <KSPParticleEmitter>(); if (emitter == null) { Debug.LogErrorFormat("Could not find a KSPParticleEmitter on {0}.", targetObject.name); this.enabled = false; return; } rotatingTransform = targetObject.GetComponent <RotatingTransform>(); if (rotatingTransform == null) { rotatingTransform = targetObject.AddComponent <RotatingTransform>(); rotatingTransform.rotationSpeed = this.rotationSpeed; rotatingTransform.enabled = emitter.emit; } }
/// <summary> /// Attaches the LaunchPadFX module and /// </summary> /// <param name="emitterTransformNames"></param> /// <param name="baseObject"></param> public void Setup(List <string> emitterTransformNames, GameObject baseObject, string smokeName) { InitializePSystems(); List <ParticleSystem> unityEmitters = new List <ParticleSystem>(); List <KSPParticleEmitter> kspEmitters = new List <KSPParticleEmitter>(); totalFXField = typeof(LaunchPadFX).GetField("totalFX", BindingFlags.NonPublic | BindingFlags.Instance); foreach (string emName in emitterTransformNames) { foreach (Transform emTransform in baseObject.transform.FindAllRecursive(emName)) { if (particleSystems.ContainsKey(smokeName)) { if (particleSystems[smokeName].pSystems != null) { foreach (ParticleSystem pSystem in particleSystems[smokeName].pSystems) { //Log.Normal("adding PSystem: " + pSystem.name); ParticleSystem emPsystem = Instantiate(pSystem, emTransform.position, emTransform.rotation, emTransform); emPsystem.gameObject.SetActive(true); unityEmitters.Add(emPsystem); FloatingOrigin.RegisterParticleSystem(emPsystem); } } if (particleSystems[smokeName].kspEmitters != null) { foreach (KSPParticleEmitter pSystem in particleSystems[smokeName].kspEmitters) { //Log.Normal("adding PSystem: " + pSystem.name); KSPParticleEmitter emPsystem = Instantiate(pSystem, emTransform.position, emTransform.rotation, emTransform); emPsystem.gameObject.SetActive(true); kspEmitters.Add(emPsystem); } } } else { Log.UserError("Cannot find a LaunchPad Smoke with name: " + smokeName); } } } // assign the emitters to the underlying component ps = unityEmitters.ToArray(); kspPS = kspEmitters.ToArray(); }
private void CreateCreatureExplosion(Creature creature, CreaturePart part) { GameObject obj = new GameObject("CreatureExplosionFX"); obj.transform.position = part.transform.position; KSPParticleEmitter particles = obj.AddComponent <KSPParticleEmitter> (); CreateKSPParticleEmitter(particles); Color color = (Settings.AllowCreatureGore ? creature.Gore.bloodColor : creature.Gore.skinColor); particles.color = color; particles.doesAnimateColor = true; particles.colorAnimation = new Color[5]; particles.colorAnimation [0] = color; particles.colorAnimation [1] = color.A(0.8f); particles.colorAnimation [2] = color.A(0.4f); particles.colorAnimation [3] = color.A(0.2f); particles.colorAnimation [4] = color.A(0f); Texture2D bloodParticleTexture = new Texture2D(4, 4); bloodParticleTexture.LoadImage(Textures.CreatureBloodExplosionParticle); particles.material.SetTexture("_MainTex", bloodParticleTexture); particles.maxEmission = 1000; particles.maxEnergy = 1.5f; particles.maxParticleSize = 2.5f; particles.maxSize = 3.5f; particles.minEmission = 1000; particles.minEnergy = 0.5f; particles.minSize = 2f; particles.damping = 0.9f; particles.force = FlightGlobals.getGeeForceAtPosition(obj.transform.position) * 2.5f; particles.rndAngularVelocity = 0f; particles.rndRotation = true; particles.rndForce = Vector3.one * 4f * creature.Gore.bloodVelocityMultiplier; particles.rndVelocity = Vector3.one * 8f * creature.Gore.bloodVelocityMultiplier; particles.shape3D = Vector3.one * creature.Gore.bloodSphereSize; CreatureExplosion creatureExplosion = obj.AddComponent <CreatureExplosion> (); creatureExplosion.particles = particles; }
void UpdateParticleEmitter(KSPParticleEmitter pe) { if (pe == null) { return; } if (!orig_scales.ContainsKey(pe)) { orig_scales[pe] = new EmitterData(pe); } var ed = orig_scales[pe]; pe.minSize = ed.MinSize * scale; pe.maxSize = ed.MaxSize * scale; pe.shape1D = ed.Shape1D * scale; pe.shape2D = ed.Shape2D * scale; pe.shape3D = ed.Shape3D * scale; pe.force = ed.Force * scale; pe.localVelocity = ed.LocalVelocity * scale; }
private void UpdateParticleEmitter(KSPParticleEmitter pe) { var factor = _ts.scalingFactor; if (!_scales.ContainsKey(pe)) { _scales[pe] = new EmitterData(pe); } var ed = _scales[pe]; pe.minSize = ed.minSize * factor.absolute.linear; pe.maxSize = ed.maxSize * factor.absolute.linear; pe.shape1D = ed.shape1D * factor.absolute.linear; pe.shape2D = ed.shape2D * factor.absolute.linear; pe.shape3D = ed.shape3D * factor.absolute.linear; pe.force = ed.force * factor.absolute.linear; pe.localVelocity = ed.localVelocity * factor.absolute.linear; }
public override void OnUpdate() { Transform ShieldTransform = base.part.FindModelTransform("Shield"); KSPParticleEmitter ShieldEmitter = ShieldTransform.gameObject.GetComponent <KSPParticleEmitter>(); SphereCollider ShieldCollider = ShieldTransform.gameObject.GetComponent <SphereCollider>(); if (shieldActivated == true) { ES = "Shield Activated"; ShieldTransform.gameObject.SetActive(true); ShieldEmitter.emit = true; } else { ES = "Shield Deactivated"; ShieldEmitter.emit = false; ShieldTransform.gameObject.SetActive(false); } }
public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing<ModuleActiveRadiator>(); radiator.isEnabled = isDeployed && isCooling; radiator.enabled = isDeployed && isCooling; emitter = this.part.GetComponentInChildren<KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isDeployed && isCooling; emitter.enabled = isDeployed && isCooling; } UpdateStatus(); if (isOpenCycle) this.Events["ToggleOpenCycle"].guiName = "Open Cycle Off"; else this.Events["ToggleOpenCycle"].guiName = "Open Cycle On"; }
public override void OnStart(StartState state) { valveEffect = (KSPParticleEmitter)this.part.GetComponentInChildren<KSPParticleEmitter>(); if (allowStage) { Events["activateStaging"].guiActiveEditor = false; Events["deactivateStaging"].guiActiveEditor = true; } else { Invoke("disableStaging", 0.25f); } GameEvents.onVesselChange.Add(onVesselChange); if (valveEffect != null) { valveEffect.emit = isOpen; valveEffect.localVelocity.y = maxSpeedY * force / 100; } else { print("Launch effect not found"); } if (state != StartState.Editor) { // determine max amount of resources in parent part double totalResourceAmount = 0; foreach (PartResource resource in part.parent.Resources) { if (resource.resourceName == "ElectricCharge") continue; totalResourceAmount += resource.maxAmount; } // determine drain ratios foreach (PartResource resource in part.parent.Resources) { if (resource.resourceName == "ElectricCharge") continue; drainRatio.Add(resource.resourceName, (totalResourceAmount > 0 ? resource.maxAmount / totalResourceAmount : 0)); print("Valve: Adding ressource:" + resource.resourceName + " DR:" + resource.maxAmount / totalResourceAmount); } } }
public void CreateEffect2() { UnityEngine.Object m = GameDatabase.Instance.GetModel(effectURL); print(m.GetType().ToString()); KSPParticleEmitter pe = new KSPParticleEmitter(); print(pe.GetType().ToString()); Type t = m.GetType(); //if (m.GetType() == typeof(KSPParticleEmitter)) //{ // print(m.name + " is a KSPParticleEmitter"); // KSPParticleEmitter mPe = (KSPParticleEmitter)m; // dustEffect.fxEmitters.Add(Emitter(mPe.pe)); //; }
private void CreateKSPParticleEmitter(KSPParticleEmitter particles) { particles.angularVelocity = 0f; particles.castShadows = false; particles.color = Color.magenta; particles.colorAnimation = new Color[5]; particles.damping = 1f; particles.doesAnimateColor = false; particles.emit = true; particles.emitterVelocityScale = 1f; particles.force = Vector3.zero; particles.lengthScale = 1f; particles.localRotationAxis = Vector3.up; particles.localVelocity = Vector3.zero; particles.material = new Material(Shader.Find("Particles/Alpha Blended")); particles.maxEmission = 250; particles.maxEnergy = 1f; particles.maxParticleSize = 1f; particles.maxSize = 1f; particles.minEmission = 0; particles.minEnergy = 0.1f; particles.minSize = 1f; particles.particleRenderMode = ParticleRenderMode.Billboard; particles.recieveShadows = false; particles.rndAngularVelocity = 0f; particles.rndForce = Vector3.one; particles.rndRotation = true; particles.rndVelocity = Vector3.one; particles.shape = KSPParticleEmitter.EmissionShape.Sphere; particles.shape1D = 1f; particles.shape2D = Vector2.one; particles.shape3D = Vector3.one; particles.sizeGrow = 1f; particles.useWorldSpace = false; particles.velocityScale = 1f; particles.worldRotationAxis = FlightGlobals.upAxis; particles.worldVelocity = Vector3.zero; }
public override void OnStart(StartState state) { base.OnStart(state); radiator = this.part.FindModuleImplementing <ModuleActiveRadiator>(); radiator.isEnabled = isDeployed && isCooling; radiator.enabled = isDeployed && isCooling; emitter = this.part.GetComponentInChildren <KSPParticleEmitter>(); if (emitter != null) { emitter.emit = isDeployed && isCooling; emitter.enabled = isDeployed && isCooling; } UpdateStatus(); if (isOpenCycle) { this.Events["ToggleOpenCycle"].guiName = "Open Cycle Off"; } else { this.Events["ToggleOpenCycle"].guiName = "Open Cycle On"; } if (isDeployed == false && this.part.Resources.Contains("Water")) { this.part.Resources["Water"].amount = 0; } if (fixedUpdateHelper == null) { fixedUpdateHelper = this.part.gameObject.AddComponent <FixedUpdateHelper>(); fixedUpdateHelper.onFixedUpdateDelegate = OnUpdateFixed; } fixedUpdateHelper.enabled = true; }
private void UpdateParticleEmitter(KSPParticleEmitter pe) { if (pe == null) { return; } ScalingFactor factor = _ts.ScalingFactor; if (!_scales.ContainsKey(pe)) { _scales[pe] = new EmitterData(pe); } EmitterData ed = _scales[pe]; pe.minSize = ed.MinSize * factor.absolute.linear; pe.maxSize = ed.MaxSize * factor.absolute.linear; pe.shape1D = ed.Shape1D * factor.absolute.linear; pe.shape2D = ed.Shape2D * factor.absolute.linear; pe.shape3D = ed.Shape3D * factor.absolute.linear; pe.force = ed.Force * factor.absolute.linear; pe.localVelocity = ed.LocalVelocity * factor.absolute.linear; }
public void setEffect(bool state) { foreach (KeyValuePair <int, KSPParticleEmitter> pair in effectsList) { KSPParticleEmitter launchEffect = pair.Value; //print ("Found Effect: " + launchEffect.name+" state"+state); launchEffect.emit = state; if (state) { if (numP != 0) { launchEffect.maxEmission = (int)(numP); } if (numP != 0) { launchEffect.minEmission = (int)(numP / 2); } } } foreach (Light launchEffectLight in lightList.Values) { launchEffectLight.intensity = (state ? 1 : 0); } }
void Start() { pEmitter = gameObject.GetComponent <KSPParticleEmitter>(); pEmitter.emit = false; EffectBehaviour.AddParticleEmitter(pEmitter); }
void Start() { pEmitter = gameObject.GetComponent<KSPParticleEmitter>(); pEmitter.emit = false; }
public PersistentKSPShurikenEmitter( GameObject go, ParticleSystem pe, ParticleSystemRenderer pr, KSPParticleEmitter templateKspParticleEmitter) { this.go = go; this.pe = pe; this.pr = pr; // TODO That s what we need to also save to emit manually with proper values // float emitterVelocityScale // Vector3 rndVelocity // bool rndRotation // float angularVelocity // float rndAngularVelocity //templateKspParticleEmitter.ve shape = templateKspParticleEmitter.shape; scale1DBase = shape1D = templateKspParticleEmitter.shape1D; scale2DBase = shape2D = templateKspParticleEmitter.shape2D; scale3DBase = shape3D = templateKspParticleEmitter.shape3D; minEmissionBase = minEmission = templateKspParticleEmitter.minEmission; maxEmissionBase = maxEmission = templateKspParticleEmitter.maxEmission; minEnergyBase = minEnergy = templateKspParticleEmitter.minEnergy; maxEnergyBase = maxEnergy = templateKspParticleEmitter.maxEnergy; minSizeBase = minSize = templateKspParticleEmitter.minSize; maxSizeBase = maxSize = templateKspParticleEmitter.maxSize; localVelocityBase = localVelocity = templateKspParticleEmitter.localVelocity; worldVelocityBase = worldVelocity = templateKspParticleEmitter.worldVelocity; forceBase = force = templateKspParticleEmitter.force; rndForce = templateKspParticleEmitter.rndForce; rndVelocity = templateKspParticleEmitter.rndVelocity; rndRotation = templateKspParticleEmitter.rndRotation; angularVelocity = templateKspParticleEmitter.angularVelocity; rndAngularVelocity = templateKspParticleEmitter.rndAngularVelocity; // Unity sure love its strange way of using struct (this actually works because each properties of the struct does magic) ParticleSystem.ForceOverLifetimeModule fol = pe.forceOverLifetime; fol.enabled = force.sqrMagnitude > 0 || rndForce.sqrMagnitude > 0; fol.x = new ParticleSystem.MinMaxCurve(forceBase.x, forceBase.x + rndForce.x); fol.y = new ParticleSystem.MinMaxCurve(forceBase.y, forceBase.y + rndForce.y); fol.z = new ParticleSystem.MinMaxCurve(forceBase.z, forceBase.z + rndForce.z); color = templateKspParticleEmitter.color; PersistentEmitterManager.Add(this); }
/// <summary> /// Initialize all the data in the OnStart method /// </summary> /// <param name="state">the Startstate of the part</param> public override void OnStart(StartState state) { base.OnStart(state); //Localization Events["jettisonResources"].guiName = Localizer.GetStringByTag("#LOC_KERBETROTTER.resourceswitch.dump"); Events["nextResourceSetup"].guiName = Localizer.GetStringByTag("#LOC_KERBETROTTER.resourceswitch.next"); Events["prevResourceSetup"].guiName = Localizer.GetStringByTag("#LOC_KERBETROTTER.resourceswitch.prev"); if (!initialized) { //find the confignode for this partModule. NOTE: This only works with //one ModuleLynxFuelSwitch per part if (particleEmitter != string.Empty) { Transform transform = part.FindModelTransform(particleEmitter); if (transform != null) { emitter = transform.GetComponentInChildren <KSPParticleEmitter>(); if (emitter != null) { emitter.emit = false; } } } int numModule = part.getModuleIndex(this); ConfigNode[] nodes = part.partInfo.partConfig.GetNodes("MODULE"); if ((numModule >= 0) && (numModule < nodes.Length) && (nodes[numModule].GetValue("name") == moduleName)) { initSwitchableResources(nodes[numModule]); initialized = true; } else { Debug.LogError("[KerbetrotterResourceSwitch] " + moduleName + ": Cannot find valid configNode for this module)"); } } //get the default resources of the part defaultResources = parseDefaultResources(part.partInfo.partConfig); //when no resource is set at the beginning, do this now if (selectedResourceID == -1) { refreshResources(0); } else { if (checkSaveConsistency()) { resourceCostsModifier = (float)switchableResources[selectedResourceID].costModifier; resourceMassModifier = (float)switchableResources[selectedResourceID].massModifier; } } //update the visibility of the GUI updateGUIVisibility(part); //update the texts of the GUI updateGUIText(part); }
public override void OnStart(StartState state) { base.OnStart(state); socket = part.CreateSocket(); //get other converters if(AnimatorID != "_none_") other_converters.AddRange(from c in part.Modules.OfType<AnimatedConverterBase>() where c != this && c.AnimatorID == AnimatorID select c); //initialize Animator emitter = part.FindModelComponents<KSPParticleEmitter>().FirstOrDefault(); if(emitter != null) { base_emission[0] = emitter.minEmission; base_emission[1] = emitter.maxEmission; } animator = part.GetAnimator(AnimatorID); var an = animator as HangarAnimator; if(an != null) base_animation_speed = an.ForwardSpeed; //initialize sound if(Sound != string.Empty) { Utils.createFXSound(part, fxSound, Sound, true, MaxDistance); fxSound.audio.volume = GameSettings.SHIP_VOLUME * MaxVolume; } //setup GUI fields Fields["Temperature"].guiActive = HeatProduction > 0; Fields["CurrentEnergyDemand"].guiName = Title+" Uses"; Fields["Rate"].guiName = Title+" Rate"; Events["StartConversion"].guiName = StartEventGUIName+" "+Title; Events["StopConversion"].guiName = StopEventGUIName+" "+Title; Actions["ToggleConversion"].guiName = ActionGUIName+" "+Title; //update state update_energy_demand(); update_events(); StartCoroutine(slow_update()); }
public override void OnStart(PartModule.StartState state) { ParseWeaponClass(); if(shortName == string.Empty) { shortName = part.partInfo.title; } gaplessEmitters = new List<BDAGaplessParticleEmitter>(); pEmitters = new List<KSPParticleEmitter>(); boostEmitters = new List<KSPParticleEmitter>(); boostGaplessEmitters = new List<BDAGaplessParticleEmitter>(); if(isTimed) { Fields["detonationTime"].guiActive = true; Fields["detonationTime"].guiActiveEditor = true; } else { Fields["detonationTime"].guiActive = false; Fields["detonationTime"].guiActiveEditor = false; } ParseModes(); foreach(var emitter in part.FindModelComponents<KSPParticleEmitter>()) { emitter.emit = false; } if(HighLogic.LoadedSceneIsFlight) { missileReferenceTransform = part.FindModelTransform("missileTransform"); if(!missileReferenceTransform) { missileReferenceTransform = part.partTransform; } if(!string.IsNullOrEmpty(exhaustPrefabPath)) { foreach(var t in part.FindModelTransforms("exhaustTransform")) { GameObject exhaustPrefab = (GameObject)Instantiate(GameDatabase.Instance.GetModel(exhaustPrefabPath)); exhaustPrefab.SetActive(true); foreach(var emitter in exhaustPrefab.GetComponentsInChildren<KSPParticleEmitter>()) { emitter.emit = false; } exhaustPrefab.transform.parent = t; exhaustPrefab.transform.localPosition = Vector3.zero; exhaustPrefab.transform.localRotation = Quaternion.identity; } } if(!string.IsNullOrEmpty(boostExhaustPrefabPath) && !string.IsNullOrEmpty(boostExhaustTransformName)) { foreach(var t in part.FindModelTransforms(boostExhaustTransformName)) { GameObject exhaustPrefab = (GameObject)Instantiate(GameDatabase.Instance.GetModel(boostExhaustPrefabPath)); exhaustPrefab.SetActive(true); foreach(var emitter in exhaustPrefab.GetComponentsInChildren<KSPParticleEmitter>()) { emitter.emit = false; } exhaustPrefab.transform.parent = t; exhaustPrefab.transform.localPosition = Vector3.zero; exhaustPrefab.transform.localRotation = Quaternion.identity; } } boosters = new List<GameObject>(); if(!string.IsNullOrEmpty(boostTransformName)) { foreach(var t in part.FindModelTransforms(boostTransformName)) { boosters.Add(t.gameObject); foreach(var be in t.GetComponentsInChildren<KSPParticleEmitter>()) { if(be.useWorldSpace) { if(!be.GetComponent<BDAGaplessParticleEmitter>()) { BDAGaplessParticleEmitter ge = be.gameObject.AddComponent<BDAGaplessParticleEmitter>(); ge.part = part; boostGaplessEmitters.Add(ge); } } else { if(!boostEmitters.Contains(be)) { boostEmitters.Add(be); } } } } } foreach(var emitter in part.partTransform.FindChild("model").GetComponentsInChildren<KSPParticleEmitter>()) { if(emitter.GetComponent<BDAGaplessParticleEmitter>() || boostEmitters.Contains(emitter)) { continue; } if(emitter.useWorldSpace) { BDAGaplessParticleEmitter gaplessEmitter = emitter.gameObject.AddComponent<BDAGaplessParticleEmitter>(); gaplessEmitter.part = part; gaplessEmitters.Add (gaplessEmitter); } else { if(emitter.transform.name != boostTransformName) { pEmitters.Add(emitter); } else { boostEmitters.Add(emitter); } } } cmTimer = Time.time; part.force_activate(); foreach(var pe in pEmitters) { if(hasRCS) { if(pe.gameObject.name == "rcsUp") upRCS = pe; else if(pe.gameObject.name == "rcsDown") downRCS = pe; else if(pe.gameObject.name == "rcsLeft") leftRCS = pe; else if(pe.gameObject.name == "rcsRight") rightRCS = pe; else if(pe.gameObject.name == "rcsForward") forwardRCS = pe; } if(!pe.gameObject.name.Contains("rcs") && !pe.useWorldSpace) { pe.sizeGrow = 99999; } } if(rotationTransformName!=string.Empty) { rotationTransform = part.FindModelTransform(rotationTransformName); } if(hasRCS) { SetupRCS(); KillRCS(); } SetupAudio(); } if(guidanceMode != GuidanceModes.Cruise) { Fields["cruiseAltitude"].guiActive = false; Fields["cruiseAltitude"].guiActiveEditor = false; } if(part.partInfo.title.Contains("Bomb")) { Fields["dropTime"].guiActive = false; Fields["dropTime"].guiActiveEditor = false; } if(deployAnimationName != "") { deployStates = Misc.SetUpAnimation(deployAnimationName, part); } else { deployedDrag = simpleDrag; } }
public override void OnInitialize() { //Print("Init"); // Restore the Curve config from the node content backup // Done because I could not get the serialization of MultiInputCurve to work if (node_backup != string.Empty) { Restore(); } // The shader loading require proper testing // Unity doc says that "Creating materials this way supports only simple shaders (fixed function ones). // If you need a surface shader, or vertex/pixel shaders, you'll need to create shader asset in the editor and use that." // But importing the same shader that the one used in the editor seems to work string filename = KSPUtil.ApplicationRootPath + "GameData/" + shaderFileName; if (shaderFileName != string.Empty && File.Exists(filename)) { try { TextReader shaderFile = new StreamReader(filename); string shaderText = shaderFile.ReadToEnd(); shader = new Material(shaderText).shader; } catch (Exception e) { Print("unable to load shader " + shaderFileName + " : " + e); } } List <Transform> transforms = new List <Transform>(hostPart.FindModelTransforms(transformName)); if (transforms.Count == 0) { Print("Cannot find transform " + transformName); return; } GameObject model = GameDatabase.Instance.GetModel(modelName); if (model == null) { Print("Cannot find model " + modelName); return; } model.SetActive(true); KSPParticleEmitter templateKspParticleEmitter = model.GetComponentInChildren <KSPParticleEmitter>(); if (templateKspParticleEmitter == null) { Print("Cannot find particle emitter on " + modelName); Destroy(model); return; } if (shader != null) { templateKspParticleEmitter.material.shader = shader; } if (persistentEmitters == null) { persistentEmitters = new List <PersistentKSPParticleEmitter>(); } if (hostPart.Modules.Contains("ProceduralSRB")) { PartModule pm = hostPart.Modules["ProceduralSRB"]; specialScale = pm.Fields.GetValue <float>("bellScale"); Print("Found ProceduralSRB. Rescaling by " + specialScale.ToString("F3") + " final scale " + (fixedScale * specialScale).ToString("F3")); } for (int i = 0; i < transforms.Count; i++) { GameObject emitterGameObject = Instantiate(model) as GameObject; KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren <KSPParticleEmitter>(); if (shader != null) { childKSPParticleEmitter.material.shader = shader; childKSPParticleEmitter.pr.material.shader = shader; } if (childKSPParticleEmitter != null) { PersistentKSPParticleEmitter pkpe = new PersistentKSPParticleEmitter( emitterGameObject, childKSPParticleEmitter, templateKspParticleEmitter); try { childKSPParticleEmitter.particleRenderMode = (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode); } catch (ArgumentException) { Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode"); } persistentEmitters.Add(pkpe); DisableCollider(pkpe.go); emitterGameObject.transform.SetParent(transforms[i]); emitterGameObject.transform.localPosition = localPosition; emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation); } } Destroy(templateKspParticleEmitter); list.Add(this); // 1.0 don't seems to properly do this for engines. OnEvent(0); }
void Awake() { pEmitter = gameObject.GetComponent <KSPParticleEmitter>(); EffectBehaviour.AddParticleEmitter(pEmitter); gpe = gameObject.GetComponent <BDAGaplessParticleEmitter>(); }
void Awake() { pEmitter = gameObject.GetComponent<KSPParticleEmitter>(); gpe = gameObject.GetComponent<BDAGaplessParticleEmitter>(); }
public override void OnStart(PartModule.StartState state) { ParseWeaponClass(); if(shortName == string.Empty) { shortName = part.partInfo.title; } gaplessEmitters = new List<BDAGaplessParticleEmitter>(); pEmitters = new List<KSPParticleEmitter>(); boostEmitters = new List<KSPParticleEmitter>(); if(isTimed) { Fields["detonationTime"].guiActive = true; Fields["detonationTime"].guiActiveEditor = true; } else { Fields["detonationTime"].guiActive = false; Fields["detonationTime"].guiActiveEditor = false; } if(HighLogic.LoadedSceneIsFlight) { ParseModes(); foreach(var emitter in part.FindModelComponents<KSPParticleEmitter>()) { if(emitter.useWorldSpace) { BDAGaplessParticleEmitter gaplessEmitter = emitter.gameObject.AddComponent<BDAGaplessParticleEmitter>(); gaplessEmitter.part = part; gaplessEmitters.Add (gaplessEmitter); } else { if(emitter.transform.name != boostTransformName) { pEmitters.Add(emitter); } else { boostEmitters.Add(emitter); } } } //pEmitters = part.FindModelComponents<KSPParticleEmitter>(); previousRotation = transform.rotation; cmTimer = Time.time; part.force_activate(); part.OnJustAboutToBeDestroyed += new Callback(Detonate); foreach(var pe in pEmitters) { if(hasRCS) { if(pe.gameObject.name == "rcsUp") upRCS = pe; else if(pe.gameObject.name == "rcsDown") downRCS = pe; else if(pe.gameObject.name == "rcsLeft") leftRCS = pe; else if(pe.gameObject.name == "rcsRight") rightRCS = pe; else if(pe.gameObject.name == "rcsForward") forwardRCS = pe; } if(!pe.gameObject.name.Contains("rcs") && !pe.useWorldSpace) { pe.sizeGrow = 99999; } } if(rotationTransformName!=string.Empty) { rotationTransform = part.FindModelTransform(rotationTransformName); } boosters = new List<GameObject>(); foreach(var tf in part.FindModelTransforms("boosterTransform")) { boosters.Add(tf.gameObject); decoupleBoosters = true; } if(hasRCS) { SetupRCS(); KillRCS(); } SetupAudio(); } if(guidanceMode != GuidanceModes.Cruise) { Fields["cruiseAltitude"].guiActive = false; Fields["cruiseAltitude"].guiActiveEditor = false; } if(part.partInfo.title.Contains("Bomb")) { Fields["dropTime"].guiActive = false; Fields["dropTime"].guiActiveEditor = false; } if(deployAnimationName != "") { deployStates = Misc.SetUpAnimation(deployAnimationName, part); } else { deployedDrag = part.maximum_drag; } }
public override void OnInitialize() { //Print("OnInitialize"); // Ship spawned somehow don't call OnLoad... if (node_backup != string.Empty) { Restore(); } List <Transform> transforms = new List <Transform>(hostPart.FindModelTransforms(transformName)); if (transforms.Count == 0) { if (transformName == "partTransform") { transforms.Add(hostPart.partTransform); } else { Log.info("Cannot find transform {0}", transformName); return; } } GameObject model = GameDatabase.Instance.GetModel(modelName); if (model == null) { Log.info("Cannot find model {0}", modelName); return; } model.SetActive(true); KSPParticleEmitter templateKspParticleEmitter = model.GetComponentInChildren <KSPParticleEmitter>(); if (templateKspParticleEmitter == null) { Log.info("Cannot find particle emitter on {0}", modelName); Destroy(model); return; } if (persistentEmitters == null) { persistentEmitters = new List <PersistentKSPShurikenEmitter>(); } if (hostPart.Modules.Contains("ProceduralSRB")) { PartModule pm = hostPart.Modules["ProceduralSRB"]; specialScale = pm.Fields.GetValue <float>("bellScale"); Log.info("Found ProceduralSRB. Rescaling by {0:0.000} final scale {1}:0.000}", specialScale, (fixedScale * specialScale)); } if (hostPart.Modules.Contains("TweakScale")) { PartModule pm = hostPart.Modules["TweakScale"]; float tweakScale = pm.Fields.GetValue <float>("currentScale"); float defaultScale = pm.Fields.GetValue <float>("defaultScale"); specialScale = tweakScale / (defaultScale <= 0 ? 1 : defaultScale); Log.info("Found TweakScale. Rescaling by {0:0.000} final scale {1:0.000}", specialScale, (fixedScale * specialScale)); } for (int i = 0; i < transforms.Count; i++) { GameObject emitterGameObject = i == 0 ? model : Instantiate(model); KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren <KSPParticleEmitter>(); if (childKSPParticleEmitter != null) { ParticleSystem particleSystem = childKSPParticleEmitter.gameObject.GetComponent <ParticleSystem>(); ParticleSystemRenderer particleSystemRenderer = childKSPParticleEmitter.gameObject.GetComponent <ParticleSystemRenderer>(); PersistentKSPShurikenEmitter pkpe = new PersistentKSPShurikenEmitter( emitterGameObject, particleSystem, particleSystemRenderer, childKSPParticleEmitter); // We do the emission and animation ourselves so we disable the KSP code childKSPParticleEmitter.emit = false; childKSPParticleEmitter.SetupProperties(); childKSPParticleEmitter.enabled = false; ParticleSystem.MainModule main = particleSystem.main; main.maxParticles = particleCountLimit; //particleSystemRenderer.alignment = ParticleSystemRenderSpace.View; pkpe.doesAnimateColor = childKSPParticleEmitter.doesAnimateColor; if (childKSPParticleEmitter.doesAnimateColor) { ParticleSystem.ColorOverLifetimeModule col = particleSystem.colorOverLifetime; // This one is annoying. The old particle system animate the color over the whole % life of the particle (0 - 1) // The new one animate it over time. So converted system may not reach the full value // The color is manually set in the update of PersistentKSPShurikenEmitter col.enabled = false; Color[] colors = childKSPParticleEmitter.colorAnimation; pkpe.colors = new Color[colors.Length]; Array.Copy(colors, pkpe.colors, colors.Length); } //try //{ // particleSystemRenderer.renderMode = // (ParticleSystemRenderMode)Enum.Parse(typeof (ParticleSystemRenderMode), renderMode); //} //catch (ArgumentException) //{ // Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleSystemRenderMode"); //} persistentEmitters.Add(pkpe); DisableCollider(pkpe.go); emitterGameObject.transform.SetParent(transforms[i], false); emitterGameObject.transform.localPosition = localPosition; emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation); emitterGameObject.SetLayerRecursive(layerId); } } list.Add(this); // 1.0 don't seems to properly do this for engines. //OnEvent(0f); }