void Start() { startTime = Time.time; pEmitters = gameObject.GetComponentsInChildren <KSPParticleEmitter>(); foreach (KSPParticleEmitter pe in pEmitters) { EffectBehaviour.AddParticleEmitter(pe); pe.emit = true; //if(pe.useWorldSpace) pe.force = (4.49f * FlightGlobals.getGeeForceAtPosition(transform.position)); if (pe.maxEnergy > maxTime) { maxTime = pe.maxEnergy; } } lightFX = gameObject.AddComponent <Light>(); lightFX.color = Misc.ParseColor255("255,238,184,255"); lightFX.intensity = 8; lightFX.range = range * 3f; lightFX.shadows = LightShadows.None; audioSource.volume = BDArmorySettings.BDARMORY_WEAPONS_VOLUME; audioSource.PlayOneShot(exSound); }
void SetupLaserSpecifics() { chargeSound = GameDatabase.Instance.GetAudioClip(chargeSoundPath); if(HighLogic.LoadedSceneIsFlight) { audioSource.clip = fireSound; } laserRenderers = new LineRenderer[fireTransforms.Length]; for(int i = 0; i < fireTransforms.Length; i++) { Transform tf = fireTransforms[i]; laserRenderers[i] = tf.gameObject.AddComponent<LineRenderer>(); Color laserColor = Misc.ParseColor255(projectileColor); laserColor.a = laserColor.a/2; laserRenderers[i].material = new Material(Shader.Find ("KSP/Particles/Alpha Blended")); laserRenderers[i].material.SetColor("_TintColor", laserColor); laserRenderers[i].material.mainTexture = GameDatabase.Instance.GetTexture("BDArmory/Textures/laser", false); laserRenderers[i].castShadows = false; laserRenderers[i].receiveShadows = false; laserRenderers[i].SetWidth(tracerStartWidth, tracerEndWidth); laserRenderers[i].SetVertexCount(2); laserRenderers[i].SetPosition(0, Vector3.zero); laserRenderers[i].SetPosition(1, Vector3.zero); laserRenderers[i].useWorldSpace = false; laserRenderers[i].enabled = false; } }
public override void OnStart (StartState state) { base.OnStart (state); ParseWeaponType(); ParseBulletDragType(); bulletBallisticCoefficient = bulletMass / bulletDragArea * 1000; //1000 to convert from tonnes to kilograms if(shortName == string.Empty) { shortName = part.partInfo.title; } foreach(var emitter in part.FindModelComponents<KSPParticleEmitter>()) { emitter.emit = false; } if(airDetonation) { var detRange = (UI_FloatRange)Fields["defaultDetonationRange"].uiControlEditor; detRange.maxValue = maxAirDetonationRange; } else { Fields["defaultDetonationRange"].guiActive = false; Fields["defaultDetonationRange"].guiActiveEditor = false; } if(HighLogic.LoadedSceneIsFlight) { if(eWeaponType != WeaponTypes.Laser) { if(bulletPool == null) { SetupBulletPool(); } if(shellPool == null) { SetupShellPool(); } } //setup transforms fireTransforms = part.FindModelTransforms(fireTransformName); shellEjectTransforms = part.FindModelTransforms(shellEjectTransformName); //setup emitters foreach(var pe in part.FindModelComponents<KSPParticleEmitter>()) { pe.maxSize *= part.rescaleFactor; pe.minSize *= part.rescaleFactor; pe.shape3D *= part.rescaleFactor; pe.shape2D *= part.rescaleFactor; pe.shape1D *= part.rescaleFactor; if(pe.useWorldSpace && !oneShotWorldParticles) { BDAGaplessParticleEmitter gpe = pe.gameObject.AddComponent<BDAGaplessParticleEmitter>(); gpe.part = part; gaplessEmitters.Add(gpe); } } //setup projectile colors projectileColorC = Misc.ParseColor255(projectileColor); startColorC = Misc.ParseColor255(startColor); //init and zero points targetPosition = Vector3.zero; pointingAtPosition = Vector3.zero; bulletPrediction = Vector3.zero; //setup audio SetupAudio(); //laser setup if(eWeaponType == WeaponTypes.Laser) { SetupLaserSpecifics(); } } else if(HighLogic.LoadedSceneIsEditor) { fireTransforms = part.FindModelTransforms(fireTransformName); } //turret setup foreach(var turr in part.FindModulesImplementing<ModuleTurret>()) { if(turr.turretID == turretID) { turret = turr; break; } } if(!turret) { Fields["onlyFireInRange"].guiActive = false; Fields["onlyFireInRange"].guiActiveEditor = false; } //setup animations if(hasDeployAnim) { deployState = Misc.SetUpSingleAnimation(deployAnimName, this.part); deployState.normalizedTime = 0; deployState.speed = 0; deployState.enabled = true; } if(hasFireAnimation) { fireState = Misc.SetUpSingleAnimation (fireAnimName, this.part); fireState.enabled = false; } BDArmorySettings.OnVolumeChange += UpdateVolume; }