- Held tools sit lower and further right; the hammer faces forward and strikes about the camera's right - Headlamp leaves held items, treats and vending machines alone (rendering layer NoLamp); other lights keep lighting them - Hay grounded on the floor in world space (it floated) - Deck fence opens at each ladder, rail colliders split around it; ladders moved to 2 m off the edge middle, clear of the intakes; climbing goes over a rail only if one is in the way - Crew stand to the soil's up (Planet.Level): flat round the base, the ball's up past it, so the horizon stays level on a small planet - Convex roof hulls for the crew cabin, garage, pitched roof and windmill tower; cabin box lowered to the eaves - Rain and acid rain hits differ by surface: soil, grass, wood, metal - Idle motion: dishes pan, sways sway, sensors turn, eyes blink, windmill turns in the breeze, reels and parked rotors tick over - Belt: take tools off at the supply wall; hold E at a vending machine for a pack of 3 on the belt, LMB has one - New meadow pieces: boulders, slab stones, crystals, mushrooms, stump, bulb plants - -demofix checks for all of the above; loc rows in all 11 tables Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
466 lines
25 KiB
C#
466 lines
25 KiB
C#
using Unity.Netcode;
|
|
using Unity.Netcode.Transports.UTP;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace GrassCutter.EditorTools
|
|
{
|
|
/// <summary>
|
|
/// The Herbaria-7 scene: sky with the ringed gas giant, the endless overgrown meadow (grass + wild hemp), the hills
|
|
/// beyond, the deck on its stilts, the static base furniture (supply wall, upgrade console, crew cabin, loading ramp and
|
|
/// the unloading yard) and the systems (cameras, networking, spawner, UI).
|
|
/// The deck tiles and everything built on them are spawned at runtime.
|
|
/// </summary>
|
|
public static partial class ProjectBuilder
|
|
{
|
|
static Transform _env;
|
|
static Transform _dockZone;
|
|
|
|
static void BuildScene()
|
|
{
|
|
System.IO.Directory.CreateDirectory("Assets/Scenes");
|
|
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
|
|
|
Lighting();
|
|
_env = new GameObject("Environment").transform;
|
|
World();
|
|
RigFurniture();
|
|
Systems();
|
|
|
|
EditorSceneManager.SaveScene(scene, ScenePath);
|
|
Debug.Log("[Builder] Scene saved");
|
|
}
|
|
|
|
// ───────────────────────── lighting ─────────────────────────
|
|
|
|
static readonly Vector3 SunDir = new Vector3(0.3f, 0.55f, -0.6f).normalized; // towards the sun
|
|
static readonly Color Horizon = new Color(0.8f, 0.9f, 0.86f);
|
|
|
|
static void Lighting()
|
|
{
|
|
RenderSettings.ambientMode = AmbientMode.Trilight;
|
|
RenderSettings.ambientSkyColor = new Color(0.66f, 0.8f, 0.98f) * 1.1f;
|
|
RenderSettings.ambientEquatorColor = new Color(0.78f, 0.88f, 0.74f);
|
|
RenderSettings.ambientGroundColor = new Color(0.3f, 0.45f, 0.2f);
|
|
var sky = Mat("M_Sky");
|
|
if (sky)
|
|
{
|
|
sky.SetVector("_SunDir", SunDir);
|
|
sky.SetColor("_HorizonColor", Horizon);
|
|
EditorUtility.SetDirty(sky);
|
|
RenderSettings.skybox = sky;
|
|
}
|
|
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Skybox;
|
|
RenderSettings.reflectionIntensity = 1f;
|
|
RenderSettings.fog = true;
|
|
RenderSettings.fogMode = FogMode.Linear;
|
|
RenderSettings.fogColor = Horizon;
|
|
RenderSettings.fogStartDistance = 30f;
|
|
RenderSettings.fogEndDistance = 1500f;
|
|
|
|
var sun = new GameObject("Sun");
|
|
var l = sun.AddComponent<Light>();
|
|
l.type = LightType.Directional;
|
|
l.color = new Color(1f, 0.95f, 0.86f);
|
|
l.intensity = 1.55f;
|
|
l.shadows = LightShadows.Soft;
|
|
l.shadowStrength = 0.75f;
|
|
sun.transform.rotation = Quaternion.LookRotation(-SunDir);
|
|
RenderSettings.sun = l;
|
|
|
|
var vol = new GameObject("PostFX").AddComponent<Volume>();
|
|
vol.isGlobal = true;
|
|
vol.priority = 1;
|
|
const string profPath = "Assets/Settings/MeadowPost.asset";
|
|
if (AssetDatabase.LoadAssetAtPath<VolumeProfile>(profPath)) AssetDatabase.DeleteAsset(profPath);
|
|
var prof = ScriptableObject.CreateInstance<VolumeProfile>();
|
|
AssetDatabase.CreateAsset(prof, profPath);
|
|
var bloom = prof.Add<Bloom>(true);
|
|
bloom.intensity.Override(0.7f); bloom.threshold.Override(0.95f); bloom.scatter.Override(0.7f);
|
|
var tm = prof.Add<Tonemapping>(true);
|
|
tm.mode.Override(TonemappingMode.Neutral);
|
|
var ca = prof.Add<ColorAdjustments>(true);
|
|
ca.postExposure.Override(0.15f); ca.contrast.Override(16f); ca.saturation.Override(12f);
|
|
var vig = prof.Add<Vignette>(true);
|
|
vig.intensity.Override(0.22f); vig.smoothness.Override(0.5f);
|
|
var wb = prof.Add<WhiteBalance>(true);
|
|
wb.temperature.Override(3f);
|
|
foreach (var c in prof.components) AssetDatabase.AddObjectToAsset(c, prof);
|
|
EditorUtility.SetDirty(prof);
|
|
AssetDatabase.SaveAssets();
|
|
vol.sharedProfile = prof;
|
|
}
|
|
|
|
// ───────────────────────── scene helpers ─────────────────────────
|
|
|
|
static GameObject Place(string model, Vector3 pos, float yaw, Transform parent = null, bool isStatic = true)
|
|
{
|
|
var m = Model(model);
|
|
if (!m) { Debug.LogWarning("[Builder] missing " + model); return null; }
|
|
// wrapper carries placement (so its forward is the model's front); the model keeps its imported rotation
|
|
var go = new GameObject(model);
|
|
go.transform.SetParent(parent ? parent : _env, false);
|
|
go.transform.position = pos;
|
|
go.transform.rotation = Quaternion.Euler(0, yaw, 0);
|
|
var inst = (GameObject)PrefabUtility.InstantiatePrefab(m);
|
|
inst.transform.SetParent(go.transform, false);
|
|
if (isStatic) foreach (var t in go.GetComponentsInChildren<Transform>()) t.gameObject.isStatic = true;
|
|
return go;
|
|
}
|
|
|
|
static Transform FindT(GameObject root, string child)
|
|
{
|
|
foreach (var t in root.GetComponentsInChildren<Transform>(true)) if (t.name == child) return t;
|
|
return null;
|
|
}
|
|
|
|
static void Blocker(GameObject go, Vector3 center, Vector2 size)
|
|
{
|
|
var b = go.AddComponent<GridBlocker>();
|
|
b.center = center;
|
|
b.size = size;
|
|
}
|
|
|
|
static BoxCollider SolidAt(string name, Vector3 center, Vector3 size, Transform parent, float yaw = 0f, float pitch = 0f)
|
|
{
|
|
var go = new GameObject(name);
|
|
go.transform.SetParent(parent, false);
|
|
go.transform.localPosition = center;
|
|
go.transform.localRotation = Quaternion.Euler(pitch, yaw, 0);
|
|
var bc = go.AddComponent<BoxCollider>();
|
|
bc.size = size;
|
|
go.isStatic = true;
|
|
return bc;
|
|
}
|
|
|
|
// ───────────────────────── the world ─────────────────────────
|
|
|
|
static void World()
|
|
{
|
|
new GameObject("Meadow").AddComponent<Meadow>();
|
|
|
|
var field = new GameObject("GrassField").AddComponent<GrassField>();
|
|
field.furMat = Mat("M_GrassFur");
|
|
field.strandMat = Mat("M_GrassStrand");
|
|
field.hempMat = Mat("M_Hemp");
|
|
field.hempMesh = BakedMesh("SM_Hemp");
|
|
field.flowerMat = Mat("M_Flowers");
|
|
field.flowerMesh = BakedPlant("SM_Wildflower");
|
|
// wheat and oats share their plant: baking one again would throw away the first
|
|
var ear = BakedPlant("SM_Prop_Plant_Wheat_Optimised_02");
|
|
var earFar = BakedPlant("SM_Prop_Plant_Wheat_Optimised_01");
|
|
field.crops = new[]
|
|
{
|
|
new GrassField.CropLook(),
|
|
new GrassField.CropLook { mat = Mat("M_CropWheat"), near = ear, far = earFar },
|
|
new GrassField.CropLook { mat = Mat("M_CropOats"), near = ear, far = earFar },
|
|
new GrassField.CropLook { mat = Mat("M_CropCorn"), near = BakedPlant("SM_Prop_Plant_Corn_01_M"), far = BakedPlant("SM_Crop_Corn_Far") },
|
|
new GrassField.CropLook { mat = Mat("M_CropSunflower"), near = BakedPlant("SM_Prop_Sunflower_02"), far = BakedPlant("SM_Crop_Sunflower_Far") },
|
|
};
|
|
|
|
var ground = new GameObject("Ground").AddComponent<Ground>();
|
|
ground.soil = Mat("M_Soil");
|
|
ground.spires = new[] { Model("SM_Spire_A"), Model("SM_Spire_B"), Model("SM_Spire_C") };
|
|
ground.trees = new[] { Model("SM_Generic_Tree_01"), Model("SM_Generic_Tree_02"), Model("SM_Generic_Tree_03") };
|
|
ground.bush = Model("SM_Prop_Plant_Bush_03_L");
|
|
ground.stones = new[] { Model("SM_Boulders"), Model("SM_SlabStones"), Model("SM_Crystals") };
|
|
ground.growths = new[] { Model("SM_Shrooms"), Model("SM_Stump"), Model("SM_BulbPlants") };
|
|
|
|
var deck = new GameObject("Deck").AddComponent<DeckManager>();
|
|
deck.tileModel = Model("SM_DeckTile");
|
|
deck.ladderModel = Model("SM_Ladder");
|
|
deck.gaps = new[] { new Vector3(0f, 0f, -9f) }; // the ramp opening in the south railing
|
|
}
|
|
|
|
/// <summary>Company furniture that every base has: the supply wall, the console, the crew cabin, the ramp and the yard. A garage has to be bought.</summary>
|
|
static void RigFurniture()
|
|
{
|
|
var rig = new GameObject("Rig").transform;
|
|
|
|
// the supply wall: tools on a pegboard along the west railing
|
|
SupplyWallPiece(rig);
|
|
|
|
ConsolePiece(rig, new Vector3(6.2f, 0f, -1.5f));
|
|
TravelPiece(rig, new Vector3(6.2f, 0f, 2.2f));
|
|
|
|
// the two treat machines against the north railing, facing the middle of the deck
|
|
VendPiece(rig, "SM_VendBeer", TreatId.Beer, new Vector3(3.9f, 0f, 8.2f));
|
|
VendPiece(rig, "SM_VendSmoke", TreatId.Cigar, new Vector3(5.9f, 0f, 8.35f));
|
|
|
|
// crew cabin on the north-west tile
|
|
var cabin = Place("SM_CrewCabin", new Vector3(-6f, 0f, 7f), 180f, rig);
|
|
if (cabin)
|
|
{
|
|
// the walls up to the eaves (2.6 m) as a box, the roof above them as drawn (the box used to stand 0.6 m
|
|
// proud of the eaves, and a body landed inside the roof)
|
|
SolidAt("CabinBox", new Vector3(0f, 1.3f, 0f), new Vector3(5.8f, 2.6f, 3.8f), cabin.transform);
|
|
Hull(cabin.transform, cabin.transform, "Hull_CrewCabin", 2.4f, 3.7f); // the chimney stays out of it
|
|
Blocker(cabin, Vector3.zero, new Vector2(5.8f, 3.8f));
|
|
}
|
|
|
|
// loading ramp off the south edge, down to the meadow (1.2 m over 6 m)
|
|
float slope = Mathf.Asin(0.2f) * Mathf.Rad2Deg;
|
|
var dock = Place("SM_Dock", new Vector3(0f, 0f, -9f), 180f, rig);
|
|
if (dock)
|
|
{
|
|
SolidAt("RampDeck", new Vector3(0f, -0.66f, 3.0f), new Vector3(3f, 0.12f, 6.2f), dock.transform, 0f, slope);
|
|
SolidAt("RampCurbL", new Vector3(-1.44f, -0.5f, 3.0f), new Vector3(0.12f, 0.3f, 6.2f), dock.transform, 0f, slope);
|
|
SolidAt("RampCurbR", new Vector3(1.44f, -0.5f, 3.0f), new Vector3(0.12f, 0.3f, 6.2f), dock.transform, 0f, slope);
|
|
var gb = dock.AddComponent<GrassBlocker>();
|
|
gb.center = new Vector3(0f, 0f, 3.2f); gb.halfSize = new Vector2(1.7f, 3.4f);
|
|
}
|
|
|
|
// the unloading yard: packed earth at the foot of the ramp where machines tip what they've cut
|
|
var pad = new GameObject("UnloadYard");
|
|
pad.transform.SetParent(rig, false);
|
|
pad.transform.position = new Vector3(0f, GameDefs.WaterY, -20f);
|
|
var padBlock = pad.AddComponent<GrassBlocker>();
|
|
padBlock.halfSize = new Vector2(9f, 8f);
|
|
var slab = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
slab.name = "PadSlab";
|
|
slab.transform.SetParent(pad.transform, false);
|
|
slab.transform.localPosition = new Vector3(0f, -0.04f, 0f);
|
|
slab.transform.localScale = new Vector3(18f, 0.1f, 16f);
|
|
slab.GetComponent<Renderer>().sharedMaterial = Mat("M_Yard");
|
|
slab.isStatic = true;
|
|
|
|
// no shed at the base: bought and called machines park on the yard by the dock (garages players build keep theirs)
|
|
|
|
var zone = new GameObject("DockZone").transform;
|
|
zone.SetParent(rig, false);
|
|
zone.position = new Vector3(0f, GameDefs.WaterY, -19f);
|
|
zone.rotation = Quaternion.Euler(0f, 180f, 0f);
|
|
_dockZone = zone;
|
|
|
|
// a few props from the company crate
|
|
Prop(rig, "SM_Decor_Lamp", new Vector3(-2.5f, 0f, -8.5f), 0f, 0.4f, 2.4f, true);
|
|
Prop(rig, "SM_Decor_Lamp", new Vector3(2.5f, 0f, -8.5f), 0f, 0.4f, 2.4f, true);
|
|
Prop(rig, "SM_Prop_Crate_01", new Vector3(-8.2f, 0f, -8.2f), 20f, 1f, 1f, false, 0.75f);
|
|
Prop(rig, "SM_Prop_Barrel_01", new Vector3(8.5f, 0f, 2.5f), 90f, 0.6f, 0.9f, false, 0.75f);
|
|
Prop(rig, "SM_Prop_Hay_Bale_Square_01", new Vector3(7.8f, 0f, -7.6f), 70f, 1.2f, 0.7f, false, 0.75f);
|
|
Prop(rig, "SM_Prop_Wheelbarrow_01", new Vector3(4.6f, 0f, -7.9f), 200f, 1f, 0.7f, false, 0.75f);
|
|
|
|
// where the crew spawns: south of the depot, looking north over the deck
|
|
var sp = new GameObject("SpawnPoints").transform;
|
|
for (int i = 0; i < NetSession.MaxPlayers; i++)
|
|
{
|
|
var p = new GameObject("Spawn" + i).transform;
|
|
p.SetParent(sp, false);
|
|
p.position = new Vector3(-6f + (i % 8) * 1.4f, 0.15f, -5f - (i / 8) * 1.4f);
|
|
p.rotation = Quaternion.Euler(0f, 0f, 0f);
|
|
}
|
|
}
|
|
|
|
/// <summary>GreenHaul console (the upgrade matrix).</summary>
|
|
static void ConsolePiece(Transform rig, Vector3 pos)
|
|
{
|
|
var term = Place("SM_Terminal", pos, -90f, rig, false);
|
|
if (!term) return;
|
|
SolidAt("TermBox", new Vector3(0f, 0.9f, 0f), new Vector3(1.2f, 1.8f, 0.9f), term.transform);
|
|
var st = term.AddComponent<ShopTerminal>();
|
|
var scr = FindT(term, "Screen");
|
|
st.screen = scr ? scr.GetComponent<Renderer>() : null;
|
|
foreach (var t in term.GetComponentsInChildren<Transform>()) t.gameObject.layer = Layers.Build;
|
|
Blocker(term, Vector3.zero, new Vector2(1.6f, 1.2f));
|
|
}
|
|
|
|
/// <summary>A vending machine that trades a kilo of grass for a treat: its moving parts found by name and handed to the script.</summary>
|
|
static void VendPiece(Transform rig, string model, TreatId kind, Vector3 pos)
|
|
{
|
|
var go = Place(model, pos, 180f, rig, false);
|
|
if (!go) return;
|
|
bool beer = kind == TreatId.Beer;
|
|
SolidAt("VendBox", new Vector3(0f, beer ? 1.07f : 0.95f, 0f), beer ? new Vector3(1.05f, 2.14f, 0.85f) : new Vector3(1.1f, 1.9f, 0.62f), go.transform);
|
|
var vm = go.AddComponent<VendingMachine>();
|
|
vm.kind = kind;
|
|
var sign = FindT(go, "Sign");
|
|
vm.sign = sign ? sign.GetComponent<Renderer>() : null;
|
|
var display = FindT(go, "Display");
|
|
vm.display = display ? display.GetComponent<Renderer>() : null;
|
|
// the whole model shudders while it works
|
|
vm.body = go.transform.childCount > 0 ? go.transform.GetChild(0) : null;
|
|
vm.button = FindT(go, "Button");
|
|
vm.tray = FindT(go, "Tray");
|
|
vm.drawer = FindT(go, "Drawer");
|
|
vm.hopper = FindT(go, "Hopper");
|
|
vm.dropPoint = FindT(go, "DropPoint");
|
|
var knobs = new System.Collections.Generic.List<Transform>();
|
|
for (int i = 0; i < 4; i++) { var k = FindT(go, "Knob" + i); if (k) knobs.Add(k); }
|
|
vm.knobs = knobs.ToArray();
|
|
foreach (var t in go.GetComponentsInChildren<Transform>()) t.gameObject.layer = Layers.Build;
|
|
Blocker(go, Vector3.zero, new Vector2(1.5f, 1.3f));
|
|
}
|
|
|
|
static void TravelPiece(Transform rig, Vector3 pos)
|
|
{
|
|
var dish = Place("SM_Decor_Dish", pos, -90f, rig, false);
|
|
if (!dish) return;
|
|
SolidAt("TravelBox", new Vector3(0f, 1f, 0f), new Vector3(1.2f, 2f, 1.2f), dish.transform);
|
|
dish.AddComponent<StationTerminal>();
|
|
foreach (var t in dish.GetComponentsInChildren<Transform>()) t.gameObject.layer = Layers.Build;
|
|
Blocker(dish, Vector3.zero, new Vector2(1.6f, 1.6f));
|
|
}
|
|
|
|
/// <summary>What stands around the depot of a far station: put together at the origin, then kept as a prefab.</summary>
|
|
static GameObject StationRig()
|
|
{
|
|
var rig = new GameObject("Station_Rig");
|
|
var yard = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
|
yard.name = "Yard";
|
|
Object.DestroyImmediate(yard.GetComponent<Collider>());
|
|
yard.transform.SetParent(rig.transform, false);
|
|
yard.transform.localPosition = Vector3.up * 0.02f;
|
|
yard.transform.localScale = new Vector3(22f, 0.04f, 22f);
|
|
yard.GetComponent<Renderer>().sharedMaterial = Mat("M_Yard");
|
|
SupplyWallPiece(rig.transform);
|
|
ConsolePiece(rig.transform, new Vector3(6.2f, 0f, -1.5f));
|
|
TravelPiece(rig.transform, new Vector3(6.2f, 0f, 2.2f));
|
|
VendPiece(rig.transform, "SM_VendBeer", TreatId.Beer, new Vector3(-2.2f, 0f, 7.6f));
|
|
VendPiece(rig.transform, "SM_VendSmoke", TreatId.Cigar, new Vector3(-0.2f, 0f, 7.7f));
|
|
var prefab = PrefabUtility.SaveAsPrefabAsset(rig, Prefabs + "Station_Rig.prefab");
|
|
Object.DestroyImmediate(rig);
|
|
return prefab;
|
|
}
|
|
|
|
static void SupplyWallPiece(Transform rig)
|
|
{
|
|
var wall = new GameObject("SupplyWall");
|
|
wall.transform.SetParent(rig, false);
|
|
wall.transform.position = new Vector3(-8.5f, 0f, -1.5f);
|
|
wall.transform.rotation = Quaternion.Euler(0f, 90f, 0f); // faces the middle of the deck
|
|
var body = Place("SM_SupplyWall", wall.transform.position, 0f, wall.transform, false);
|
|
if (body) body.transform.localRotation = Quaternion.identity;
|
|
SolidAt("WallBox", new Vector3(0f, 1.3f, 0f), new Vector3(4.54f, 2.6f, 0.34f), wall.transform);
|
|
// the tools hang with their blades up, the cheapest on the left as you face the wall
|
|
float[] sizes = { 0.5f, 0.8f, 0.24f, 0.46f, 0.52f, 0.6f, 0.7f };
|
|
for (int i = 0; i < GameDefs.Tools.Length && i < sizes.Length; i++)
|
|
{
|
|
var hung = Place(GameDefs.Tools[i].model, wall.transform.TransformPoint(new Vector3(1.8f - i * 0.6f, 0.9f, 0.14f)), 0f, wall.transform, false);
|
|
if (!hung) continue;
|
|
hung.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
|
|
hung.transform.localScale = Vector3.one * sizes[i];
|
|
}
|
|
// the lawn mower is too big to hang: it stands on the deck at the end of the wall, handle toward you
|
|
var mower = Place(GameDefs.Tool(ToolId.LawnMower).model, wall.transform.TransformPoint(new Vector3(-2.75f, 0.95f, 1.4f)), 0f, wall.transform, false);
|
|
if (mower) mower.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
|
|
wall.AddComponent<SupplyWall>();
|
|
foreach (var t in wall.GetComponentsInChildren<Transform>()) t.gameObject.layer = Layers.Build;
|
|
Blocker(wall, new Vector3(0f, 0f, 0.2f), new Vector2(4.8f, 0.8f));
|
|
}
|
|
|
|
/// <summary>A small piece of base furniture with a box you can't walk through.</summary>
|
|
static void Prop(Transform rig, string model, Vector3 pos, float yaw, float size, float height, bool lamp, float scale = 1f)
|
|
{
|
|
var go = Place(model, pos, yaw, rig);
|
|
if (!go) return;
|
|
// where the floor is, in the world: pos is the rig's, the bounds are the world's
|
|
float floor = go.transform.position.y;
|
|
go.transform.localScale *= scale;
|
|
// pack props are not all pivoted at their base (the hay bale sits at its middle): stand the lowest point on the floor
|
|
var rs = go.GetComponentsInChildren<Renderer>();
|
|
if (rs.Length > 0)
|
|
{
|
|
var b = rs[0].bounds;
|
|
foreach (var r in rs) b.Encapsulate(r.bounds);
|
|
float sink = floor - b.min.y;
|
|
if (sink > 0.01f) go.transform.position += Vector3.up * sink;
|
|
}
|
|
SolidAt("Solid", new Vector3(0f, height * 0.5f, 0f), new Vector3(size, height, size), go.transform);
|
|
Blocker(go, Vector3.zero, new Vector2(size + 0.4f, size + 0.4f));
|
|
if (!lamp) return;
|
|
var bulb = FindT(go, "Bulb");
|
|
var l = new GameObject("Light").AddComponent<Light>();
|
|
l.transform.SetParent(bulb ? bulb : go.transform, false);
|
|
if (!bulb) l.transform.localPosition = new Vector3(0f, 2.2f, 0f);
|
|
l.type = LightType.Point; l.range = 7f; l.intensity = 1.6f; l.color = new Color(1f, 0.85f, 0.6f); l.shadows = LightShadows.None;
|
|
}
|
|
|
|
// ───────────────────────── systems ─────────────────────────
|
|
|
|
static void Systems()
|
|
{
|
|
new GameObject("Steam").AddComponent<SteamManager>();
|
|
new GameObject("Boot").AddComponent<GameBoot>();
|
|
|
|
// ambience: wind over the meadow, crickets
|
|
new GameObject("Soundscape").AddComponent<Soundscape>();
|
|
|
|
// cameras
|
|
var rig = new GameObject("MenuRig");
|
|
var mc = rig.AddComponent<MenuCamera>();
|
|
mc.focus = new Vector3(0f, 3f, 2f);
|
|
mc.radius = 24f; mc.height = 7f; mc.speed = 0.018f;
|
|
var camGo = new GameObject("Main Camera");
|
|
camGo.tag = "MainCamera";
|
|
camGo.transform.SetParent(rig.transform, false);
|
|
var cam = camGo.AddComponent<Camera>();
|
|
cam.nearClipPlane = 0.05f; cam.farClipPlane = 14000f; cam.fieldOfView = 78f;
|
|
cam.cullingMask = ~(1 << Layers.ViewModel);
|
|
camGo.AddComponent<AudioListener>();
|
|
var data = camGo.AddComponent<UniversalAdditionalCameraData>();
|
|
data.renderPostProcessing = true;
|
|
data.antialiasing = AntialiasingMode.SubpixelMorphologicalAntiAliasing;
|
|
data.requiresDepthTexture = true;
|
|
camGo.AddComponent<CameraFx>();
|
|
mc.cam = camGo.transform;
|
|
|
|
var vmGo = new GameObject("ViewModelCamera");
|
|
vmGo.transform.SetParent(camGo.transform, false);
|
|
var vmCam = vmGo.AddComponent<Camera>();
|
|
vmCam.cullingMask = 1 << Layers.ViewModel;
|
|
vmCam.fieldOfView = 62f;
|
|
vmCam.nearClipPlane = 0.01f; vmCam.farClipPlane = 6f;
|
|
var vmData = vmGo.AddComponent<UniversalAdditionalCameraData>();
|
|
vmData.renderType = CameraRenderType.Overlay;
|
|
data.cameraStack.Add(vmCam);
|
|
var vm = new GameObject("ViewModel");
|
|
vm.transform.SetParent(vmGo.transform, false);
|
|
vm.layer = Layers.ViewModel;
|
|
vm.AddComponent<ViewModel>();
|
|
|
|
// networking
|
|
var netGo = new GameObject("NetworkManager");
|
|
var nm = netGo.AddComponent<NetworkManager>();
|
|
var utp = netGo.AddComponent<UnityTransport>();
|
|
netGo.AddComponent<SteamSocketsTransport>();
|
|
netGo.AddComponent<NetSession>();
|
|
nm.NetworkConfig = new NetworkConfig
|
|
{
|
|
NetworkTransport = utp,
|
|
PlayerPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(Prefabs + "Player.prefab"),
|
|
ConnectionApproval = true,
|
|
EnableSceneManagement = false,
|
|
TickRate = 30,
|
|
ForceSamePrefabs = true,
|
|
};
|
|
nm.NetworkConfig.Prefabs.NetworkPrefabsLists.Add(AssetDatabase.LoadAssetAtPath<NetworkPrefabsList>(Prefabs + "NetworkPrefabs.asset"));
|
|
|
|
// spawner
|
|
var sp = new GameObject("Spawner").AddComponent<Spawner>();
|
|
NetworkObject P(string n) { if (string.IsNullOrEmpty(n)) return null; var g = AssetDatabase.LoadAssetAtPath<GameObject>(Prefabs + n + ".prefab"); return g ? g.GetComponent<NetworkObject>() : null; }
|
|
sp.teamStatePrefab = P("TeamState");
|
|
sp.cargoPrefabs = new[] { P("Cargo_Grass"), P("Cargo_Hay"), P("Cargo_Brick") };
|
|
sp.vehiclePrefabs = new[] { P("Vehicle_Push"), P("Vehicle_Rider"), P("Vehicle_Pickup"), P("Vehicle_Tractor"), P("Vehicle_Combine"), P("Vehicle_Hauler"), P("Vehicle_Mulcher"), P("Vehicle_Baler") };
|
|
sp.piecePrefabs = new NetworkObject[GameDefs.Pieces.Length];
|
|
for (int i = 0; i < GameDefs.Pieces.Length; i++) sp.piecePrefabs[i] = P(GameDefs.Pieces[i].prefab);
|
|
sp.dock = _dockZone;
|
|
|
|
new GameObject("Stations").AddComponent<Stations>().rig = StationRig();
|
|
|
|
new GameObject("PowerWires").AddComponent<PowerWires>();
|
|
new GameObject("BeltSound").AddComponent<BeltSound>();
|
|
|
|
// UI
|
|
var ui = new GameObject("UI");
|
|
var doc = ui.AddComponent<UIDocument>();
|
|
doc.panelSettings = AssetDatabase.LoadAssetAtPath<PanelSettings>("Assets/UI/PanelSettings.asset");
|
|
var root = ui.AddComponent<UIRoot>();
|
|
root.style = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/UI/GrassCutter.uss");
|
|
}
|
|
}
|
|
}
|