70 lines
1.2 KiB
C#
70 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class AIState
|
|
{
|
|
public string key;
|
|
public int value;
|
|
}
|
|
public class AIStates
|
|
{
|
|
public Dictionary<string, int> states;
|
|
|
|
public AIStates()
|
|
{
|
|
states = new Dictionary<string, int>();
|
|
}
|
|
|
|
public bool HasState(string key)
|
|
{
|
|
return states.ContainsKey(key);
|
|
}
|
|
|
|
void AddState(string key, int value)
|
|
{
|
|
states.Add(key, value);
|
|
}
|
|
|
|
public void ModifyState(string key, int value)
|
|
{
|
|
if (states.ContainsKey(key))
|
|
{
|
|
states[key] += value;
|
|
if (states[key] <= 0)
|
|
{
|
|
RemoveState(key);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddState(key, value);
|
|
}
|
|
}
|
|
|
|
public void RemoveState(string key)
|
|
{
|
|
if (states.ContainsKey(key))
|
|
{
|
|
states.Remove(key);
|
|
}
|
|
}
|
|
|
|
public void SetState(string key, int value)
|
|
{
|
|
if (states.ContainsKey(key))
|
|
{
|
|
states[key] = value;
|
|
}
|
|
else
|
|
{
|
|
AddState(key, value);
|
|
}
|
|
}
|
|
|
|
public Dictionary<string, int> GetStates()
|
|
{
|
|
return states;
|
|
}
|
|
} |