using ColdMint.scripts.character; using ColdMint.scripts.map.events; using ColdMint.scripts.utils; using Godot; namespace ColdMint.scripts.map; /// /// Ai character generation point /// Ai角色生成点 /// public partial class AiCharacterSpawn : Marker2D { private PackedScene? _packedScene; public override void _Ready() { base._Ready(); var resPath = GetMeta("ResPath", Name).AsString(); if (!string.IsNullOrEmpty(resPath)) { _packedScene = GD.Load(resPath); } EventManager.AiCharacterGenerateEvent += OnAiCharacterGenerateEvent; } /// /// When an event is triggered /// 当触发事件时 /// /// public void OnAiCharacterGenerateEvent(AiCharacterGenerateEvent aiCharacterGenerateEvent) { if (GameSceneNodeHolder.AiCharacterContainer == null) { return; } if (_packedScene == null) { return; } var aiCharacter = NodeUtils.InstantiatePackedScene(_packedScene); if (aiCharacter == null) { return; } NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.AiCharacterContainer, aiCharacter); aiCharacter.GlobalPosition = GlobalPosition; } public override void _ExitTree() { EventManager.AiCharacterGenerateEvent -= OnAiCharacterGenerateEvent; } }