Created
April 4, 2017 12:31
-
-
Save zhenlinyang/5608fa760c1254ad02ae41e8abf98b94 to your computer and use it in GitHub Desktop.
UnityEngine Simulation Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace UnityEngine.Simulation | |
{ | |
public class Object | |
{ | |
private static int s_IdCount = 0; | |
private int m_InstanceID; | |
private bool m_Alive = true; | |
private string m_Name = ""; | |
public Object() | |
{ | |
do | |
{ | |
m_InstanceID = ++s_IdCount; | |
} while (0 == m_InstanceID); | |
} | |
public static void Destroy(Object obj) | |
{ | |
obj.m_Alive = false; | |
} | |
public override bool Equals(object other) | |
{ | |
Object obj = other as Object; | |
return (!(obj == null) || other == null || other is Object) && Compare(this, obj); | |
} | |
public override int GetHashCode() | |
{ | |
return m_InstanceID; | |
} | |
public static bool operator ==(Object x, Object y) | |
{ | |
return Compare(x, y); | |
} | |
public static bool operator !=(Object x, Object y) | |
{ | |
return !Compare(x, y); | |
} | |
public static implicit operator bool(Object exists) | |
{ | |
return !Compare(exists, null); | |
} | |
private static bool Compare(Object x, Object y) | |
{ | |
bool flagX = !(x is Object); | |
bool flagY = !(y is Object); | |
bool result; | |
if (flagX && flagY) | |
{ | |
return true; | |
} | |
else if (flagY) | |
{ | |
result = !x.m_Alive; | |
} | |
else if (flagX) | |
{ | |
result = !y.m_Alive; | |
} | |
else | |
{ | |
result = x.m_InstanceID == y.m_InstanceID; | |
} | |
return result; | |
} | |
public string Name | |
{ | |
get | |
{ | |
if (m_Alive) | |
{ | |
return m_Name; | |
} | |
else | |
{ | |
throw new UnityEngine.MissingReferenceException(string.Format( | |
"The object of type '{0}' has been destroyed but you are still trying to access it.\nYour script should either check if it is null or you should not destroy the object.", | |
GetType())); | |
} | |
} | |
set | |
{ | |
if (m_Alive) | |
{ | |
m_Name = value; | |
} | |
else | |
{ | |
throw new UnityEngine.MissingReferenceException(string.Format( | |
"The object of type '{0}' has been destroyed but you are still trying to access it.\nYour script should either check if it is null or you should not destroy the object.", | |
GetType())); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment