2018-10-30 20:05:06 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2019-03-29 10:38:00 +01:00
|
|
|
using UnityAtoms.Extensions;
|
2018-10-30 20:05:06 +01:00
|
|
|
|
|
|
|
namespace UnityAtoms
|
|
|
|
{
|
2019-04-07 16:03:16 +02:00
|
|
|
public abstract class ScriptableObjectList<T, E> : ScriptableObject
|
|
|
|
where E : GameEvent<T>
|
2018-10-30 20:05:06 +01:00
|
|
|
{
|
2018-11-04 10:00:06 +01:00
|
|
|
public E Added;
|
2019-04-07 16:03:16 +02:00
|
|
|
|
2018-11-04 10:00:06 +01:00
|
|
|
public E Removed;
|
2019-04-07 16:03:16 +02:00
|
|
|
|
2018-10-30 20:05:06 +01:00
|
|
|
public VoidEvent Cleared;
|
|
|
|
|
|
|
|
public int Count { get { return list.Count; } }
|
|
|
|
|
2019-04-07 16:03:16 +02:00
|
|
|
[SerializeField]
|
|
|
|
private List<T> list = new List<T>();
|
|
|
|
|
2018-10-30 20:05:06 +01:00
|
|
|
public void Add(T item)
|
|
|
|
{
|
|
|
|
if (!list.Contains(item))
|
|
|
|
{
|
|
|
|
list.Add(item);
|
2018-11-04 10:00:06 +01:00
|
|
|
if (null != Added)
|
2018-10-30 20:05:06 +01:00
|
|
|
{
|
2018-11-04 10:00:06 +01:00
|
|
|
Added.Raise(item);
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(T item)
|
|
|
|
{
|
|
|
|
if (list.Contains(item))
|
|
|
|
{
|
|
|
|
list.Remove(item);
|
2018-11-04 10:00:06 +01:00
|
|
|
if (null != Removed)
|
2018-10-30 20:05:06 +01:00
|
|
|
{
|
2018-11-04 10:00:06 +01:00
|
|
|
Removed.Raise(item);
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
{
|
|
|
|
list.Clear();
|
|
|
|
if (null != Cleared)
|
|
|
|
{
|
|
|
|
Cleared.Raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 10:38:00 +01:00
|
|
|
public bool Some(Func<T, bool> func)
|
|
|
|
{
|
|
|
|
return list.Some(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
public T First(Func<T, bool> func)
|
|
|
|
{
|
|
|
|
return list.First(func);
|
|
|
|
}
|
|
|
|
|
2018-11-04 10:00:06 +01:00
|
|
|
public bool Contains(T item)
|
|
|
|
{
|
|
|
|
return list.Contains(item);
|
|
|
|
}
|
|
|
|
|
2018-10-30 20:05:06 +01:00
|
|
|
public T Get(int i)
|
|
|
|
{
|
|
|
|
return list[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<T> List
|
|
|
|
{
|
|
|
|
get { return list; }
|
|
|
|
set { list = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public T this[int index]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return list[index];
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
list[index] = value;
|
|
|
|
}
|
|
|
|
}
|
2018-11-04 10:00:06 +01:00
|
|
|
|
2018-10-30 20:05:06 +01:00
|
|
|
}
|
2019-03-17 23:43:20 +01:00
|
|
|
}
|