forked from SubnauticaNitrox/Nitrox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameObject.cs
65 lines (54 loc) · 1.79 KB
/
GameObject.cs
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
using System;
using System.Collections.Generic;
using NitroxModel.DataStructures.GameLogic;
using NitroxServer.Serialization;
namespace NitroxServer.UnityStubs
{
public class GameObject
{
public bool IsActive { get; }
public int Layer { get; }
public string Tag { get; }
public string Id { get; }
public string ClassId { get; }
public string Parent { get; }
public int TotalComponents { get { return components.Count; } }
private readonly Dictionary<Type, object> components = new Dictionary<Type, object>();
public GameObject(GameObjectData goData)
{
IsActive = goData.IsActive;
Layer = goData.Layer;
Tag = goData.Tag;
Id = goData.Id;
ClassId = goData.ClassId;
Parent = goData.Parent;
}
public override string ToString()
{
object transform = null;
components.TryGetValue(typeof(NitroxTransform), out transform); // Honestly this should never be null every gameObject has a Transform
return string.Format("Id: {0}, Class Id: {1}, Transform: {2}", Id, ClassId, transform as NitroxTransform);
}
public void AddComponent(object component, Type componentType)
{
components.Add(componentType, component);
}
public object GetComponent(Type type)
{
object res;
if (components.TryGetValue(type, out res))
{
return res;
}
return null;
}
public T GetComponent<T>()
{
return (T)GetComponent(typeof(T));
}
public bool HasComponent<T>()
{
return components.ContainsKey(typeof(T));
}
}
}