Repository navigation
Expand file tree
/
Copy pathGameObject.cs
More file actions
88 lines (71 loc) · 2.01 KB
/
Copy pathGameObject.cs
File metadata and controls
88 lines (71 loc) · 2.01 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
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
namespace TipeEngine
{
public abstract class GameObject
{
public Rect rect { get; set; }
internal readonly Dictionary<Type, IComponent> components = [];
public GameObject(Rect _rect)
{
rect = _rect;
}
public bool AddComponent(IComponent component)
{
if (components.ContainsKey(component.GetType()))
{
return false;
}
components[component.GetType()] = component;
return true;
}
public bool RemoveComponent(IComponent component)
{
return components.Remove(component.GetType());
}
public T? GetComponent<T>() where T : class, IComponent
{
return components.TryGetValue(typeof(T), out IComponent? component) ? (T?)component : null;
}
public virtual void InternalUpdate()
{
foreach (IComponent component in components.Values)
{
component.Update();
}
Update();
}
public virtual void Update() { }
public virtual void InternalDraw()
{
foreach (IComponent component in components.Values)
{
component.Draw();
}
Draw();
}
public virtual void Draw() { }
public virtual void InternalGUI()
{
foreach (IComponent component in components.Values)
{
component.GUI();
}
GUI();
}
public virtual void GUI() { }
public virtual void InternalUnload()
{
foreach (IComponent component in components.Values)
{
component.Unload();
}
Unload();
}
public virtual void Unload() { }
public void Move(Vector2 delta)
{
rect = new Rect(rect.Position + delta, rect.Size);
}
}
}