59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
[System.Serializable]
|
|
public class AbilityCreationData
|
|
{
|
|
public string name;
|
|
public string description;
|
|
public Sprite icon;
|
|
public AbilityAnimationType animationType;
|
|
public float manaCost;
|
|
public float healthCost;
|
|
public float cooldown;
|
|
public float castTime;
|
|
public bool castableWhileMoving;
|
|
public SerializedDictionary<string, object> typeSpecificData = new SerializedDictionary<string, object>();
|
|
|
|
public T GetOrCreateTypeSpecific<T>(string key)
|
|
{
|
|
if (!typeSpecificData.ContainsKey(key))
|
|
{
|
|
typeSpecificData[key] = default(T);
|
|
}
|
|
return (T)typeSpecificData[key];
|
|
}
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class SerializedDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
|
|
{
|
|
[SerializeField]
|
|
private List<TKey> keys = new List<TKey>();
|
|
|
|
[SerializeField]
|
|
private List<TValue> values = new List<TValue>();
|
|
|
|
public void OnBeforeSerialize()
|
|
{
|
|
keys.Clear();
|
|
values.Clear();
|
|
foreach(KeyValuePair<TKey, TValue> pair in this)
|
|
{
|
|
keys.Add(pair.Key);
|
|
values.Add(pair.Value);
|
|
}
|
|
}
|
|
|
|
public void OnAfterDeserialize()
|
|
{
|
|
this.Clear();
|
|
|
|
if(keys.Count != values.Count)
|
|
throw new System.Exception($"There are {keys.Count} keys and {values.Count} values after deserialization. Make sure that both key and value types are serializable.");
|
|
|
|
for(int i = 0; i < keys.Count; i++)
|
|
this.Add(keys[i], values[i]);
|
|
}
|
|
}
|