protected override void onPartFixedUpdate() { core.onPartFixedUpdate(); base.onPartFixedUpdate(); if (eye == null) { eye = transform.Find("model/base/eye"); if (eye == null) { return; } } if (cam == null) { cam = (FlightCamera)GameObject.FindObjectOfType(typeof(FlightCamera)); } if (core.attitudeActive) { eye.rotation = Quaternion.RotateTowards(eye.rotation, core.attitudeGetReferenceRotation(core.attitudeReference) * core.attitudeTarget * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime); } else { if (brainStress < brainStressMin) { eye.rotation = Quaternion.RotateTowards(eye.rotation, Quaternion.LookRotation((cam.transform.position - eye.position).normalized, cam.transform.up) * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime); } else { eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime); } } brainStress += core.stress * TimeWarp.fixedDeltaTime; brainStress -= brainStress * ((shellStat != ShellStat.CLOSED) ? brainStressReliefOpen : brainStressReliefClosed) * TimeWarp.fixedDeltaTime; if (brainStress < brainStressMin) { brain.particleEmitter.emit = false; lightUp = false; brain.light.intensity = 0; } else { if (shellStat != ShellStat.CLOSED) { brain.particleEmitter.maxEmission = (brainStress - brainStressMin) * 1000.0F; brain.particleEmitter.minEmission = brain.particleEmitter.maxEmission / 2.0F; brain.particleEmitter.emit = true; } if (lightUp) { brain.light.intensity -= TimeWarp.fixedDeltaTime * Mathf.Sqrt(brainStress); if (brain.light.intensity <= 0) { lightUp = false; } } else { brain.light.intensity += TimeWarp.fixedDeltaTime * Mathf.Sqrt(brainStress); if (brain.light.intensity >= 1.0F) { lightUp = true; } } } if ((shellStat == ShellStat.CLOSED) && (brainStress >= brainStressMax)) { shellStat = ShellStat.EJECTING; shellDecay = 0; } if (shellStat == ShellStat.EJECTING) { shellDecay += TimeWarp.fixedDeltaTime; transform.Find("model/base/shell01").position += (transform.Find("model/base/shell01").position - transform.Find("model/base").position).normalized * 50 * TimeWarp.fixedDeltaTime; transform.Find("model/base/shell02").position += (transform.Find("model/base/shell02").position - transform.Find("model/base").position).normalized * 50 * TimeWarp.fixedDeltaTime; transform.Find("model/base/shell03").position += (transform.Find("model/base/shell03").position - transform.Find("model/base").position).normalized * 50 * TimeWarp.fixedDeltaTime; if (shellDecay >= 5) { GameObject.Destroy(transform.Find("model/base/shell01").gameObject); GameObject.Destroy(transform.Find("model/base/shell02").gameObject); GameObject.Destroy(transform.Find("model/base/shell03").gameObject); shellStat = ShellStat.EJECTED; } } }
protected override void onPartFixedUpdate() { core.onPartFixedUpdate(); base.onPartFixedUpdate(); if (eye == null) { eye = transform.Find("model/base/eye"); if (eye == null) { return; } } if (cam == null) { cam = (FlightCamera)GameObject.FindObjectOfType(typeof(FlightCamera)); } if (innereye == null) { eyelid = new Transform[2]; eyelidRot = new Quaternion[2]; eyelid[0] = eye.Find("eyelid1"); eyelid[1] = eye.Find("eyelid2"); if (eyelid[0] != null) { eyelidRot[0] = eyelid[0].localRotation; } if (eyelid[1] != null) { eyelidRot[1] = eyelid[1].localRotation; } innereye = eye.Find("innereye"); if (innereye != null) { innereyeRot = innereye.localRotation; } doors = new LandingLeg[] { null, null, null, null }; if (vessel != null) { foreach (Part p in vessel.parts) { if (p.name == "MultiMech.JebPod.Leg") { doors[0] = (LandingLeg)p; for (int i = 0; i < Math.Min(3, p.symmetryCounterparts.Count); i++) { doors[i + 1] = (LandingLeg)p.symmetryCounterparts[i]; } } } } } brainStress += core.stress * TimeWarp.fixedDeltaTime; brainStress -= brainStress * (((doors[0] == null) || (doors[0].legState == LandingLeg.LegStates.DEPLOYED)) ? brainStressReliefOpen : brainStressReliefClosed) * TimeWarp.fixedDeltaTime; if ((brainStress > brainStressMin) && ((doors[0] == null) || (doors[0].legState == LandingLeg.LegStates.DEPLOYED))) { brain[0].particleEmitter.maxEmission = brain[1].particleEmitter.maxEmission = (brainStress - brainStressMin) * 1000.0F; brain[0].particleEmitter.minEmission = brain[1].particleEmitter.minEmission = brain[0].particleEmitter.maxEmission / 2.0F; brain[0].particleEmitter.emit = brain[1].particleEmitter.emit = true; } else { brain[0].particleEmitter.emit = brain[1].particleEmitter.emit = false; } if (brainStress >= brainStressMax) { foreach (LandingLeg door in doors) { if ((door != null) && (door.legState == LandingLeg.LegStates.RETRACTED)) { door.DeployOnActivate = true; door.force_activate(); } } } if (vessel.Landed || vessel.Splashed) { eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime); if ((eyelid[0] != null) && (eyelid[1] != null)) { eyelid[0].localRotation = eyelidRot[0]; eyelid[1].localRotation = eyelidRot[1]; } } else { if (core.attitudeActive) { eye.rotation = Quaternion.RotateTowards(eye.rotation, core.attitudeGetReferenceRotation(core.attitudeReference) * core.attitudeTarget * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime); } else { if (brainStress < brainStressMin) { eye.rotation = Quaternion.RotateTowards(eye.rotation, Quaternion.LookRotation((cam.transform.position - eye.position).normalized, cam.transform.up) * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime); } else { eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime); } } if ((eyelid[0] == null) || (eyelid[1] == null) || (innereye == null)) { return; } double eyeStressAngle = Math.Max(5, 27 - brainStress / 2); if ((blinkStatus == BlinkStatus.NONE) && (UnityEngine.Random.Range(0, 10.0F / TimeWarp.fixedDeltaTime) < (Time.time - blinkLast))) { blinkStatus = BlinkStatus.CLOSING; blinkProgress = 0; } switch (blinkStatus) { case BlinkStatus.CLOSING: eyeStressAngle *= 1 - blinkProgress; blinkProgress = Mathf.Clamp01(blinkProgress + TimeWarp.fixedDeltaTime * 10); if (blinkProgress >= 1) { blinkStatus = BlinkStatus.OPENING; blinkProgress = 0; } break; case BlinkStatus.OPENING: eyeStressAngle *= blinkProgress; blinkProgress = Mathf.Clamp01(blinkProgress + TimeWarp.fixedDeltaTime * 10); if (blinkProgress >= 1) { blinkStatus = BlinkStatus.NONE; blinkLast = Time.time; } break; } eyelid[0].localRotation = eyelidRot[0] * Quaternion.AngleAxis((float)eyeStressAngle, -Vector3.right); eyelid[1].localRotation = eyelidRot[1] * Quaternion.AngleAxis((float)eyeStressAngle, Vector3.right); innereye.localRotation = innereyeRot * Quaternion.AngleAxis((Mathf.PingPong(Time.time, 0.05f) * 40 - 1) * Mathf.Sqrt(brainStress) / 10, Vector3.forward); } }