Search Results for

    Show / Hide Table of Contents

    VehicleLightAttachment 使用说明

    中文 | English

    在仓库根目录运行以下命令,用本机 Unity MCP 回放本页示例。 命令也会重拍两种语言的配图。

    python Docs/Manual/manual/tools/tutorials.py run vehicle-light-component --capture
    
    点击展开 MCP 操作点击收起 MCP 操作

    准备教学样例。${变量} 由配方提供。

    {
      "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}"
          }
        }
      ]
    }
    

    本例配置一个圆形近光灯。VehicleLightAttachment 是序列化配置数据;挂载到 GameObject 的组件是 VehicleLightAttachmentMonoComponent。字段名保留 C# 原始标识符。

    1. 创建组件并绑定对象

    1. 在载具 prefab 中创建灯光物体,添加 VehicleLightAttachmentMonoComponent。展开 lightAttachmentSlot 和其中的 attachment,将灯光定位节点赋给 lightTransform。本例使用独立的 Tutorial_Light.prefab,节点名为 LightOrigin。
    2. 同一对象上还需要 VehicleAttachmentMonoComponent:attachmentSlotType 设为 Specific,specificAttachmentMonoComponent 指向灯光组件。项目 CustomEditor 显示灯光 Inspector 时会自动补这个伴随组件;配方会显式创建并保存它。

    配置整车时,在 MainBody 下为左右近光、远光、刹车、倒车和转向灯各建定位节点。先校好一侧,再用 创建镜像 - Create Mirror 检查另一侧。要添加独立实例时可用 复制 - Duplicate。

    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "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. 形状与尺寸

    1. 把形状设为 Circle;Circle 与 HalfCircle 显示 radiusSize,本例填 0.3。
    2. 矩形改用 rectSize;CustomShape 改用 customShapeRenderers,现有 Light/AuthoringSamples 资源可作参考。

    真实 Inspector 中带编号高亮的配置字段

    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "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. 外观与可见性

    1. lightType 选 LowBeam。点击 使用预设 - Set From Preset 可应用近光的基础色和 HDR 自发光。手动配色时分别编辑 baseColor 与 emissionColor。旧 VT-1A 图中的亮度和半径是该车的示例值。
    2. 本例保持 isAlwaysVisible = true、isBlinker = false,关闭 isAutoNaming。勾选 isBlinker 后会显示频率与点亮比例。以 blinkerFrequency = 1、blinkerStep = 0.5 为例,每秒约亮半秒。
    3. lensEmitters 是镜片眩光采样节点,最多 8 个。可在 beamOrigin 指定光束的单独原点,节点的局部 +Z 是出光方向。基础 Circle 可将两项留空。使用 CustomShape 时,可用 预览开灯/关灯 查看 Renderer 的切换。

    真实 Inspector 中带编号高亮的配置字段

    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "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. 检查

    1. 确认对象与 lightTransform 绑定、伴随运行时组件已保存、Circle 半径与颜色写入正确、lensEmitters 不超过 8 个;Inspector 截图只证明字段位置与取值,代表不了实际表现,仍需在游戏里再看一次。
    点击展开 MCP 操作点击收起 MCP 操作
    [
      {
        "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