-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CharacterIdentifiable.cs
69 lines (61 loc) · 2.27 KB
/
CharacterIdentifiable.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
66
67
68
69
using UnityEngine;
using SALT.Extensions;
namespace SALT
{
/// <summary>
/// A way to differentiate which character is which.
/// </summary>
public class CharacterIdentifiable : MonoBehaviour
{
private Character idnt = Character.NONE;
/// <summary>
/// The current <see cref="Character"/> id of the <see cref="CharacterPack"/>
/// </summary>
public Character Id { get => idnt; set => SetId(value); }
/// <summary>
/// Sets the <see cref="Id"/>
/// </summary>
/// <param name="enumValue">The value the id will be set to</param>
public void SetId(Character enumValue) => idnt = enumValue;
/// <summary>
/// Sets the <see cref="Id"/>
/// </summary>
/// <param name="enumValue">An <see cref="int"/> equal to the <see cref="Character"/> id</param>
public void SetId(int enumValue) => idnt = SALT.Registries.CharacterRegistry.GetFromInt(enumValue);
/// <summary>
/// Gets the <see cref="Id"/>
/// </summary>
/// <returns></returns>
public Character GetId() => idnt;
/// <summary>
/// Gets the <see cref="Id"/> from the <see cref="GameObject"/>
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
public static Character GetId(GameObject b)
{
if (b == null)
return Character.NONE;
CharacterIdentifiable identifiable = b.GetComponent<CharacterIdentifiable>();
if (identifiable == null)
return Character.NONE;
return identifiable.idnt;
}
/// <summary>
/// Adds a <see cref="CharacterIdentifiable"/> to a <see cref="GameObject"/>
/// </summary>
/// <param name="b"></param>
/// <param name="id"></param>
/// <returns></returns>
public static void AddIdentifiable(GameObject b, Character id)
{
if (b.HasComponent<CharacterIdentifiable>())
b.GetComponent<CharacterIdentifiable>().Id = id;
else
b.AddComponent<CharacterIdentifiable>().Id = id;
}
private void Awake() { }
private void Start() { }
private void Update() { }
}
}