public override void OnStart(PartModule.StartState state) { BaseTransform = this.part.transform.FindChild("model").FindChild("Kethane Small Miner").FindChild("Main Box"); Cyl3Transform = BaseTransform.FindChild("1 Cyl"); Cyl2Transform = Cyl3Transform.FindChild("2 Cyl"); Cyl1Transform = Cyl2Transform.FindChild("3 Cyl"); }
public void Update() { var dt = Time.deltaTime; var down = ArmWantToGoDown; if (DrillDeploymentState != DeployState.Idle) { float Rotation = dt * 3.75f; Cyl1Transform.Rotate(new Vector3(0, 1, 0), Rotation); Cyl2Transform.Rotate(new Vector3(0, 1, 0), Rotation); Cyl3Transform.Rotate(new Vector3(0, 1, 0), Rotation); } switch (DrillDeploymentState) { case DeployState.Idle: { if (down) { DrillDeploymentState = DeployState.DeployBase; } } break; case DeployState.DeployBase: { Vector3 Translation = new Vector3(-dt * 0.35f, 0, 0); BaseTransform.localPosition += (down ? Translation : -Translation); if (down) { if (BaseTransform.localPosition.x <= -0.35) { BaseTransform.localPosition = new Vector3(-0.35f, BaseTransform.localPosition.y, BaseTransform.localPosition.z); DrillDeploymentState = DeployState.DeployArm1; } } else { if (BaseTransform.localPosition.x >= -0.0521) { BaseTransform.localPosition = new Vector3(-0.0521f, BaseTransform.localPosition.y, BaseTransform.localPosition.z); DrillDeploymentState = DeployState.Idle; } } } break; case DeployState.DeployArm1: { float Speed = 0.5f; Vector3 Translation = new Vector3(0, -dt * Speed, 0); Cyl1Transform.localPosition += (down ? Translation : -Translation); if (down) { if (Cyl1Transform.localPosition.y <= -0.399f) { Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, -0.399f, Cyl1Transform.localPosition.z); DrillDeploymentState = DeployState.DeployArm2; } } else { if (Cyl1Transform.localPosition.y >= 0.417346f) { Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, 0.417346f, Cyl1Transform.localPosition.z); DrillDeploymentState = DeployState.DeployBase; } } } break; case DeployState.DeployArm2: { float Speed = 0.5f; Vector3 Translation = new Vector3(0, -dt * Speed, 0); Cyl2Transform.localPosition += (down ? Translation : -Translation); if (down) { if (Cyl2Transform.localPosition.y <= -0.899f) { Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.899f, Cyl2Transform.localPosition.z); DrillDeploymentState = DeployState.DeployArm3; } } else { if (Cyl2Transform.localPosition.y >= -0.01016799f) { Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.01016799f, Cyl2Transform.localPosition.z); DrillDeploymentState = DeployState.DeployArm1; } } } break; case DeployState.DeployArm3: { float Speed = 0.5f; Vector3 Translation = new Vector3(0, -dt * Speed, 0); Cyl3Transform.localPosition += (down ? Translation : -Translation); if (down) { if (Cyl3Transform.localPosition.y <= -0.899f) { Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, -0.899f, Cyl3Transform.localPosition.z); DrillDeploymentState = DeployState.Deployed; } } else { if (Cyl3Transform.localPosition.y >= 0.037) { Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, 0.037f, Cyl3Transform.localPosition.z); DrillDeploymentState = DeployState.DeployArm2; } } } break; case DeployState.Deployed: { if (down == false) { DrillDeploymentState = DeployState.DeployArm3; } } break; } }
/// <summary> /// Do all operations related to deploing drill (or hiding it) - animation /// </summary> private void HandleDeployment(float dt, bool down = true) { if (DrillDeploymentState != DeployState.Idle) { float Rotation = dt * 3.75f; Cyl1Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation); Cyl2Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation); Cyl3Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation); } switch (DrillDeploymentState) { case DeployState.Idle: { if (down) { DrillDeploymentState = DeployState.DeployBase; } } break; case DeployState.DeployBase: { Vector3 Translation = new Vector3(-dt * 0.35f, 0, 0); BaseTransform.localPosition += (down ? Translation : -Translation); //BaseTransform.collider.transform.localPosition += Translation; if (down) { if (BaseTransform.localPosition.x <= -0.35) { BaseTransform.localPosition = new Vector3(-0.35f, BaseTransform.localPosition.y, BaseTransform.localPosition.z); //BaseTransform.collider.transform.localPosition.Set(-0.25f, 0, 0); DrillDeploymentState = DeployState.DeployArm1; } } else { if (BaseTransform.localPosition.x >= -0.0521) { BaseTransform.localPosition = new Vector3(-0.0521f, BaseTransform.localPosition.y, BaseTransform.localPosition.z); //BaseTransform.collider.transform.localPosition.Set(-0.25f, 0, 0); DrillDeploymentState = DeployState.Idle; } } } break; case DeployState.DeployArm1: { float Speed = (!IsDrillUndergorund ? 0.5f : 0.2f); Vector3 Translation = new Vector3(0, -dt * Speed, 0); Cyl1Transform.localPosition += (down ? Translation : -Translation); //Cyl1Transform.collider.transform.localPosition += Translation; if (down) { if (Cyl1Transform.localPosition.y <= -0.399f) { Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, -0.399f, Cyl1Transform.localPosition.z); //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0); DrillDeploymentState = DeployState.DeployArm2; } } else { if (Cyl1Transform.localPosition.y >= 0.417346f) { Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, 0.417346f, Cyl1Transform.localPosition.z); //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0); DrillDeploymentState = DeployState.DeployBase; } } } break; case DeployState.DeployArm2: { float Speed = (!IsDrillUndergorund ? 0.5f : 0.2f); Vector3 Translation = new Vector3(0, -dt * Speed, 0); Cyl2Transform.localPosition += (down ? Translation : -Translation); //Cyl2Transform.collider.transform.localPosition += Translation; if (down) { if (Cyl2Transform.localPosition.y <= -0.899f) { Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.899f, Cyl2Transform.localPosition.z); //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0); DrillDeploymentState = DeployState.DeployArm3; } } else { if (Cyl2Transform.localPosition.y >= -0.01016799f) { Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.01016799f, Cyl2Transform.localPosition.z); //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0); DrillDeploymentState = DeployState.DeployArm1; } } } break; case DeployState.DeployArm3: { float Speed = (!IsDrillUndergorund ? 0.5f : 0.2f); Vector3 Translation = new Vector3(0, -dt * Speed, 0); Cyl3Transform.localPosition += (down ? Translation : -Translation); //Cyl2Transform.collider.transform.localPosition += Translation; if (down) { if (Cyl3Transform.localPosition.y <= -0.899f) { Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, -0.899f, Cyl3Transform.localPosition.z); //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0); DrillDeploymentState = DeployState.Deployed; } } else { if (Cyl3Transform.localPosition.y >= 0.037) { Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, 0.037f, Cyl3Transform.localPosition.z); //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0); DrillDeploymentState = DeployState.DeployArm2; } } } break; case DeployState.Deployed: { if (down == false) { DrillDeploymentState = DeployState.DeployArm3; } } break; } DeployLength = Math.Abs(Cyl1Transform.localPosition.y - 0.417346f) + Math.Abs(Cyl2Transform.localPosition.y + 0.01016799f) + Math.Abs(Cyl3Transform.localPosition.y - 0.037f); }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } this.part.force_activate(); #region Configuration if (FlightGlobals.fetch != null) { foreach (CelestialBody Body in FlightGlobals.Bodies) { CollsionLayerMask = 1 << Body.gameObject.layer; } } #endregion #region Sound effects DrillIn = gameObject.AddComponent <AudioSource>(); WWW dIn = new WWW("file://" + KSPUtil.ApplicationRootPath.Replace("\\", "/") + "PluginData/mmi_kethane/sounds/drillIn.wav"); if ((DrillIn != null) && (dIn != null)) { DrillIn.clip = dIn.GetAudioClip(false); DrillIn.volume = 2; DrillIn.Stop(); } DrillOut = gameObject.AddComponent <AudioSource>(); WWW dOut = new WWW("file://" + KSPUtil.ApplicationRootPath.Replace("\\", "/") + "PluginData/mmi_kethane/sounds/drillOut.wav"); if ((DrillOut != null) && (dOut != null)) { DrillOut.clip = dOut.GetAudioClip(false); DrillOut.volume = 0.25f; DrillOut.Stop(); } #endregion #region Child model parts BaseTransform = this.part.transform.FindChild("model").FindChild("Kethane Small Miner").FindChild("Main Box"); Cyl3Transform = BaseTransform.FindChild("1 Cyl"); Cyl2Transform = Cyl3Transform.FindChild("2 Cyl"); Cyl1Transform = Cyl2Transform.FindChild("3 Cyl"); #endregion #region Setup effects for (int i = 0; i < EffectsNumber; i++) { DigEffects[i] = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("Effects/fx_gasJet_white")); DigEffects[i].name = "DigEffect" + i.ToString(); DigEffects[i].transform.parent = BaseTransform; DigEffects[i].gameObject.SetActive(false); } DigEffectRotations[0] = new Vector3(30, 0, 0); DigEffectRotations[1] = new Vector3(0, 0, 30); DigEffectRotations[2] = new Vector3(-30, 0, 0); DigEffectRotations[3] = new Vector3(0, 0, -30); UpdateEffects(); #endregion }