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

View File

@@ -0,0 +1,58 @@
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
public class CameraController : MonoBehaviour
{
[SerializeField]
private Camera _cam;
[SerializeField]
private InputAction pressed, axis, scroll;
private float speed = 1f;
private Vector2 rotation;
private float scrollVal;
private bool canRotate;
// Start is called before the first frame update
void Awake()
{
pressed.Enable();
axis.Enable();
scroll.Enable();
pressed.performed += _ => { StartCoroutine(Rotate()); };
pressed.canceled += _ => { canRotate = false; };
axis.performed += context => { rotation = context.ReadValue<Vector2>(); };
axis.canceled += _ => { rotation = Vector3.zero; };
scroll.performed += context =>
{
scrollVal = context.ReadValue<float>();
ZoomIn();
};
}
private void ZoomIn()
{
RaycastHit hit;
if(scrollVal < 0 && Physics.Raycast(_cam.transform.position, transform.forward, out hit, 4))
return;
if(scrollVal < 0 || Vector3.Distance(_cam.transform.position, transform.position) < 20)
_cam.transform.position += -scrollVal * transform.forward;
}
private IEnumerator Rotate()
{
canRotate = true;
while (canRotate)
{
rotation *= speed;
transform.Rotate(Vector3.up, rotation.x);
transform.Rotate(transform.right, -rotation.y, Space.World);
yield return null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a62312a5bb77e82668e921d9e8d5c823
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

33
Assets/Scripts/Demo.cs Normal file
View File

@@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem.HID;
using UnityEngine.UI;
public class Demo : MonoBehaviour
{
[SerializeField]
private ObjectQ _queue;
[SerializeField] private Button previousBtn;
[SerializeField] private Button nextBtn;
void Awake()
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Quad);
_queue.Add(cube);
_queue.Add(sphere);
_queue.Add(capsule);
_queue.Add(cylinder);
_queue.Add(plane);
previousBtn.onClick.AddListener(() => _queue.Change(true));
nextBtn.onClick.AddListener(() => _queue.Change(false));
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f25ae0d97fedb0c394a3a3aca1bac60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d3baca064e59ccf2af3180895601755
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.PlayerLoop;
//Q(ueue)able Object used by the ObjectQ handler.
public class QableObject : MonoBehaviour
{
public float _dissolveTime = 0.5f;
public Renderer renderer;
private void Awake()
{
renderer = gameObject.GetComponent<Renderer>();
}
public IEnumerator Dissolve(bool reverse = false)
{
float timer = 0;
float from = reverse ? 1 : 0;
float to = reverse ? 0 : 1;
while (timer < _dissolveTime)
{
var val = Mathf.SmoothStep(from, to, timer/_dissolveTime);
val = Mathf.Clamp01(val);
renderer.material.SetFloat("Vector1_9fb2dc688df04073ae34e838656f2a2e", val);
timer += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
yield return timer;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1386ac625c7984cdcbeec5b76b2ef968
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: