Danro/Assets/Scripts/Behaviour/MessageController.cs
Danil Iarosh 7f14981d8b added dialogue system
- Добавил систему диалогов
- Создал классы Sequencer.cs и SequenceAction.cs для воссоздания последовательности действий
- Добавил иеханику последовательности действий в Message.cs и MessageController.cs
2025-12-10 08:32:15 +03:00

47 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using UnityEngine;
namespace RR.Common.Behaviour
{
public class MessageController : Sequencer
{
[SerializeField] private GameObject messagePlaceholderPrefab;
[SerializeField] private GameObject messageBubblePrefab;
private void OnTriggerEnter2D(Collider2D other)
{
if (!IsExecuting && other.CompareTag("Player"))
{
StartCoroutine(ExecuteSequence(other.gameObject));
}
}
public void Add(GameObject targetObject, string text)
{
// Ищем объект "Message Placeholder" среди дочерних объектов
Transform placeholder = targetObject.transform.Find("Message Placeholder");
// Если placeholder не найден, создаем его
if (!placeholder)
{
GameObject placeholderInstance = Instantiate(messagePlaceholderPrefab, targetObject.transform);
if (targetObject.transform.localScale != Vector3.one)
{
placeholderInstance.transform.localScale = Vector3.one / targetObject.transform.localScale.x;
}
placeholderInstance.name = "Message Placeholder";
placeholder = placeholderInstance.transform;
}
// Создаем Message и добавляем его в placeholder
GameObject messageInstance = Instantiate(messageBubblePrefab, placeholder);
Message message = messageInstance.GetComponent<Message>();
if (message)
{
message.Initialize(text);
}
}
}
}