using MEC;
using System.Collections.Generic;
using UnityEngine;

public class BaseBehavior : MonoBehaviour
{
    protected static bool lockInterface = false;

    private Transform _transform;
    private Rigidbody2D _rigidbody;
    private Collider2D _collider;

    [HideInInspector]
    public new Transform transform
    {
        get
        {
            if (this._transform == null)
            {
                this._transform = this.GetComponent<Transform>();
            }
            return this._transform;
        }
    }

    [HideInInspector]
    public new Rigidbody2D rigidbody
    {
        get
        {
            if (this._rigidbody == null)
            {
                this._rigidbody = this.GetComponent<Rigidbody2D>();
            }
            return this._rigidbody;
        }
    }

    [HideInInspector]
    public new Collider2D collider
    {
        get
        {
            if (this._collider == null && this != null)
            {
                this._collider = this.GetComponent<Collider2D>();
            }
            return this._collider;
        }
    }

    protected string guid;

    protected virtual void Awake()
    {
        this.guid = System.Guid.NewGuid().ToString();
    }

    protected void setTrigger(Animator animator, string trigger)
    {
        if (this.gameObject.activeInHierarchy)
        {
            Timing.RunCoroutine(this._setTrigger(animator, trigger), this.guid);
        }
    }

    private IEnumerator<float> _setTrigger(Animator animator, string trigger)
    {
        while (!animator.isInitialized)
        {
            yield return 0;
        }

        animator.SetTrigger(trigger);
    }

    protected void setFloat(Animator animator, string trigger, float value)
    {
        if (this.gameObject.activeInHierarchy)
        {
            Timing.RunCoroutine(this._setFloat(animator, trigger, value), this.guid);
        }
    }

    private IEnumerator<float> _setFloat(Animator animator, string trigger, float value)
    {
        while (!animator.isInitialized)
        {
            yield return 0;
        }

        animator.SetFloat(trigger, value);
    }

    protected void setBool(Animator animator, string trigger, bool flag)
    {
        if (this.gameObject.activeInHierarchy)
        {
            Timing.RunCoroutine(this._setBool(animator, trigger, flag), this.guid);
        }
    }

    private IEnumerator<float> _setBool(Animator animator, string trigger, bool flag)
    {
        while (!animator.isInitialized)
        {
            yield return 0;
        }

        animator.SetBool(trigger, flag);
    }

    protected void killCoroutines()
    {
        Timing.KillCoroutines(this.guid);
    }
}