From bee496d9d15e4a0157facbd9befc67cb8d060d16 Mon Sep 17 00:00:00 2001 From: FlorianSpeicher Date: Thu, 8 May 2025 21:03:27 +0200 Subject: [PATCH] Refactored code structure, naming. Translated comments. --- .../.idea/indexLayout.xml | 4 +- .../Assets/Scripts/Models/BaseModel.cs | 5 +- .../Scripts/Models/BaseModelBehaviour.cs | 7 +- .../Assets/Scripts/Models/ChildModel.cs | 13 +- .../Scripts/Models/ChildModelBehaviour.cs | 5 +- .../Assets/Scripts/Models/Model.cs | 58 +++++---- .../Assets/Scripts/Models/ModelBehaviour.cs | 82 ++++++------ .../Assets/Scripts/Models/ModelList.cs | 19 ++- .../Assets/Scripts/Models/ModelManager.cs | 82 ++++++------ vr-configurator/Assets/Scripts/Models/Port.cs | 41 +++--- .../Assets/Scripts/Transform/ExplodeBike.cs | 24 ++-- .../Assets/Scripts/UI/BaseModelSelector.cs | 121 +++++++++--------- .../Scripts/UI/ReturnButtonBehaviour.cs | 7 +- .../Assets/Scripts/Util/MathUtil.cs | 1 + .../Assets/Scripts/Util/ModelLoader.cs | 4 +- 15 files changed, 228 insertions(+), 245 deletions(-) diff --git a/vr-configurator/.idea/.idea.vr-configurator/.idea/indexLayout.xml b/vr-configurator/.idea/.idea.vr-configurator/.idea/indexLayout.xml index 390ba90..7b08163 100644 --- a/vr-configurator/.idea/.idea.vr-configurator/.idea/indexLayout.xml +++ b/vr-configurator/.idea/.idea.vr-configurator/.idea/indexLayout.xml @@ -1,9 +1,7 @@ - - ../../vr-configurator - + diff --git a/vr-configurator/Assets/Scripts/Models/BaseModel.cs b/vr-configurator/Assets/Scripts/Models/BaseModel.cs index 3a0ff6d..13ff70c 100644 --- a/vr-configurator/Assets/Scripts/Models/BaseModel.cs +++ b/vr-configurator/Assets/Scripts/Models/BaseModel.cs @@ -4,7 +4,8 @@ using UnityEngine; // Data definition of BaseModel public class BaseModel : Model { - public BaseModel(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, Quaternion rotation, Vector3 scale, List ports) + public BaseModel(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, + Quaternion rotation, Vector3 scale, List ports) : base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports) { @@ -14,5 +15,5 @@ public class BaseModel : Model { } + } - diff --git a/vr-configurator/Assets/Scripts/Models/BaseModelBehaviour.cs b/vr-configurator/Assets/Scripts/Models/BaseModelBehaviour.cs index 79ca37c..6c6f0c8 100644 --- a/vr-configurator/Assets/Scripts/Models/BaseModelBehaviour.cs +++ b/vr-configurator/Assets/Scripts/Models/BaseModelBehaviour.cs @@ -1,6 +1,4 @@ using System; -using Unity.VisualScripting; -using UnityEngine; //Only one should exist at the same time public class BaseModelBehaviour : ModelBehaviour @@ -21,6 +19,5 @@ public class BaseModelBehaviour : ModelBehaviour } } - - -} \ No newline at end of file + +} diff --git a/vr-configurator/Assets/Scripts/Models/ChildModel.cs b/vr-configurator/Assets/Scripts/Models/ChildModel.cs index bb579ec..6ee2569 100644 --- a/vr-configurator/Assets/Scripts/Models/ChildModel.cs +++ b/vr-configurator/Assets/Scripts/Models/ChildModel.cs @@ -4,17 +4,20 @@ using UnityEngine; // Data definition of ChildModel public class ChildModel : Model { - public string port { get; private set; } // port + public string Port { get; private set; } // port - public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, Quaternion rotation, Vector3 scale, List ports = null) + public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, + Quaternion rotation, Vector3 scale, List ports = null) : base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports) { - this.port = port; + this.Port = port; } - public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, List ports = null) + public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, + Material material, List ports = null) : base(nameHuman, nameId, mesh, material, ports) { - this.port = port; + this.Port = port; } + } diff --git a/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs b/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs index 3955fb5..c3f323d 100644 --- a/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs +++ b/vr-configurator/Assets/Scripts/Models/ChildModelBehaviour.cs @@ -1,6 +1,4 @@ -using JetBrains.Annotations; using System; -using UnityEngine; public class ChildModelBehaviour : ModelBehaviour { @@ -23,6 +21,5 @@ public class ChildModelBehaviour : ModelBehaviour Model = value; } } - -} \ No newline at end of file +} diff --git a/vr-configurator/Assets/Scripts/Models/Model.cs b/vr-configurator/Assets/Scripts/Models/Model.cs index d27b1f6..034cf3a 100644 --- a/vr-configurator/Assets/Scripts/Models/Model.cs +++ b/vr-configurator/Assets/Scripts/Models/Model.cs @@ -3,47 +3,49 @@ using System.Collections.Generic; public class Model { - public string nameHuman { get; internal set; } // human-readable name - public string nameId { get; internal set; } // JSON export name, should be unique - public Mesh mesh { get; internal set; } // obj/fbx - public Material material { get; internal set; } // skin + public string NameHuman { get; internal set; } // human-readable name + public string NameId { get; internal set; } // JSON export name, should be unique + public Mesh Mesh { get; internal set; } // obj/fbx + public Material Material { get; internal set; } // skin - public readonly List ports; + public readonly List Ports; - public readonly Vector3 offset; - public readonly Quaternion rotation; - public readonly Vector3 scale; + public readonly Vector3 Offset; + public readonly Quaternion Rotation; + public readonly Vector3 Scale; - public Model(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, Quaternion rotation, Vector3 scale, List ports = null) + public Model(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset, + Quaternion rotation, Vector3 scale, List ports = null) { - this.nameHuman = nameHuman; - this.nameId = nameId; - this.mesh = mesh; - this.material = material; - this.ports = ports; - this.offset = offset; - this.rotation = rotation; - this.scale = scale; + this.NameHuman = nameHuman; + this.NameId = nameId; + this.Mesh = mesh; + this.Material = material; + this.Ports = ports; + this.Offset = offset; + this.Rotation = rotation; + this.Scale = scale; } public Model(string nameHuman, string nameId, Mesh mesh, Material material, List ports = null) { - this.nameHuman = nameHuman; - this.nameId = nameId; - this.mesh = mesh; - this.material = material; - this.ports = ports; - this.offset = Vector3.zero; - this.rotation = Quaternion.identity; - this.scale = Vector3.one; + this.NameHuman = nameHuman; + this.NameId = nameId; + this.Mesh = mesh; + this.Material = material; + this.Ports = ports; + this.Offset = Vector3.zero; + this.Rotation = Quaternion.identity; + this.Scale = Vector3.one; } public bool HasPorts() { - return ports != null && ports.Count > 0; + return Ports != null && Ports.Count > 0; } public void AddPort(Port port) { - ports.Add(port); + Ports.Add(port); } -} \ No newline at end of file + +} diff --git a/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs b/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs index e7f84cb..3a6ff29 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelBehaviour.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Meta.XR.ImmersiveDebugger.UserInterface; using Unity.VisualScripting; using UnityEngine; @@ -22,45 +21,45 @@ public class ModelBehaviour : MonoBehaviour _model = value; } } //should be verified - internal List Children = new List(); - internal MeshFilter meshFilter; - internal MeshRenderer meshRenderer; + private readonly List _children = new List(); + private MeshFilter _meshFilter; + private MeshRenderer _meshRenderer; void Start() { Init(); } - void Init() // unity my beloved edge case + void Init() { - if(meshFilter == null) - meshFilter = gameObject.GetOrAddComponent(); - if(meshRenderer == null) - meshRenderer = gameObject.GetOrAddComponent(); + if(_meshFilter == null) + _meshFilter = gameObject.GetOrAddComponent(); + if(_meshRenderer == null) + _meshRenderer = gameObject.GetOrAddComponent(); } private void UpdateModel(Model newModel) { if (newModel is BaseModel) { - this.name = "BaseModel:" + newModel.nameId; + this.name = "BaseModel:" + newModel.NameId; } else if (newModel is ChildModel cModel) { - this.name = cModel.port + ":" + newModel.nameId; + this.name = cModel.Port + ":" + newModel.NameId; } Init(); Debug.Log($"Model {name} update to new {newModel} Model."); //unapply model offset if (Model != null) { - transform.localPosition -= Model.offset; + transform.localPosition -= Model.Offset; //rotation + scale is set, not modified } //kill old children foreach (var compo in GetComponentsInChildren()) { - if (compo == this) // why does InChildren include the parent + if (compo == this) // because InChildren include the parent { continue; } @@ -72,30 +71,30 @@ public class ModelBehaviour : MonoBehaviour if (newModel.HasPorts()) { Debug.Log($"Spawning {gameObject.name}'s ports"); - spawnChildPorts(newModel); + SpawnChildPorts(newModel); } //change ourselves - meshFilter.mesh = newModel.mesh; - meshFilter.sharedMesh = newModel.mesh; - meshRenderer.material = newModel.material; - meshRenderer.sharedMaterial = newModel.material; - transform.rotation = newModel.rotation; - transform.localScale = newModel.scale; - transform.localPosition += newModel.offset; + _meshFilter.mesh = newModel.Mesh; + _meshFilter.sharedMesh = newModel.Mesh; + _meshRenderer.material = newModel.Material; + _meshRenderer.sharedMaterial = newModel.Material; + transform.rotation = newModel.Rotation; + transform.localScale = newModel.Scale; + transform.localPosition += newModel.Offset; } public void UpdateChild(int childNum, string id) { - var newChildModel = FindAnyObjectByType().getById(id); - Children[childNum].GetComponent().UpdateModel(newChildModel); + var newChildModel = FindAnyObjectByType().GetById(id); + _children[childNum].GetComponent().UpdateModel(newChildModel); } public List GetChildrenWithPort(string port) { List list = new List(); - for (int i = 0; i < Children.Count; i++) + for (int i = 0; i < _children.Count; i++) { - if (Children[i].GetComponent().ChildModel.port == port) + if (_children[i].GetComponent().ChildModel.Port == port) { list.Add(i); } @@ -105,23 +104,23 @@ public class ModelBehaviour : MonoBehaviour public bool SetFirstWithPort(string port, ChildModel childModel) { - Debug.Log($"{this.name}: has {Children.Count} children"); - for (int i = 0; i < Children.Count; i++) + Debug.Log($"{this.name}: has {_children.Count} children"); + for (int i = 0; i < _children.Count; i++) { - var cmb = Children[i].GetComponent(); - Debug.Log($"{this.name}: {i} name {Children[i].name} - port {cmb.ChildModel.port}"); - if(cmb.ChildModel.port == port) + var cmb = _children[i].GetComponent(); + Debug.Log($"{this.name}: {i} name {_children[i].name} - port {cmb.ChildModel.Port}"); + if(cmb.ChildModel.Port == port) { if (childModel == null) { - Debug.LogWarning($"{this.name}: Cant replace port {port} with model, model is null"); + Debug.LogWarning($"{this.name}: Can't replace port {port} with model, model is null"); return false; } cmb.UpdateModel(Model); return true; } } - Debug.LogWarning($"{this.name}: Didnt find port {port}"); + Debug.LogWarning($"{this.name}: Didn't find port {port}"); return false; } @@ -129,13 +128,13 @@ public class ModelBehaviour : MonoBehaviour /// Spawns all Port-GO's, should be called only on Model Switch after cleanup /// /// Model the New Model to spawn ports from - private void spawnChildPorts(Model newModel) + private void SpawnChildPorts(Model newModel) { - Debug.Log($"{newModel.nameId}: Spawning {this.name} count of {newModel.ports.Count} Ports"); + Debug.Log($"{newModel.NameId}: Spawning {this.name} count of {newModel.Ports.Count} Ports"); - for (int i = 0; i < newModel.ports.Count; i++) + for (int i = 0; i < newModel.Ports.Count; i++) { - var port = newModel.ports[i]; + var port = newModel.Ports[i]; Debug.Log(i + ". Creating port " + port.port); // bike:wheel:num GameObject child = new GameObject(this.name + ":" + port.port + ":" + i); @@ -148,16 +147,17 @@ public class ModelBehaviour : MonoBehaviour Debug.LogError("ModelManager not found"); } - var childModel = mm.getById(port.defaultId); - if (childModel.mesh == null) + var childModel = mm.GetById(port.DefaultId); + if (childModel.Mesh == null) { - Debug.LogError("Default Mesh Not Found, destoying child"); + Debug.LogError("Default Mesh Not Found, destroying child"); Destroy(child); continue; } cmb.ChildModel = childModel; - port.apply(child.transform); // move to correct position - Children.Add(child); + port.Apply(child.transform); // move to correct position + _children.Add(child); } } + } diff --git a/vr-configurator/Assets/Scripts/Models/ModelList.cs b/vr-configurator/Assets/Scripts/Models/ModelList.cs index fa85ca4..bf74606 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelList.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelList.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Unity.Mathematics; using UnityEngine; /// @@ -11,7 +10,7 @@ public class ModelList public static readonly List BaseModels = new List() { new BaseModel( - "Fahrrad", + "Bike", "bike", Resources.Load("Model/Bicycle/Models/Low-Poly Bicycle"), Resources.Load($"Model/Universal_Material"), @@ -20,7 +19,6 @@ public class ModelList Vector3.one, new List { - //please dont ask about the numbers new Port(Definitions.PORT_BIKE_SPROCKET, new Vector3(0.007933f, 0.444f, -0.1614f), "idBikeSprocket"), new Port(Definitions.PORT_BIKE_PEDAL_L, new Vector3(-0.1252177f, 0.5490288f, -0.312027f), "idBikePedalL_1"), new Port(Definitions.PORT_BIKE_PEDAL_R, new Vector3(0.1410843f, 0.3393247f, -0.01154391f), "idBikePedalR_1"), @@ -35,9 +33,9 @@ public class ModelList "erlbach", Resources.Load("Model/ERLbach/02.01.98.0000-ERLbach_vereinfacht"), Resources.Load($"Model/Universal_Material"), - new Vector3(0,0,4f), //big car needs big space + new Vector3(0,0,4f), //car space Quaternion.Euler(-90f,0f,0f), //rotate correctly - new Vector3(0.03f,0.03f,0.03f), //model bisschen groß + new Vector3(0.03f,0.03f,0.03f), //because model is too big in space new List { new Port(Definitions.PORT_ERLBACH_0, new Vector3(0f, 0f, 0f), "idErlbachPart0"), @@ -157,7 +155,7 @@ public class ModelList ), new ChildModel( Definitions.PORT_BIKE_WHEEL, - "30 Zoller MehrSpeicherFelge", + "30\" Rim", "bike30inchAlloy", Resources.Load("Plagues/Mesh/Hex"), Resources.Load($"Model/Universal_Material"), @@ -165,7 +163,7 @@ public class ModelList ), new ChildModel( "bikePedalR", - "Pedal Rechts", + "Pedal (right)", "bikePedalR", Resources.Load("Plagues/Mesh/Hex"), Resources.Load($"Model/Universal_Material"), @@ -173,7 +171,7 @@ public class ModelList ), new ChildModel( "bikePedalL", - "Pedal Links", + "Pedal (left)", "bikePedalL", Resources.Load("Plagues/Mesh/Hex"), Resources.Load($"Model/Universal_Material"), @@ -183,7 +181,6 @@ public class ModelList static ModelList() { - // I love importing .fbx, maybe refactor this function some day /* * ██████ ██ ██ ██ ███████ @@ -242,7 +239,7 @@ public class ModelList null, null, }, - 1 //skip the first mesh, which is the basemodel + 1 //skip the first mesh, which is the baseModel ); /* @@ -749,7 +746,7 @@ public class ModelList null, }, - 0 //skip the first mesh, which is the basemodel + 0 //skip the first mesh, which is the baseModel ); } } diff --git a/vr-configurator/Assets/Scripts/Models/ModelManager.cs b/vr-configurator/Assets/Scripts/Models/ModelManager.cs index f49d27a..7af20bb 100644 --- a/vr-configurator/Assets/Scripts/Models/ModelManager.cs +++ b/vr-configurator/Assets/Scripts/Models/ModelManager.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; public class ModelManager : MonoBehaviour { - private Dictionary> portDict; //port mapped on - private Dictionary childModelDict; //childModels by their ID + private Dictionary> _portDict; //port mapped on + private Dictionary _childModelDict; //childModels by their ID - public List baseModelList; //available BaseModels + private List _baseModelList; //available BaseModels public GameObject baseModel; //current baseModel public BaseModelSelector baseModelSelector; @@ -14,20 +14,20 @@ public class ModelManager : MonoBehaviour // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { - Debug.Log("ModelManager: " + this.gameObject.name); - portDict = new Dictionary>(); - childModelDict = new Dictionary(); - baseModelList = new List(); + Debug.Log("ModelManager: " + gameObject.name); + _portDict = new Dictionary>(); + _childModelDict = new Dictionary(); + _baseModelList = new List(); //baseModelSelector = FindFirstObjectByType(); foreach (var baseModel in ModelList.BaseModels) { - registerBaseModel(baseModel); + RegisterBaseModel(baseModel); } foreach (var childModel in ModelList.ChildModels) { - registerChildModel(childModel); + RegisterChildModel(childModel); } if (baseModel == null) //set in the editor { @@ -42,71 +42,71 @@ public class ModelManager : MonoBehaviour } - void registerChildModel(ChildModel model) + void RegisterChildModel(ChildModel model) { //childModelDict - if (childModelDict.ContainsKey(model.nameId)) + if (_childModelDict.ContainsKey(model.NameId)) { - Debug.LogWarning("Model " + model.nameId + " already registered! [childModelDict] Skipping..."); + Debug.LogWarning("Model " + model.NameId + " already registered! [childModelDict] Skipping..."); return; } - childModelDict[model.nameId] = model; + _childModelDict[model.NameId] = model; //portDict - if (!portDict.ContainsKey(model.port)) + if (!_portDict.ContainsKey(model.Port)) { - portDict.Add(model.port, new HashSet()); + _portDict.Add(model.Port, new HashSet()); } - if (portDict[model.port].Contains(model)) + if (_portDict[model.Port].Contains(model)) { - Debug.LogWarning("Model " + model.nameId + " already registered! [portDict] Skipping..."); + Debug.LogWarning("Model " + model.NameId + " already registered! [portDict] Skipping..."); return; } - portDict[model.port].Add(model); + _portDict[model.Port].Add(model); } - void registerBaseModel(BaseModel baseModel) + void RegisterBaseModel(BaseModel baseModel) { if (baseModel == null) { return; } - baseModelList ??= new List(); - baseModelList.Add(baseModel); + _baseModelList ??= new List(); + _baseModelList.Add(baseModel); } - public HashSet getChildModelsForPort(string port) + public HashSet GetChildModelsForPort(string port) { - // Überprüfen, ob der Schlüssel im Dictionary vorhanden ist - if (portDict.TryGetValue(port, out HashSet childModels)) + // Check if key exists in the dictionary + if (_portDict.TryGetValue(port, out HashSet childModels)) { - return childModels; // Gibt die ChildModels zurück, die zu diesem Port gehören + return childModels; // Return childModels of the port } else { - // Wenn der Schlüssel nicht gefunden wird, gebe eine Warnung aus und gebe null oder ein leeres Set zurück - Debug.LogWarning($"Kein Modell für den Port {port} gefunden."); - return new HashSet(); // Leeres Set zurückgeben + // Warning and return empty set if key not found + Debug.LogWarning($"No model found for port {port}."); + return new HashSet(); } } - public ChildModel getById(string id) + public ChildModel GetById(string id) { - return childModelDict[id]; + return _childModelDict[id]; } public void LoadSelectedModel(BaseModel baseModel) { - //create if doesnt exist + //create if doesn't exist if (this.baseModel == null) { - // Neues GameObject für das BaseModel erstellen - this.baseModel = new GameObject(baseModel.nameId) + // Create new GameObject for the baseModel + this.baseModel = new GameObject(baseModel.NameId) { - name = baseModel.nameId, + name = baseModel.NameId, }; this.baseModel.AddComponent(); - // Positionieren + // Positioning this.baseModel.transform.position = new Vector3(0, 0, 1); this.baseModel.transform.rotation = Quaternion.Euler(0, 90, 0); this.baseModel.SetActive(true); @@ -114,21 +114,15 @@ public class ModelManager : MonoBehaviour this.baseModel.GetComponent().BaseModel = baseModel; this.baseModel.SetActive(true); - Debug.Log($"Model {baseModel.nameHuman} lock and loaded."); + Debug.Log($"Model {baseModel.NameHuman} lock and loaded."); } - public void openSelector() + public void OpenSelector() { Debug.Log("Open Selector"); baseModel.SetActive(false); - baseModelSelector.Activate(); //actimel aktiviert auswahlkräfte + baseModelSelector.Activate(); } - - } - - - - diff --git a/vr-configurator/Assets/Scripts/Models/Port.cs b/vr-configurator/Assets/Scripts/Models/Port.cs index b749677..9d5d4d2 100644 --- a/vr-configurator/Assets/Scripts/Models/Port.cs +++ b/vr-configurator/Assets/Scripts/Models/Port.cs @@ -1,44 +1,45 @@ using UnityEngine; public class Port { - Vector3 position; - Quaternion rotation; - Vector3 scale; + private readonly Vector3 _position; + private readonly Quaternion _rotation; + private readonly Vector3 _scale; public string port { private set; get; } // port name - public string defaultId { private set; get; } + public string DefaultId { private set; get; } - public void apply(Transform target) + public void Apply(Transform target) { - target.localPosition = position; - target.localRotation = rotation; - target.localScale = scale; + target.localPosition = _position; + target.localRotation = _rotation; + target.localScale = _scale; } public Port(string name, Vector3 position, string defaultId) { port = name; - this.position = position; - this.rotation = Quaternion.identity; - this.scale = new Vector3(1f,1f,1f); - this.defaultId = defaultId; + this._position = position; + this._rotation = Quaternion.identity; + this._scale = new Vector3(1f,1f,1f); + this.DefaultId = defaultId; } public Port(string port, Vector3 position, Quaternion rotation, Vector3 scale, string defaultId) { this.port = port; - this.position = position; - this.rotation = rotation; - this.scale = scale; - this.defaultId = defaultId; + this._position = position; + this._rotation = rotation; + this._scale = scale; + this.DefaultId = defaultId; } public Port(string port, Vector3 position, Quaternion rotation, string defaultId) { this.port = port; - this.position = position; - this.rotation = rotation; - this.scale = new Vector3(1f,1f,1f); - this.defaultId = defaultId; + this._position = position; + this._rotation = rotation; + this._scale = new Vector3(1f,1f,1f); + this.DefaultId = defaultId; } + } diff --git a/vr-configurator/Assets/Scripts/Transform/ExplodeBike.cs b/vr-configurator/Assets/Scripts/Transform/ExplodeBike.cs index ff92bf9..79a967a 100644 --- a/vr-configurator/Assets/Scripts/Transform/ExplodeBike.cs +++ b/vr-configurator/Assets/Scripts/Transform/ExplodeBike.cs @@ -6,42 +6,42 @@ public class ExplodeBike : MonoBehaviour public class BikePart { public Transform part; - public Vector3 explodeDirection; // Richtung, in die das Teil explodiert + public Vector3 explodeDirection; } public BikePart[] bikeParts; public float explosionDistance = 2f; public float explosionSpeed = 2f; - private bool isExploding = false; + private bool _isExploding = false; - private Vector3[] originalPositions; + private Vector3[] _originalPositions; void Start() { - originalPositions = new Vector3[bikeParts.Length]; + _originalPositions = new Vector3[bikeParts.Length]; for (int i = 0; i < bikeParts.Length; i++) { - originalPositions[i] = bikeParts[i].part.localPosition; + _originalPositions[i] = bikeParts[i].part.localPosition; } } void Update() { - if (isExploding) + if (_isExploding) { for (int i = 0; i < bikeParts.Length; i++) { - Vector3 targetPos = originalPositions[i] + bikeParts[i].explodeDirection.normalized * explosionDistance; - bikeParts[i].part.localPosition = Vector3.Lerp(bikeParts[i].part.localPosition, targetPos, Time.deltaTime * explosionSpeed); + Vector3 targetPos = _originalPositions[i] + + bikeParts[i].explodeDirection.normalized * explosionDistance; + bikeParts[i].part.localPosition = Vector3 + .Lerp(bikeParts[i].part.localPosition, targetPos, Time.deltaTime * explosionSpeed); } } } public void Explode() { - isExploding = true; + _isExploding = true; } + } - - - diff --git a/vr-configurator/Assets/Scripts/UI/BaseModelSelector.cs b/vr-configurator/Assets/Scripts/UI/BaseModelSelector.cs index 2403b45..6528e5d 100644 --- a/vr-configurator/Assets/Scripts/UI/BaseModelSelector.cs +++ b/vr-configurator/Assets/Scripts/UI/BaseModelSelector.cs @@ -1,19 +1,15 @@ -using System; -using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; -using UnityEngine.InputSystem.UI; public class BaseModelSelector : MonoBehaviour { - private Canvas canvas; - private GameObject buttonPrefab; - private Button[] modelButtons; - private BaseModel selectedModel = null; // Gemerkte Auswahl! + private Canvas _canvas; + private GameObject _buttonPrefab; + private Button[] _modelButtons; - public ModelManager modelManager; // <-- ziehen wir im Inspector rein + public ModelManager modelManager; // <-- to be put in inspector public ReturnButtonBehaviour returnButton; @@ -32,77 +28,77 @@ public class BaseModelSelector : MonoBehaviour { if (FindObjectOfType() == null) { - GameObject eventSystemGO = new GameObject("EventSystem"); - var eventSys = eventSystemGO.AddComponent(); - //var inputModule = eventSystemGO.AddComponent(); - var MetaInputModule = eventSystemGO.AddComponent(); + GameObject eventSystemGo = new GameObject("EventSystem"); + eventSystemGo.AddComponent(); + //var inputModule = eventSystemGO.AddComponent(); //Put in for keyboard input. Must be commented out on quest + eventSystemGo.AddComponent(); } else { - Debug.Log("EventSystem existiert bereits - neues wird nicht erstellt."); + Debug.Log("EventSystem already exists - new one will not be created."); } } void SetupCanvas() { - GameObject canvasGO = new GameObject("ModelSelectorCanvas"); - canvasGO.transform.SetParent(gameObject.transform); - canvas = canvasGO.AddComponent(); - canvas.renderMode = RenderMode.WorldSpace; + GameObject canvasGo = new GameObject("ModelSelectorCanvas"); + canvasGo.transform.SetParent(gameObject.transform); + _canvas = canvasGo.AddComponent(); + _canvas.renderMode = RenderMode.WorldSpace; var cameraRig = GameObject.Find("[BuildingBlock] Camera Rig"); if (cameraRig != null) { var centerEye = cameraRig.transform.Find("TrackingSpace/CenterEyeAnchor"); - canvas.worldCamera = centerEye.GetComponent(); - canvas.transform.position = centerEye.position + centerEye.forward * 2f; - canvas.transform.rotation = Quaternion.LookRotation(canvas.transform.position - centerEye.position); + _canvas.worldCamera = centerEye.GetComponent(); + _canvas.transform.position = centerEye.position + centerEye.forward * 2f; + _canvas.transform.rotation = Quaternion.LookRotation(_canvas.transform.position - centerEye.position); } else { - Debug.LogError("Camera Rig nicht gefunden!"); + Debug.LogError("Camera Rig not found!"); } - canvasGO.AddComponent().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; - canvasGO.AddComponent(); - canvasGO.AddComponent(); + canvasGo.AddComponent().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; + canvasGo.AddComponent(); + canvasGo.AddComponent(); } void CreatePrefabButtons() { - float startY = 0; // Anfangsposition auf Y-Achse - float buttonHeight = 0.5f; // Abstand zwischen den Buttons + float startY = 0; // Start position on Y axis + float buttonHeight = 0.5f; // Distance between Buttons foreach (var baseModel in ModelList.BaseModels) { - GameObject buttonGO = SetupPrefab(baseModel); - buttonGO.transform.SetParent(canvas.transform); - RectTransform rt = buttonGO.GetComponent(); - var collider = buttonGO.AddComponent(); + GameObject buttonGo = SetupPrefab(baseModel); + buttonGo.transform.SetParent(_canvas.transform); + RectTransform rt = buttonGo.GetComponent(); + var collider = buttonGo.AddComponent(); rt.sizeDelta = new Vector2(300, 50); - rt.localScale = Vector3.one * 0.005f;// Größe des Buttons - rt.localPosition = new Vector3(0, startY, 0); // Position im Canvas + rt.localScale = Vector3.one * 0.005f;// Buttons size + rt.localPosition = new Vector3(0, startY, 0); // Position in the Canvas rt.localRotation = Quaternion.identity; - // Collider richtig setzen + // Setup Collider correctly collider.size = new Vector3(rt.sizeDelta.x * rt.localScale.x, rt.sizeDelta.y * rt.localScale.y, 1f); collider.center = Vector3.zero; - buttonGO.GetComponent public class ModelLoader { - public static void LoadChildModelsFromPackedModel(List appendList, string[] port, string[] nameHuman, string[] nameId, Mesh[] meshes, Material[] mats, List[] ports, int fromMesh = 0, int toMesh = -1) + public static void LoadChildModelsFromPackedModel(List appendList, string[] port, string[] nameHuman, + string[] nameId, Mesh[] meshes, Material[] mats, List[] ports, int fromMesh = 0, int toMesh = -1) { Debug.Log("LoadChildModels " + fromMesh + " to " + toMesh + " from " + mats.Length + " meshes"); if (toMesh == -1) @@ -19,4 +20,5 @@ public class ModelLoader appendList.Add(new ChildModel(port[i], nameHuman[i], nameId[i], meshes[fromMesh + i], mats[i], ports[i])); } } + }