using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class IRunUserData : MonoBehaviour
{
    private Dictionary<string, System.Object> runObjDatas = new Dictionary<string, System.Object>();
    public bool setData(string key, System.Object obj)
    {
        if (this.runObjDatas.ContainsKey(key) == false)
            this.runObjDatas.Add(key, obj);
        else
            runObjDatas[key] = obj;
        return true;
    }
    public bool delDataByKey(string key)
    {
        if (this.runObjDatas.ContainsKey(key))
        {
            this.runObjDatas.Remove(key);
        }
        return true;
    }
    
    public bool getUserData<T>(string key, out System.Object value, System.Object defvalue)
    {
        if (runObjDatas.ContainsKey(key))
        {
            if(runObjDatas[key] is T)
            {
                value = runObjDatas[key];
                return true;
            }
        }
        value = defvalue;
        return true;
    }
    public bool ContainsKey(string key)
    {
        return runObjDatas.ContainsKey(key);
    }
    public void OnDestroy()
    {
        runObjDatas.Clear();
    }
}
