-
Notifications
You must be signed in to change notification settings - Fork 2
/
ObjectCollection.cs
78 lines (62 loc) · 1.78 KB
/
ObjectCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Experimental.SceneManagement;
#endif
namespace Ardenfall
{
public class ObjectCollection : Collection
{
public List<GameObject> objects;
public bool initialPickRandom;
[HideInInspector] public int selectedIndex;
public override void UpdateCollection()
{
Select(selectedIndex);
}
public override void Step(int step)
{
Select(selectedIndex + step);
}
public override void Randomize()
{
if (objects.Count == 0)
return;
int index = UnityEngine.Random.Range(0, objects.Count);
Select(index);
}
public override void Select(int index)
{
if (objects.Count == 0)
return;
if (index >= objects.Count)
index = 0;
if (index < 0)
index = objects.Count - 1;
selectedIndex = index;
//Disable
foreach (GameObject obj in objects)
{
if(obj != null)
{
obj.hideFlags = HideFlags.DontSaveInBuild;
obj.SetActive(false);
}
}
//Enable
if (objects[index] != null)
{
objects[index].hideFlags = HideFlags.None;
objects[index].SetActive(true);
}
#if UNITY_EDITOR
if(gameObject.scene != null)
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene);
EditorUtility.SetDirty(this);
#endif
}
}
}