This commit is contained in:
2023-02-07 16:44:00 +01:00
commit aba5e89872
47 changed files with 5702 additions and 0 deletions

69
Assets/Scripts/ObjectQ.cs Normal file
View File

@@ -0,0 +1,69 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
//Handle Objects in Queue
public class ObjectQ : MonoBehaviour
{
//all objects in the Q(ueue) are stored here
[SerializeField]
private List<QableObject> queue = new List<QableObject>();
[SerializeField]
private Material material;
private QableObject currentObject = null;
private int currentIndex = 0;
private State currentState = State.Changing;
//switch to next or previous object in Q
public void Change(bool previous = false)
{
if(queue.Count < 2 || currentState != State.ViewMode)
return;
currentIndex = previous ? currentIndex - 1 : currentIndex + 1;
currentIndex = (currentIndex + queue.Count) % queue.Count;
StartCoroutine(ShowNext());
currentState = State.Changing;
}
//add Object to Q
public void Add(GameObject gameObject)
{
var o = gameObject.AddComponent<QableObject>();
gameObject.transform.SetParent(transform);
gameObject.transform.position = transform.position;
o.renderer.material = material;
queue.Add(o);
//if no object is currently visible then show the first object in Q
if(currentObject == null)
StartCoroutine(ShowNext());
}
//Show next object from currentIndex
private IEnumerator ShowNext()
{
if(currentObject != null)
yield return StartCoroutine(currentObject.Dissolve());
currentObject = queue[currentIndex];
StartCoroutine(currentObject.Dissolve(true));
currentState = State.ViewMode;
}
//States of ObjectQ
public enum State
{
ViewMode,
Changing
}
}