diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Export/TrackedReference.cs |
Diffstat (limited to 'Runtime/Export/TrackedReference.cs')
-rw-r--r-- | Runtime/Export/TrackedReference.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Runtime/Export/TrackedReference.cs b/Runtime/Export/TrackedReference.cs new file mode 100644 index 0000000..dcc3f80 --- /dev/null +++ b/Runtime/Export/TrackedReference.cs @@ -0,0 +1,39 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Collections; +using UnityEngineInternal; +namespace UnityEngine +{ + +[StructLayout (LayoutKind.Sequential)] +//This class should be internal. Next time we can break backwardscompatibility we should do it. +public class TrackedReference +{ + [NotRenamed] + internal IntPtr m_Ptr; + + protected TrackedReference () { } + + public static bool operator == (TrackedReference x, TrackedReference y) + { + object xo = x; + object yo = y; + + if (yo == null && xo == null) return true; + if (yo == null) return x.m_Ptr == IntPtr.Zero; + if (xo == null) return y.m_Ptr == IntPtr.Zero; + return x.m_Ptr == y.m_Ptr; + } + public static bool operator != (TrackedReference x, TrackedReference y) { return !(x == y); } + + public override bool Equals(object o) { return (o as TrackedReference) == this; } + public override int GetHashCode() { return (int)m_Ptr; } + + public static implicit operator bool (TrackedReference exists) + { + return exists != null; + } +} + +} |