Files
virtualclassroomdhbw/Assets/Scripts/Classroom/OBJBar.cs
T
2024-10-29 17:16:17 +01:00

72 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
//this script is the second part of the menu bar
public class OBJBar : MonoBehaviour
{
[SerializeField] private GameObject OBJCanvas;
[SerializeField] private GameObject MenuCanvas;
[SerializeField] private GameObject MainCamera;
private void Update()
{
// see menu bar
Vector3 newPosition = MainCamera.transform.position + MainCamera.transform.forward * 0.7f;
newPosition.y = MainCamera.transform.position.y - 0.45f;
OBJCanvas.transform.position = newPosition;
OBJCanvas.transform.rotation = Quaternion.Euler(15, MainCamera.transform.rotation.eulerAngles.y, 0);
}
//change back to the menu bar default
public void changeToMenu()
{
OBJCanvas.SetActive(false);
MenuCanvas.SetActive(true);
}
//open the file explorer provided by OBJLoader
public void openOBJLoader() {
GameObject.Find("ObjectSpawner").GetComponent<OBJLoader>().OpenObjLoadingDialog();
}
//scale the last selected object
public void scaleUP()
{
GameObject lastTouchesObj = GameObject.Find("ObjectSpawner").GetComponent<OBJGrabListener>().lastTouchedOBJ;
lastTouchesObj.transform.localScale += new Vector3(0.1f, 0.1f, 0.1f);
ObjectSync objSyn = GameObject.Find("ObjectSpawner").GetComponent<ObjectSync>();
//get the index of the scaled object in object lists (for sync)
int index = objSyn.spawnedObjects.IndexOf(lastTouchesObj);
//try to sync the new location to the server (all clients too)
objSyn.syncScaleServerRPC(index, lastTouchesObj.transform.localScale);
}
//same as scale up
public void scaleDown()
{
GameObject lastTouchesObj = GameObject.Find("ObjectSpawner").GetComponent<OBJGrabListener>().lastTouchedOBJ;
lastTouchesObj.transform.localScale -= new Vector3(0.1f, 0.1f, 0.1f);
ObjectSync objSyn = GameObject.Find("ObjectSpawner").GetComponent<ObjectSync>();
int index = objSyn.spawnedObjects.IndexOf(lastTouchesObj);
objSyn.syncScaleServerRPC(index, lastTouchesObj.transform.localScale);
}
//same as scale up BUT the location is set to 1, 1, 1 instead of adding or substring
public void resetScale()
{
GameObject lastTouchesObj = GameObject.Find("ObjectSpawner").GetComponent<OBJGrabListener>().lastTouchedOBJ;
lastTouchesObj.transform.localScale = new Vector3(1, 1, 1);
ObjectSync objSyn = GameObject.Find("ObjectSpawner").GetComponent<ObjectSync>();
int index = objSyn.spawnedObjects.IndexOf(lastTouchesObj);
objSyn.syncScaleServerRPC(index, lastTouchesObj.transform.localScale);
}
}