-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatusManager.cs
More file actions
80 lines (68 loc) · 2.21 KB
/
StatusManager.cs
File metadata and controls
80 lines (68 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace ModsPlus
{
internal class StatusManager : MonoBehaviour
{
private Transform _holder;
private Transform Holder
{
get
{
if (_holder == null)
{
_holder = new GameObject("Status Group").transform;
_holder.SetParent(transform);
_holder.localScale = Vector3.one;
_holder.localPosition = Vector3.zero;
}
return _holder;
}
}
private List<StatusObject> objects = new List<StatusObject>();
private void Update()
{
if (objects.Count == 0) return;
var offset = Vector3.zero;
foreach (var obj in objects)
{
offset += Vector3.up * 0.25f + Vector3.up * obj.verticalPadding;
obj.transform.localPosition = offset;
offset += Vector3.up * obj.verticalPadding;
}
}
public void AddStatusObject(GameObject statusObj, float verticalPadding, bool normalizeScale)
{
var obj = statusObj.AddComponent<StatusObject>().Initialize(this, verticalPadding);
obj.transform.SetParent(Holder);
if (normalizeScale)
{
obj.transform.localScale = Vector3.one;
}
objects.Add(obj);
}
public void RemoveStatusObject(StatusObject objToRemove)
{
objects.Remove(objToRemove);
}
}
internal class StatusObject : MonoBehaviour
{
private StatusManager parent;
public float verticalPadding { get; private set; }
public StatusObject Initialize(StatusManager parent, float verticalPadding)
{
this.parent = parent;
this.verticalPadding = verticalPadding;
return this;
}
private void OnDestroy()
{
parent.RemoveStatusObject(this);
}
}
}