Ending: the Director's call, flyovers into orbit, Earth turning green, credits
When the planet is mown the ending plays by itself: G.R.A.S.S.A. calls, the camera skims the stubble into the base, circles it and rises without a cut into orbit over the bald planet (title, the crew's results). Then a jump across space to a scorched, dried-out Earth: a rocket from Herbaria-7 passes the lens and lands in Africa, and the green spreads from there over the whole globe (seed pods, a glowing front, clouds and blue air coming back). The credits roll over the green Earth (PlayWay credited as publisher), then THE END and a card to keep mowing, leave a review or go to the menu. Space, Enter or Esc skips to the green Earth and the card. - EndingCinematic, EndingEarth (globe, air shell, rocket, seeds), SpaceSky (split out of the intro), EarthGlobe/EarthAir shaders and Earth maps in Resources/Ending - the far meadow shows as stubble once the planet is mown - "all of it" mown now means no sector with grass left (MowMap.Left); mown area summed in double - the crew's total pay and play time are counted and saved for the results - the "ending" cheat; -ending previews it in a test world; the -ending bot shoots every stage - loc for the new lines in all 11 languages Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -65,6 +65,8 @@ namespace GrassCutter
|
||||
/// <summary>Rings with this line. Calls wait their turn.</summary>
|
||||
/// <summary>The trailer: no calls but the ones it asks for.</summary>
|
||||
public static bool Quiet;
|
||||
/// <summary>A call is over: which line, and whether V put the phone away before he finished.</summary>
|
||||
public static event Action<string, bool> Ended;
|
||||
|
||||
public static void Call(string line)
|
||||
{
|
||||
@ -73,6 +75,12 @@ namespace GrassCutter
|
||||
I._queue.Enqueue(line);
|
||||
}
|
||||
|
||||
/// <summary>Forgets every call still waiting to ring (the one on the line goes on).</summary>
|
||||
public static void Drop()
|
||||
{
|
||||
if (I) I._queue.Clear();
|
||||
}
|
||||
|
||||
/// <summary>The opening film plays the call itself: no ring, the phone already up.</summary>
|
||||
public static IEnumerator Speak(string line, bool hangUp)
|
||||
{
|
||||
@ -178,6 +186,7 @@ namespace GrassCutter
|
||||
}
|
||||
_view?.Show(false);
|
||||
_on = false;
|
||||
Ended?.Invoke(line, hungUp);
|
||||
}
|
||||
|
||||
/// <summary>The jaw follows how loud he is, quick to open and a little slower to shut.</summary>
|
||||
@ -358,7 +367,8 @@ namespace GrassCutter
|
||||
return;
|
||||
}
|
||||
foreach (var (at, line) in Milestones)
|
||||
if (_mown < at && mown >= at) Call(line);
|
||||
// the last one is the ending's: it plays the call inside its own film
|
||||
if (_mown < at && mown >= at && line != "dir_m100") Call(line);
|
||||
if (machine && !_machine) Call("dir_machine");
|
||||
if (combine && !_combine) Call("dir_combine");
|
||||
if (drones && !_drones) Call("dir_drones");
|
||||
|
||||
825
Assets/Scripts/UI/EndingCinematic.cs
Normal file
825
Assets/Scripts/UI/EndingCinematic.cs
Normal file
@ -0,0 +1,825 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace GrassCutter
|
||||
{
|
||||
/// <summary>
|
||||
/// The end of the game: the last blade on Herbaria-7 is down. A beat, the phone rings, and the Director, voice breaking,
|
||||
/// tells the crew they did it. The phone goes down and the cuts climb away from the bare ground, slower than the opening
|
||||
/// film's, until the planet hangs in space, mown bald. Over it: the title, a line, what the crew did. Then a jump across space
|
||||
/// to where the grass went: Earth, scorched and dried out. A rocket from Herbaria-7 comes past the lens and down onto it, the
|
||||
/// green spreads from where it lands over the whole ball, and the credits roll up past it, THE END… and a card to go on
|
||||
/// mowing, leave a review or go back to the menu. Space, Enter or
|
||||
/// Esc jumps to that card. Every player in the session sees it at once on their own screen; it plays once per world, when
|
||||
/// the planet goes past <see cref="Done"/> while you are in it (the cheat "ending" plays it again).
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(10000)]
|
||||
public class EndingCinematic : MonoBehaviour
|
||||
{
|
||||
const string SeenKey = "gc_ending_seen";
|
||||
/// <summary>The planet counts as mown from here, the same line as the Director's last milestone.</summary>
|
||||
public const double Done = 0.99999d;
|
||||
public const string ReviewUrl = "https://store.steampowered.com/recommended/recommendgame/5551720";
|
||||
|
||||
/// <summary>This computer has watched the ending at least once.</summary>
|
||||
public static bool Seen => PlayerPrefs.GetInt(SeenKey, 0) == 1;
|
||||
public static bool Running { get; private set; }
|
||||
/// <summary>The cheat and the dev bot: play it now, whatever the planet says.</summary>
|
||||
public static bool Force;
|
||||
/// <summary>Where the film is, for the dev bot's pictures.</summary>
|
||||
public static string Stage => Running ? I._phase.ToString() : "";
|
||||
static EndingCinematic I;
|
||||
|
||||
// who made it: roles and names, in the order they roll (roles go through Loc, names never do)
|
||||
static readonly (string role, string[] names)[] Credits =
|
||||
{
|
||||
(Loc.N("A game by"), new[] { "Exbyte Studios" }),
|
||||
(Loc.N("Publisher"), new[] { "PlayWay" }),
|
||||
(Loc.N("Art"), new[] { "POLYGON art by Synty Studios" }),
|
||||
(Loc.N("Fonts"), new[] { "Lilita One by Juan Montoreano", "Nunito by the Nunito Project Authors", "Noto Sans CJK by Google and Adobe" }),
|
||||
(Loc.N("Made with"), new[] { "Unity", "Netcode for GameObjects", "Steamworks.NET" }),
|
||||
(Loc.N("Mission control"), new[] { "G.R.A.S.S.A." }),
|
||||
};
|
||||
|
||||
enum Phase { None, Call, Climb, Space, Results, Earth, Credits, End }
|
||||
enum Shot { None, Path, Rise, Orbit, Earth }
|
||||
|
||||
Phase _phase;
|
||||
Shot _shot;
|
||||
Coroutine _run;
|
||||
float _near = 0.05f, _far = 14000f;
|
||||
// the orbit: round the ball's centre about an axis, the ball easing off to one side of the frame
|
||||
Vector3 _orbitFrom, _orbitAxis;
|
||||
float _orbitAngle, _orbitSpeed, _orbitDist, _shift, _shiftTo;
|
||||
|
||||
// what the watcher saw last
|
||||
bool _seeded, _due;
|
||||
float _seedAt = -1f;
|
||||
double _mown;
|
||||
|
||||
VisualElement _layer, _black, _top, _bottom, _titleBox, _stats, _creditsBox, _flash;
|
||||
// Earth, and the lens round it: how far round from the sun (degrees) and how far out
|
||||
EndingEarth _earth;
|
||||
float _eTheta, _eDist, _eDistTo, _warp;
|
||||
Label _ring, _title, _sub, _line, _skip, _theEnd, _unless;
|
||||
VisualElement _cardLayer;
|
||||
|
||||
/// <summary>
|
||||
/// "-ending" on the command line (without a test bot): straight into a test world of its own, every sector mown, and
|
||||
/// the ending as a player gets it. Saves and awards go to the dev folders, never the player's.
|
||||
/// </summary>
|
||||
public static bool Preview => CommandLine.Has("-ending") && !CommandLine.Has("-autodemo");
|
||||
|
||||
void Awake() => I = this;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (Preview) StartCoroutine(MowForPreview());
|
||||
}
|
||||
|
||||
IEnumerator MowForPreview()
|
||||
{
|
||||
// from the menu, as the test bots start: a fresh test world of its own (never the player's slots)
|
||||
yield return new WaitForSeconds(2f);
|
||||
TeamState.DeleteSave();
|
||||
NetSession.Instance.HostLocal();
|
||||
while (!TeamState.Instance || !TeamState.Instance.IsSpawned || !PlayerAgent.Local || !PlayerAgent.Local.IsSpawned) yield return null;
|
||||
yield return new WaitForSeconds(4f);
|
||||
var ts = TeamState.Instance;
|
||||
if (!ts.IsServer) yield break;
|
||||
// the milestones on the way would ring first and keep the ending waiting
|
||||
DirectorCall.Quiet = true;
|
||||
ts.ServerDeposit(48000f, CargoKind.Grass, PlayerAgent.Local.transform.position);
|
||||
for (int id = 0; id < HexGrid.Cells; id++)
|
||||
{
|
||||
MowMap.Close(id);
|
||||
if (id % 4000 == 0) yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The dev bot's Space: straight to THE END and the card.</summary>
|
||||
public static void SkipNow()
|
||||
{
|
||||
if (I && Running && I._phase != Phase.End) I.SkipToEnd();
|
||||
}
|
||||
|
||||
static readonly int BaldId = Shader.PropertyToID("_GcBald");
|
||||
float _bald = -1f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
Watch();
|
||||
// the far meadow turns to stubble once the planet is mown, and in the film whatever the planet says
|
||||
var tsb = TeamState.Instance;
|
||||
float bald = Running || (tsb && tsb.IsSpawned && tsb.Mown01 >= Done) ? 1f : 0f;
|
||||
if (bald != _bald) { _bald = bald; Shader.SetGlobalFloat(BaldId, bald); }
|
||||
// calls still waiting (a lesser milestone passed on the way) would be stale after it: they go
|
||||
if (_due) DirectorCall.Drop();
|
||||
if (_due && !Running && Ready()) { _due = false; _run = StartCoroutine(Run()); }
|
||||
if (!Running) return;
|
||||
var k = Keyboard.current;
|
||||
bool skip = k != null && (k.spaceKey.wasPressedThisFrame || k.enterKey.wasPressedThisFrame || k.escapeKey.wasPressedThisFrame);
|
||||
if (skip && _phase != Phase.End) SkipToEnd();
|
||||
// the card is shut (its button, or Esc through the modal stack): back to the game
|
||||
if (_phase == Phase.End && _cardLayer != null && _cardLayer.pickingMode == PickingMode.Ignore) Finish();
|
||||
}
|
||||
|
||||
/// <summary>The planet going past the line while you are in the world; a save that loads already mown doesn't count.</summary>
|
||||
void Watch()
|
||||
{
|
||||
var ts = TeamState.Instance;
|
||||
var me = PlayerAgent.Local;
|
||||
if (!ts || !ts.IsSpawned || !me || !me.IsSpawned) { _seeded = false; _seedAt = -1f; _due = false; if (Running) Finish(); return; }
|
||||
if (Force) { Force = false; _due = true; }
|
||||
if (Demo.On) return;
|
||||
if (_seedAt < 0f) _seedAt = Time.time + 6f;
|
||||
double mown = ts.Mown01;
|
||||
if (!_seeded)
|
||||
{
|
||||
if (Time.time < _seedAt) return;
|
||||
_seeded = true;
|
||||
_mown = mown;
|
||||
return;
|
||||
}
|
||||
if (_mown < Done && mown >= Done) _due = true;
|
||||
_mown = mown;
|
||||
}
|
||||
|
||||
/// <summary>Not over the opening film, a call or a menu.</summary>
|
||||
static bool Ready() => !IntroCinematic.Running && !Ctl.Cinematic && !DirectorCall.Busy && !Ctl.UIOpen && Phone.I && UIRoot.I;
|
||||
|
||||
// ───────── the film ─────────
|
||||
|
||||
IEnumerator Run()
|
||||
{
|
||||
Running = true;
|
||||
_phase = Phase.Call;
|
||||
Ctl.Cinematic = true;
|
||||
UIRoot.I.HideHud(true);
|
||||
Build();
|
||||
|
||||
// 1. a breath: the last blade is down, eyes out to the horizon. Then the phone.
|
||||
var me0 = PlayerAgent.Local;
|
||||
if (me0)
|
||||
{
|
||||
var up0 = Planet.Up(me0.transform.position);
|
||||
var f0 = Vector3.ProjectOnPlane(me0.transform.forward, up0).normalized;
|
||||
if (f0.sqrMagnitude > 0.01f) me0.LookAt(Planet.Surface(me0.transform.position + f0 * 60f) + up0 * 1.5f);
|
||||
}
|
||||
Sfx.Play("milestone", 0.8f, 1f, 0f);
|
||||
yield return new WaitForSeconds(1.8f);
|
||||
_ring.style.display = DisplayStyle.Flex;
|
||||
UIK.PopIn(_ring, 0f, 0.3f);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Sfx.Play("phone_ring", 0.5f, 1f, 0f);
|
||||
UIK.Punch(_ring, 0.12f);
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
}
|
||||
_ring.style.display = DisplayStyle.None;
|
||||
Phone.I?.Show(PhoneMode.Up);
|
||||
yield return new WaitForSeconds(0.7f);
|
||||
yield return DirectorCall.Speak("dir_m100", true);
|
||||
Phone.I?.Show(PhoneMode.Away);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 2. flights: skimming the stubble in to the base, round the base, past a machine at work, then one long rise
|
||||
// from the ground into space that turns into the slow orbit of the ball
|
||||
_phase = Phase.Climb;
|
||||
Sfx.Music("music_menu_loop", 3f);
|
||||
Bars(true);
|
||||
GrassField.FurReach = 3.5f;
|
||||
var home = Planet.OnSurface(Vector3.up);
|
||||
var up = Planet.Up(home);
|
||||
var cam = CameraFx.Cam;
|
||||
var look0 = cam ? Vector3.ProjectOnPlane(cam.transform.forward, up) : Vector3.forward;
|
||||
var d = ClearHeading(home, look0.sqrMagnitude > 0.01f ? look0.normalized : Vector3.ProjectOnPlane(Vector3.forward, up).normalized);
|
||||
var side = Vector3.Cross(up, d);
|
||||
|
||||
// skim: a metre and a half over the stubble, fast, straight in at the base and up over its rail
|
||||
{
|
||||
float[] at = { 135f, 100f, 66f, 36f, 15f };
|
||||
float[] h = { 1.5f, 1.3f, 1.5f, 3.2f, 8.5f };
|
||||
var eyes = new Vector3[at.Length];
|
||||
var looks = new Vector3[at.Length];
|
||||
for (int i = 0; i < at.Length; i++)
|
||||
{
|
||||
eyes[i] = Ground(home + d * at[i] + side * Mathf.Sin(i * 0.9f) * 3f, h[i]);
|
||||
looks[i] = i >= at.Length - 2 ? home + up * (i == at.Length - 1 ? 1f : 4f) : Ground(home + d * (at[i] - 45f), 1.6f);
|
||||
}
|
||||
Sfx.Play("cut_whoosh_1", 0.32f, 0.85f, 0f);
|
||||
yield return Fly(eyes, looks, 6.2f);
|
||||
}
|
||||
|
||||
// past a machine or a robot near the base, if the crew has one
|
||||
if (Worker(home, out var wPos, out var wFwd))
|
||||
{
|
||||
var wUp = Planet.Up(wPos);
|
||||
var wSide = Vector3.Cross(wUp, wFwd);
|
||||
var eyes = new[] { Ground(wPos - wFwd * 14f + wSide * 7f, 2.2f), Ground(wPos - wFwd * 2f + wSide * 6f, 1.8f), Ground(wPos + wFwd * 11f + wSide * 5f, 2.4f) };
|
||||
var looks = new[] { wPos + wUp * 1f, wPos + wUp * 1f, wPos + wUp * 1.2f };
|
||||
Sfx.Play("cut_whoosh_2", 0.3f, 0.95f, 0f);
|
||||
yield return Fly(eyes, looks, 5f);
|
||||
}
|
||||
|
||||
// round the base, close, over the roofs, half way round it
|
||||
Vector3 arcEnd;
|
||||
{
|
||||
var c = home + up * 2.5f;
|
||||
int n = 7;
|
||||
var eyes = new Vector3[n];
|
||||
var looks = new Vector3[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
var r = Quaternion.AngleAxis(-20f + i * 30f, up) * d;
|
||||
eyes[i] = Ground(home + r * (26f - i * 0.6f), 9.5f + i * 0.9f);
|
||||
looks[i] = c;
|
||||
}
|
||||
arcEnd = eyes[n - 1];
|
||||
yield return Fly(eyes, looks, 8f);
|
||||
}
|
||||
|
||||
// the rise: on from where the arc left off, straight up over the base, then out, without a cut, into the orbit
|
||||
_phase = Phase.Space;
|
||||
OrbitSetup(Planet.Up(arcEnd), side);
|
||||
Sfx.Play("space_rumble", 0.8f, 1f, 0f);
|
||||
Sfx.Play("cut_whoosh_2", 0.35f, 0.7f, 0f);
|
||||
yield return Rise(arcEnd, home + up * 2.5f, 12f);
|
||||
_shot = Shot.Orbit;
|
||||
yield return new WaitForSeconds(1.2f);
|
||||
_title.text = Loc.T("HERBARIA-7");
|
||||
_sub.text = Loc.T("100% MOWN");
|
||||
_sub.style.display = DisplayStyle.Flex;
|
||||
Show(_titleBox, 1.4f);
|
||||
UIK.PopIn(_title, 0f, 0.6f);
|
||||
yield return new WaitForSeconds(4.6f);
|
||||
Hide(_titleBox, 1.2f);
|
||||
yield return new WaitForSeconds(1.4f);
|
||||
_line.text = Loc.T("Every blade. Cut, packed and shipped.");
|
||||
Show(_line, 0.9f);
|
||||
yield return new WaitForSeconds(3.4f);
|
||||
Hide(_line, 0.9f);
|
||||
yield return new WaitForSeconds(1.1f);
|
||||
|
||||
// 4. what the crew did, the ball easing off to the right
|
||||
_phase = Phase.Results;
|
||||
_shiftTo = 1f;
|
||||
yield return new WaitForSeconds(0.8f);
|
||||
FillStats(true);
|
||||
yield return new WaitForSeconds(9.5f);
|
||||
Hide(_stats, 1.2f);
|
||||
_shiftTo = 0f;
|
||||
yield return new WaitForSeconds(1.4f);
|
||||
|
||||
// 5. a jump across space to where the grass went: Earth, scorched and dry
|
||||
_phase = Phase.Earth;
|
||||
yield return Warp();
|
||||
yield return new WaitForSeconds(1.4f);
|
||||
_title.text = Loc.T("EARTH");
|
||||
_sub.style.display = DisplayStyle.None;
|
||||
Show(_titleBox, 1.4f);
|
||||
UIK.PopIn(_title, 0f, 0.6f);
|
||||
yield return new WaitForSeconds(3.6f);
|
||||
Hide(_titleBox, 1.2f);
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
|
||||
// 6. the rocket from Herbaria-7 past the lens and down onto it, and the green spreading from where it lands
|
||||
yield return _earth.Rocket(EarthPose, LandingPlace, 7f);
|
||||
float greenT = 0f;
|
||||
bool said = false;
|
||||
while (!_earth.Healed && greenT < 25f)
|
||||
{
|
||||
greenT += Time.deltaTime;
|
||||
if (!said && greenT > 9f)
|
||||
{
|
||||
said = true;
|
||||
_line.text = Loc.T("Earth has grass again.");
|
||||
Show(_line, 0.9f);
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
yield return new WaitForSeconds(2.5f);
|
||||
if (said) Hide(_line, 0.9f);
|
||||
yield return new WaitForSeconds(1.2f);
|
||||
|
||||
// 7. the credits roll up past it, the ball easing off to the right
|
||||
_phase = Phase.Credits;
|
||||
_shiftTo = 1f;
|
||||
yield return new WaitForSeconds(0.8f);
|
||||
yield return RollCredits(32f);
|
||||
|
||||
// 8. THE END… and the card
|
||||
yield return End();
|
||||
}
|
||||
|
||||
/// <summary>The screen goes white while the lens falls away from the ball; it comes back on Earth.</summary>
|
||||
IEnumerator Warp()
|
||||
{
|
||||
Sfx.Play("meteor_whoosh", 0.7f, 0.7f, 0f);
|
||||
Sfx.Play("cut_whoosh_2", 0.5f, 0.6f, 0f);
|
||||
_flash.style.display = DisplayStyle.Flex;
|
||||
float t = 0f;
|
||||
while (t < 0.7f)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float k = Mathf.Clamp01(t / 0.7f);
|
||||
_warp = k * k;
|
||||
_flash.style.opacity = k * k;
|
||||
yield return null;
|
||||
}
|
||||
_flash.style.opacity = 1f;
|
||||
EarthSetup();
|
||||
_warp = 0f;
|
||||
yield return null;
|
||||
Sfx.Play("space_rumble", 0.6f, 0.8f, 0f);
|
||||
t = 0f;
|
||||
while (t < 1.3f)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
_flash.style.opacity = 1f - Mathf.SmoothStep(0f, 1f, t / 1.3f);
|
||||
yield return null;
|
||||
}
|
||||
_flash.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
/// <summary>Earth made (once) and the lens out in front of it, stars round the new spot.</summary>
|
||||
void EarthSetup()
|
||||
{
|
||||
if (_earth == null)
|
||||
{
|
||||
var sun = Sun.Dir.sqrMagnitude > 0.01f ? Sun.Dir.normalized : Vector3.up;
|
||||
_earth = new EndingEarth(Planet.Center, sun);
|
||||
_eTheta = 58f;
|
||||
_eDist = EndingEarth.R * 3.0f;
|
||||
_eDistTo = EndingEarth.R * 2.3f;
|
||||
// Africa under the rocket when it comes down (about 15 s on), Europe and the Middle East up round it
|
||||
_earth.Face(LandingPlace, EarthLanding(), 15f);
|
||||
}
|
||||
_shift = _shiftTo = 0f;
|
||||
_shot = Shot.Earth;
|
||||
_near = 1f;
|
||||
_far = 60000f;
|
||||
SpaceSky.Set(false, Vector3.zero);
|
||||
SpaceSky.Set(true, EarthEye());
|
||||
}
|
||||
|
||||
static readonly Vector3 LandingPlace = EndingEarth.Geo(12f, 18f);
|
||||
|
||||
Vector3 EarthView()
|
||||
{
|
||||
float th = _eTheta * Mathf.Deg2Rad;
|
||||
return (_earth.Sun * Mathf.Cos(th) + _earth.Side * Mathf.Sin(th)).normalized;
|
||||
}
|
||||
|
||||
Vector3 EarthEye() => _earth.Center + EarthView() * EarthDist();
|
||||
|
||||
// further out while the ball sits off to one side, so it stays round at the edge of the frame
|
||||
float EarthDist() => _eDist + EndingEarth.R * 0.9f * _shift;
|
||||
|
||||
/// <summary>Where the lens is round Earth this frame, and which way it looks.</summary>
|
||||
Pose EarthPose()
|
||||
{
|
||||
var v = EarthView();
|
||||
var e = _earth.Center + v * EarthDist();
|
||||
var right = Vector3.Cross(_earth.Up, -v).normalized;
|
||||
var look = _earth.Center - right * EndingEarth.R * 1.15f * _shift;
|
||||
return new Pose(e, Quaternion.LookRotation(look - e, _earth.Up));
|
||||
}
|
||||
|
||||
/// <summary>Where the rocket comes down: on the face we see, up a little and towards the sun.</summary>
|
||||
Vector3 EarthLanding() => (EarthView() * 0.9f + _earth.Up * 0.32f + _earth.Sun * 0.22f).normalized;
|
||||
|
||||
/// <summary>A point this high over the ground under p.</summary>
|
||||
static Vector3 Ground(Vector3 p, float h)
|
||||
{
|
||||
var g = Planet.Surface(p);
|
||||
return g + Planet.Up(g) * h;
|
||||
}
|
||||
|
||||
/// <summary>The way out from the base with a clear run along the ground, starting from the one given.</summary>
|
||||
static Vector3 ClearHeading(Vector3 home, Vector3 prefer)
|
||||
{
|
||||
var up = Planet.Up(home);
|
||||
for (int k = 0; k < 8; k++)
|
||||
{
|
||||
var d = Quaternion.AngleAxis(k * 45f, up) * prefer;
|
||||
if (!Physics.Linecast(Ground(home + d * 180f, 1.5f), Ground(home + d * 60f, 2.5f)) && !Physics.Linecast(Ground(home + d * 60f, 4.5f), home + up * 6f))
|
||||
return d;
|
||||
}
|
||||
return prefer;
|
||||
}
|
||||
|
||||
/// <summary>The crew's machine or robot nearest the base (within reach of a flight), and which way it faces.</summary>
|
||||
static bool Worker(Vector3 home, out Vector3 pos, out Vector3 fwd)
|
||||
{
|
||||
pos = fwd = Vector3.zero;
|
||||
float best = 600f * 600f;
|
||||
Transform pick = null;
|
||||
foreach (var v in Vehicle.All) if (v && (v.transform.position - home).sqrMagnitude < best) { best = (v.transform.position - home).sqrMagnitude; pick = v.transform; }
|
||||
if (!pick) foreach (var m in Mowbot.All) if (m && (m.transform.position - home).sqrMagnitude < best) { best = (m.transform.position - home).sqrMagnitude; pick = m.transform; }
|
||||
if (!pick) return false;
|
||||
pos = pick.position;
|
||||
var up = Planet.Up(pos);
|
||||
fwd = Vector3.ProjectOnPlane(pick.forward, up).normalized;
|
||||
if (fwd.sqrMagnitude < 0.01f) fwd = Vector3.ProjectOnPlane(Vector3.forward, up).normalized;
|
||||
return true;
|
||||
}
|
||||
|
||||
// a flight along a smooth curve through the eyes, looking along a smooth curve through the looks
|
||||
Vector3[] _pathEyes, _pathLooks;
|
||||
float _pathT, _pathFor;
|
||||
// the rise: from an eye over the ground out to the orbit's first spot
|
||||
Vector3 _riseFrom, _riseLook, _riseTop;
|
||||
float _riseAlt0;
|
||||
|
||||
IEnumerator Fly(Vector3[] eyes, Vector3[] looks, float seconds)
|
||||
{
|
||||
_pathEyes = eyes; _pathLooks = looks;
|
||||
_pathT = 0f; _pathFor = seconds;
|
||||
_shot = Shot.Path;
|
||||
_near = 0.05f; _far = 14000f;
|
||||
while (_pathT < _pathFor) yield return null;
|
||||
}
|
||||
|
||||
IEnumerator Rise(Vector3 from, Vector3 look, float seconds)
|
||||
{
|
||||
_riseFrom = from; _riseLook = look;
|
||||
// the top of the frame while the lens looks down: the way from the start to the base, fixed in the world, so it
|
||||
// never flips when the eye passes over the base
|
||||
_riseTop = Vector3.ProjectOnPlane(look - from, Planet.Up(from)).normalized;
|
||||
_riseAlt0 = Mathf.Max(1f, Planet.Altitude(from));
|
||||
_pathT = 0f; _pathFor = seconds;
|
||||
_shot = Shot.Rise;
|
||||
while (_pathT < _pathFor) yield return null;
|
||||
}
|
||||
|
||||
static Vector3 Spline(Vector3[] p, float u)
|
||||
{
|
||||
int n = p.Length;
|
||||
if (n == 1) return p[0];
|
||||
u = Mathf.Clamp(u, 0f, n - 1.0001f);
|
||||
int i = (int)u;
|
||||
float t = u - i;
|
||||
var p0 = p[Mathf.Max(0, i - 1)];
|
||||
var p1 = p[i];
|
||||
var p2 = p[Mathf.Min(n - 1, i + 1)];
|
||||
var p3 = p[Mathf.Min(n - 1, i + 2)];
|
||||
return 0.5f * (2f * p1 + (p2 - p0) * t + (2f * p0 - 5f * p1 + 4f * p2 - p3) * t * t + (3f * p1 - p0 - 3f * p2 + p3) * t * t * t);
|
||||
}
|
||||
|
||||
IEnumerator RollCredits(float seconds)
|
||||
{
|
||||
FillCredits();
|
||||
_creditsBox.style.opacity = 1f;
|
||||
_creditsBox.style.display = DisplayStyle.Flex;
|
||||
// one frame for it to lay out, then it climbs from under the screen to over the top
|
||||
_creditsBox.style.translate = new Translate(0f, 4000f);
|
||||
yield return null;
|
||||
yield return null;
|
||||
float screen = _layer.resolvedStyle.height > 0f ? _layer.resolvedStyle.height : 1080f;
|
||||
float tall = Mathf.Max(400f, _creditsBox.resolvedStyle.height);
|
||||
float t = 0f;
|
||||
while (t < seconds)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float y = Mathf.Lerp(screen, -tall, t / seconds);
|
||||
_creditsBox.style.translate = new Translate(0f, y);
|
||||
yield return null;
|
||||
}
|
||||
_creditsBox.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
IEnumerator End()
|
||||
{
|
||||
_phase = Phase.End;
|
||||
PlayerPrefs.SetInt(SeenKey, 1);
|
||||
PlayerPrefs.Save();
|
||||
_shiftTo = 0f;
|
||||
_theEnd.style.display = DisplayStyle.Flex;
|
||||
_theEnd.style.opacity = 0f;
|
||||
Show(_theEnd, 1.6f);
|
||||
yield return new WaitForSeconds(2.6f);
|
||||
_unless.style.display = DisplayStyle.Flex;
|
||||
_unless.style.opacity = 0f;
|
||||
Show(_unless, 0.8f);
|
||||
yield return new WaitForSeconds(2.2f);
|
||||
Hide(_theEnd, 0.8f);
|
||||
Hide(_unless, 0.8f);
|
||||
Bars(false);
|
||||
_skip.style.display = DisplayStyle.None;
|
||||
yield return new WaitForSeconds(0.6f);
|
||||
OpenCard();
|
||||
_run = null;
|
||||
}
|
||||
|
||||
/// <summary>Space / Enter / Esc: whatever is left, straight to THE END and the card.</summary>
|
||||
void SkipToEnd()
|
||||
{
|
||||
if (_run != null) StopCoroutine(_run);
|
||||
if (_phase == Phase.Call) DirectorCall.Abort();
|
||||
Sfx.Play("cut_return", 0.5f, 1f, 0f);
|
||||
if (Phone.I && Phone.I.Mode != PhoneMode.Away) Phone.I.Show(PhoneMode.Away);
|
||||
_ring.style.display = DisplayStyle.None;
|
||||
foreach (var e in new VisualElement[] { _titleBox, _line, _stats, _creditsBox, _flash }) { Tween.Kill(e); e.style.display = DisplayStyle.None; }
|
||||
Sfx.Music("music_menu_loop", 1.5f);
|
||||
Bars(true);
|
||||
GrassField.FurReach = 3.5f;
|
||||
// the last picture is Earth, green all over
|
||||
_warp = 0f;
|
||||
EarthSetup();
|
||||
_earth.HealNow();
|
||||
_run = StartCoroutine(End());
|
||||
}
|
||||
|
||||
void Finish()
|
||||
{
|
||||
if (_run != null) StopCoroutine(_run);
|
||||
_run = null;
|
||||
if (_phase == Phase.Call) DirectorCall.Abort();
|
||||
Running = false;
|
||||
_phase = Phase.None;
|
||||
_shot = Shot.None;
|
||||
_shift = _shiftTo = 0f;
|
||||
_warp = 0f;
|
||||
_earth?.Destroy();
|
||||
_earth = null;
|
||||
if (_flash != null) _flash.style.display = DisplayStyle.None;
|
||||
SpaceSky.Set(false, Vector3.zero);
|
||||
GrassField.FurReach = 1f;
|
||||
var cam = CameraFx.Cam;
|
||||
if (cam) { cam.nearClipPlane = 0.05f; cam.farClipPlane = 14000f; }
|
||||
if (cam && cam.transform.parent) cam.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
Ctl.Cinematic = false;
|
||||
if (UIRoot.I) UIRoot.I.HideHud(false);
|
||||
Sfx.Duck(1f);
|
||||
if (_cardLayer != null && _cardLayer.pickingMode != PickingMode.Ignore) UIRoot.I?.CloseModal(_cardLayer);
|
||||
_cardLayer = null;
|
||||
if (_layer != null) _layer.style.display = DisplayStyle.None;
|
||||
if (Phone.I && Phone.I.Mode != PhoneMode.Away) Phone.I.Show(PhoneMode.Away);
|
||||
}
|
||||
|
||||
// ───────── the card at the end ─────────
|
||||
|
||||
void OpenCard()
|
||||
{
|
||||
_cardLayer = UIRoot.I.OpenModal(layer =>
|
||||
{
|
||||
var card = UIK.El("card", layer);
|
||||
card.pickingMode = PickingMode.Position;
|
||||
card.style.width = 760;
|
||||
card.style.alignItems = Align.Stretch;
|
||||
UIK.Text(Loc.T("HERBARIA-7 IS MOWN"), "t-h1 t-dark t-center", card);
|
||||
var body = UIK.Text(Loc.T("Earth has grass again. Thank you for mowing with us."), "t-body t-dark t-center", card, false);
|
||||
body.style.whiteSpace = WhiteSpace.Normal;
|
||||
body.style.marginBottom = 10;
|
||||
var note = UIK.Text(Loc.T("The world is still yours: every machine, every belt, every robot."), "t-small t-muted t-center", card, false);
|
||||
note.style.whiteSpace = WhiteSpace.Normal;
|
||||
note.style.marginBottom = 16;
|
||||
UIK.Btn(Loc.T("KEEP MOWING"), () => UIRoot.I.CloseModal(layer), "btn btn-green", card);
|
||||
UIK.Btn(Loc.T("LEAVE A REVIEW"), () => SteamManager.OpenWeb(ReviewUrl), "btn btn-blue", card);
|
||||
UIK.Btn(Loc.T("LEAVE TO MENU"), () => { UIRoot.I.CloseModal(layer); Finish(); NetSession.Instance.Leave(); }, "btn btn-red", card);
|
||||
return card;
|
||||
});
|
||||
}
|
||||
|
||||
// ───────── the screen ─────────
|
||||
|
||||
void Build()
|
||||
{
|
||||
if (_layer == null || _layer.panel == null)
|
||||
{
|
||||
var root = UIRoot.I.Cinema;
|
||||
_layer = UIK.El("layer", root);
|
||||
_layer.pickingMode = PickingMode.Ignore;
|
||||
_flash = new VisualElement { pickingMode = PickingMode.Ignore };
|
||||
_flash.style.position = Position.Absolute;
|
||||
_flash.style.left = _flash.style.right = _flash.style.top = _flash.style.bottom = 0;
|
||||
_flash.style.backgroundColor = new Color(1f, 0.99f, 0.95f);
|
||||
_flash.style.display = DisplayStyle.None;
|
||||
_layer.Add(_flash);
|
||||
_top = Bar(_layer, true);
|
||||
_bottom = Bar(_layer, false);
|
||||
_ring = UIK.Text("", "director-ring t-outline", _layer);
|
||||
_titleBox = UIK.El("ending-titlebox", _layer);
|
||||
_title = UIK.Text("", "ending-title t-outline", _titleBox);
|
||||
_sub = UIK.Text("", "ending-sub t-outline", _titleBox);
|
||||
_line = UIK.Text("", "ending-line t-outline", _layer, false);
|
||||
_stats = UIK.El("ending-stats", _layer);
|
||||
_creditsBox = UIK.El("ending-credits", _layer);
|
||||
_theEnd = UIK.Text("", "ending-theend t-outline", _layer);
|
||||
_unless = UIK.Text("", "ending-unless t-outline", _layer, false);
|
||||
_skip = UIK.Text("", "cinema-skip t-outline", _layer, false);
|
||||
}
|
||||
_layer.style.display = DisplayStyle.Flex;
|
||||
_ring.text = Loc.T("G.R.A.S.S.A. IS CALLING");
|
||||
_theEnd.text = Loc.T("THE END");
|
||||
_unless.text = Loc.T("…unless?");
|
||||
_skip.text = Loc.T("SPACE skip");
|
||||
foreach (var e in new VisualElement[] { _ring, _titleBox, _line, _stats, _creditsBox, _theEnd, _unless }) { Tween.Kill(e); e.style.display = DisplayStyle.None; }
|
||||
_skip.style.display = DisplayStyle.Flex;
|
||||
Bars(false);
|
||||
}
|
||||
|
||||
void FillStats(bool animate)
|
||||
{
|
||||
var ts = TeamState.Instance;
|
||||
_stats.Clear();
|
||||
if (!ts) return;
|
||||
UIK.Text(Loc.T("WHAT YOUR CREW DID"), "ending-stats-head t-outline", _stats);
|
||||
var rows = new List<(string label, double value, System.Func<double, string> show)>
|
||||
{
|
||||
(Loc.T("Grass shipped to Earth"), ts.Shipped.Value, v => GameDefs.Kilos(v)),
|
||||
(Loc.T("Planet mown"), System.Math.Min(100d, ts.Mown01 * 100d), v => Loc.F("{0}%", Loc.Num(v, "0.##"))),
|
||||
(Loc.T("Sectors mown clean"), ts.Closed.Value, v => Loc.Num(v, "N0")),
|
||||
(Loc.T("Money earned"), ts.Earned.Value, v => UIK.Money(v)),
|
||||
(Loc.T("Days on Herbaria-7"), Mathf.Max(1, ts.Days), v => Loc.Num(v, "N0")),
|
||||
(Loc.T("Machines"), Vehicle.All.Count(v => v), v => Loc.Num(v, "N0")),
|
||||
(Loc.T("Robots at work"), Mowbot.All.Count, v => Loc.Num(v, "N0")),
|
||||
(Loc.T("Stations found"), ts.Opened.Count, v => Loc.F("{0} / {1}", Loc.Num(v, "N0"), Loc.Num(Stations.Count - 1))),
|
||||
(Loc.T("Survey stakes sorted out"), ts.FoundCount(false), v => Loc.F("{0} / {1}", Loc.Num(v, "N0"), Loc.Num(Landmarks.Stakes))),
|
||||
};
|
||||
int i = 0;
|
||||
foreach (var (label, value, show) in rows)
|
||||
{
|
||||
var row = UIK.El("ending-row", _stats);
|
||||
UIK.Text(label, "ending-row-label t-outline", row, false);
|
||||
var val = UIK.Text(show(animate ? 0d : value), "ending-row-value t-outline", row);
|
||||
if (animate)
|
||||
{
|
||||
row.style.opacity = 0f;
|
||||
float delay = 0.25f + i * 0.35f;
|
||||
Tween.Run(row, 0.4f, k => row.style.opacity = k, Ease.OutQuad, delay);
|
||||
Tween.Run(val, 1.3f, k => val.text = show(value * k), Ease.OutQuad, delay);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
var crew = PlayerAgent.All.Where(p => p).Select(p => p.DisplayName).ToList();
|
||||
if (crew.Count > 0)
|
||||
{
|
||||
var c = UIK.Text(Loc.F("The crew: {0}", string.Join(", ", crew)), "ending-crew t-outline", _stats, false);
|
||||
if (animate) { c.style.opacity = 0f; Tween.Run(c, 0.6f, k => c.style.opacity = k, Ease.OutQuad, 0.4f + rows.Count * 0.35f); }
|
||||
}
|
||||
_stats.style.opacity = 1f;
|
||||
_stats.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
|
||||
void FillCredits()
|
||||
{
|
||||
_creditsBox.Clear();
|
||||
UIK.Text("GRASS CUTTERS TOGETHER", "ending-credits-title t-outline", _creditsBox);
|
||||
foreach (var (role, names) in Credits)
|
||||
{
|
||||
UIK.Text(Loc.T(role), "ending-credits-role t-outline", _creditsBox, false);
|
||||
foreach (var n in names) UIK.Text(n, "ending-credits-name t-outline", _creditsBox);
|
||||
}
|
||||
UIK.Text(Loc.T("And you"), "ending-credits-role t-outline", _creditsBox, false);
|
||||
UIK.Text(Loc.T("for every blade."), "ending-credits-name t-outline", _creditsBox);
|
||||
var crew = PlayerAgent.All.Where(p => p).Select(p => p.DisplayName).ToList();
|
||||
foreach (var n in crew) UIK.Text(n, "ending-credits-name t-outline", _creditsBox);
|
||||
UIK.Text(Loc.T("We take grass very seriously."), "ending-credits-motto t-outline", _creditsBox, false);
|
||||
}
|
||||
|
||||
static VisualElement Bar(VisualElement root, bool top)
|
||||
{
|
||||
var b = new VisualElement { pickingMode = PickingMode.Ignore };
|
||||
b.AddToClassList("cinema-bars");
|
||||
if (top) b.style.top = 0; else b.style.bottom = 0;
|
||||
b.style.display = DisplayStyle.None;
|
||||
root.Add(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
void Bars(bool on)
|
||||
{
|
||||
if (_top == null) return;
|
||||
_top.style.display = _bottom.style.display = on ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
|
||||
static void Show(VisualElement e, float seconds)
|
||||
{
|
||||
e.style.display = DisplayStyle.Flex;
|
||||
Tween.Kill(e);
|
||||
e.style.opacity = 0f;
|
||||
Tween.Run(e, seconds, k => e.style.opacity = k, Ease.InOutQuad);
|
||||
}
|
||||
|
||||
static void Hide(VisualElement e, float seconds)
|
||||
{
|
||||
float from = e.resolvedStyle.opacity;
|
||||
Tween.Kill(e);
|
||||
Tween.Run(e, seconds, k => e.style.opacity = Mathf.Lerp(from, 0f, k), Ease.InOutQuad, 0f, () => e.style.display = DisplayStyle.None);
|
||||
}
|
||||
|
||||
// ───────── the camera ─────────
|
||||
|
||||
void Orbit(Vector3 from, Vector3 axisHint)
|
||||
{
|
||||
OrbitSetup(from, axisHint);
|
||||
_shot = Shot.Orbit;
|
||||
SpaceSky.Set(true, Planet.Center + _orbitFrom * _orbitDist);
|
||||
}
|
||||
|
||||
void OrbitSetup(Vector3 from, Vector3 axisHint)
|
||||
{
|
||||
// round the sun's own axis, two thirds of the way to the sunny side of where the cuts ended: the light on the ball
|
||||
// stays the same however far it turns, the day side with the terminator along one edge
|
||||
var sun = Sun.Dir.normalized;
|
||||
var across = Vector3.ProjectOnPlane(from, sun);
|
||||
if (across.sqrMagnitude < 0.01f) across = Vector3.ProjectOnPlane(axisHint, sun);
|
||||
across.Normalize();
|
||||
_orbitFrom = (sun * 0.62f + across * 0.78f + Vector3.Cross(sun, across) * 0.1f).normalized;
|
||||
_orbitAxis = sun;
|
||||
_orbitAngle = 0f;
|
||||
_orbitSpeed = 2.2f;
|
||||
_orbitDist = Planet.Radius * 2.6f;
|
||||
_near = 4f;
|
||||
_far = 60000f;
|
||||
}
|
||||
|
||||
/// <summary>The orbit's eye and up at an angle round it.</summary>
|
||||
void OrbitPose(float angle, out Vector3 eye, out Vector3 up)
|
||||
{
|
||||
var dir = Quaternion.AngleAxis(angle, _orbitAxis) * _orbitFrom;
|
||||
eye = Planet.Center + dir * _orbitDist;
|
||||
up = Vector3.ProjectOnPlane(Vector3.Cross(_orbitAxis, dir), dir).normalized;
|
||||
if (up.sqrMagnitude < 0.01f) up = Vector3.ProjectOnPlane(Vector3.up, dir).normalized;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
var cam = CameraFx.Cam;
|
||||
if (!cam || !Running || _shot == Shot.None) return;
|
||||
if (_shot == Shot.Path)
|
||||
{
|
||||
_pathT += Time.deltaTime;
|
||||
float k = Mathf.Clamp01(_pathT / _pathFor);
|
||||
// eased in and out, but never standing still at either end of a flight
|
||||
k = Mathf.Lerp(k, k * k * (3f - 2f * k), 0.6f);
|
||||
float u = k * (_pathEyes.Length - 1);
|
||||
var e = Spline(_pathEyes, u);
|
||||
// never under the ground between the points
|
||||
float alt = Planet.Altitude(e);
|
||||
if (alt < 0.9f) e += Planet.Up(e) * (0.9f - alt);
|
||||
var l = Spline(_pathLooks, u);
|
||||
cam.transform.SetPositionAndRotation(e, Quaternion.LookRotation(l - e, Planet.Up(e)));
|
||||
}
|
||||
else if (_shot == Shot.Rise)
|
||||
{
|
||||
_pathT += Time.deltaTime;
|
||||
float k = Mathf.Clamp01(_pathT / _pathFor);
|
||||
OrbitPose(0f, out var oEye, out var oUp);
|
||||
// the height grows by the same factor every second: the ground falls away the same at 10 m as at 10 km
|
||||
float altTo = _orbitDist - Planet.Radius;
|
||||
float alt = Mathf.Exp(Mathf.Lerp(Mathf.Log(_riseAlt0), Mathf.Log(altTo), Mathf.Pow(k, 1.2f)));
|
||||
// straight up over the base first, then across to where the orbit begins
|
||||
float across = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.4f, 1f, k));
|
||||
var dir = Vector3.Slerp(Planet.Up(_riseFrom), (oEye - Planet.Center).normalized, across);
|
||||
var e = Planet.Center + dir * (Planet.Radius + alt);
|
||||
float lookK = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.45f, 0.95f, k));
|
||||
var l = Vector3.Lerp(_riseLook, Planet.Center, lookK);
|
||||
var upE = Planet.Up(e);
|
||||
var top = Vector3.ProjectOnPlane(_riseTop, upE);
|
||||
// the head tips down over the base as it climbs: the top of the frame leans from the sky to the way ahead
|
||||
var upv = top.sqrMagnitude > 1e-4f ? Vector3.Slerp(upE, top.normalized, Mathf.InverseLerp(15f, 300f, alt) * 0.95f) : upE;
|
||||
upv = Vector3.Slerp(upv, oUp, Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.6f, 1f, k)));
|
||||
var fwd = l - e;
|
||||
if (Vector3.Cross(fwd.normalized, upv).sqrMagnitude < 1e-4f) upv = top.sqrMagnitude > 1e-4f ? top.normalized : oUp;
|
||||
cam.transform.SetPositionAndRotation(e, Quaternion.LookRotation(fwd, upv));
|
||||
_near = Mathf.Clamp(alt * 0.004f, 0.05f, 4f);
|
||||
_far = alt > 500f ? 60000f : 14000f;
|
||||
// the sky goes black while the lens still looks down at the ground, before the edge of the ball is in view
|
||||
if (alt > Planet.Radius * 0.15f && !SpaceSky.On) SpaceSky.Set(true, e);
|
||||
}
|
||||
else if (_shot == Shot.Earth)
|
||||
{
|
||||
if (_earth == null) return;
|
||||
float dt = Time.deltaTime;
|
||||
_earth.Tick(dt);
|
||||
// slowly round towards the sun and in a little: more of the ball lit as it turns green
|
||||
_eTheta = Mathf.MoveTowards(_eTheta, 22f, dt * 0.6f);
|
||||
_eDist = Mathf.Lerp(_eDist, _eDistTo, 1f - Mathf.Exp(-dt * 0.12f));
|
||||
_shift = Mathf.Lerp(_shift, _shiftTo, 1f - Mathf.Exp(-dt * 0.9f));
|
||||
var pose = EarthPose();
|
||||
cam.transform.SetPositionAndRotation(pose.position, pose.rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
_orbitAngle += _orbitSpeed * Time.deltaTime;
|
||||
_shift = Mathf.Lerp(_shift, _shiftTo, 1f - Mathf.Exp(-Time.deltaTime * 0.9f));
|
||||
OrbitPose(_orbitAngle, out var e, out var up0);
|
||||
var dir = (e - Planet.Center).normalized;
|
||||
if (_warp > 0f) e += dir * _orbitDist * 2.5f * _warp;
|
||||
var right = Vector3.Cross(up0, -dir).normalized;
|
||||
// the ball slides to the right of the frame while the words are on the left
|
||||
var look = Planet.Center - right * Planet.Radius * 1.25f * _shift;
|
||||
cam.transform.SetPositionAndRotation(e, Quaternion.LookRotation(look - e, up0));
|
||||
}
|
||||
cam.nearClipPlane = _near;
|
||||
cam.farClipPlane = _far;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/EndingCinematic.cs.meta
Normal file
2
Assets/Scripts/UI/EndingCinematic.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6cb6c4b85fee22449391cd24bfe0fdb
|
||||
419
Assets/Scripts/UI/EndingEarth.cs
Normal file
419
Assets/Scripts/UI/EndingEarth.cs
Normal file
@ -0,0 +1,419 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GrassCutter
|
||||
{
|
||||
/// <summary>
|
||||
/// The ending's last stop: Earth, out in a patch of space of its own, scorched and dried out. A rocket from Herbaria-7
|
||||
/// comes past the lens and down onto it, and from where it lands the green spreads over the whole ball, seed pods thrown
|
||||
/// off it starting patches of their own, the air going from dust to blue and the clouds coming back.
|
||||
/// </summary>
|
||||
public sealed class EndingEarth
|
||||
{
|
||||
public const float R = 2000f;
|
||||
// a seed spread this far (radians, before the shader's wobble) has covered the ball
|
||||
const float Full = 4.8f;
|
||||
const int MaxSeeds = 12;
|
||||
const float Spin = 1.1f;
|
||||
|
||||
public readonly Vector3 Center;
|
||||
/// <summary>Towards the sun; the frame the camera keeps to: Side across the sun, Up square to both.</summary>
|
||||
public readonly Vector3 Sun, Side, Up;
|
||||
/// <summary>The main patch has covered the ball.</summary>
|
||||
public bool Healed => _seeds.Count > 0 && _seeds[0].age >= _seeds[0].grow;
|
||||
public bool Landed => _seeds.Count > 0;
|
||||
/// <summary>0 dead … 1 green all over: the air, the clouds.</summary>
|
||||
public float Life { get; private set; }
|
||||
|
||||
readonly GameObject _root;
|
||||
readonly Transform _ball;
|
||||
readonly Material _mat, _airMat;
|
||||
readonly ParticleSystem _glow, _rings, _sparks;
|
||||
readonly Quaternion _tilt;
|
||||
float _spin;
|
||||
|
||||
class Seed { public Vector3 dir; public float age, grow, full; }
|
||||
class Pod { public Vector3 from, to; public float t, time; }
|
||||
readonly List<Seed> _seeds = new List<Seed>();
|
||||
readonly List<Pod> _pods = new List<Pod>();
|
||||
readonly Vector4[] _seedVec = new Vector4[MaxSeeds], _seedFx = new Vector4[MaxSeeds];
|
||||
|
||||
static readonly int SeedsId = Shader.PropertyToID("_Seeds"), SeedFxId = Shader.PropertyToID("_SeedFx"), SeedCountId = Shader.PropertyToID("_SeedCount"),
|
||||
LifeId = Shader.PropertyToID("_Life"), AirId = Shader.PropertyToID("_AirColor"), SunId = Shader.PropertyToID("_SunDir"),
|
||||
PowerId = Shader.PropertyToID("_Power"), EdgeId = Shader.PropertyToID("_Edge");
|
||||
static readonly Color DeadAir = new Color(0.85f, 0.52f, 0.28f), LiveAir = new Color(0.3f, 0.58f, 1f);
|
||||
static Mesh s_sphere;
|
||||
|
||||
/// <summary>Earth far out from Herbaria-7 (its centre given), on the side of it that the lens keeps behind itself.</summary>
|
||||
public EndingEarth(Vector3 herbaria, Vector3 sun)
|
||||
{
|
||||
Sun = sun.normalized;
|
||||
Up = Vector3.ProjectOnPlane(Mathf.Abs(Sun.y) < 0.9f ? Vector3.up : Vector3.right, Sun).normalized;
|
||||
Side = Vector3.Cross(Up, Sun).normalized;
|
||||
// the lens sits between the sun and Side from the ball: Herbaria-7 out along sun + Side is behind it
|
||||
Center = herbaria - (Sun * 0.5f + Side).normalized * 150000f;
|
||||
var center = Center;
|
||||
|
||||
_root = new GameObject("EndingEarth");
|
||||
var ball = new GameObject("Ball", typeof(MeshFilter), typeof(MeshRenderer));
|
||||
_ball = ball.transform;
|
||||
_ball.SetParent(_root.transform, false);
|
||||
_ball.position = center;
|
||||
_ball.localScale = Vector3.one * R;
|
||||
// the poles a little towards the lens, the way a globe stands
|
||||
_tilt = Quaternion.LookRotation(Side, Up) * Quaternion.Euler(16f, 0f, 0f);
|
||||
_ball.rotation = _tilt;
|
||||
ball.GetComponent<MeshFilter>().sharedMesh = Sphere();
|
||||
_mat = new Material(Resources.Load<Shader>("Ending/EarthGlobe"));
|
||||
_mat.SetTexture("_DryTex", Resources.Load<Texture2D>("Ending/earth_dry"));
|
||||
_mat.SetTexture("_GreenTex", Resources.Load<Texture2D>("Ending/earth_green"));
|
||||
var mr = ball.GetComponent<MeshRenderer>();
|
||||
mr.sharedMaterial = _mat;
|
||||
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
mr.receiveShadows = false;
|
||||
|
||||
var air = new GameObject("Air", typeof(MeshFilter), typeof(MeshRenderer));
|
||||
air.transform.SetParent(_root.transform, false);
|
||||
air.transform.position = center;
|
||||
air.transform.localScale = Vector3.one * R * 1.07f;
|
||||
air.GetComponent<MeshFilter>().sharedMesh = Sphere();
|
||||
_airMat = new Material(Resources.Load<Shader>("Ending/EarthAir"));
|
||||
_airMat.SetFloat(EdgeId, Mathf.Sqrt(1f - 1f / (1.07f * 1.07f)));
|
||||
var amr = air.GetComponent<MeshRenderer>();
|
||||
amr.sharedMaterial = _airMat;
|
||||
amr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
amr.receiveShadows = false;
|
||||
|
||||
var bank = AssetBank.I;
|
||||
_glow = Particles("Glow", bank.Mat("FX_Soft"), AnimationCurve.EaseInOut(0f, 1f, 1f, 0.6f));
|
||||
_rings = Particles("Rings", bank.Mat("FX_Ring") ?? bank.Mat("FX_Soft"), AnimationCurve.EaseInOut(0f, 0.08f, 1f, 1f));
|
||||
_sparks = Particles("Sparks", bank.Mat("FX_Sparkle") ?? bank.Mat("FX_Soft"), AnimationCurve.EaseInOut(0f, 1f, 1f, 0.2f));
|
||||
Apply();
|
||||
}
|
||||
|
||||
ParticleSystem Particles(string name, Material mat, AnimationCurve size)
|
||||
{
|
||||
var go = new GameObject(name);
|
||||
go.transform.SetParent(_root.transform, false);
|
||||
var ps = go.AddComponent<ParticleSystem>();
|
||||
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = ps.main;
|
||||
main.playOnAwake = false; main.loop = false;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
main.maxParticles = 6000;
|
||||
main.startSpeed = 0f;
|
||||
var em = ps.emission; em.enabled = false;
|
||||
var sh = ps.shape; sh.enabled = false;
|
||||
var sol = ps.sizeOverLifetime; sol.enabled = true; sol.size = new ParticleSystem.MinMaxCurve(1f, size);
|
||||
var col = ps.colorOverLifetime; col.enabled = true;
|
||||
var g = new Gradient();
|
||||
g.SetKeys(new[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) },
|
||||
new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(0.8f, 0.4f), new GradientAlphaKey(0f, 1f) });
|
||||
col.color = g;
|
||||
var r = go.GetComponent<ParticleSystemRenderer>();
|
||||
r.sharedMaterial = mat;
|
||||
r.maxParticleSize = 4f;
|
||||
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
ps.Play();
|
||||
return ps;
|
||||
}
|
||||
|
||||
static void Emit(ParticleSystem ps, Vector3 pos, Vector3 vel, float size, Color c, float life)
|
||||
{
|
||||
var ep = new ParticleSystem.EmitParams { position = pos, velocity = vel, startSize = size, startColor = c, startLifetime = life, applyShapeToPosition = false };
|
||||
ps.Emit(ep, 1);
|
||||
}
|
||||
|
||||
/// <summary>The ball's own direction to a place on the map (latitude, longitude in degrees, as the map is laid out).</summary>
|
||||
public static Vector3 Geo(float lat, float lon)
|
||||
{
|
||||
float a = lat * Mathf.Deg2Rad, o = lon * Mathf.Deg2Rad;
|
||||
return new Vector3(Mathf.Cos(a) * Mathf.Cos(o), Mathf.Sin(a), Mathf.Cos(a) * Mathf.Sin(o));
|
||||
}
|
||||
|
||||
/// <summary>Spin the ball so the place given (its own direction) faces the world direction given, this many seconds from now.</summary>
|
||||
public void Face(Vector3 dirOS, Vector3 worldDir, float inSeconds)
|
||||
{
|
||||
var w = Quaternion.Inverse(_tilt) * worldDir.normalized;
|
||||
float aw = Mathf.Atan2(w.x, w.z) * Mathf.Rad2Deg, ad = Mathf.Atan2(dirOS.x, dirOS.z) * Mathf.Rad2Deg;
|
||||
_spin = aw - ad - Spin * inSeconds;
|
||||
_ball.rotation = _tilt * Quaternion.AngleAxis(_spin, Vector3.up);
|
||||
}
|
||||
|
||||
/// <summary>A world point on the ball (a little over it) for a direction in the ball's own space.</summary>
|
||||
public Vector3 Surface(Vector3 dirOS, float over = 0f) => Center + _ball.rotation * dirOS.normalized * (R + over);
|
||||
public Vector3 ToBall(Vector3 worldDir) => Quaternion.Inverse(_ball.rotation) * worldDir.normalized;
|
||||
|
||||
public void Tick(float dt)
|
||||
{
|
||||
_spin += dt * Spin;
|
||||
_ball.rotation = _tilt * Quaternion.AngleAxis(_spin, Vector3.up);
|
||||
|
||||
foreach (var s in _seeds) s.age += dt;
|
||||
for (int i = _pods.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var p = _pods[i];
|
||||
p.t += dt;
|
||||
if (p.t < 0f) continue;
|
||||
float k = Mathf.Clamp01(p.t / p.time);
|
||||
var dir = Vector3.Slerp(p.from, p.to, k);
|
||||
var pos = Surface(dir, R * 0.24f * Mathf.Sin(k * Mathf.PI));
|
||||
Emit(_glow, pos, Vector3.zero, 46f, new Color(0.75f, 1f, 0.45f, 0.95f), 0.9f);
|
||||
Emit(_sparks, pos, Random.onUnitSphere * 12f, Random.Range(10f, 18f), new Color(1f, 0.95f, 0.6f), 0.7f);
|
||||
if (k >= 1f)
|
||||
{
|
||||
_pods.RemoveAt(i);
|
||||
Plant(p.to, Random.Range(0.8f, 1.35f), Random.Range(6f, 9f));
|
||||
var at = Surface(p.to, 4f);
|
||||
Emit(_glow, at, Vector3.zero, 320f, new Color(0.8f, 1f, 0.55f, 0.9f), 1f);
|
||||
Emit(_rings, at, Vector3.zero, 900f, new Color(0.7f, 1f, 0.5f, 0.9f), 1.6f);
|
||||
Sfx.Play("plater_shimmer", 0.25f, Random.Range(1.1f, 1.4f), 0f);
|
||||
}
|
||||
}
|
||||
|
||||
// sparkles along every front still moving
|
||||
for (int i = 0; i < _seeds.Count; i++)
|
||||
{
|
||||
var s = _seeds[i];
|
||||
float w = Spread(s);
|
||||
if (w >= s.full * 0.98f || w <= 0f) continue;
|
||||
int n = Mathf.Min(14, Mathf.CeilToInt((i == 0 ? 120f : 30f) * dt * Mathf.Clamp(w, 0.3f, 2f)));
|
||||
var ortho = Vector3.Cross(s.dir, Mathf.Abs(s.dir.y) < 0.9f ? Vector3.up : Vector3.right).normalized;
|
||||
for (int k = 0; k < n; k++)
|
||||
{
|
||||
float a = Mathf.Min(Mathf.PI * 0.999f, w * Random.Range(0.72f, 1.05f));
|
||||
var axis = Quaternion.AngleAxis(Random.Range(0f, 360f), s.dir) * ortho;
|
||||
var d = Quaternion.AngleAxis(a * Mathf.Rad2Deg, axis) * s.dir;
|
||||
var pos = Surface(d, 6f);
|
||||
var nrm = (pos - Center).normalized;
|
||||
Emit(_sparks, pos, nrm * Random.Range(25f, 70f), Random.Range(9f, 22f),
|
||||
Color.Lerp(new Color(0.6f, 1f, 0.35f), new Color(1f, 0.92f, 0.5f), Random.value), Random.Range(0.6f, 1.3f));
|
||||
}
|
||||
}
|
||||
Apply();
|
||||
}
|
||||
|
||||
static float Spread(Seed s)
|
||||
{
|
||||
float k = Mathf.Clamp01(s.age / s.grow);
|
||||
// under way at once, quickest half way, easing into its last stretch
|
||||
return s.full * Mathf.Max(0.5f - 0.5f * Mathf.Cos(Mathf.PI * k), Mathf.Min(k * 0.6f, 0.05f));
|
||||
}
|
||||
|
||||
void Apply()
|
||||
{
|
||||
int n = Mathf.Min(MaxSeeds, _seeds.Count);
|
||||
for (int i = 0; i < MaxSeeds; i++)
|
||||
_seedVec[i] = i < n ? new Vector4(_seeds[i].dir.x, _seeds[i].dir.y, _seeds[i].dir.z, Spread(_seeds[i])) : Vector4.zero;
|
||||
for (int i = 0; i < MaxSeeds; i++)
|
||||
_seedFx[i] = i < n ? new Vector4(1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.7f, 1f, _seeds[i].age / _seeds[i].grow)), 0f, 0f, 0f) : Vector4.zero;
|
||||
_mat.SetVectorArray(SeedsId, _seedVec);
|
||||
_mat.SetVectorArray(SeedFxId, _seedFx);
|
||||
_mat.SetFloat(SeedCountId, n);
|
||||
float main = n > 0 ? Spread(_seeds[0]) / Full : 0f;
|
||||
Life = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.08f, 0.85f, main));
|
||||
var air = Color.Lerp(DeadAir, LiveAir, Life);
|
||||
_mat.SetFloat(LifeId, Life);
|
||||
_mat.SetColor(AirId, air);
|
||||
_mat.SetVector(SunId, Sun);
|
||||
_airMat.SetColor(AirId, air);
|
||||
_airMat.SetVector(SunId, Sun);
|
||||
_airMat.SetFloat(PowerId, Mathf.Lerp(0.55f, 1.25f, Life));
|
||||
}
|
||||
|
||||
void Plant(Vector3 dirOS, float full, float grow)
|
||||
{
|
||||
if (_seeds.Count >= MaxSeeds) return;
|
||||
_seeds.Add(new Seed { dir = dirOS.normalized, full = full, grow = grow });
|
||||
}
|
||||
|
||||
/// <summary>The rocket comes down here (a direction in the ball's own space): the flash, and the green under way.</summary>
|
||||
public void Land(Vector3 dirOS, Vector3 viewDirWorld)
|
||||
{
|
||||
Plant(dirOS, Full, 17f);
|
||||
var at = Surface(dirOS, 6f);
|
||||
var nrm = (at - Center).normalized;
|
||||
Emit(_glow, at, Vector3.zero, 1100f, new Color(1f, 1f, 0.85f, 1f), 1.3f);
|
||||
Emit(_glow, at, Vector3.zero, 520f, new Color(0.7f, 1f, 0.45f, 1f), 2.2f);
|
||||
Emit(_rings, at, Vector3.zero, 2600f, new Color(0.75f, 1f, 0.55f, 1f), 2.4f);
|
||||
Emit(_rings, at, Vector3.zero, 1500f, new Color(1f, 0.95f, 0.7f, 0.9f), 1.6f);
|
||||
for (int k = 0; k < 90; k++)
|
||||
Emit(_sparks, at, (nrm * 0.8f + Random.insideUnitSphere).normalized * Random.Range(60f, 260f), Random.Range(12f, 30f),
|
||||
Color.Lerp(new Color(0.6f, 1f, 0.35f), new Color(1f, 0.9f, 0.5f), Random.value), Random.Range(1f, 2.2f));
|
||||
// seed pods thrown out all round: half to the side we see, half anywhere
|
||||
var view = ToBall(viewDirWorld);
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
Vector3 to;
|
||||
int tries = 0;
|
||||
do
|
||||
{
|
||||
to = Random.onUnitSphere;
|
||||
if (i % 2 == 0 && Vector3.Dot(to, view) < 0.25f) to = Vector3.Slerp(to, view, 0.6f).normalized;
|
||||
} while (Vector3.Angle(to, dirOS) < 35f && ++tries < 20);
|
||||
_pods.Add(new Pod { from = dirOS.normalized, to = to, t = -(0.7f + i * 0.32f), time = Random.Range(1.5f, 2.4f) });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Green all over at once (the skip).</summary>
|
||||
public void HealNow()
|
||||
{
|
||||
_pods.Clear();
|
||||
if (_seeds.Count == 0) Plant(Vector3.up, Full, 17f);
|
||||
_seeds[0].full = Full;
|
||||
_seeds[0].age = _seeds[0].grow;
|
||||
_rocketDone = true;
|
||||
if (_rocket) _rocket.gameObject.SetActive(false);
|
||||
Apply();
|
||||
}
|
||||
|
||||
// ───────── the rocket ─────────
|
||||
|
||||
Transform _rocket;
|
||||
bool _rocketDone;
|
||||
|
||||
/// <summary>
|
||||
/// From behind the lens, past it close on the right, then away and down onto the ball where it lands (a direction in the
|
||||
/// ball's own space). It never gets smaller than a speck with a trail; then it lands.
|
||||
/// </summary>
|
||||
/// The lens is asked for each frame (the film's own pose of it: the camera's transform is the player's until late in the frame).
|
||||
public IEnumerator Rocket(System.Func<Pose> lens, Vector3 landOS, float seconds)
|
||||
{
|
||||
var prefab = AssetBank.I.Model("SM_Rocket");
|
||||
if (prefab)
|
||||
{
|
||||
var go = Object.Instantiate(prefab, _root.transform);
|
||||
foreach (var r in go.GetComponentsInChildren<Renderer>()) { r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; r.receiveShadows = false; }
|
||||
foreach (var c in go.GetComponentsInChildren<Collider>()) Object.Destroy(c);
|
||||
_rocket = go.transform;
|
||||
}
|
||||
float tall = 1f;
|
||||
if (_rocket)
|
||||
{
|
||||
var b = new Bounds(_rocket.position, Vector3.zero);
|
||||
bool any = false;
|
||||
foreach (var r in _rocket.GetComponentsInChildren<Renderer>()) { if (!any) { b = r.bounds; any = true; } else b.Encapsulate(r.bounds); }
|
||||
tall = Mathf.Max(0.1f, b.size.y);
|
||||
}
|
||||
const float Height = 9f;
|
||||
float baseScale = Height / tall;
|
||||
|
||||
// the pass: straight by the lens on the right, measured from the lens as it moves (it is still drifting in on the
|
||||
// ball, about as fast as the rocket goes by); then a boost away along a smooth curve down onto the ball
|
||||
var a0 = new Vector3(6f, -2.2f, -25f);
|
||||
var a1 = new Vector3(9f, -0.6f, 110f);
|
||||
var l0 = lens();
|
||||
var p1 = l0.position + l0.rotation * a0;
|
||||
var passDir = l0.rotation * (a1 - a0).normalized;
|
||||
var up = l0.up;
|
||||
Sfx.Play("rocket_launch", 0.5f, 1.2f, 0f);
|
||||
bool whoosh = false;
|
||||
var prev = p1;
|
||||
float t = 0f;
|
||||
while (t < seconds && !_rocketDone)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
float k = Mathf.Clamp01(t / seconds);
|
||||
var land = Surface(landOS, 0f);
|
||||
var nrm = (land - Center).normalized;
|
||||
var ln = lens();
|
||||
Vector3 pos;
|
||||
if (k < 0.3f)
|
||||
{
|
||||
pos = ln.position + ln.rotation * Vector3.Lerp(a0, a1, k / 0.3f);
|
||||
// where the pass ends and which way it was going: the curve down starts from there
|
||||
p1 = pos;
|
||||
passDir = ln.rotation * (a1 - a0).normalized;
|
||||
up = ln.up;
|
||||
}
|
||||
else
|
||||
{
|
||||
// off quick, easing in to land
|
||||
float v = (k - 0.3f) / 0.7f;
|
||||
float w = Mathf.Lerp(v, v * v * (3f - 2f * v), 0.85f);
|
||||
var b1 = p1 + passDir * R * 0.9f + up * R * 0.1f;
|
||||
var b2 = land + nrm * R * 0.9f;
|
||||
pos = Bezier(p1, b1, b2, land + nrm * 3f, w);
|
||||
}
|
||||
var dir = pos - prev;
|
||||
if (dir.sqrMagnitude < 1e-6f) dir = passDir;
|
||||
dir.Normalize();
|
||||
float far = Vector3.Distance(ln.position, pos);
|
||||
float s = Mathf.Max(1f, far / 320f);
|
||||
if (_rocket)
|
||||
{
|
||||
_rocket.position = pos;
|
||||
_rocket.rotation = Quaternion.FromToRotation(Vector3.up, dir) * Quaternion.AngleAxis(t * 90f, Vector3.up);
|
||||
_rocket.localScale = Vector3.one * baseScale * s;
|
||||
}
|
||||
// the flame and the trail, filled in between frames so it never breaks into dots
|
||||
float step = Mathf.Max(0.6f, s * 2.2f);
|
||||
int n = Mathf.Clamp(Mathf.CeilToInt(Vector3.Distance(prev, pos) / step), 1, 40);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
var at = Vector3.Lerp(prev, pos, (i + 1f) / n);
|
||||
// close by the lens a small flame and no smoke: left in the air there, it would fill the frame
|
||||
float flame = Mathf.Min(s * Random.Range(2.2f, 3.2f), 0.4f + far * 0.035f);
|
||||
Emit(_glow, at - dir * s * 0.4f, -dir * s * 6f, flame, new Color(1f, 0.62f, 0.25f, 0.95f), 0.22f);
|
||||
if (i % 2 == 0 && far > 45f)
|
||||
Emit(_glow, at - dir * s * 1.2f, Random.insideUnitSphere * s * 0.6f, s * Random.Range(2.6f, 3.8f), new Color(0.92f, 0.9f, 0.86f, 0.55f), 2.4f);
|
||||
}
|
||||
if (!whoosh && Vector3.Dot(pos - ln.position, ln.forward) > 0f) { whoosh = true; Sfx.Play("meteor_whoosh", 0.6f, 0.95f, 0f); }
|
||||
prev = pos;
|
||||
yield return null;
|
||||
}
|
||||
if (_rocket) _rocket.gameObject.SetActive(false);
|
||||
if (!_rocketDone)
|
||||
{
|
||||
_rocketDone = true;
|
||||
Sfx.Play("rocket_land", 0.7f, 0.8f, 0f);
|
||||
Sfx.Play("buff_shimmer", 0.5f, 0.9f, 0f);
|
||||
Land(landOS, lens().position - Center);
|
||||
}
|
||||
}
|
||||
|
||||
static Vector3 Bezier(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float t)
|
||||
{
|
||||
float u = 1f - t;
|
||||
return u * u * u * a + 3f * u * u * t * b + 3f * u * t * t * c + t * t * t * d;
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
if (_root) Object.Destroy(_root);
|
||||
if (_mat) Object.Destroy(_mat);
|
||||
if (_airMat) Object.Destroy(_airMat);
|
||||
}
|
||||
|
||||
/// <summary>A unit sphere fine enough that its edge stays round across the screen.</summary>
|
||||
static Mesh Sphere()
|
||||
{
|
||||
if (s_sphere) return s_sphere;
|
||||
const int lon = 160, lat = 80;
|
||||
var v = new Vector3[(lon + 1) * (lat + 1)];
|
||||
var idx = new int[lon * lat * 6];
|
||||
int vi = 0;
|
||||
for (int y = 0; y <= lat; y++)
|
||||
{
|
||||
float th = Mathf.PI * y / lat;
|
||||
for (int x = 0; x <= lon; x++)
|
||||
{
|
||||
float ph = 2f * Mathf.PI * x / lon;
|
||||
v[vi++] = new Vector3(Mathf.Sin(th) * Mathf.Cos(ph), Mathf.Cos(th), Mathf.Sin(th) * Mathf.Sin(ph));
|
||||
}
|
||||
}
|
||||
int ii = 0;
|
||||
for (int y = 0; y < lat; y++)
|
||||
for (int x = 0; x < lon; x++)
|
||||
{
|
||||
int a = y * (lon + 1) + x, b = a + lon + 1;
|
||||
idx[ii++] = a; idx[ii++] = a + 1; idx[ii++] = b;
|
||||
idx[ii++] = a + 1; idx[ii++] = b + 1; idx[ii++] = b;
|
||||
}
|
||||
s_sphere = new Mesh { name = "EndingSphere", indexFormat = UnityEngine.Rendering.IndexFormat.UInt32, vertices = v, normals = v, triangles = idx };
|
||||
s_sphere.RecalculateBounds();
|
||||
return s_sphere;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/EndingEarth.cs.meta
Normal file
2
Assets/Scripts/UI/EndingEarth.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e85e4a557582c84b83f91a694a144fb
|
||||
@ -20,7 +20,7 @@ namespace GrassCutter
|
||||
/// <summary>The trailer films it without the "Space: skip" in the corner.</summary>
|
||||
public static bool NoSkipHint;
|
||||
/// <summary>A game starting now could open on the film (not under a dev bot unless it asked).</summary>
|
||||
public static bool MightRun => Force || !CommandLine.Has("-autodemo");
|
||||
public static bool MightRun => Force || (!CommandLine.Has("-autodemo") && !EndingCinematic.Preview);
|
||||
/// <summary>Whether the film plays has been decided for this game and it isn't playing: until then nobody talks.</summary>
|
||||
public static bool Settled { get; private set; }
|
||||
|
||||
@ -56,7 +56,7 @@ namespace GrassCutter
|
||||
{
|
||||
_tried = true;
|
||||
bool fresh = ts.Shipped.Value <= 0d && ts.Mown.Value <= 0d;
|
||||
bool bot = CommandLine.Has("-autodemo");
|
||||
bool bot = CommandLine.Has("-autodemo") || EndingCinematic.Preview;
|
||||
if ((fresh && !bot) || Force) _run = StartCoroutine(Run());
|
||||
else { UIRoot.I?.ReleaseFade(0.6f); Settled = true; }
|
||||
}
|
||||
@ -240,62 +240,7 @@ namespace GrassCutter
|
||||
|
||||
// ───────── out in space: black sky and stars instead of the day's blue ─────────
|
||||
|
||||
ParticleSystem _stars;
|
||||
CameraClearFlags _clear;
|
||||
Color _clearColour;
|
||||
bool _inSpace;
|
||||
|
||||
void Space(bool on, Vector3 eye)
|
||||
{
|
||||
var cam = CameraFx.Cam;
|
||||
if (!cam || on == _inSpace) return;
|
||||
_inSpace = on;
|
||||
if (on)
|
||||
{
|
||||
_clear = cam.clearFlags;
|
||||
_clearColour = cam.backgroundColor;
|
||||
cam.clearFlags = CameraClearFlags.SolidColor;
|
||||
cam.backgroundColor = new Color(0.008f, 0.012f, 0.03f);
|
||||
if (!_stars)
|
||||
{
|
||||
var go = new GameObject("IntroStars");
|
||||
_stars = go.AddComponent<ParticleSystem>();
|
||||
_stars.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = _stars.main;
|
||||
main.playOnAwake = false; main.loop = false;
|
||||
main.startLifetime = 60f; main.startSpeed = 0f;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
main.maxParticles = 2000;
|
||||
var em = _stars.emission; em.enabled = false;
|
||||
var sh = _stars.shape; sh.enabled = false;
|
||||
var r = go.GetComponent<ParticleSystemRenderer>();
|
||||
r.sharedMaterial = AssetBank.I.Mat("FX_Sparkle") ?? AssetBank.I.Mat("FX_Soft");
|
||||
r.maxParticleSize = 0.02f;
|
||||
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
_stars.Play();
|
||||
}
|
||||
_stars.Clear();
|
||||
for (int i = 0; i < 1400; i++)
|
||||
{
|
||||
var d = Random.onUnitSphere;
|
||||
float far = 30000f;
|
||||
var ep = new ParticleSystem.EmitParams
|
||||
{
|
||||
position = eye + d * far,
|
||||
startSize = far * Random.Range(0.0012f, 0.0034f),
|
||||
startColor = Color.Lerp(new Color(0.75f, 0.85f, 1f), new Color(1f, 0.92f, 0.8f), Random.value) * Random.Range(0.55f, 1f),
|
||||
applyShapeToPosition = false,
|
||||
};
|
||||
_stars.Emit(ep, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cam.clearFlags = _clear;
|
||||
cam.backgroundColor = _clearColour;
|
||||
if (_stars) _stars.Clear();
|
||||
}
|
||||
}
|
||||
static void Space(bool on, Vector3 eye) => SpaceSky.Set(on, eye);
|
||||
|
||||
// ───────── the screen ─────────
|
||||
|
||||
|
||||
69
Assets/Scripts/UI/SpaceSky.cs
Normal file
69
Assets/Scripts/UI/SpaceSky.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GrassCutter
|
||||
{
|
||||
/// <summary>
|
||||
/// Out in space for the films: a black sky and a shell of stars round the eye instead of the day's blue. The opening film
|
||||
/// goes up into it once; the ending stays there.
|
||||
/// </summary>
|
||||
public static class SpaceSky
|
||||
{
|
||||
static ParticleSystem s_stars;
|
||||
static CameraClearFlags s_clear;
|
||||
static Color s_clearColour;
|
||||
public static bool On { get; private set; }
|
||||
|
||||
public static void Set(bool on, Vector3 eye)
|
||||
{
|
||||
var cam = CameraFx.Cam;
|
||||
if (!cam || on == On) return;
|
||||
On = on;
|
||||
if (on)
|
||||
{
|
||||
s_clear = cam.clearFlags;
|
||||
s_clearColour = cam.backgroundColor;
|
||||
cam.clearFlags = CameraClearFlags.SolidColor;
|
||||
cam.backgroundColor = new Color(0.008f, 0.012f, 0.03f);
|
||||
if (!s_stars)
|
||||
{
|
||||
var go = new GameObject("SpaceStars");
|
||||
Object.DontDestroyOnLoad(go);
|
||||
s_stars = go.AddComponent<ParticleSystem>();
|
||||
s_stars.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = s_stars.main;
|
||||
main.playOnAwake = false; main.loop = false;
|
||||
main.startLifetime = 600f; main.startSpeed = 0f;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
main.maxParticles = 2000;
|
||||
var em = s_stars.emission; em.enabled = false;
|
||||
var sh = s_stars.shape; sh.enabled = false;
|
||||
var r = go.GetComponent<ParticleSystemRenderer>();
|
||||
r.sharedMaterial = AssetBank.I.Mat("FX_Sparkle") ?? AssetBank.I.Mat("FX_Soft");
|
||||
r.maxParticleSize = 0.02f;
|
||||
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
||||
s_stars.Play();
|
||||
}
|
||||
s_stars.Clear();
|
||||
for (int i = 0; i < 1400; i++)
|
||||
{
|
||||
var d = Random.onUnitSphere;
|
||||
float far = 30000f;
|
||||
var ep = new ParticleSystem.EmitParams
|
||||
{
|
||||
position = eye + d * far,
|
||||
startSize = far * Random.Range(0.0012f, 0.0034f),
|
||||
startColor = Color.Lerp(new Color(0.75f, 0.85f, 1f), new Color(1f, 0.92f, 0.8f), Random.value) * Random.Range(0.55f, 1f),
|
||||
applyShapeToPosition = false,
|
||||
};
|
||||
s_stars.Emit(ep, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cam.clearFlags = s_clear;
|
||||
cam.backgroundColor = s_clearColour;
|
||||
if (s_stars) s_stars.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/SpaceSky.cs.meta
Normal file
2
Assets/Scripts/UI/SpaceSky.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 134b2a0fa4edae24b94694cecc91b9ba
|
||||
@ -70,6 +70,7 @@ namespace GrassCutter
|
||||
_hud.style.display = DisplayStyle.None;
|
||||
gameObject.AddComponent<DirectorCall>();
|
||||
gameObject.AddComponent<IntroCinematic>();
|
||||
gameObject.AddComponent<EndingCinematic>();
|
||||
gameObject.AddComponent<Assistant>();
|
||||
BuildMenu();
|
||||
BuildConnecting();
|
||||
@ -104,7 +105,8 @@ namespace GrassCutter
|
||||
{
|
||||
if (_modalStack.Count > 0) CloseTopModal();
|
||||
else if (Phone.Back()) { }
|
||||
else if (_inGame) OpenPause();
|
||||
// the ending takes Esc itself: it jumps to the last card
|
||||
else if (_inGame && !EndingCinematic.Running) OpenPause();
|
||||
}
|
||||
if (Ctl.ConsolePressed) ToggleConsole();
|
||||
if (Ctl.MapPressed && _inGame && _consoleLayer == null)
|
||||
|
||||
Reference in New Issue
Block a user