feature: Message behaviour separation

This commit is contained in:
Gerard Gascón 2024-01-26 20:44:43 +01:00
parent c66047cd26
commit 4b5689a283
7 changed files with 72 additions and 12 deletions

View file

@ -0,0 +1,12 @@
using System;
using UnityEngine;
namespace Messaging {
public class Message : MonoBehaviour{
public RectTransform RectTransform { private set; get; }
private void Awake() {
RectTransform = GetComponent<RectTransform>();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d8cc3fce6c7f415fa982510d4778f914
timeCreated: 1706297952

View file

@ -0,0 +1,14 @@
using System;
using UnityEngine;
namespace Messaging {
public class MessageManager : MonoBehaviour{
[SerializeField] private MessageStructureGenerator messageStructureGenerator;
private Message[] _messages;
private void Awake() {
_messages = messageStructureGenerator.GenerateMessages();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7f1284442a5c4154b8d794493ae14b5e
timeCreated: 1706297692

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
namespace Messaging {
@ -6,21 +7,21 @@ namespace Messaging {
[SerializeField, Min(0)] private int maxVisibleMessages = 3;
[SerializeField, Min(0)] private int messageHeight = 16;
[SerializeField] private RectTransform messagePrefab;
private void Awake() {
GenerateMessages();
}
[SerializeField] private Message messagePrefab;
private void GenerateMessages() {
public Message[] GenerateMessages() {
List<Message> messages = new();
for (int i = 0; i < maxVisibleMessages; i++) {
GenerateMessage(i * messageHeight);
Message message = GenerateMessage(i * messageHeight);
messages.Add(message);
}
return messages.ToArray();
}
private void GenerateMessage(int offsetY) {
RectTransform message = Instantiate(messagePrefab, Vector2.zero, Quaternion.identity, transform);
message.anchoredPosition = new Vector2(0, -offsetY);
private Message GenerateMessage(int offsetY) {
Message message = Instantiate(messagePrefab, Vector2.zero, Quaternion.identity, transform);
message.RectTransform.anchoredPosition = new Vector2(0, -offsetY);
return message;
}
}
}