163 lines
3.4 KiB
C#
163 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace ProGroups
|
|
{
|
|
public class GroupContainer : MonoBehaviour
|
|
{
|
|
public Group[] sceneGroups = new Group[0];
|
|
|
|
public void NewGroup(string InName, GameObject[] InObjects)
|
|
{
|
|
Group obj = new Group(InName, InObjects, false, false);
|
|
if (sceneGroups != null)
|
|
{
|
|
ArrayExt.Add(ref sceneGroups, obj);
|
|
return;
|
|
}
|
|
sceneGroups = new Group[1] { obj };
|
|
}
|
|
|
|
public void ToggleFreeze(Group InGroup)
|
|
{
|
|
InGroup.RemoveNullOrEmpty();
|
|
InGroup.frozen = !InGroup.frozen;
|
|
GameObject[] objects = InGroup.objects;
|
|
foreach (GameObject gameObject in objects)
|
|
{
|
|
if (InGroup.frozen)
|
|
{
|
|
gameObject.hideFlags = HideFlags.NotEditable;
|
|
}
|
|
else if (!InGroup.hidden)
|
|
{
|
|
gameObject.hideFlags = HideFlags.None;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ToggleVis(Group InGroup)
|
|
{
|
|
if (InGroup.hidden)
|
|
{
|
|
ShowGroup(InGroup);
|
|
}
|
|
else
|
|
{
|
|
HideGroup(InGroup);
|
|
}
|
|
}
|
|
|
|
public void HideGroup(Group InGroup)
|
|
{
|
|
InGroup.RemoveNullOrEmpty();
|
|
GameObject[] objects = InGroup.objects;
|
|
foreach (GameObject gameObject in objects)
|
|
{
|
|
gameObject.hideFlags = HideFlags.NotEditable;
|
|
gameObject.SetActive(false);
|
|
}
|
|
InGroup.hidden = true;
|
|
}
|
|
|
|
public void ShowGroup(Group InGroup)
|
|
{
|
|
InGroup.RemoveNullOrEmpty();
|
|
GameObject[] objects = InGroup.objects;
|
|
foreach (GameObject gameObject in objects)
|
|
{
|
|
if (!InGroup.frozen)
|
|
{
|
|
gameObject.hideFlags = HideFlags.None;
|
|
}
|
|
gameObject.SetActive(true);
|
|
}
|
|
InGroup.hidden = false;
|
|
}
|
|
|
|
public void Isolate(int i)
|
|
{
|
|
for (int j = 0; j < sceneGroups.Length; j++)
|
|
{
|
|
if (j != i)
|
|
{
|
|
HideGroup(sceneGroups[j]);
|
|
}
|
|
}
|
|
ShowGroup(sceneGroups[i]);
|
|
}
|
|
|
|
public void RemoveGroups(IEnumerable<int> indices)
|
|
{
|
|
List<int> list = new List<int>(indices);
|
|
list.Sort();
|
|
int num = 0;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
int i2 = list[i] - num++;
|
|
RemoveGroup(i2);
|
|
}
|
|
}
|
|
|
|
public void RemoveGroup(int i)
|
|
{
|
|
sceneGroups[i].RemoveNullOrEmpty();
|
|
GameObject[] objects = sceneGroups[i].objects;
|
|
foreach (GameObject gameObject in objects)
|
|
{
|
|
gameObject.SetActive(true);
|
|
gameObject.hideFlags = HideFlags.None;
|
|
}
|
|
ArrayExt.RemoveAt(ref sceneGroups, i);
|
|
}
|
|
|
|
public void UpdateGroup(Group InGroup, GameObject[] InObjects)
|
|
{
|
|
InGroup.RemoveNullOrEmpty();
|
|
GameObject[] objects = InGroup.objects;
|
|
foreach (GameObject gameObject in objects)
|
|
{
|
|
gameObject.SetActive(true);
|
|
gameObject.hideFlags = HideFlags.None;
|
|
}
|
|
InGroup.objects = InObjects;
|
|
InGroup.hidden = false;
|
|
InGroup.frozen = false;
|
|
}
|
|
|
|
public void MoveGroupUp(int InShiftIndex)
|
|
{
|
|
if (InShiftIndex >= 1 && InShiftIndex <= sceneGroups.Length - 1)
|
|
{
|
|
Group obj = sceneGroups[InShiftIndex - 1];
|
|
sceneGroups[InShiftIndex - 1] = sceneGroups[InShiftIndex];
|
|
sceneGroups[InShiftIndex] = obj;
|
|
}
|
|
}
|
|
|
|
public void MoveGroupDown(int InShiftIndex)
|
|
{
|
|
if (InShiftIndex >= 0 && InShiftIndex <= sceneGroups.Length - 2)
|
|
{
|
|
Group obj = sceneGroups[InShiftIndex + 1];
|
|
sceneGroups[InShiftIndex + 1] = sceneGroups[InShiftIndex];
|
|
sceneGroups[InShiftIndex] = obj;
|
|
}
|
|
}
|
|
|
|
public void RemoveNullOrEmpty()
|
|
{
|
|
sceneGroups = sceneGroups.Where((Group x) => x != null && x.objects.Length > 0).ToArray();
|
|
}
|
|
|
|
public void Clean()
|
|
{
|
|
for (int i = 0; i < sceneGroups.Length; i++)
|
|
{
|
|
sceneGroups[i].RemoveNullOrEmpty();
|
|
}
|
|
}
|
|
}
|
|
}
|