敌人追踪
This commit is contained in:
1 parent
e839c158ac
commit
1aeaebcddb
17 files changed
+297
-2365
No files matched your search
@@ -42,6 +42,29 @@ private void Awake()
|
|||||||
|
|
||||||
**边界**:这条只约束游戏运行时代码。编辑器工具、一次性批处理脚本需要按结构查找节点时可以照常查找。
|
**边界**:这条只约束游戏运行时代码。编辑器工具、一次性批处理脚本需要按结构查找节点时可以照常查找。
|
||||||
|
|
||||||
|
## Inspector 里的字段名怎么显示成中文
|
||||||
|
|
||||||
|
**`[InspectorName]` 管不了普通字段**:Unity 6 的文档对这个特性写的是 "enum value declarations"(只讲枚举值),实测把 `[InspectorName("...")]` 加在 `[SerializeField]` 字段上,字段的 `displayName` 仍是英文原名。别用它来改字段标签。
|
||||||
|
|
||||||
|
想让字段在 Inspector 里显示中文,只有这几条路:
|
||||||
|
|
||||||
|
1. **中文字段名**(要精确控制标签时用这个)。C# 允许 Unicode 标识符,字段名写中文,Inspector 里就显示这个中文——编辑器不会给中文插空格、术语表也不会翻译它(实测 `NicifyVariableName("可到达半径")` → `可到达半径`)。**改名前必须加 `[FormerlySerializedAs("旧名")]`**:Unity 按字段名反序列化,直接改名会清空 Inspector 里已经接好的引用。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 语义是「玩家可到达的半径」,Inspector 里就显示「可到达半径」
|
||||||
|
[Tooltip("玩家可到达的半径,单位米")]
|
||||||
|
[FormerlySerializedAs("reachableRadius")]
|
||||||
|
[SerializeField] private float 可到达半径 = 5f;
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **自定义 Editor**:`[CustomEditor(typeof(Xxx))]` 里 `EditorGUILayout.PropertyField(prop, new GUIContent("可到达半径"))`。字段少又必须换标签时才用,字段一多就是维护负担。
|
||||||
|
|
||||||
|
3. **不改标签,用 `[Tooltip]` 补说明**:字段名保持英文(项目现状),鼠标悬停能看到中文说明。字段名本身够清楚时,这条就够了。
|
||||||
|
|
||||||
|
**中文名按「这个字段在这个项目里干什么」来定,不要直译英文名**:表示玩家可到达的半径,就写「可到达半径」,不要写成「半径」或「可达半径值」——同一个 Inspector 里经常并列出现好几个半径 / 距离 / 目标,标签本身就得能分清谁是谁。
|
||||||
|
|
||||||
|
**顺带一个坑**:编辑器语言是中文时,Unity 会按**内置术语表**翻译常见字段名(`prefab` → 预制件、`radius` → 半径 之类),只覆盖常见词——字段名一旦不是标准词,标签就原样显示英文。所以 Inspector 上看到的中文未必写在代码里,别去 `.cs` 里搜。
|
||||||
|
|
||||||
## 动画一律用 Animator 播,不用 legacy 的 Animation 组件
|
## 动画一律用 Animator 播,不用 legacy 的 Animation 组件
|
||||||
|
|
||||||
要在物体上播放动画时,走 `Animator`(状态 / 触发器 / 参数):
|
要在物体上播放动画时,走 `Animator`(状态 / 触发器 / 参数):
|
||||||
|
|||||||
@@ -121,9 +121,9 @@ Texture2D:
|
|||||||
Hash: 00000000000000000000000000000000
|
Hash: 00000000000000000000000000000000
|
||||||
m_IsAlphaChannelOptional: 0
|
m_IsAlphaChannelOptional: 0
|
||||||
serializedVersion: 4
|
serializedVersion: 4
|
||||||
m_Width: 2048
|
m_Width: 1
|
||||||
m_Height: 2048
|
m_Height: 1
|
||||||
m_CompleteImageSize: 4194304
|
m_CompleteImageSize: 1
|
||||||
m_MipsStripped: 0
|
m_MipsStripped: 0
|
||||||
m_TextureFormat: 1
|
m_TextureFormat: 1
|
||||||
m_MipCount: 1
|
m_MipCount: 1
|
||||||
@@ -148,8 +148,8 @@ Texture2D:
|
|||||||
m_LightmapFormat: 0
|
m_LightmapFormat: 0
|
||||||
m_ColorSpace: 0
|
m_ColorSpace: 0
|
||||||
m_PlatformBlob:
|
m_PlatformBlob:
|
||||||
image data: 4194304
|
image data: 1
|
||||||
_typelessdata: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040607070807060401000402000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030608090806030000000000000004060706040000000004060709090707050100000000000000020608080a0b090706040100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Line truncated
|
_typelessdata: 00
|
||||||
m_StreamData:
|
m_StreamData:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
offset: 0
|
offset: 0
|
||||||
@@ -215,350 +215,8 @@ MonoBehaviour:
|
|||||||
m_SourceFontFilePath:
|
m_SourceFontFilePath:
|
||||||
m_AtlasPopulationMode: 1
|
m_AtlasPopulationMode: 1
|
||||||
InternalDynamicOS: 0
|
InternalDynamicOS: 0
|
||||||
m_GlyphTable:
|
m_GlyphTable: []
|
||||||
- m_Index: 7486
|
m_CharacterTable: []
|
||||||
m_Metrics:
|
|
||||||
m_Width: 64.96875
|
|
||||||
m_Height: 86.046875
|
|
||||||
m_HorizontalBearingX: 2.4375
|
|
||||||
m_HorizontalBearingY: 78.9375
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 10
|
|
||||||
m_Width: 66
|
|
||||||
m_Height: 87
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 1148
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 62.375
|
|
||||||
m_Height: 86.484375
|
|
||||||
m_HorizontalBearingX: 5.3125
|
|
||||||
m_HorizontalBearingY: 79.921875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 116
|
|
||||||
m_Width: 63
|
|
||||||
m_Height: 87
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 7029
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 62.375
|
|
||||||
m_Height: 86.9375
|
|
||||||
m_HorizontalBearingX: 5.3125
|
|
||||||
m_HorizontalBearingY: 79.828125
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 222
|
|
||||||
m_Width: 63
|
|
||||||
m_Height: 88
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 5911
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 63.4375
|
|
||||||
m_Height: 84.5
|
|
||||||
m_HorizontalBearingX: 5.046875
|
|
||||||
m_HorizontalBearingY: 77.125
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 329
|
|
||||||
m_Width: 64
|
|
||||||
m_Height: 86
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 2613
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 64.625
|
|
||||||
m_Height: 84.421875
|
|
||||||
m_HorizontalBearingX: 4.046875
|
|
||||||
m_HorizontalBearingY: 75.875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 92
|
|
||||||
m_Y: 116
|
|
||||||
m_Width: 65
|
|
||||||
m_Height: 85
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 2085
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 67.234375
|
|
||||||
m_Height: 86.953125
|
|
||||||
m_HorizontalBearingX: 2.515625
|
|
||||||
m_HorizontalBearingY: 80.015625
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 92
|
|
||||||
m_Y: 220
|
|
||||||
m_Width: 68
|
|
||||||
m_Height: 88
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 4272
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 68.390625
|
|
||||||
m_Height: 87.109375
|
|
||||||
m_HorizontalBearingX: 2.34375
|
|
||||||
m_HorizontalBearingY: 79.734375
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 176
|
|
||||||
m_Y: 10
|
|
||||||
m_Width: 69
|
|
||||||
m_Height: 88
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 2936
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 64.34375
|
|
||||||
m_Height: 87.75
|
|
||||||
m_HorizontalBearingX: 3.515625
|
|
||||||
m_HorizontalBearingY: 79.921875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 434
|
|
||||||
m_Width: 65
|
|
||||||
m_Height: 88
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 3449
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 61.109375
|
|
||||||
m_Height: 87.296875
|
|
||||||
m_HorizontalBearingX: 8.640625
|
|
||||||
m_HorizontalBearingY: 80.09375
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 541
|
|
||||||
m_Width: 62
|
|
||||||
m_Height: 89
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 994
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 67.140625
|
|
||||||
m_Height: 87.296875
|
|
||||||
m_HorizontalBearingX: 3.328125
|
|
||||||
m_HorizontalBearingY: 80.09375
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 10
|
|
||||||
m_Y: 649
|
|
||||||
m_Width: 68
|
|
||||||
m_Height: 89
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 5813
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 66.78125
|
|
||||||
m_Height: 84.875
|
|
||||||
m_HorizontalBearingX: 4.046875
|
|
||||||
m_HorizontalBearingY: 79.5625
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 93
|
|
||||||
m_Y: 327
|
|
||||||
m_Width: 67
|
|
||||||
m_Height: 86
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 5818
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 66.5
|
|
||||||
m_Height: 88.015625
|
|
||||||
m_HorizontalBearingX: 3.15625
|
|
||||||
m_HorizontalBearingY: 79.921875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 91
|
|
||||||
m_Y: 541
|
|
||||||
m_Width: 67
|
|
||||||
m_Height: 89
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 1756
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 64.53125
|
|
||||||
m_Height: 82.34375
|
|
||||||
m_HorizontalBearingX: 5.3125
|
|
||||||
m_HorizontalBearingY: 76.046875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 176
|
|
||||||
m_Y: 117
|
|
||||||
m_Width: 65
|
|
||||||
m_Height: 84
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 1180
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 66.6875
|
|
||||||
m_Height: 87.21875
|
|
||||||
m_HorizontalBearingX: 4.59375
|
|
||||||
m_HorizontalBearingY: 79.921875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 94
|
|
||||||
m_Y: 432
|
|
||||||
m_Width: 68
|
|
||||||
m_Height: 88
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 699
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 61.203125
|
|
||||||
m_Height: 85.140625
|
|
||||||
m_HorizontalBearingX: 5.84375
|
|
||||||
m_HorizontalBearingY: 79.921875
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 179
|
|
||||||
m_Y: 220
|
|
||||||
m_Width: 63
|
|
||||||
m_Height: 86
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 6466
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 66.6875
|
|
||||||
m_Height: 87.03125
|
|
||||||
m_HorizontalBearingX: 4.5
|
|
||||||
m_HorizontalBearingY: 79.828125
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 179
|
|
||||||
m_Y: 325
|
|
||||||
m_Width: 68
|
|
||||||
m_Height: 88
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 1299
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 62.28125
|
|
||||||
m_Height: 87.109375
|
|
||||||
m_HorizontalBearingX: 5.84375
|
|
||||||
m_HorizontalBearingY: 79.015625
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 261
|
|
||||||
m_Y: 117
|
|
||||||
m_Width: 64
|
|
||||||
m_Height: 89
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
- m_Index: 9280
|
|
||||||
m_Metrics:
|
|
||||||
m_Width: 24.109375
|
|
||||||
m_Height: 68.75
|
|
||||||
m_HorizontalBearingX: 3.515625
|
|
||||||
m_HorizontalBearingY: 48.59375
|
|
||||||
m_HorizontalAdvance: 72
|
|
||||||
m_GlyphRect:
|
|
||||||
m_X: 261
|
|
||||||
m_Y: 225
|
|
||||||
m_Width: 25
|
|
||||||
m_Height: 70
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasIndex: 0
|
|
||||||
m_ClassDefinitionType: 0
|
|
||||||
m_CharacterTable:
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 36864
|
|
||||||
m_GlyphIndex: 7486
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 20986
|
|
||||||
m_GlyphIndex: 1148
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 35774
|
|
||||||
m_GlyphIndex: 7029
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 32622
|
|
||||||
m_GlyphIndex: 5911
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 24320
|
|
||||||
m_GlyphIndex: 2613
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 22987
|
|
||||||
m_GlyphIndex: 2085
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 28216
|
|
||||||
m_GlyphIndex: 4272
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 25103
|
|
||||||
m_GlyphIndex: 2936
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 26242
|
|
||||||
m_GlyphIndex: 3449
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 20572
|
|
||||||
m_GlyphIndex: 994
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 32487
|
|
||||||
m_GlyphIndex: 5813
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 32493
|
|
||||||
m_GlyphIndex: 5818
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 22238
|
|
||||||
m_GlyphIndex: 1756
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 21040
|
|
||||||
m_GlyphIndex: 1180
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 20027
|
|
||||||
m_GlyphIndex: 699
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 33756
|
|
||||||
m_GlyphIndex: 6466
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 21333
|
|
||||||
m_GlyphIndex: 1299
|
|
||||||
m_Scale: 1
|
|
||||||
- m_ElementType: 1
|
|
||||||
m_Unicode: 65307
|
|
||||||
m_GlyphIndex: 9280
|
|
||||||
m_Scale: 1
|
|
||||||
m_AtlasTextures:
|
m_AtlasTextures:
|
||||||
- {fileID: -4117240312920070829}
|
- {fileID: -4117240312920070829}
|
||||||
m_AtlasTextureIndex: 0
|
m_AtlasTextureIndex: 0
|
||||||
@@ -569,136 +227,12 @@ MonoBehaviour:
|
|||||||
m_AtlasHeight: 2048
|
m_AtlasHeight: 2048
|
||||||
m_AtlasPadding: 9
|
m_AtlasPadding: 9
|
||||||
m_AtlasRenderMode: 4165
|
m_AtlasRenderMode: 4165
|
||||||
m_UsedGlyphRects:
|
m_UsedGlyphRects: []
|
||||||
- m_X: 0
|
|
||||||
m_Y: 0
|
|
||||||
m_Width: 85
|
|
||||||
m_Height: 106
|
|
||||||
- m_X: 0
|
|
||||||
m_Y: 106
|
|
||||||
m_Width: 82
|
|
||||||
m_Height: 106
|
|
||||||
- m_X: 0
|
|
||||||
m_Y: 212
|
|
||||||
m_Width: 82
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 0
|
|
||||||
m_Y: 319
|
|
||||||
m_Width: 83
|
|
||||||
m_Height: 105
|
|
||||||
- m_X: 82
|
|
||||||
m_Y: 106
|
|
||||||
m_Width: 84
|
|
||||||
m_Height: 104
|
|
||||||
- m_X: 82
|
|
||||||
m_Y: 210
|
|
||||||
m_Width: 87
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 166
|
|
||||||
m_Y: 0
|
|
||||||
m_Width: 88
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 0
|
|
||||||
m_Y: 424
|
|
||||||
m_Width: 84
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 0
|
|
||||||
m_Y: 531
|
|
||||||
m_Width: 81
|
|
||||||
m_Height: 108
|
|
||||||
- m_X: 0
|
|
||||||
m_Y: 639
|
|
||||||
m_Width: 87
|
|
||||||
m_Height: 108
|
|
||||||
- m_X: 83
|
|
||||||
m_Y: 317
|
|
||||||
m_Width: 86
|
|
||||||
m_Height: 105
|
|
||||||
- m_X: 81
|
|
||||||
m_Y: 531
|
|
||||||
m_Width: 86
|
|
||||||
m_Height: 108
|
|
||||||
- m_X: 166
|
|
||||||
m_Y: 107
|
|
||||||
m_Width: 84
|
|
||||||
m_Height: 103
|
|
||||||
- m_X: 84
|
|
||||||
m_Y: 422
|
|
||||||
m_Width: 87
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 169
|
|
||||||
m_Y: 210
|
|
||||||
m_Width: 82
|
|
||||||
m_Height: 105
|
|
||||||
- m_X: 169
|
|
||||||
m_Y: 315
|
|
||||||
m_Width: 87
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 251
|
|
||||||
m_Y: 107
|
|
||||||
m_Width: 83
|
|
||||||
m_Height: 108
|
|
||||||
- m_X: 251
|
|
||||||
m_Y: 215
|
|
||||||
m_Width: 44
|
|
||||||
m_Height: 89
|
|
||||||
m_FreeGlyphRects:
|
m_FreeGlyphRects:
|
||||||
- m_X: 85
|
|
||||||
m_Y: 0
|
|
||||||
m_Width: 81
|
|
||||||
m_Height: 106
|
|
||||||
- m_X: 0
|
- m_X: 0
|
||||||
m_Y: 747
|
m_Y: 0
|
||||||
m_Width: 2047
|
m_Width: 2047
|
||||||
m_Height: 1300
|
|
||||||
- m_X: 82
|
|
||||||
m_Y: 317
|
|
||||||
m_Width: 1
|
|
||||||
m_Height: 2
|
|
||||||
- m_X: 87
|
|
||||||
m_Y: 639
|
|
||||||
m_Width: 1960
|
|
||||||
m_Height: 1408
|
|
||||||
- m_X: 83
|
|
||||||
m_Y: 422
|
|
||||||
m_Width: 1
|
|
||||||
m_Height: 2
|
|
||||||
- m_X: 84
|
|
||||||
m_Y: 529
|
|
||||||
m_Width: 1963
|
|
||||||
m_Height: 2
|
|
||||||
- m_X: 167
|
|
||||||
m_Y: 529
|
|
||||||
m_Width: 1880
|
|
||||||
m_Height: 1518
|
|
||||||
- m_X: 171
|
|
||||||
m_Y: 422
|
|
||||||
m_Width: 1876
|
|
||||||
m_Height: 1625
|
|
||||||
- m_X: 250
|
|
||||||
m_Y: 107
|
|
||||||
m_Width: 1
|
|
||||||
m_Height: 103
|
|
||||||
- m_X: 254
|
|
||||||
m_Y: 0
|
|
||||||
m_Width: 1793
|
|
||||||
m_Height: 107
|
|
||||||
- m_X: 334
|
|
||||||
m_Y: 0
|
|
||||||
m_Width: 1713
|
|
||||||
m_Height: 2047
|
m_Height: 2047
|
||||||
- m_X: 256
|
|
||||||
m_Y: 304
|
|
||||||
m_Width: 1791
|
|
||||||
m_Height: 1743
|
|
||||||
- m_X: 295
|
|
||||||
m_Y: 215
|
|
||||||
m_Width: 1752
|
|
||||||
m_Height: 1832
|
|
||||||
- m_X: 251
|
|
||||||
m_Y: 304
|
|
||||||
m_Width: 1796
|
|
||||||
m_Height: 11
|
|
||||||
m_FontFeatureTable:
|
m_FontFeatureTable:
|
||||||
m_MultipleSubstitutionRecords: []
|
m_MultipleSubstitutionRecords: []
|
||||||
m_LigatureSubstitutionRecords: []
|
m_LigatureSubstitutionRecords: []
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 6cfa95cf7b0a943c4904a13297c823e3, type: 3}
|
m_Script: {fileID: 11500000, guid: 6cfa95cf7b0a943c4904a13297c823e3, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::EnemyChaseController
|
m_EditorClassIdentifier: Assembly-CSharp::EnemyChaseController
|
||||||
target: {fileID: 0}
|
target: {fileID: 9034613337173532632, guid: 905259bd26d574ba586c38b5e91d0b7f, type: 3}
|
||||||
moveSpeed: 3
|
moveSpeed: 3
|
||||||
acceleration: 10
|
acceleration: 10
|
||||||
turnSpeed: 10
|
turnSpeed: 10
|
||||||
@@ -294,7 +294,7 @@ PrefabInstance:
|
|||||||
- target: {fileID: 4708354386871929370, guid: 305d0010d8b0944179d12671922ebbdb,
|
- target: {fileID: 4708354386871929370, guid: 305d0010d8b0944179d12671922ebbdb,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: m_IsActive
|
propertyPath: m_IsActive
|
||||||
value: 0
|
value: 1
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8132815969298277413, guid: 305d0010d8b0944179d12671922ebbdb,
|
- target: {fileID: 8132815969298277413, guid: 305d0010d8b0944179d12671922ebbdb,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ MeshRenderer:
|
|||||||
m_ReflectionProbeUsage: 1
|
m_ReflectionProbeUsage: 1
|
||||||
m_RayTracingMode: 2
|
m_RayTracingMode: 2
|
||||||
m_RayTraceProcedural: 0
|
m_RayTraceProcedural: 0
|
||||||
|
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||||
|
m_RayTracingAccelStructBuildFlags: 1
|
||||||
|
m_SmallMeshCulling: 1
|
||||||
|
m_ForceMeshLod: -1
|
||||||
|
m_MeshLodSelectionBias: 0
|
||||||
m_RenderingLayerMask: 1
|
m_RenderingLayerMask: 1
|
||||||
m_RendererPriority: 0
|
m_RendererPriority: 0
|
||||||
m_Materials:
|
m_Materials:
|
||||||
@@ -81,9 +86,11 @@ MeshRenderer:
|
|||||||
m_AutoUVMaxDistance: 0.5
|
m_AutoUVMaxDistance: 0.5
|
||||||
m_AutoUVMaxAngle: 89
|
m_AutoUVMaxAngle: 89
|
||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_GlobalIlluminationMeshLod: 0
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!143 &7156104879043876676
|
--- !u!143 &7156104879043876676
|
||||||
CharacterController:
|
CharacterController:
|
||||||
@@ -100,7 +107,6 @@ CharacterController:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 0
|
m_Bits: 0
|
||||||
m_LayerOverridePriority: 0
|
m_LayerOverridePriority: 0
|
||||||
m_IsTrigger: 0
|
|
||||||
m_ProvidesContacts: 0
|
m_ProvidesContacts: 0
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
@@ -138,6 +144,7 @@ GameObject:
|
|||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 9034613337173532632}
|
- component: {fileID: 9034613337173532632}
|
||||||
|
- component: {fileID: 4855449060187578418}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: PlayerRoot
|
m_Name: PlayerRoot
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -161,3 +168,19 @@ Transform:
|
|||||||
- {fileID: 3405330547492594424}
|
- {fileID: 3405330547492594424}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &4855449060187578418
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 3051461309865635013}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 2aef3dd8d016749eba828b4711807579, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::PrefabSpawner
|
||||||
|
prefab: {fileID: 1831812836464488284, guid: f87a6591649d84a678b76e550f60c5f1, type: 3}
|
||||||
|
target: {fileID: 3405330547492594424}
|
||||||
|
interval: 1
|
||||||
|
radius: 5
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8407dd29e03460a49b26942f7405cf2e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"TestSuite":"","Date":0,"Player":{"Development":false,"ScreenWidth":0,"ScreenHeight":0,"ScreenRefreshRate":0,"Fullscreen":false,"Vsync":0,"AntiAliasing":0,"Batchmode":false,"RenderThreadingMode":"MultiThreaded","MtRendering":false,"GraphicsJobs":false,"GpuSkinning":true,"Platform":"","ColorSpace":"","AnisotropicFiltering":"","BlendWeights":"","GraphicsApi":"","ScriptingBackend":"IL2CPP","AndroidTargetSdkVersion":"AndroidApiLevelAuto","AndroidBuildSystem":"Gradle","BuildTarget":"iOS","StereoRenderingPath":"MultiPass"},"Hardware":{"OperatingSystem":"","DeviceModel":"","DeviceName":"","ProcessorType":"","ProcessorCount":0,"GraphicsDeviceName":"","SystemMemorySizeMB":0},"Editor":{"Version":"6000.3.26f1","Branch":"6000.3/staging","Changeset":"de8167e7440c","Date":1790706048},"Dependencies":["com.coplaydev.unity-mcp@10.3.0","com.esotericsoftware.spine.spine-csharp@4.2.37","com.esotericsoftware.spine.spine-unity@4.2.120","com.esotericsoftware.spine.timeline@4.2.15","com.esotericsoftware.spine.urp-shaders@4.2.49","com.unity.2d.sprite@1.0.0","com.unity.ai.assistant@2.20.0-pre.2","com.unity.ai.inference@2.6.1","com.unity.burst@1.8.30","com.unity.cinemachine@2.10.7","com.unity.collab-proxy@2.13.6","com.unity.collections@2.6.8","com.unity.dt.app-ui@2.2.4","com.unity.ext.nunit@2.0.5","com.unity.ide.rider@3.0.40","com.unity.ide.visualstudio@2.0.26","com.unity.ide.vscode@1.2.5","com.unity.mathematics@1.3.3","com.unity.modules.accessibility@1.0.0","com.unity.modules.adaptiveperformance@1.0.0","com.unity.modules.ai@1.0.0","com.unity.modules.androidjni@1.0.0","com.unity.modules.animation@1.0.0","com.unity.modules.assetbundle@1.0.0","com.unity.modules.audio@1.0.0","com.unity.modules.cloth@1.0.0","com.unity.modules.director@1.0.0","com.unity.modules.hierarchycore@1.0.0","com.unity.modules.imageconversion@1.0.0","com.unity.modules.imgui@1.0.0","com.unity.modules.jsonserialize@1.0.0","com.unity.modules.particlesystem@1.0.0","com.unity.modules.physics@1.0.0","com.unity.modules.physics2d@1.0.0","com.unity.modules.screencapture@1.0.0","com.unity.modules.subsystems@1.0.0","com.unity.modules.terrain@1.0.0","com.unity.modules.terrainphysics@1.0.0","com.unity.modules.tilemap@1.0.0","com.unity.modules.ui@1.0.0","com.unity.modules.uielements@1.0.0","com.unity.modules.umbra@1.0.0","com.unity.modules.unityanalytics@1.0.0","com.unity.modules.unitywebrequest@1.0.0","com.unity.modules.unitywebrequestassetbundle@1.0.0","com.unity.modules.unitywebrequestaudio@1.0.0","com.unity.modules.unitywebrequesttexture@1.0.0","com.unity.modules.unitywebrequestwww@1.0.0","com.unity.modules.vectorgraphics@1.0.0","com.unity.modules.vehicles@1.0.0","com.unity.modules.video@1.0.0","com.unity.modules.vr@1.0.0","com.unity.modules.wind@1.0.0","com.unity.modules.xr@1.0.0","com.unity.multiplayer.center@1.0.1","com.unity.nuget.mono-cecil@1.11.6","com.unity.nuget.newtonsoft-json@3.2.2","com.unity.render-pipelines.core@17.3.0","com.unity.render-pipelines.universal@17.3.0","com.unity.render-pipelines.universal-config@17.0.3","com.unity.searcher@4.9.5","com.unity.shadergraph@17.3.0","com.unity.test-framework.performance@3.5.0","com.unity.test-framework@1.6.0","com.unity.timeline@1.8.13","com.unity.ugui@2.0.0","com.unity.visualeffectgraph@17.3.0","com.unity.visualscripting@1.9.12"],"Results":[]}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e3620f394d3ff45269bf1c4a6eccf2f9
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"MeasurementCount":-1}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0e51b92c67e914fb381f04cd84dfdaa6
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+46
-1880
File diff suppressed because it is too large.
Load diff
@@ -3,8 +3,9 @@ using UnityEngine;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 敌人追踪:朝目标(玩家)移动,进入销毁半径后自我销毁。
|
/// 敌人追踪:朝目标(玩家)移动,进入销毁半径后自我销毁。
|
||||||
///
|
///
|
||||||
/// 目标引用在 Inspector / 预制体实例里接好——预制体资产本身存不下场景对象,
|
/// 目标来源两种:场景里手摆的敌人在 Inspector / 预制体实例里接好(预制体资产本身存不下场景对象,
|
||||||
/// 所以每个场景实例各自接一次;代码里不按名字 / 标签查找节点。
|
/// 所以每个场景实例各自接一次);运行时生成的敌人由生成方(PrefabSpawner)在 Instantiate 之后
|
||||||
|
/// 调 SetTarget 传进来。代码里不按名字 / 标签查找节点。
|
||||||
/// 移动直接改 transform,不依赖 CharacterController / Rigidbody,只在水平面内走,
|
/// 移动直接改 transform,不依赖 CharacterController / Rigidbody,只在水平面内走,
|
||||||
/// 高度保持不变。
|
/// 高度保持不变。
|
||||||
///
|
///
|
||||||
@@ -56,13 +57,25 @@ public class EnemyChaseController : MonoBehaviour
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
if (target == null)
|
|
||||||
Debug.LogError("[EnemyChaseController] 没有指定追踪目标(target),请在 Inspector / 预制体实例里拖入玩家。", this);
|
|
||||||
|
|
||||||
if (animator == null)
|
if (animator == null)
|
||||||
Debug.LogError("[EnemyChaseController] 没有指定 Animator(animator),死亡动画不会播。", this);
|
Debug.LogError("[EnemyChaseController] 没有指定 Animator(animator),死亡动画不会播。", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
// 放在 Start 而不是 Awake:敌人是 Instantiate 出来的,生成方在实例化之后才调 SetTarget,
|
||||||
|
// 而 Instantiate 会立刻跑 Awake,那时目标还没递进来。
|
||||||
|
if (target == null)
|
||||||
|
Debug.LogError("[EnemyChaseController] 没有追踪目标(target):请在 Inspector / 预制体实例里拖入玩家," +
|
||||||
|
"或由生成方(PrefabSpawner)在实例化后调 SetTarget 传入。", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>由生成方在实例化之后调用,把追踪目标接进来;场景里手摆的敌人直接在 Inspector 接。</summary>
|
||||||
|
public void SetTarget(Transform value)
|
||||||
|
{
|
||||||
|
target = value;
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (_dying)
|
if (_dying)
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 每隔 x 秒,在自身半径 n 米的范围内随机生成一个预制体,并把追踪目标递给它。
|
||||||
|
///
|
||||||
|
/// 用法:挂在场景里任意物体上,把要生成的预制体拖到 prefab 字段,把玩家根节点拖到 target 字段,
|
||||||
|
/// 再填间隔和半径。
|
||||||
|
/// 生成位置在以自身为圆心、半径 n 米的**水平圆面**内(Y 跟自身一致),不会掉到地下或飘到天上。
|
||||||
|
/// 生成的物体放在场景根节点下,朝向用 Identity。
|
||||||
|
///
|
||||||
|
/// 目标传递:生成出来的敌人拿不到场景里的玩家引用(预制体资产存不下场景对象),
|
||||||
|
/// 所以在 Instantiate 之后把 target 赋给它身上的 EnemyChaseController。
|
||||||
|
/// </summary>
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class PrefabSpawner : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("敌人引用(必须在 Inspector / 预制体里指定)")]
|
||||||
|
[Tooltip("要生成的预制体,根节点上必须有 EnemyChaseController")]
|
||||||
|
[SerializeField] private GameObject prefab;
|
||||||
|
|
||||||
|
[Tooltip("生成后赋给敌人的追踪目标,拖玩家根节点进来")]
|
||||||
|
[SerializeField] private Transform target;
|
||||||
|
|
||||||
|
[Header("生成")]
|
||||||
|
[Tooltip("生成间隔(秒),必须大于 0")]
|
||||||
|
[SerializeField] private float interval = 1f;
|
||||||
|
|
||||||
|
[Tooltip("随机范围半径(米),以自身位置为圆心")]
|
||||||
|
[SerializeField] private float radius = 5f;
|
||||||
|
|
||||||
|
private float _timer;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (prefab == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("[PrefabSpawner] 没有指定要生成的预制体(prefab),请在 Inspector 里拖入。", this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
Debug.LogError("[PrefabSpawner] 没有指定目标(target),生成出来的敌人不会有追踪目标。", this);
|
||||||
|
|
||||||
|
if (prefab.GetComponent<EnemyChaseController>() == null)
|
||||||
|
Debug.LogError("[PrefabSpawner] 这个预制体上没有 EnemyChaseController,目标传不进去。", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (prefab == null)
|
||||||
|
return; // Awake 已经报过错
|
||||||
|
|
||||||
|
_timer += Time.deltaTime;
|
||||||
|
if (_timer < interval)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_timer -= interval;
|
||||||
|
Spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>在自身半径 radius 米的水平圆面内随机取一点,生成预制体。</summary>
|
||||||
|
private void Spawn()
|
||||||
|
{
|
||||||
|
Vector2 offset = Random.insideUnitCircle * radius;
|
||||||
|
Vector3 position = transform.position + new Vector3(offset.x, 0f, offset.y);
|
||||||
|
|
||||||
|
GameObject instance = Instantiate(prefab, position, Quaternion.identity);
|
||||||
|
|
||||||
|
// 实例拿不到场景里的玩家引用,这里递进去
|
||||||
|
EnemyChaseController enemy = instance.GetComponent<EnemyChaseController>();
|
||||||
|
if (enemy != null)
|
||||||
|
enemy.SetTarget(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2aef3dd8d016749eba828b4711807579
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using Cinemachine;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按屏幕方向切换虚拟相机的跟随距离。
|
||||||
|
///
|
||||||
|
/// 挂在 Canvas 或任意「拉伸铺满」的 UI 节点上(这类节点的尺寸会随屏幕变化,Unity 才会回调),
|
||||||
|
/// 再把要改的虚拟相机拖到 virtualCamera 字段。该虚拟相机的 Body 必须是 Framing Transposer
|
||||||
|
/// (Camera Distance 是 Body 上的字段,不在虚拟相机组件本身)。
|
||||||
|
///
|
||||||
|
/// 触发时机:Unity 只在 RectTransform 尺寸变化时调用 OnRectTransformDimensionsChange,
|
||||||
|
/// 所以这里没有 Update、不轮询、初始化时不写值;只有屏幕方向真的翻转那一次才写一次距离。
|
||||||
|
/// (尺寸变了但方向没变——比如布局调整——也不会写。)
|
||||||
|
/// </summary>
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class CameraDistanceByOrientation : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("引用(必须在 Inspector / 预制体里指定)")]
|
||||||
|
[Tooltip("要改跟随距离的虚拟相机;它的 Body 必须是 Framing Transposer")]
|
||||||
|
[SerializeField] private CinemachineVirtualCamera virtualCamera;
|
||||||
|
|
||||||
|
[Header("相机距离")]
|
||||||
|
[Tooltip("横屏时的 Camera Distance")]
|
||||||
|
[SerializeField] private float landscapeDistance = 13f;
|
||||||
|
|
||||||
|
[Tooltip("竖屏时的 Camera Distance")]
|
||||||
|
[SerializeField] private float portraitDistance = 30f;
|
||||||
|
|
||||||
|
private CinemachineFramingTransposer _framingTransposer;
|
||||||
|
private bool _isPortrait;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (GetComponent<RectTransform>() == null)
|
||||||
|
Debug.LogError("[CameraDistanceByOrientation] 这个物体没有 RectTransform,收不到尺寸变化回调;" +
|
||||||
|
"请挂到 Canvas 或任意拉伸铺满的 UI 节点上。", this);
|
||||||
|
|
||||||
|
if (virtualCamera == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("[CameraDistanceByOrientation] 没有指定 virtualCamera,请在 Inspector 里拖入。", this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_framingTransposer = virtualCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
|
||||||
|
if (_framingTransposer == null)
|
||||||
|
Debug.LogError("[CameraDistanceByOrientation] 虚拟相机的 Body 不是 Framing Transposer,改不了 Camera Distance。", this);
|
||||||
|
|
||||||
|
// 只记下开局方向,不写相机
|
||||||
|
_isPortrait = IsPortrait();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>RectTransform 尺寸变化时由 Unity 调用(屏幕旋转、分辨率变化都会触发)。</summary>
|
||||||
|
private void OnRectTransformDimensionsChange()
|
||||||
|
{
|
||||||
|
bool portrait = IsPortrait();
|
||||||
|
if (portrait == _isPortrait)
|
||||||
|
return; // 尺寸变了但方向没变,不动相机
|
||||||
|
|
||||||
|
_isPortrait = portrait; // 只在翻转的这一次写值
|
||||||
|
|
||||||
|
if (_framingTransposer == null)
|
||||||
|
return; // Awake 已经报过错
|
||||||
|
|
||||||
|
_framingTransposer.m_CameraDistance = portrait ? portraitDistance : landscapeDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>屏幕高度大于宽度算竖屏。编辑器里拖动 Game 视图尺寸也能触发,方便验证。</summary>
|
||||||
|
private static bool IsPortrait() => Screen.height > Screen.width;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 508bb4f2c6ebb49ffbe7c3cb6ee43239
|
||||||
@@ -34,7 +34,8 @@ GraphicsSettings:
|
|||||||
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
|
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
|
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
|
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
m_PreloadedShaders: []
|
m_PreloadedShaders:
|
||||||
|
- {fileID: 20000000, guid: c2e91508e48ee474b871d4dd48d772a3, type: 2}
|
||||||
m_PreloadShadersBatchTimeLimit: -1
|
m_PreloadShadersBatchTimeLimit: -1
|
||||||
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
|
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
|
||||||
type: 0}
|
type: 0}
|
||||||
|
|||||||
@@ -148,7 +148,8 @@ PlayerSettings:
|
|||||||
visionOSBundleVersion: 1.0
|
visionOSBundleVersion: 1.0
|
||||||
tvOSBundleVersion: 1.0
|
tvOSBundleVersion: 1.0
|
||||||
bundleVersion: 0.1.0
|
bundleVersion: 0.1.0
|
||||||
preloadedAssets: []
|
preloadedAssets:
|
||||||
|
- {fileID: 11400000, guid: 1b1c20d82303e4b5781c3ef50ac1449f, type: 2}
|
||||||
metroInputSource: 0
|
metroInputSource: 0
|
||||||
wsaTransparentSwapchain: 0
|
wsaTransparentSwapchain: 0
|
||||||
m_HolographicPauseOnTrackingLoss: 1
|
m_HolographicPauseOnTrackingLoss: 1
|
||||||
|
|||||||
Reference in new issue
Block a user