using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x02000067 RID: 103
[ExecuteInEditMode]
public class InteractionIconAnimator : MonoBehaviour
{
	// Token: 0x06000B67 RID: 2919 RVA: 0x000DE8C4 File Offset: 0x000DCAC4
	private void Awake()
	{
		if (this.randomStart)
		{
			this.delay = Random.Range(0f, 0.1f);
			this.startTime = Time.timeSinceLevelLoad;
			this.updateTime = Time.timeSinceLevelLoad + this.delay;
			if (this.realtime)
			{
				this.updateTime = Time.realtimeSinceStartup + this.delay;
			}
			if (this.sprites != null)
			{
				this.currentIndex = Random.Range(0, this.sprites.Count - 1);
			}
		}
	}

	// Token: 0x06000B68 RID: 2920 RVA: 0x000DE948 File Offset: 0x000DCB48
	private void OnEnable()
	{
		this.GetSpriteList();
		if (this.randomStart)
		{
			this.delay = Random.Range(0f, 0.1f);
			this.startTime = Time.timeSinceLevelLoad;
			this.updateTime = Time.timeSinceLevelLoad + this.delay;
			if (this.realtime)
			{
				this.updateTime = Time.realtimeSinceStartup + this.delay;
			}
			this.currentIndex = Random.Range(0, this.sprites.Count - 1);
		}
		this.canPlay = true;
	}

	// Token: 0x06000B69 RID: 2921 RVA: 0x000DE9D0 File Offset: 0x000DCBD0
	private void OnDisable()
	{
		if (this.randomStart)
		{
			this.delay = Random.Range(0f, 0.5f);
			this.startTime = Time.timeSinceLevelLoad;
			this.currentIndex = Random.Range(0, this.sprites.Count - 1);
		}
		else
		{
			this.currentIndex = 0;
		}
		this.canPlay = true;
	}

	// Token: 0x06000B6A RID: 2922 RVA: 0x000DEA30 File Offset: 0x000DCC30
	public void GetSpriteList()
	{
		if (this.animationType == InteractionIconAnimator.type.Talk)
		{
			this.sprites = this.spritesTalk;
		}
		if (this.animationType == InteractionIconAnimator.type.Quip)
		{
			this.sprites = this.spritesQuip;
		}
		if (this.animationType == InteractionIconAnimator.type.Use)
		{
			this.sprites = this.spritesUse;
		}
		if (this.animationType == InteractionIconAnimator.type.Kick)
		{
			this.sprites = this.spritesKick;
		}
		if (this.animationType == InteractionIconAnimator.type.Lockpick)
		{
			this.sprites = this.spritesLock;
		}
		if (this.animationType == InteractionIconAnimator.type.Unlock)
		{
			this.sprites = this.spritesUnlock;
		}
		this.imageRenderer.sprite = this.sprites[0];
	}

	// Token: 0x06000B6B RID: 2923 RVA: 0x000DEAD4 File Offset: 0x000DCCD4
	private void Update()
	{
		if (!this.canPlay)
		{
			return;
		}
		if (this.speed > 0f && ((!this.realtime && Time.timeSinceLevelLoad > this.updateTime + this.updateInterval) || (this.realtime && Time.realtimeSinceStartup > this.updateTime + this.updateInterval)))
		{
			this.updateTime = Time.timeSinceLevelLoad;
			if (this.realtime)
			{
				this.updateTime = Time.realtimeSinceStartup;
			}
			this.currentIndex++;
			if (this.currentIndex > this.sprites.Count - 1)
			{
				if (!this.loop)
				{
					this.currentIndex = 0;
					this.canPlay = false;
					return;
				}
				this.currentIndex = 0;
			}
			if (base.enabled)
			{
				this.imageRenderer.sprite = this.sprites[this.currentIndex];
			}
		}
	}

	// Token: 0x040010E0 RID: 4320
	[Header("ANIMATION INFO")]
	private float updateTime;

	// Token: 0x040010E1 RID: 4321
	public float speed = 1f;

	// Token: 0x040010E2 RID: 4322
	public bool realtime;

	// Token: 0x040010E3 RID: 4323
	public float updateInterval = 0.2f;

	// Token: 0x040010E4 RID: 4324
	public InteractionIconAnimator.type animationType;

	// Token: 0x040010E5 RID: 4325
	private int currentIndex;

	// Token: 0x040010E6 RID: 4326
	public bool randomStart;

	// Token: 0x040010E7 RID: 4327
	public bool loop = true;

	// Token: 0x040010E8 RID: 4328
	public Image imageRenderer;

	// Token: 0x040010E9 RID: 4329
	private List<Sprite> sprites;

	// Token: 0x040010EA RID: 4330
	public List<Sprite> spritesTalk = new List<Sprite>();

	// Token: 0x040010EB RID: 4331
	public List<Sprite> spritesQuip = new List<Sprite>();

	// Token: 0x040010EC RID: 4332
	public List<Sprite> spritesUse = new List<Sprite>();

	// Token: 0x040010ED RID: 4333
	public List<Sprite> spritesKick = new List<Sprite>();

	// Token: 0x040010EE RID: 4334
	public List<Sprite> spritesLock = new List<Sprite>();

	// Token: 0x040010EF RID: 4335
	public List<Sprite> spritesUnlock = new List<Sprite>();

	// Token: 0x040010F0 RID: 4336
	private float t;

	// Token: 0x040010F1 RID: 4337
	private float start;

	// Token: 0x040010F2 RID: 4338
	private float target;

	// Token: 0x040010F3 RID: 4339
	private float delay;

	// Token: 0x040010F4 RID: 4340
	private float startTime;

	// Token: 0x040010F5 RID: 4341
	private bool canPlay;

	// Token: 0x020001CF RID: 463
	public enum type
	{
		// Token: 0x04002E0D RID: 11789
		Talk,
		// Token: 0x04002E0E RID: 11790
		Quip,
		// Token: 0x04002E0F RID: 11791
		Use,
		// Token: 0x04002E10 RID: 11792
		Kick,
		// Token: 0x04002E11 RID: 11793
		Lockpick,
		// Token: 0x04002E12 RID: 11794
		Unlock
	}
}
