//-------------------------------------------------------------------- // AddVesselFlare // Add a new vessel flare to our library private void AddVesselFlare(Vessel referenceShip) { // DistantObject/Flare/model has extents of (0.5, 0.5, 0.0), a 1/2 meter wide square. GameObject flare = GameDatabase.Instance.GetModel("DistantObject/Flare/model"); GameObject flareMesh = Mesh.Instantiate(flare) as GameObject; Destroy(flareMesh.GetComponent <Collider>()); DestroyObject(flare); flareMesh.name = referenceShip.vesselName; flareMesh.SetActive(true); MeshRenderer flareMR = flareMesh.GetComponentInChildren <MeshRenderer>(); // MOARdV: valerian recommended moving vessel and body flares to // layer 10, but that behaves poorly for nearby / co-orbital objects. // Move vessels back to layer 0 until I can find a better place to // put it. // Renderer layers: http://wiki.kerbalspaceprogram.com/wiki/API:Layers flareMR.gameObject.layer = 15; flareMR.material.shader = Shader.Find("KSP/Alpha/Unlit Transparent"); flareMR.material.color = Color.white; flareMR.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; flareMR.receiveShadows = false; VesselFlare vesselFlare = new VesselFlare(); vesselFlare.flareMesh = flareMesh; vesselFlare.meshRenderer = flareMR; vesselFlare.referenceShip = referenceShip; vesselFlare.luminosity = 5.0f + Mathf.Pow(referenceShip.GetTotalMass(), 1.25f); vesselFlare.brightness = 0.0f; vesselFlares.Add(referenceShip, vesselFlare); }
//-------------------------------------------------------------------- // DestroyVesselFlare // Destroy the things associated with a VesselFlare private static void DestroyVesselFlare(VesselFlare v) { if (v.meshRenderer != null) { if (v.meshRenderer.material != null) { Destroy(v.meshRenderer.material); } Destroy(v.meshRenderer); } if (v.flareMesh != null) { Destroy(v.flareMesh); } }
//-------------------------------------------------------------------- // AddVesselFlare // Add a new vessel flare to our library private void AddVesselFlare(Vessel referenceShip) { // DistantObject/Flare/model has extents of (0.5, 0.5, 0.0), a 1/2 meter wide square. GameObject flare = GameDatabase.Instance.GetModel("DistantObject/Flare/model"); GameObject flareMesh = Mesh.Instantiate(flare) as GameObject; Destroy(flareMesh.collider); DestroyObject(flare); flareMesh.name = referenceShip.vesselName; flareMesh.SetActive(true); MeshRenderer flareMR = flareMesh.GetComponentInChildren<MeshRenderer>(); // MOARdV: valerian recommended moving vessel and body flares to // layer 10, but that behaves poorly for nearby / co-orbital objects. // Move vessels back to layer 0 until I can find a better place to // put it. // Renderer layers: http://wiki.kerbalspaceprogram.com/wiki/API:Layers flareMR.gameObject.layer = 15; flareMR.material.shader = Shader.Find("KSP/Alpha/Unlit Transparent"); flareMR.material.color = Color.white; flareMR.castShadows = false; flareMR.receiveShadows = false; VesselFlare vesselFlare = new VesselFlare(); vesselFlare.flareMesh = flareMesh; vesselFlare.meshRenderer = flareMR; vesselFlare.referenceShip = referenceShip; vesselFlare.luminosity = 5.0f + Mathf.Pow(referenceShip.GetTotalMass(), 1.25f); vesselFlare.brightness = 0.0f; vesselFlares.Add(referenceShip, vesselFlare); }