- Robot docks and drone pads with no belt ship straight to Earth; robots widen their rings up to 4x once everything in reach is mown, travel 2.5x faster empty, hoppers 60/150 kg. Drone reach 70 m + 25 m per upgrade. - New Sky Mower: a big mowing drone on a pad, 91 sectors, flies over the grass. - Cut paint follows the blade as a strip, no disc ahead of the machine. - Sector toasts aggregate, chimes and till sounds throttled, toasts moved and narrowed. - Menus no longer rebuild on every money change (price tint follows the wallet), scroll position kept. - Map drawn as one mesh, opens near the player, ME / + / - / GLOBE, scale bar. - Key-art still (x_key) and -shotsize for the store stills; -demobots test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
547 lines
32 KiB
C#
547 lines
32 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
namespace GrassCutter.EditorTools
|
|
{
|
|
/// <summary>
|
|
/// Renders every UI icon from the real game models (3/4 view, three-point light, transparent background),
|
|
/// then adds a chunky navy outline and a soft drop shadow so they read like one sticker set.
|
|
/// Also renders the hanging gate signs (sector name + price / open arrow).
|
|
/// </summary>
|
|
public static class IconStudio
|
|
{
|
|
const string Models = "Assets/Art/Models/";
|
|
const string Mats = "Assets/Art/Materials/";
|
|
const string OutDir = "Assets/Art/UI/";
|
|
|
|
const int Layer = 31;
|
|
const int Render = 768, Final = 256;
|
|
static readonly Color Navy = new Color(0.075f, 0.1f, 0.22f, 1f);
|
|
|
|
class Part
|
|
{
|
|
public string model, mat;
|
|
public Vector2 pos;
|
|
public float size = 1f;
|
|
public Vector3 euler;
|
|
public Color? tint;
|
|
public bool mirror;
|
|
}
|
|
|
|
static Part P(string model, float x, float y, float size, float ex = 0, float ey = 0, float ez = 0, string mat = null, Color? tint = null, bool mirror = false) =>
|
|
new Part { model = model, pos = new Vector2(x, y), size = size, euler = new Vector3(ex, ey, ez), mat = mat, tint = tint, mirror = mirror };
|
|
|
|
// badge in the lower-right corner of a composition
|
|
static Part Badge(string model, float ex = 0, float ey = 0, float ez = 0, string mat = null, float size = 0.55f) => P(model, 0.5f, -0.42f, size, ex, ey, ez, mat);
|
|
|
|
static Dictionary<string, Part[]> Icons()
|
|
{
|
|
const string Coin = "SM_IconCoin", Arrow = "SM_IconArrow", Bolt = "SM_IconBolt", Star = "SM_IconStar", Clock = "SM_IconClock", Gear = "SM_IconGear";
|
|
Part[] Up(string model, float ey, string badge = Arrow, float bez = 0f, float ex = 0f) => new[] { P(model, -0.1f, 0.06f, 1f, ex, ey, 0), Badge(badge, 0, badge == Arrow ? 0 : 15, bez) };
|
|
var d = new Dictionary<string, Part[]>
|
|
{
|
|
// tools
|
|
["icon_tool_scissors"] = new[] { P("SM_Tool_NailScissors", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_shears"] = new[] { P("SM_Tool_GardenShears", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_sickle"] = new[] { P("SM_Tool_Sickle", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_scythe"] = new[] { P("SM_Tool_Scythe", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_longscythe"] = new[] { P("SM_Tool_LongScythe", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_widescythe"] = new[] { P("SM_Tool_WideScythe", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_hammer"] = new[] { P("SM_Tool_Hammer", 0, 0, 1, -90, 0, 0) },
|
|
["icon_tool_handpump"] = new[] { P("SM_Tool_HandPump", 0, 0, 1, 0, -60, 0) },
|
|
["icon_tool_slurpgun"] = new[] { P("SM_Tool_SlurpGun", 0, 0, 1, 0, -60, 0) },
|
|
["icon_tool_hydrocannon"] = new[] { P("SM_Tool_HydroCannon", 0, 0, 1, 0, -60, 0) },
|
|
["icon_tool_megasiphon"] = new[] { P("SM_Tool_MegaSiphon", 0, 0, 1, 0, -60, 0) },
|
|
["icon_tool_lawnmower"] = new[] { P("SM_Tool_LawnMower", 0, 0, 1, 15, -40, 0) },
|
|
["icon_gadget_tablet"] = new[] { P("SM_Gadget_Tablet", 0, 0, 1, 0, 200, -8) },
|
|
// currency
|
|
// the crew
|
|
["icon_crew_hank"] = new[] { P("SM_Crew_Hank", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_otis"] = new[] { P("SM_Crew_Otis", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_lin"] = new[] { P("SM_Crew_Lin", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_rustam"] = new[] { P("SM_Crew_Rustam", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_marcus"] = new[] { P("SM_Crew_Marcus", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_gus"] = new[] { P("SM_Crew_Gus", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_wade"] = new[] { P("SM_Crew_Wade", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_crew_kenji"] = new[] { P("SM_Crew_Kenji", 0, -0.17f, 1.5f, 0, -8, 0) },
|
|
["icon_coin"] = new[] { P(Coin, 0, 0, 1, 0, 20, 0) },
|
|
["icon_star"] = new[] { P(Star, 0, 0, 1, 0, 15, 0) },
|
|
// build pieces
|
|
["icon_piece_binder"] = new[] { P("SM_Binder", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_robot"] = new[] { P("SM_RobotDock", 0, 0, 1, 20, -30, 0) },
|
|
["icon_piece_robot2"] = new[] { P("SM_RobotDock", 0, -0.1f, 0.9f, 20, -30, 0), P("SM_RobotMower", 0.3f, 0.3f, 0.45f, 10, -30, 0) },
|
|
["icon_piece_reaper"] = new[] { P("SM_Reaper", 0, 0, 1, 10, -40, 0) },
|
|
["icon_piece_catcher"] = new[] { P("SM_BundleCatcher", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_foundation"] = new[] { P("SM_Foundation_Square", 0, 0, 1, 25, 30, 0) },
|
|
// structures and decor
|
|
["icon_piece_wall"] = new[] { P("SM_Wall", 0, 0, 1, 12, -30, 0) },
|
|
["icon_piece_windowwall"] = new[] { P("SM_WallWindow", 0, 0, 1, 12, -30, 0) },
|
|
["icon_piece_doorwall"] = new[] { P("SM_WallDoor", 0, 0, 1, 12, -30, 0) },
|
|
["icon_piece_railing"] = new[] { P("SM_Railing", 0, 0, 1, 15, -30, 0) },
|
|
["icon_piece_fence"] = new[] { P("SM_Fence", 0, 0, 1, 15, -30, 0) },
|
|
["icon_piece_floor"] = new[] { P("SM_Floor", 0, 0, 1, 25, 30, 0) },
|
|
["icon_piece_flatroof"] = new[] { P("SM_FlatRoof", 0, 0, 1, 25, 30, 0) },
|
|
["icon_piece_roof"] = new[] { P("SM_Roof", 0, 0, 1, 30, -35, 0) },
|
|
["icon_piece_stairs"] = new[] { P("SM_Stairs", 0, 0, 1, 15, 120, 0) },
|
|
["icon_piece_steps"] = new[] { P("SM_Steps", 0, 0, 1, 15, 140, 0) },
|
|
["icon_piece_pillar"] = new[] { P("SM_Pillar", 0, 0, 1, 10, 30, 0) },
|
|
["icon_piece_planter"] = new[] { P("SM_Planter", 0, 0, 1, 25, 150, 0) },
|
|
["icon_piece_lamppost"] = new[] { P("SM_Lamppost", 0, 0, 1, 10, 150, 0) },
|
|
["icon_piece_bench"] = new[] { P("SM_Bench", 0, 0, 1, 15, 150, 0) },
|
|
["icon_piece_crates"] = new[] { P("SM_Crate", 0, 0, 1, 15, 150, 0) },
|
|
["icon_treat_beer"] = new[] { P("SM_BeerCan", 0, 0, 1, 15, 150, -14) },
|
|
["icon_treat_cigar"] = new[] { P("SM_Cigar", 0, 0, 1, 35, 130, 25) },
|
|
["icon_piece_flagpole"] = new[] { P("SM_Flagpole", 0, 0, 1, 10, 150, 0) },
|
|
["icon_piece_hopper"] = new[] { P("SM_Hopper", 0, 0, 1, 15, -30, 0) },
|
|
["icon_piece_tank"] = new[] { P("SM_WaterTank", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_pump"] = new[] { P("SM_Pump", 0, 0, 1, 10, -50, 0) },
|
|
["icon_piece_megapump"] = new[] { P("SM_Pump", -0.05f, 0.05f, 1, 10, -50, 0, tint: new Color(1f, 0.75f, 0.35f)), Badge(Star, 0, 15, 0) },
|
|
["icon_piece_dronehub"] = new[] { P("SM_DroneHub", 0, -0.15f, 0.9f, 20, -30, 0), P("SM_RainDrone", 0.1f, 0.35f, 0.6f, 15, -20, 0) },
|
|
["icon_piece_filler"] = new[] { P("SM_Filler", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_vaporizer"] = new[] { P("SM_Windmill", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_cryo"] = new[] { P("SM_CryoPress", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_belt"] = new[] { P("SM_Belt", 0, 0, 1, 0, 0, 0) },
|
|
["icon_piece_turnright"] = new[] { P("SM_BeltTurn", 0, 0, 1, 0, 0, 0) },
|
|
["icon_piece_turnleft"] = new[] { P("SM_BeltTurn", 0, 0, 1, 0, 0, 0, mirror: true) },
|
|
["icon_piece_splitter"] = new[] { P("SM_BeltSplitter", 0, 0, 1, 0, 0, 0) },
|
|
["icon_piece_solars"] = new[] { P("SM_SolarPost", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_solarm"] = new[] { P("SM_SolarPair", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_solarl"] = new[] { P("SM_SolarTracker", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_merger"] = new[] { P("SM_BeltMerger", 0, 0, 1, 0, 0, 0) },
|
|
["icon_piece_pole"] = new[] { P("SM_Prop_Power_Pole_01", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_battery"] = new[] { P("SM_BatteryRack", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_batteryl"] = new[] { P("SM_BatteryBank", 0, 0, 1, 10, -30, 0) },
|
|
["icon_piece_unloadbay"] = new[] { P("SM_UnloadBay", 0, 0, 1, 25, 140, 0) },
|
|
["icon_piece_hexfoundation"] = new[] { P("SM_Foundation_Hex", 0, 0, 1, 0, 30, 0, tint: new Color(0.8f, 0.8f, 0.7f)) },
|
|
["icon_piece_sorter"] = new[] { P("SM_BeltSorter", 0, 0, 1, 0, -30, 0) },
|
|
["icon_piece_dronepad"] = new[] { P("SM_Drone", 0, 0.05f, 1, 18, -30, 0) },
|
|
["icon_piece_skymower"] = new[] { P("SM_DronePad", 0, -0.2f, 0.85f, 20, -30, 0), P("SM_Drone", 0.05f, 0.22f, 0.8f, 14, -30, 0) },
|
|
["icon_piece_launcher"] = new[] { P("SM_Launcher", 0, 0, 1, 0, -30, 0) },
|
|
["icon_piece_launchpad"] = new[] { P("SM_LaunchPad", 0, -0.2f, 1, 25, -30, 0), P("SM_Rocket", 0.05f, 0.25f, 0.8f, 0, -30, 0) },
|
|
// vehicles
|
|
["icon_vehicle_ski"] = new[] { P("SM_RiderMower", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_push"] = new[] { P("SM_PushMower", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_tug"] = new[] { P("SM_Veh_Tractor_01", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_combine"] = new[] { P("SM_Veh_Harvester_01", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_hover"] = new[] { P("SM_Veh_Pickup_01", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_hauler"] = new[] { P("SM_HaulTractor", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_mulcher"] = new[] { P("SM_WideMulcher", 0, 0, 1, 10, -50, 0) },
|
|
["icon_vehicle_baler"] = new[] { P("SM_BalerTractor", 0, 0, 1, 10, -50, 0) },
|
|
// SUCTION
|
|
["icon_perk_suction"] = Up("SM_Tool_HandPump", -60f, Bolt),
|
|
["icon_perk_nozzle"] = Up("SM_Tool_SlurpGun", -90f, Arrow, 90f),
|
|
["icon_perk_flow"] = new[] { P("SM_Tool_SlurpGun", -0.1f, 0.06f, 1f, 0, -60, 0), Badge(Clock, 0, 15, 0) },
|
|
["icon_perk_pure"] = new[] { P("SM_IceBlock", -0.05f, 0.05f, 0.9f, 20, 30, 0), P(Star, 0.48f, 0.42f, 0.45f, 0, 15, 0) },
|
|
["icon_perk_blast"] = Up("SM_Tool_HydroCannon", -60f, Bolt),
|
|
["icon_perk_abyss"] = new[] { P("SM_Tool_MegaSiphon", -0.1f, 0.06f, 1f, 0, -60, 0, tint: new Color(0.5f, 0.6f, 1f)), Badge(Star, 0, 15, 0) },
|
|
// GEAR
|
|
["icon_perk_backpack"] = new[] { P("SM_Crew_Hank", 0, 0, 1, 0, 150, 0), Badge(Arrow) },
|
|
["icon_perk_sneakers"] = new[] { P("SM_Crew_Hank", -0.1f, 0.05f, 1, 0, -30, 0), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_release"] = new[] { P("SM_Hopper", -0.1f, 0.05f, 1, 15, -30, 0), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_fins"] = new[] { P("SM_Crew_Hank", -0.1f, 0.05f, 1, 60, -20, 0), Badge(Arrow, 0, 0, -90) },
|
|
["icon_perk_boots"] = new[] { P("SM_Crew_Hank", -0.1f, 0.05f, 1, 0, -30, 0), Badge(Arrow) },
|
|
["icon_perk_pressure"] = new[] { P("SM_WaterTank", -0.1f, 0.05f, 1, 10, -30, 0, tint: new Color(0.6f, 0.85f, 1f)), Badge(Arrow) },
|
|
["icon_perk_snorkel"] = new[] { P("SM_Crew_Hank", -0.1f, 0.05f, 1, 50, -20, 0, tint: new Color(0.5f, 0.85f, 1f)), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_jetpack"] = new[] { P("SM_Crew_Hank", -0.1f, 0.05f, 1, 0, 150, 0), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_remote"] = new[] { P("SM_Crew_Hank", -0.1f, 0.05f, 1, 0, 150, 0), Badge(Gear, 0, 15, 0) },
|
|
["icon_perk_jetfuel"] = new[] { P("SM_Canister", -0.1f, 0.05f, 1, 0, 30, 0), Badge(Bolt, 0, 15, 0) },
|
|
// PROCESSING
|
|
["icon_perk_filler"] = Up("SM_Filler", -30f, Clock),
|
|
["icon_perk_contracts"] = new[] { P(Coin, -0.1f, 0.05f, 1, 0, 20, 0), Badge(Arrow) },
|
|
["icon_perk_tankcap"] = Up("SM_WaterTank", -30f),
|
|
["icon_perk_superheat"] = Up("SM_Windmill", -30f, Bolt),
|
|
["icon_perk_purity"] = new[] { P("SM_Canister", -0.1f, 0.05f, 1, 0, 30, 0), Badge(Star, 0, 15, 0) },
|
|
["icon_perk_overclock"] = new[] { P(Gear, -0.15f, 0.12f, 0.9f, 0, 15, 0, tint: new Color(0.4f, 0.85f, 1f)), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_freeze"] = Up("SM_CryoPress", -30f, Clock),
|
|
["icon_perk_megablock"] = new[] { P("SM_IceBlock", -0.1f, 0.05f, 1, 20, 30, 0), Badge(Arrow) },
|
|
// LOGISTICS
|
|
["icon_perk_rocket"] = new[] { P("SM_Rocket", -0.05f, 0.05f, 1, 0, -30, 0), Badge(Arrow) },
|
|
["icon_perk_turnaround"] = new[] { P("SM_Rocket", -0.05f, 0.05f, 1, 0, -30, 0), Badge(Clock, 0, 15, 0) },
|
|
["icon_perk_autolaunch"] = new[] { P("SM_LaunchLever", -0.05f, 0.05f, 1, 0, -40, 0), Badge(Gear, 0, 15, 0) },
|
|
["icon_perk_beltspeed"] = new[] { P("SM_Belt", -0.1f, 0.08f, 1, 0, 0, 0), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_beltlogic"] = new[] { P("SM_BeltSplitter", -0.1f, 0.08f, 1, 0, 0, 0), Badge(Gear, 0, 15, 0) },
|
|
["icon_perk_express"] = new[] { P("SM_Rocket", -0.05f, 0.05f, 1, 0, -30, 0, tint: new Color(1f, 0.85f, 0.4f)), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_dronefleet"] = new[] { P("SM_Drone", -0.38f, -0.22f, 0.6f, 18, -30, 0), P("SM_Drone", 0.38f, -0.22f, 0.6f, 18, -40, 0), P("SM_Drone", 0f, 0.3f, 0.66f, 18, -20, 0) },
|
|
// AUTOMATION
|
|
["icon_perk_pumppower"] = Up("SM_Pump", -50f, Bolt),
|
|
["icon_perk_reservoir"] = new[] { P("SM_WaterTank", -0.25f, 0f, 0.8f, 10, -30, 0), P("SM_WaterTank", 0.3f, 0f, 0.8f, 10, -30, 0) },
|
|
["icon_perk_deepintake"] = Up("SM_Pump", -50f, Arrow, 180f),
|
|
["icon_perk_dronetank"] = Up("SM_RainDrone", -30f, Arrow, 0f, 20f),
|
|
["icon_perk_swarm"] = new[] { P("SM_RainDrone", -0.38f, -0.22f, 0.6f, 18, -30, 0), P("SM_RainDrone", 0.38f, -0.22f, 0.6f, 18, -40, 0), P("SM_RainDrone", 0f, 0.3f, 0.66f, 18, -20, 0) },
|
|
["icon_perk_storm"] = new[] { P("SM_Buoy", -0.1f, 0.05f, 1, 0, -30, 0), Badge(Bolt, 0, 15, 0) },
|
|
// FLEET
|
|
["icon_perk_turbo"] = Up("SM_SlurpSki", -50f, Bolt, 0f, 10f),
|
|
["icon_perk_vehtank"] = Up("SM_TugPump", -50f, Arrow, 0f, 10f),
|
|
["icon_perk_dockpump"] = new[] { P("SM_Dock", -0.1f, 0.05f, 1, 20, -30, 0), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_tugarm"] = Up("SM_TugPump", 40f, Gear, 0f, 10f),
|
|
["icon_perk_fleet"] = new[] { P("SM_SlurpSki", -0.35f, -0.2f, 0.65f, 10, -50, 0), P("SM_SlurpSki", 0.35f, 0.15f, 0.65f, 10, -50, 0) },
|
|
["icon_perk_hoverboost"] = Up("SM_HoverTanker", -50f, Bolt, 0f, 10f),
|
|
// RIG
|
|
["icon_perk_decor"] = new[] { P("SM_Decor_Palm", -0.25f, 0f, 0.85f, 0, -30, 0), P("SM_Decor_Umbrella", 0.3f, 0f, 0.85f, 0, -30, 0) },
|
|
["icon_perk_coffee"] = new[] { P("SM_Decor_Vending", -0.1f, 0.05f, 1, 0, -30, 0), Badge(Bolt, 0, 15, 0) },
|
|
["icon_perk_foundation"] = new[] { P("SM_Foundation_Square", -0.1f, 0.05f, 1, 25, 30, 0), Badge(Coin, 0, 20, 0) },
|
|
["icon_perk_milestone"] = new[] { P(Star, -0.1f, 0.05f, 1, 0, 15, 0), Badge(Coin, 0, 20, 0) },
|
|
["icon_perk_gnome"] = new[] { P("SM_Decor_Gnome", 0, 0, 1, 0, -30, 0) },
|
|
["icon_perk_landmark"] = new[] { P("SM_Decor_Beacon", -0.1f, 0.05f, 1, 0, -30, 0), Badge(Star, 0, 15, 0) },
|
|
["icon_perk_shares"] = new[] { P(Coin, -0.3f, -0.15f, 0.75f, 0, 20, 0), P(Coin, 0.15f, 0.12f, 0.75f, 0, 35, 0), Badge(Arrow) },
|
|
};
|
|
return d;
|
|
}
|
|
|
|
// ───────────────────────── entry ─────────────────────────
|
|
|
|
public static void BatchRender()
|
|
{
|
|
RenderAll();
|
|
EditorApplication.Exit(0);
|
|
}
|
|
|
|
[MenuItem("GrassCutter/Render Icons")]
|
|
public static void RenderAll()
|
|
{
|
|
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null)
|
|
{
|
|
Debug.LogWarning("[IconStudio] no graphics device (-nographics?) — keeping existing icons");
|
|
return;
|
|
}
|
|
Directory.CreateDirectory(OutDir);
|
|
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
|
var prevAmbient = RenderSettings.ambientLight;
|
|
RenderSettings.ambientMode = AmbientMode.Flat;
|
|
RenderSettings.ambientLight = new Color(0.52f, 0.54f, 0.6f);
|
|
RenderSettings.fog = false;
|
|
// metals (coins, gold, tools) need something to reflect: a bright procedural sky as the environment
|
|
var sky = new Material(Shader.Find("Skybox/Procedural"));
|
|
sky.SetColor("_SkyTint", new Color(0.55f, 0.7f, 1f));
|
|
sky.SetColor("_GroundColor", new Color(0.95f, 0.9f, 0.8f));
|
|
sky.SetFloat("_Exposure", 1.6f);
|
|
RenderSettings.skybox = sky;
|
|
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Skybox;
|
|
RenderSettings.reflectionIntensity = 1f;
|
|
DynamicGI.UpdateEnvironment();
|
|
|
|
var cam = MakeCamera();
|
|
var lights = MakeLights();
|
|
int n = 0;
|
|
foreach (var kv in Icons())
|
|
{
|
|
var root = new GameObject("Icon_" + kv.Key);
|
|
bool ok = true;
|
|
foreach (var part in kv.Value) ok &= Spawn(part, root.transform, cam.transform);
|
|
if (ok)
|
|
{
|
|
Frame(cam, root);
|
|
var px = RenderAlpha(cam, Render, Render);
|
|
var tex = Sticker(px, Render, Render, Mathf.RoundToInt(Render * 0.022f), Render / Final);
|
|
Write(tex, OutDir + kv.Key + ".png");
|
|
n++;
|
|
}
|
|
else Debug.LogWarning("[IconStudio] skipped " + kv.Key);
|
|
Object.DestroyImmediate(root);
|
|
}
|
|
|
|
|
|
foreach (var l in lights) Object.DestroyImmediate(l);
|
|
Object.DestroyImmediate(cam.gameObject);
|
|
RenderSettings.ambientLight = prevAmbient;
|
|
RenderSettings.skybox = null;
|
|
Object.DestroyImmediate(sky);
|
|
|
|
// the v1 icon set is retired
|
|
var keep = new HashSet<string>(Icons().Keys);
|
|
foreach (var old in Directory.GetFiles(OutDir, "icon_*.png"))
|
|
if (!keep.Contains(Path.GetFileNameWithoutExtension(old))) AssetDatabase.DeleteAsset(old.Replace('\\', '/'));
|
|
AssetDatabase.Refresh();
|
|
foreach (var f in Directory.GetFiles(OutDir, "icon_*.png")) ConfigureImporter(f.Replace('\\', '/'), false);
|
|
Debug.Log($"[IconStudio] rendered {n} icons");
|
|
}
|
|
|
|
// ───────────────────────── staging ─────────────────────────
|
|
|
|
static Camera MakeCamera()
|
|
{
|
|
var go = new GameObject("IconCam");
|
|
var cam = go.AddComponent<Camera>();
|
|
cam.orthographic = true;
|
|
cam.clearFlags = CameraClearFlags.SolidColor;
|
|
cam.backgroundColor = Color.black;
|
|
cam.cullingMask = 1 << Layer;
|
|
cam.allowHDR = false;
|
|
cam.allowMSAA = false;
|
|
cam.nearClipPlane = 0.01f;
|
|
cam.farClipPlane = 100f;
|
|
cam.enabled = false;
|
|
var data = go.AddComponent<UniversalAdditionalCameraData>();
|
|
data.renderPostProcessing = false;
|
|
data.antialiasing = AntialiasingMode.None;
|
|
data.renderShadows = false;
|
|
go.transform.rotation = Quaternion.Euler(24f, 215f, 0f);
|
|
return cam;
|
|
}
|
|
|
|
static List<GameObject> MakeLights()
|
|
{
|
|
var list = new List<GameObject>();
|
|
void L(string n, Vector3 euler, Color c, float i)
|
|
{
|
|
var g = new GameObject(n);
|
|
var l = g.AddComponent<Light>();
|
|
l.type = LightType.Directional;
|
|
l.color = c; l.intensity = i;
|
|
l.shadows = LightShadows.None;
|
|
l.cullingMask = 1 << Layer;
|
|
g.transform.rotation = Quaternion.Euler(euler);
|
|
list.Add(g);
|
|
}
|
|
L("Key", new Vector3(42f, 160f, 0f), new Color(1f, 0.95f, 0.86f), 1.55f);
|
|
L("Fill", new Vector3(18f, 290f, 0f), new Color(0.62f, 0.75f, 1f), 0.55f);
|
|
L("Rim", new Vector3(-10f, 20f, 0f), new Color(1f, 1f, 1f), 0.9f);
|
|
return list;
|
|
}
|
|
|
|
static bool Spawn(Part p, Transform root, Transform cam)
|
|
{
|
|
var model = ProjectBuilder.Model(p.model);
|
|
if (!model) return false;
|
|
var holder = new GameObject(p.model).transform;
|
|
holder.SetParent(root, false);
|
|
var inst = (GameObject)PrefabUtility.InstantiatePrefab(model);
|
|
inst.transform.SetParent(holder, false);
|
|
holder.rotation = Quaternion.Euler(p.euler);
|
|
if (p.mirror) holder.localScale = new Vector3(-1f, 1f, 1f);
|
|
|
|
Material over = p.mat != null ? AssetDatabase.LoadAssetAtPath<Material>(Mats + p.mat + ".mat") : null;
|
|
foreach (var r in inst.GetComponentsInChildren<Renderer>())
|
|
{
|
|
r.gameObject.layer = Layer;
|
|
r.shadowCastingMode = ShadowCastingMode.Off;
|
|
if (over) { var arr = r.sharedMaterials; for (int i = 0; i < arr.Length; i++) arr[i] = over; r.sharedMaterials = arr; }
|
|
{
|
|
// full metals go murky without a real environment: render them as bright glossy paint instead
|
|
var arr = r.sharedMaterials;
|
|
for (int i = 0; i < arr.Length; i++)
|
|
{
|
|
if (!arr[i] || !arr[i].HasProperty("_Metallic") || arr[i].GetFloat("_Metallic") < 0.5f) continue;
|
|
var m = new Material(arr[i]);
|
|
m.SetFloat("_Metallic", 0.25f);
|
|
m.SetFloat("_Smoothness", 0.78f);
|
|
arr[i] = m;
|
|
}
|
|
r.sharedMaterials = arr;
|
|
}
|
|
if (p.tint is Color tint)
|
|
{
|
|
var arr = r.sharedMaterials;
|
|
for (int i = 0; i < arr.Length; i++)
|
|
{
|
|
if (!arr[i] || !arr[i].HasProperty("_BaseColor")) continue;
|
|
var m = new Material(arr[i]);
|
|
var bc = m.GetColor("_BaseColor");
|
|
// tint only the coloured parts (keeps soles / metal neutral)
|
|
float sat = Mathf.Max(bc.r, bc.g, bc.b) - Mathf.Min(bc.r, bc.g, bc.b);
|
|
if (sat > 0.15f) m.SetColor("_BaseColor", new Color(tint.r, tint.g, tint.b, bc.a));
|
|
arr[i] = m;
|
|
}
|
|
r.sharedMaterials = arr;
|
|
}
|
|
}
|
|
|
|
// normalise: biggest extent = size, then centre on the screen-plane position
|
|
var b = BoundsOf(holder.gameObject);
|
|
float ext = Mathf.Max(b.size.x, Mathf.Max(b.size.y, b.size.z));
|
|
if (ext < 1e-4f) return false;
|
|
holder.localScale *= p.size / ext;
|
|
b = BoundsOf(holder.gameObject);
|
|
var target = cam.right * p.pos.x + cam.up * p.pos.y;
|
|
holder.position += target - b.center;
|
|
return true;
|
|
}
|
|
|
|
static Bounds BoundsOf(GameObject go)
|
|
{
|
|
var rs = go.GetComponentsInChildren<Renderer>();
|
|
if (rs.Length == 0) return new Bounds(go.transform.position, Vector3.zero);
|
|
var b = rs[0].bounds;
|
|
foreach (var r in rs) b.Encapsulate(r.bounds);
|
|
return b;
|
|
}
|
|
|
|
/// <summary>Fits the ortho camera tightly around the composition (projected corners), with room for the outline.</summary>
|
|
static void Frame(Camera cam, GameObject root)
|
|
{
|
|
var b = BoundsOf(root);
|
|
var t = cam.transform;
|
|
float minX = float.MaxValue, maxX = float.MinValue, minY = float.MaxValue, maxY = float.MinValue;
|
|
// corners of every renderer's bounds give a tighter projected box than the global AABB
|
|
foreach (var r in root.GetComponentsInChildren<Renderer>())
|
|
{
|
|
var rb = r.bounds;
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
var c = rb.center + Vector3.Scale(rb.extents, new Vector3((i & 1) == 0 ? -1 : 1, (i & 2) == 0 ? -1 : 1, (i & 4) == 0 ? -1 : 1));
|
|
var l = c - b.center;
|
|
float x = Vector3.Dot(l, t.right), y = Vector3.Dot(l, t.up);
|
|
minX = Mathf.Min(minX, x); maxX = Mathf.Max(maxX, x); minY = Mathf.Min(minY, y); maxY = Mathf.Max(maxY, y);
|
|
}
|
|
}
|
|
var mid = b.center + t.right * ((minX + maxX) * 0.5f) + t.up * ((minY + maxY) * 0.5f);
|
|
float half = Mathf.Max(maxX - minX, maxY - minY) * 0.5f;
|
|
cam.orthographicSize = half * 1.16f;
|
|
cam.aspect = 1f;
|
|
t.position = mid - t.forward * (b.extents.magnitude * 2f + 5f);
|
|
}
|
|
|
|
// ───────────────────────── capture ─────────────────────────
|
|
|
|
/// <summary>Renders over black and over white and recovers straight colour + alpha (works whatever the pipeline does with alpha).</summary>
|
|
static Color[] RenderAlpha(Camera cam, int w, int h)
|
|
{
|
|
var rt = RenderTexture.GetTemporary(new RenderTextureDescriptor(w, h, RenderTextureFormat.ARGB32, 24) { sRGB = true, msaaSamples = 1 });
|
|
var read = new Texture2D(w, h, TextureFormat.RGBA32, false, false);
|
|
Color[] Shot(Color bg)
|
|
{
|
|
cam.backgroundColor = bg;
|
|
cam.targetTexture = rt;
|
|
cam.Render();
|
|
var prev = RenderTexture.active;
|
|
RenderTexture.active = rt;
|
|
read.ReadPixels(new Rect(0, 0, w, h), 0, 0, false);
|
|
read.Apply();
|
|
RenderTexture.active = prev;
|
|
return read.GetPixels();
|
|
}
|
|
var black = Shot(Color.black);
|
|
var white = Shot(Color.white);
|
|
cam.targetTexture = null;
|
|
RenderTexture.ReleaseTemporary(rt);
|
|
Object.DestroyImmediate(read);
|
|
|
|
var outPx = new Color[w * h];
|
|
for (int i = 0; i < outPx.Length; i++)
|
|
{
|
|
var k = black[i]; var wt = white[i];
|
|
float a = 1f - ((wt.r - k.r) + (wt.g - k.g) + (wt.b - k.b)) / 3f;
|
|
a = Mathf.Clamp01(a);
|
|
if (a < 0.004f) { outPx[i] = new Color(0, 0, 0, 0); continue; }
|
|
outPx[i] = new Color(Mathf.Clamp01(k.r / a), Mathf.Clamp01(k.g / a), Mathf.Clamp01(k.b / a), a);
|
|
}
|
|
return outPx;
|
|
}
|
|
|
|
/// <summary>Outline + drop shadow around the alpha shape, then box-downscale by <paramref name="down"/>.</summary>
|
|
static Texture2D Sticker(Color[] px, int w, int h, int radius, int down, Color? outline = null, bool shadow = true)
|
|
{
|
|
var ol = outline ?? Navy;
|
|
var dist = Distance(px, w, h);
|
|
int sh = Mathf.RoundToInt(radius * 0.7f);
|
|
var comp = new Color[w * h];
|
|
for (int y = 0; y < h; y++)
|
|
for (int x = 0; x < w; x++)
|
|
{
|
|
int i = y * w + x;
|
|
float oa = Mathf.Clamp01(radius + 1f - dist[i]);
|
|
float sa = 0f;
|
|
if (shadow)
|
|
{
|
|
int sy = y + sh;
|
|
if (sy < h) sa = Mathf.Clamp01(radius + 1f - dist[sy * w + x]) * 0.32f;
|
|
}
|
|
// shadow (black) → outline → object, all straight-alpha "over"
|
|
var c = new Color(0, 0, 0, sa);
|
|
c = Over(new Color(ol.r, ol.g, ol.b, oa), c);
|
|
c = Over(px[i], c);
|
|
comp[i] = c;
|
|
}
|
|
int fw = w / down, fh = h / down;
|
|
var tex = new Texture2D(fw, fh, TextureFormat.RGBA32, false, false);
|
|
var outPx = new Color[fw * fh];
|
|
float inv = 1f / (down * down);
|
|
for (int y = 0; y < fh; y++)
|
|
for (int x = 0; x < fw; x++)
|
|
{
|
|
// premultiplied average so edges don't fringe
|
|
float r = 0, g = 0, b = 0, a = 0;
|
|
for (int dy = 0; dy < down; dy++)
|
|
for (int dx = 0; dx < down; dx++)
|
|
{
|
|
var c = comp[(y * down + dy) * w + x * down + dx];
|
|
r += c.r * c.a; g += c.g * c.a; b += c.b * c.a; a += c.a;
|
|
}
|
|
outPx[y * fw + x] = a > 0 ? new Color(r / a, g / a, b / a, a * inv) : new Color(0, 0, 0, 0);
|
|
}
|
|
tex.SetPixels(outPx);
|
|
tex.Apply();
|
|
return tex;
|
|
}
|
|
|
|
static Color Over(Color top, Color bottom)
|
|
{
|
|
float a = top.a + bottom.a * (1f - top.a);
|
|
if (a <= 0f) return new Color(0, 0, 0, 0);
|
|
float k = bottom.a * (1f - top.a);
|
|
return new Color((top.r * top.a + bottom.r * k) / a, (top.g * top.a + bottom.g * k) / a, (top.b * top.a + bottom.b * k) / a, a);
|
|
}
|
|
|
|
/// <summary>Two-pass chamfer distance (px) to the nearest solid pixel.</summary>
|
|
static float[] Distance(Color[] px, int w, int h)
|
|
{
|
|
const float Inf = 1e6f, D = 1.4142f;
|
|
var d = new float[w * h];
|
|
for (int i = 0; i < d.Length; i++) d[i] = px[i].a > 0.45f ? 0f : Inf;
|
|
for (int y = 0; y < h; y++)
|
|
for (int x = 0; x < w; x++)
|
|
{
|
|
int i = y * w + x;
|
|
float v = d[i];
|
|
if (x > 0) v = Mathf.Min(v, d[i - 1] + 1f);
|
|
if (y > 0)
|
|
{
|
|
v = Mathf.Min(v, d[i - w] + 1f);
|
|
if (x > 0) v = Mathf.Min(v, d[i - w - 1] + D);
|
|
if (x < w - 1) v = Mathf.Min(v, d[i - w + 1] + D);
|
|
}
|
|
d[i] = v;
|
|
}
|
|
for (int y = h - 1; y >= 0; y--)
|
|
for (int x = w - 1; x >= 0; x--)
|
|
{
|
|
int i = y * w + x;
|
|
float v = d[i];
|
|
if (x < w - 1) v = Mathf.Min(v, d[i + 1] + 1f);
|
|
if (y < h - 1)
|
|
{
|
|
v = Mathf.Min(v, d[i + w] + 1f);
|
|
if (x < w - 1) v = Mathf.Min(v, d[i + w + 1] + D);
|
|
if (x > 0) v = Mathf.Min(v, d[i + w - 1] + D);
|
|
}
|
|
d[i] = v;
|
|
}
|
|
return d;
|
|
}
|
|
|
|
static void Write(Texture2D t, string path)
|
|
{
|
|
File.WriteAllBytes(path, t.EncodeToPNG());
|
|
Object.DestroyImmediate(t);
|
|
}
|
|
|
|
static void ConfigureImporter(string path, bool sign)
|
|
{
|
|
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport);
|
|
if (AssetImporter.GetAtPath(path) is not TextureImporter ti) return;
|
|
ti.textureType = TextureImporterType.Default;
|
|
ti.alphaIsTransparency = true;
|
|
ti.sRGBTexture = true;
|
|
ti.mipmapEnabled = sign;
|
|
ti.wrapMode = TextureWrapMode.Clamp;
|
|
ti.textureCompression = TextureImporterCompression.Uncompressed;
|
|
ti.SaveAndReimport();
|
|
}
|
|
}
|
|
}
|