Created
July 31, 2015 17:14
-
-
Save michaelbartnett/146fb4351a67e3b62679 to your computer and use it in GitHub Desktop.
stripped down decompiled UnityEngine.Object to show operator== and Equals overloads
This file contains hidden or 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 | |
| { | |
| public class Object | |
| { | |
| // | |
| // Operators | |
| // | |
| public static bool operator ==(Object x, Object y) { | |
| return Object.CompareBaseObjects(x, y); | |
| } | |
| public static implicit operator bool(Object exists) { | |
| return !Object.CompareBaseObjects(exists, null); | |
| } | |
| public static bool operator !=(Object x, Object y) { | |
| return !Object.CompareBaseObjects(x, y); | |
| } | |
| // | |
| // Static Methods | |
| // | |
| private static void CheckNullArgument(object arg, string message) | |
| { | |
| if (arg == null) { | |
| throw new ArgumentException(message); | |
| } | |
| } | |
| private static bool CompareBaseObjects(Object lhs, Object rhs) | |
| { | |
| bool flag = lhs == null; | |
| bool flag2 = rhs == null; | |
| if (flag2 && flag) { | |
| return true; | |
| } | |
| if (flag2) { | |
| return !Object.IsNativeObjectAlive(lhs); | |
| } | |
| if (flag) { | |
| return !Object.IsNativeObjectAlive(rhs); | |
| } | |
| return lhs.m_InstanceID == rhs.m_InstanceID; | |
| } | |
| [WrapperlessIcall] | |
| [MethodImpl(MethodImplOptions.InternalCall)] | |
| internal static extern bool DoesObjectWithInstanceIDExist(int instanceID); | |
| private static bool IsNativeObjectAlive(Object o) | |
| { | |
| return o.GetCachedPtr() != IntPtr.Zero || (!(o is MonoBehaviour) && !(o is ScriptableObject) && Object.DoesObjectWithInstanceIDExist(o.GetInstanceID())); | |
| } | |
| // | |
| // Methods | |
| // | |
| public override bool Equals(object o) | |
| { | |
| return Object.CompareBaseObjects(this, o as Object); | |
| } | |
| private IntPtr GetCachedPtr() | |
| { | |
| return this.m_CachedPtr; | |
| } | |
| public override int GetHashCode() | |
| { | |
| return this.GetInstanceID(); | |
| } | |
| public int GetInstanceID() | |
| { | |
| return this.m_InstanceID; | |
| } | |
| [WrapperlessIcall] | |
| [MethodImpl(MethodImplOptions.InternalCall)] | |
| public override extern string ToString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment