using System;
using System.Collections;
using UnityEngine;

public class Billboard : MonoBehaviour
{
	private void Start()
	{
		base.StartCoroutine(this.CoGetTargetCam());
	}

	private IEnumerator CoGetTargetCam()
	{
		while (this.m_targetCamera == null)
		{
			if (GameMain.Instance.VRMode && Application.isPlaying)
			{
				if (GameMain.Instance.OvrMgr != null)
				{
					this.m_targetCamera = GameMain.Instance.OvrMgr.EyeAnchor;
				}
			}
			else if (GameMain.Instance.MainCamera != null)
			{
				this.m_targetCamera = GameMain.Instance.MainCamera.transform;
			}
			yield return null;
		}
		this.m_bEnableTargetCam = true;
		yield break;
	}

	private void Update()
	{
		if (!this.m_bEnableTargetCam)
		{
			return;
		}
		Vector3 position = this.m_targetCamera.position;
		if (this.m_eLockLocal != Billboard.LOCK.NON)
		{
			Vector3 a = base.transform.InverseTransformPoint(position);
			if (this.m_eLockLocal == Billboard.LOCK.LOCK_X)
			{
				a.x = base.transform.localPosition.x;
			}
			else if (this.m_eLockLocal == Billboard.LOCK.LOCK_Y)
			{
				a.y = base.transform.localPosition.y;
			}
			else if (this.m_eLockLocal == Billboard.LOCK.LOCK_Z)
			{
				a.z = base.transform.localPosition.z;
			}
			Vector3 normalized = (a - base.transform.localPosition).normalized;
			base.transform.localRotation *= Quaternion.LookRotation(normalized);
		}
		else if (this.m_bUseUpVector)
		{
			base.transform.LookAt(position, this.m_vUpVector);
		}
		else
		{
			base.transform.LookAt(position);
		}
	}

	public Transform m_targetCamera;

	[Header("Up方向を固定する(World系)")]
	public bool m_bUseUpVector;

	public Vector3 m_vUpVector = new Vector3(0f, 1f, 0f);

	[Header("回転軸を指定する(Local系)")]
	public Billboard.LOCK m_eLockLocal;

	private bool m_bEnableTargetCam;

	public enum LOCK
	{
		NON,
		LOCK_X,
		LOCK_Y,
		LOCK_Z
	}
}
