Repository navigation
Expand file tree
/
Copy pathObject.cs
More file actions
148 lines (128 loc) · 3.48 KB
/
Copy pathObject.cs
File metadata and controls
148 lines (128 loc) · 3.48 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// -----------------------------------------------------------------
// File: Object
// Author: ruanban
// Date: 1/4/2018 3:55:14 PM
// Description:
//
// -----------------------------------------------------------------
using UnityEngine;
using System.Diagnostics;
namespace UnityEngine
{
public class Object
{
protected enum ObjectState
{
Active,
WaitForDestroy,
Destroy,
}
private static int instance_id_counter = 0;
private int _instance_id = 0;
public Object()
{
this.state = ObjectState.Active;
_instance_id = ++instance_id_counter;
}
private string _name="GameObject";
virtual public string name
{
set
{
this.CheckDestroy();
this._name = value;
}
get { this.CheckDestroy(); return _name; }
}
private ObjectState _state;
protected ObjectState state
{
set
{
this.CheckDestroy();
this._state = value;
}
get
{
this.CheckDestroy();
return this._state;
}
}
protected Scene scene
{
get { this.CheckDestroy(); return SceneManager.Instance.currentScene; }
}
[Conditional("DEBUG")]
protected void CheckDestroy()
{
if (this._state == ObjectState.Destroy)
{
throw new MissingReferenceException(this);
}
}
virtual protected void __OnDestroy__()
{
}
virtual protected void __OnWaitDestroy__()
{
}
private static bool IsDestroyTransform(Object obj)
{
if (obj is Transform)
{
Debug.Error("Can't destroy Transform component of 'Transform'. If you want to destroy the game object, please call 'Destroy' on the game object instead. Destroying the transform component is not allowed.");
return true;
}
return false;
}
public static void Destroy(Object obj)
{
if (!IsDestroyTransform(obj))
{
__Destroy__(obj);
}
}
public static void DestroyImmediate(Object obj)
{
if (!IsDestroyTransform(obj))
{
__DestroyImmediate__(obj);
}
}
internal static void __Destroy__(Object obj)
{
if (obj != null)
{
obj.__OnWaitDestroy__();
obj.state = ObjectState.WaitForDestroy;
}
}
internal static void __DestroyImmediate__(Object obj)
{
if (obj != null)
{
obj.__OnDestroy__();
obj.state = ObjectState.Destroy;
}
}
public override bool Equals(object obj)
{
if (obj == null &&
this.state == ObjectState.Destroy)
{
return true;
}
return base.Equals(obj);
}
public int GetInstanceID()
{
this.CheckDestroy();
return _instance_id;
}
public override int GetHashCode()
{
this.CheckDestroy();
return base.GetHashCode();
}
}
}