124 lines
1.9 KiB
C#
124 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace EditorPlus
|
|
{
|
|
[Serializable]
|
|
public class EditorPlusHistorySceneObjects : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
public int ClearID = -1;
|
|
|
|
[SerializeField]
|
|
public List<int> IDs;
|
|
|
|
[SerializeField]
|
|
public List<GameObject> OBJs;
|
|
|
|
private void Start()
|
|
{
|
|
if (IDs == null)
|
|
{
|
|
IDs = new List<int>();
|
|
}
|
|
if (OBJs == null)
|
|
{
|
|
OBJs = new List<GameObject>();
|
|
}
|
|
if (!Application.isEditor)
|
|
{
|
|
UnityEngine.Object.Destroy(this);
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
IDs.Clear();
|
|
OBJs.Clear();
|
|
}
|
|
|
|
public void CheckConsistency()
|
|
{
|
|
if (IDs == null)
|
|
{
|
|
IDs = new List<int>();
|
|
}
|
|
if (OBJs == null)
|
|
{
|
|
OBJs = new List<GameObject>();
|
|
}
|
|
if (IDs.Count != OBJs.Count)
|
|
{
|
|
Debug.LogWarning("Scene object data corrupted - discarding");
|
|
Clear();
|
|
return;
|
|
}
|
|
for (int i = 0; i < OBJs.Count; i++)
|
|
{
|
|
if (OBJs[i] == null)
|
|
{
|
|
OBJs.RemoveAt(i);
|
|
IDs.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Set(int objId, UnityEngine.Object go)
|
|
{
|
|
if (IDs == null)
|
|
{
|
|
IDs = new List<int>();
|
|
}
|
|
if (OBJs == null)
|
|
{
|
|
OBJs = new List<GameObject>();
|
|
}
|
|
if (!OBJs.Contains((GameObject)go) && !IDs.Contains(objId))
|
|
{
|
|
OBJs.Add((GameObject)go);
|
|
IDs.Add(objId);
|
|
}
|
|
}
|
|
|
|
public int GetID(UnityEngine.Object go)
|
|
{
|
|
if (IDs == null)
|
|
{
|
|
IDs = new List<int>();
|
|
}
|
|
if (OBJs == null)
|
|
{
|
|
OBJs = new List<GameObject>();
|
|
}
|
|
for (int i = 0; i < OBJs.Count; i++)
|
|
{
|
|
if (OBJs[i] != null && OBJs[i] == go)
|
|
{
|
|
return IDs[i];
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public UnityEngine.Object GetOBJ(int id)
|
|
{
|
|
if (IDs == null)
|
|
{
|
|
IDs = new List<int>();
|
|
}
|
|
if (OBJs == null)
|
|
{
|
|
OBJs = new List<GameObject>();
|
|
}
|
|
int num = IDs.IndexOf(id);
|
|
if (num != -1)
|
|
{
|
|
return OBJs[num];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|