Files
unity/Assets/Game/Scripts/Runs/TrainingCrate.cs
RCiBot eb819c6688 feat: improve map lighting and expand the playable training range
Add real-time lighting and shadows, training courses and targets, and animated salvage crates. Include bilingual assets and curated verification results.
2026-11-12 18:03:04 +08:00

54 lines
2.3 KiB
C#

using System.Collections;
using UnityEngine;
namespace Ironspore
{
public sealed class TrainingCrate : WorldInteractable
{
Transform hinge;
Transform latch;
const float UnlatchSeconds = .16f;
const float LiftSeconds = .55f;
bool started;
public void Build(Transform world, Vector3 basePosition, bool part, bool showLabel)
{
Color accent = part ? new Color(.98f,.53f,.17f) : new Color(.16f,.85f,.67f);
hinge = new GameObject("CaseHinge").transform;
hinge.SetParent(world, false);
hinge.position = basePosition + new Vector3(0,1.36f,.71f);
var lid = WorldFactory.Box("CaseLid", hinge.position + Vector3.back * .72f, new Vector3(1.96f,.16f,1.49f), accent, hinge, false);
lid.layer = 10;
foreach (int side in new[] { -1, 1 })
WorldFactory.Box("CaseStrap", lid.transform.position + new Vector3(side * .66f,.1f,0), new Vector3(.14f,.07f,1.42f), Color.gray, hinge, false).layer = 10;
latch = new GameObject("CaseLatchPivot").transform;
latch.SetParent(hinge, false);
latch.localPosition = new Vector3(0, 0, -1.49f);
WorldFactory.Box("CaseLatch", latch.position + Vector3.down * .13f, new Vector3(.38f, .26f, .09f), Color.gray, latch, false).layer = 10;
WorldFactory.Box("CaseLiner", basePosition + Vector3.up * 1.30f, new Vector3(1.58f, .02f, 1.18f), new Color(.07f, .10f, .11f), world, false).layer = 10;
if (showLabel)
WorldFactory.Label(part ? "range.parts" : "range.material", basePosition + Vector3.up * 2.4f, accent, world);
}
public override void RefreshLabel()
{
if (collected && !started)
{
started = true;
StartCoroutine(OpenLid());
}
}
IEnumerator OpenLid()
{
float elapsed = 0;
while (elapsed < UnlatchSeconds + LiftSeconds)
{
yield return null;
elapsed += Time.deltaTime;
latch.localRotation = Quaternion.Euler(Mathf.SmoothStep(0, 78, elapsed / UnlatchSeconds), 0, 0);
hinge.localRotation = Quaternion.Euler(Mathf.SmoothStep(0, 92, (elapsed - UnlatchSeconds) / LiftSeconds), 0, 0);
}
}
}
}