using System;
using UnityEngine;
using Yotogis;

public class YotogiSkillIcon : MonoBehaviour
{
	public void Awake()
	{
		this.ui2d_sprite_ = base.GetComponent<UI2DSprite>();
		this.box_collider_ = base.GetComponent<BoxCollider>();
		NDebug.AssertNull(this.ui2d_sprite_);
	}

	public void OnDestroy()
	{
		if (this.ui2d_sprite_.sprite2D != null && this.ui2d_sprite_.sprite2D.texture != null)
		{
			UnityEngine.Object.DestroyImmediate(this.ui2d_sprite_.sprite2D.texture);
		}
	}

	public void SetSkillData(Skill.Data skill_data)
	{
		this.skill_data_ = skill_data;
		if (this.skill_data_ == null)
		{
			if (this.ui2d_sprite_.sprite2D != null && this.ui2d_sprite_.sprite2D.texture != null)
			{
				UnityEngine.Object.DestroyImmediate(this.ui2d_sprite_.sprite2D.texture);
			}
			this.ui2d_sprite_.sprite2D = null;
		}
		else
		{
			this.LoadImage(this.skill_data_.icon_file_name);
		}
	}

	public void LoadImage(string file_name)
	{
		file_name += ".tex";
		if (!GameUty.FileSystem.IsExistentFile(file_name))
		{
			file_name = "icon_none.tex";
		}
		this.tex_ = ImportCM.CreateTexture(file_name);
		Sprite sprite = Sprite.Create(this.tex_, new Rect(0f, 0f, (float)this.tex_.width, (float)this.tex_.height), default(Vector2));
		sprite.name = file_name;
		if (this.ui2d_sprite_.sprite2D != null && this.ui2d_sprite_.sprite2D.texture != null)
		{
			UnityEngine.Object.DestroyImmediate(this.ui2d_sprite_.sprite2D.texture);
		}
		this.ui2d_sprite_.sprite2D = sprite;
		this.ui2d_sprite_.SetDimensions(this.IconSize, this.IconSize);
		if (this.box_collider_ != null && this.AutoColliderChange)
		{
			this.box_collider_.size = new Vector3((float)this.IconSize, (float)this.IconSize, 1f);
		}
	}

	public void SetOnClickEvent(YotogiSkillIcon.OnClickEvent set_event)
	{
		UIButton component = base.GetComponent<UIButton>();
		if (component == null || set_event == null)
		{
			return;
		}
		this.on_click_event_ = set_event;
		EventDelegate eventDelegate = new EventDelegate(this, "OnClickButtonCallBack");
		EventDelegate.Parameter parameter = eventDelegate.parameters[0];
		parameter.obj = base.gameObject;
		EventDelegate.Add(component.onClick, eventDelegate);
	}

	public Color color
	{
		get
		{
			return this.ui2d_sprite_.color;
		}
		set
		{
			this.ui2d_sprite_.color = value;
		}
	}

	public Skill.Data skill_data
	{
		get
		{
			return this.skill_data;
		}
	}

	private void OnClickButtonCallBack(GameObject my)
	{
		if (this.on_click_event_ != null)
		{
			this.on_click_event_(my, my.GetComponent<YotogiSkillIcon>());
		}
	}

	public int IconSize = 80;

	public bool AutoColliderChange = true;

	private UI2DSprite ui2d_sprite_;

	private BoxCollider box_collider_;

	private Texture2D tex_;

	private Skill.Data skill_data_;

	private YotogiSkillIcon.OnClickEvent on_click_event_;

	public delegate void OnClickEvent(GameObject my, YotogiSkillIcon click_obj);
}
