using System.Collections;
using System.Collections.Generic;
using Cute;
using UnityEngine;

public class BingoBall : MonoBehaviour
{
	public const string NUM_SPRITE_NAME_HEAD = "bingo_ball_";

	public const string TEXTURE_BINGOBALL_BACK = "bingo_ball_back";

	public const string TEXTURE_BINGOBALL_FRONT = "bingo_ball_front";

	public const float NUM_SPACE = 11f;

	[SerializeField]
	private UISprite _numSpriteLeft;

	[SerializeField]
	private UISprite _numSpriteRight;

	[SerializeField]
	private UISprite _ballSprite;

	[SerializeField]
	private Transform _bottomPos;

	[SerializeField]
	private TweenPositionX _tweenPositionX;

	[SerializeField]
	private TweenPositionY _tweenPositionY;

	[SerializeField]
	private Vector2 _ballMovement;

	private GameObject _effectObject;

	private GameObject _dustEffect1;

	private GameObject _dustEffect2;

	private int _ballNum;

	private List<Coroutine> _inProcessCoroutines = new List<Coroutine>();

	private void Start()
	{
		_numSpriteLeft.gameObject.SetActive(value: false);
		_numSpriteRight.gameObject.SetActive(value: false);
	}

	public void SetBallNum(int num)
	{
		_ballNum = num;
	}

	public void SetNumSprite()
	{
		if (_ballNum >= 0 && _ballNum <= 9)
		{
			_numSpriteRight.gameObject.SetActive(value: false);
			_numSpriteLeft.gameObject.SetActive(value: true);
			_numSpriteLeft.transform.localPosition = Vector3.zero;
			_numSpriteLeft.spriteName = "bingo_ball_" + _ballNum;
		}
		else if (_ballNum >= 10)
		{
			_numSpriteRight.gameObject.SetActive(value: true);
			_numSpriteLeft.gameObject.SetActive(value: true);
			_numSpriteLeft.spriteName = "bingo_ball_" + _ballNum / 10;
			_numSpriteRight.spriteName = "bingo_ball_" + _ballNum % 10;
		}
	}

	public void SetBallSprite(bool isFront)
	{
		_ballSprite.spriteName = (isFront ? "bingo_ball_front" : "bingo_ball_back");
	}

	public List<string> PlayEffect(string effectName, bool isOnBottom)
	{
		List<string> list = new List<string>();
		if (_effectObject != null)
		{
			Object.Destroy(_effectObject);
		}
		_effectObject = Object.Instantiate(Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(effectName, ResourcesManager.AssetLoadPathType.Effect2D, isfetch: true)) as GameObject);
		_effectObject.transform.parent = base.gameObject.transform;
		list.AddRange(GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(_effectObject, null));
		_effectObject.transform.localPosition = (isOnBottom ? _bottomPos.transform.localPosition : Vector3.zero);
		_effectObject.SetActive(value: true);
		return list;
	}

	public List<string> PlayDustEffect(string effectName, GameObject dustEffectContainer, float fallTime, float endWorldPosY, float delayTime)
	{
		List<string> list = new List<string>();
		_dustEffect1 = Object.Instantiate(Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(effectName, ResourcesManager.AssetLoadPathType.Effect2D, isfetch: true)) as GameObject);
		_dustEffect2 = Object.Instantiate(Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(effectName, ResourcesManager.AssetLoadPathType.Effect2D, isfetch: true)) as GameObject);
		list.AddRange(GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(_dustEffect1, null));
		list.AddRange(GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(_dustEffect2, null));
		_dustEffect1.transform.parent = dustEffectContainer.transform;
		_dustEffect2.transform.parent = dustEffectContainer.transform;
		_dustEffect1.SetActive(value: false);
		_dustEffect2.SetActive(value: false);
		_inProcessCoroutines.Add(UIManager.GetInstance().StartCoroutine(PlayDustEffect(fallTime, endWorldPosY, delayTime)));
		return list;
	}

	private IEnumerator PlayDustEffect(float fallTime, float endWorldPosY, float delayTime)
	{
		yield return new WaitForSeconds(delayTime + fallTime * 0.164f);
		Vector3 position = base.gameObject.transform.position;
		position.y = endWorldPosY - (base.gameObject.transform.position.y - _bottomPos.transform.position.y) * 0.95f;
		_dustEffect1.transform.position = position;
		_dustEffect1.SetActive(value: true);
		yield return new WaitForSeconds(fallTime * 0.323f);
		position = base.gameObject.transform.position;
		position.y = endWorldPosY - (base.gameObject.transform.position.y - _bottomPos.transform.position.y) * 0.98f;
		_dustEffect2.transform.position = position;
		_dustEffect2.SetActive(value: true);
		yield return new WaitForSeconds(0.4f);
		Object.Destroy(_dustEffect1);
		Object.Destroy(_dustEffect2);
	}

	public void StopCoroutine()
	{
		if (_inProcessCoroutines.Count <= 0)
		{
			return;
		}
		foreach (Coroutine inProcessCoroutine in _inProcessCoroutines)
		{
			if (inProcessCoroutine != null)
			{
				UIManager.GetInstance().StopCoroutine(inProcessCoroutine);
			}
		}
	}

	public void PlayTweenAnimation(Vector3 from, float delay)
	{
		_tweenPositionX.from = from.x;
		_tweenPositionX.to = from.x + _ballMovement.x;
		_tweenPositionY.from = from.y;
		_tweenPositionY.to = from.y + _ballMovement.y;
		_inProcessCoroutines.Add(UIManager.GetInstance().StartCoroutine(PlayBallFallAnimation(delay)));
	}

	private IEnumerator PlayBallFallAnimation(float delay)
	{
		yield return new WaitForSeconds(delay);
		GameMgr.GetIns().GetSoundMgr().PlaySeByStr("se_sys_bng_ballfall_01", "se_sys_bng_ballfall_01", 0f, 0L);
		base.gameObject.SetActive(value: true);
	}

	public Vector2 GetBallMovement()
	{
		return _ballMovement;
	}
}
