Search Results for

    Show / Hide Table of Contents

    VehicleLightAttachment Guide

    中文 | English

    Run this command at the repository root to replay the examples through the local Unity MCP. The command also captures screenshots in both languages.

    python Docs/Manual/manual/tools/tutorials.py run vehicle-light-component --capture
    
    Click to expand MCP actionsClick to collapse MCP actions

    Prepare the teaching sample. The recipe provides ${variables}.

    {
      "variables": {
        "asset": "${fixture}/Tutorial_Light.prefab"
      },
      "calls": [
        {
          "tool": "invoke",
          "arguments": {
            "path": "static:UnityEditor.AssetDatabase/CreateFolder",
            "args": [
              "${fixtureParent}",
              "${folder}"
            ]
          },
          "expect": {
            "regex": "\\(String\\) [a-f0-9]{32}"
          }
        }
      ]
    }
    

    This example configures a circular low-beam light. VehicleLightAttachment is serialized configuration data; VehicleLightAttachmentMonoComponent is the component attached to a GameObject. Field names keep their original C# identifiers.

    1. Create the component and bind the object

    1. Create a light object in the vehicle prefab and add VehicleLightAttachmentMonoComponent. Expand lightAttachmentSlot, then attachment, and assign the light origin to lightTransform. This example uses a separate Tutorial_Light.prefab with a node named LightOrigin.
    2. The same object needs VehicleAttachmentMonoComponent for runtime discovery. Set attachmentSlotType to Specific and assign the light component to specificAttachmentMonoComponent. The project's CustomEditor adds this companion when drawing the light Inspector; the recipe creates and saves it explicitly.

    For a complete vehicle, create separate origin nodes under MainBody for left and right low beams, high beams, brake lights, reverse lights and indicators. Line up one side, then use Create Mirror and check the other side. Use Duplicate to make another independent light.

    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "prefab_edit",
        "arguments": {
          "json": {
            "path": "${asset}",
            "mode": "create",
            "component": "ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent",
            "values": {
              "lightAttachmentSlot": {
                "attachment": {}
              }
            },
            "children": [
              "LightOrigin"
            ]
          }
        },
        "expect": {
          "equals": {
            "ok": true
          }
        }
      },
      {
        "tool": "prefab_edit",
        "arguments": {
          "json": {
            "path": "${asset}",
            "mode": "update",
            "component": "ShanghaiWindy.Core.VehicleAttachmentMonoComponent",
            "values": {
              "attachmentSlotType": 1
            },
            "references": [
              {
                "property": "specificAttachmentMonoComponent",
                "child": "",
                "component": "ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent"
              }
            ]
          }
        },
        "expect": {
          "equals": {
            "ok": true
          }
        }
      },
      {
        "tool": "prefab_edit",
        "arguments": {
          "json": {
            "path": "${asset}",
            "mode": "update",
            "component": "ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent",
            "references": [
              {
                "property": "lightAttachmentSlot.attachment.lightTransform",
                "child": "LightOrigin"
              }
            ]
          }
        },
        "expect": {
          "equals": {
            "ok": true
          }
        }
      }
    ]
    

    2. Shape and size

    1. Set the shape to Circle. Circle and HalfCircle show radiusSize; this example uses 0.3.
    2. Rectangles use rectSize instead, and CustomShape uses customShapeRenderers; the existing Light/AuthoringSamples assets are a reference.

    Numbered configuration fields in the actual Inspector

    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "prefab_edit",
        "arguments": {
          "json": {
            "path": "${asset}",
            "mode": "update",
            "component": "ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent",
            "values": {
              "lightAttachmentSlot": {
                "attachment": {
                  "lightSizeType": 0,
                  "radiusSize": 0.3
                }
              }
            }
          }
        },
        "expect": {
          "equals": {
            "ok": true
          }
        }
      }
    ]
    

    3. Appearance and visibility

    1. Set lightType to LowBeam, then use Set From Preset to fill its colors. To tune the light by hand, edit baseColor and HDR emissionColor separately. The brightness and radius in the older VT-1A example suit that vehicle.
    2. Keep isAlwaysVisible = true and isBlinker = false, and turn off isAutoNaming for this example. Enabling isBlinker reveals frequency and the fraction of each cycle spent on. At blinkerFrequency = 1 and blinkerStep = 0.5, the light stays on for about half a second per cycle.
    3. lensEmitters holds up to eight lens-glare sampling nodes. beamOrigin sets a separate beam origin, whose local +Z points along the beam. Both are optional for this basic Circle setup. With CustomShape, use Preview lights on/off to check the renderers.

    Numbered configuration fields in the actual Inspector

    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "prefab_edit",
        "arguments": {
          "json": {
            "path": "${asset}",
            "mode": "update",
            "component": "ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent",
            "values": {
              "lightAttachmentSlot": {
                "attachment": {
                  "lightType": 0,
                  "baseColor": {
                    "r": 1,
                    "g": 1,
                    "b": 1,
                    "a": 1
                  },
                  "emissionColor": {
                    "r": 3.5,
                    "g": 3.5,
                    "b": 3.5,
                    "a": 1
                  },
                  "isAlwaysVisible": true,
                  "isBlinker": false,
                  "isAutoNaming": false
                }
              }
            }
          }
        },
        "expect": {
          "equals": {
            "ok": true
          }
        }
      }
    ]
    

    4. Verify

    1. Check the object binding to lightTransform, that the companion runtime components were saved, that the Circle radius and colors were written, and that lensEmitters has at most 8 entries; Inspector screenshots show field locations and values, not runtime behavior, so look at the light in game once as well.
    Click to expand MCP actionsClick to collapse MCP actions
    [
      {
        "tool": "inspect",
        "arguments": {
          "path": "asset:${asset}/GetComponent(ShanghaiWindy.Core.VehicleAttachmentMonoComponent)/attachmentSlotType"
        },
        "expect": {
          "contains": "Specific"
        }
      },
      {
        "tool": "inspect",
        "arguments": {
          "path": "asset:${asset}/GetComponent(ShanghaiWindy.Core.VehicleAttachmentMonoComponent)/specificAttachmentMonoComponent"
        },
        "expect": {
          "contains": "--- VehicleLightAttachmentMonoComponent ---"
        }
      },
      {
        "tool": "inspect",
        "arguments": {
          "path": "asset:${asset}/GetComponent(ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent)/lightAttachmentSlot/attachment/lightTransform/name"
        },
        "expect": {
          "contains": "LightOrigin"
        }
      },
      {
        "tool": "inspect",
        "arguments": {
          "path": "asset:${asset}/GetComponent(ShanghaiWindy.Core.VehicleLightAttachmentMonoComponent)/lightAttachmentSlot/attachment/radiusSize"
        },
        "expect": {
          "contains": "0.3"
        }
      }
    ]
    
    In this article
    Back to top Panzer War Document