summaryrefslogtreecommitdiff
path: root/Runtime/Export/TrackedReference.cs
blob: dcc3f80223eba077854abc914402f7ae88c3a683 (plain)
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
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;
	}
}

}