-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseEntityPrefabInstance.cs
84 lines (69 loc) · 2.4 KB
/
BaseEntityPrefabInstance.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using Gemserk.Utilities;
using MyBox;
using UnityEngine;
using UnityEngine.Serialization;
namespace Gemserk.Leopotam.Ecs
{
public abstract class BaseEntityPrefabInstance : MonoBehaviour
{
public enum OnInstantiateActionType
{
// InstantiateAndDestroy = 0,
Disable = 0,
LinkObject = 2,
Destroy = 3,
None = 4
}
public enum InstantiationType
{
Manual = 0,
AutomaticOnEnable = 1,
AutomaticOnceOnStart = 2
}
// rename to link type
[FormerlySerializedAs("instanceType")]
public OnInstantiateActionType onInstantiateActionType = OnInstantiateActionType.Disable;
// rename to instantiation type?
[FormerlySerializedAs("autoInstantiateOnAwake")]
public InstantiationType instantiationType = InstantiationType.AutomaticOnEnable;
[NonSerialized]
public Entity instance = Entity.NullEntity;
// could be something like:
// linkType: None, LinkWithGameObject
// instantiationType: OnAwake, OnStart, OnEnable, Manual
// onInstantiateType: None, AutoDisable, AutoDestroy
// cant AutoDestroy or AutoDisable with LinkWithGameObject
public WorldReference worldReference;
public abstract IEntityDefinition GetEntityDefinition();
private void OnEnable()
{
if (instantiationType == InstantiationType.AutomaticOnEnable)
{
InstantiateEntity();
}
}
private void Start()
{
if (instantiationType == InstantiationType.AutomaticOnceOnStart)
{
InstantiateEntity();
}
}
public void InstantiateEntity()
{
// var world = GameObject.FindWithTag(worldTag).GetComponent<World>();
var world = worldReference.GetReference(gameObject);
var instanceEntity = world.CreateEntity();
world.AddComponent(instanceEntity, new EntityPrefabComponent()
{
prefabInstance = this
});
}
public void GetEntityParameters(List<IEntityInstanceParameter> list)
{
gameObject.GetComponents<IEntityInstanceParameter>(list);
}
}
}