//GimbalDebug foo4 = new GimbalDebug(); internal void CreateBeam(Vessel v) { UnityEngine.Debug.Log("ImpulseDrive TractorBeam: CreateBeam 1 "); Vessel Parent = FlightGlobals.ActiveVessel; //Vector3d parentPosition_current = Parent.findWorldCenterOfMass(); //Vector3d childPosition_current = v.findWorldCenterOfMass(); Vector3d parentPosition_current = Parent.GetWorldPos3D(); Vector3d childPosition_current = v.GetWorldPos3D(); float distance = Vector3.Distance(parentPosition_current, childPosition_current); Vector3 newVector = childPosition_current - parentPosition_current; //UnityEngine.Debug.Log("ImpulseDrive TractorBeam: CreateBeam 2 "); TBeam nb = new TBeam(); UnityEngine.Debug.Log("ImpulseDrive TractorBeam: CreateBeam 3-7 "); BeamDrawer BD1 = new BeamDrawer(); LineRenderer LR1 = new LineRenderer(); BeamDrawer BD2 = new BeamDrawer(); LineRenderer LR2 = new LineRenderer(); BeamDrawer debug_BD1 = new BeamDrawer(); LineRenderer debug_LR1 = new LineRenderer(); BeamDrawer debug_BD2 = new BeamDrawer(); LineRenderer debug_LR2 = new LineRenderer(); nb.beamID = v.id.ToString(); nb.ship = v; nb.ShipPosition = childPosition_current; nb.ShipRotation = nb.ship.transform.rotation; nb.ParentPosition = parentPosition_current; nb.ParentRotation = Parent.transform.rotation; nb.force = 0.5F; nb.distance = distance; nb.Empty1 = new GameObject("Empty1"); nb.Empty2 = new GameObject("Empty2"); /* */ nb.ship.GoOffRails(); //foo1.drawGimbal(nb.Empty1, 10, 1f); foo2.drawGimbal(nb.Empty2, 12, 0.5f); //foo4.drawGimbal(childPosition_current, 20, 0.5f); //nb.Empty2.transform.parent = nb.Empty1.transform; //nb.Empty2.transform.rotation = FlightGlobals.ActiveVessel.transform.rotation; nb.Vector = newVector; nb.y_slider = nb.yAngle; nb.z_slider = nb.zAngle; nb.x_slider = nb.xAngle; nb.BeamDrawer1 = BD1; nb.LineRenderer1 = LR1; nb.BeamDrawer2 = BD2; nb.LineRenderer2 = LR2; nb.debug1_BeamDrawer = debug_BD1; nb.debug1_LineRenderer = debug_LR1; nb.debug2_BeamDrawer = debug_BD2; nb.debug2_LineRenderer = debug_LR2; nb.hold_distance = true; nb.hold_Vector = true; UnityEngine.Debug.Log("ImpulseDrive WeaponSystems: CreateTarget TractorSound "); nb.TractorSound = new FXGroup("TractorSound"); GameObject audioObj = new GameObject(); nb.audioObj = audioObj; nb.audioObj.transform.position = FlightGlobals.ActiveVessel.transform.position; nb.audioObj.transform.parent = FlightGlobals.ActiveVessel.transform; // add to parent nb.TractorSound.audio = audioObj.AddComponent <AudioSource>(); nb.TractorSound.audio.dopplerLevel = 0f; nb.TractorSound.audio.Stop(); nb.TractorSound.audio.clip = GameDatabase.Instance.GetAudioClip(TractorSoundFile); nb.TractorSound.audio.loop = true; // Seek to a random position in the sound file so we don't have // harmonic effects when burning at multiple RCS nozzles. nb.TractorSound.audio.time = UnityEngine.Random.Range(0, nb.TractorSound.audio.clip.length); nb.TractorSound.audio.Play(); nb.TractorSound.audio.enabled = false; try { if (nb.TractorSound != null && nb.TractorSound.audio != null) { nb.soundVolume = GameSettings.SHIP_VOLUME * TractorSoundVolume; nb.TractorSound.audio.enabled = true; nb.TractorSound.audio.volume = nb.soundVolume; } } catch (Exception ex) { Debug.LogError("TractorSound Error OnUpdate: " + ex.Message); } this.BeamList.Add(nb); this.BeamIDList.Add(nb.beamID); nb = null; BD1 = null; LR1 = null; BD2 = null; LR2 = null; debug_BD1 = null; debug_LR1 = null; debug_BD2 = null; debug_LR2 = null; childPosition_current = Vector3.zero; }
private void RemoveBeam(TBeam b) { b.TractorSound.audio.Stop(); b.TractorSound.audio.enabled = false; //foo1.removeGimbal(); foo2.removeGimbal(); //foo4.removeGimbal(); UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 1 : " + b.ship.vesselName); BeamDrawer BD1 = b.BeamDrawer1; LineRenderer LR1 = b.LineRenderer1; BeamDrawer BD2 = b.BeamDrawer2; LineRenderer LR2 = b.LineRenderer2; BeamDrawer debug_BD1 = b.debug1_BeamDrawer; LineRenderer debug_LR1 = b.debug1_LineRenderer; BeamDrawer debug_BD2 = b.debug2_BeamDrawer; LineRenderer debug_LR2 = b.debug2_LineRenderer; UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 2 : " + b.ship.vesselName); UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 3 : " + b.ship.vesselName); //b.debug1_LineRenderer.enabled = false; UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 4 : " + b.ship.vesselName); LR1 = BD1.render(Vector3.zero, Color.blue, 1); LR1.SetWidth(0, 0); LR1.SetPosition(0, Vector3.zero); LR1.SetPosition(1, Vector3.zero); //BD1.Destroy(); UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 5 : " + b.ship.vesselName); Color fc = new Color(0.469F, 0.484F, 0.371F, 0.8F); LR2 = BD2.render(Vector3.zero, fc, 1); LR2.SetWidth(0, 0); LR2.SetPosition(0, Vector3.zero); LR2.SetPosition(1, Vector3.zero); //BD2.Destroy(); UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 6 : " + b.ship.vesselName); /* * debug_LR1 = debug_BD1.render(Vector3.zero, Color.green); * debug_LR1.SetWidth(0, 0); * debug_LR1.SetPosition(0, Vector3.zero); * debug_LR1.SetPosition(1, Vector3.zero); * //debug_BD1.Destroy(); * UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 7 : " + b.ship.vesselName); * * debug_LR2 = debug_BD2.render(Vector3.zero, Color.yellow); * debug_LR2.SetWidth(0, 0); * debug_LR2.SetPosition(0, Vector3.zero); * debug_LR2.SetPosition(1, Vector3.zero); * //debug_BD2.Destroy(); * UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 8 : " + b.ship.vesselName); */ this.BeamIDList.Remove(b.beamID); this.BeamList.Remove(b); //BD = null; //LR = null; //b = null; UnityEngine.Debug.Log("ImpulseDrive TractorBeam: RemoveBeam 9 : " + b.ship.vesselName); }