Refactored code structure, naming. Translated comments.
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders>
|
||||
<Path>../../vr-configurator</Path>
|
||||
</attachedFolders>
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
|
||||
@@ -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<Port> ports)
|
||||
public BaseModel(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset,
|
||||
Quaternion rotation, Vector3 scale, List<Port> ports)
|
||||
: base(nameHuman, nameId, mesh, material, offset, rotation, scale, ports)
|
||||
{
|
||||
|
||||
@@ -14,5 +15,5 @@ public class BaseModel : Model
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Port> ports = null)
|
||||
public ChildModel(string port, string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset,
|
||||
Quaternion rotation, Vector3 scale, List<Port> 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<Port> ports = null)
|
||||
public ChildModel(string port, string nameHuman, string nameId, Mesh mesh,
|
||||
Material material, List<Port> ports = null)
|
||||
: base(nameHuman, nameId, mesh, material, ports)
|
||||
{
|
||||
this.port = port;
|
||||
this.Port = port;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Port> ports;
|
||||
public readonly List<Port> 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<Port> ports = null)
|
||||
public Model(string nameHuman, string nameId, Mesh mesh, Material material, Vector3 offset,
|
||||
Quaternion rotation, Vector3 scale, List<Port> 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<Port> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<GameObject> Children = new List<GameObject>();
|
||||
internal MeshFilter meshFilter;
|
||||
internal MeshRenderer meshRenderer;
|
||||
private readonly List<GameObject> _children = new List<GameObject>();
|
||||
private MeshFilter _meshFilter;
|
||||
private MeshRenderer _meshRenderer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init() // unity my beloved edge case
|
||||
void Init()
|
||||
{
|
||||
if(meshFilter == null)
|
||||
meshFilter = gameObject.GetOrAddComponent<MeshFilter>();
|
||||
if(meshRenderer == null)
|
||||
meshRenderer = gameObject.GetOrAddComponent<MeshRenderer>();
|
||||
if(_meshFilter == null)
|
||||
_meshFilter = gameObject.GetOrAddComponent<MeshFilter>();
|
||||
if(_meshRenderer == null)
|
||||
_meshRenderer = gameObject.GetOrAddComponent<MeshRenderer>();
|
||||
}
|
||||
|
||||
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<ChildModelBehaviour>())
|
||||
{
|
||||
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<ModelManager>().getById(id);
|
||||
Children[childNum].GetComponent<ChildModelBehaviour>().UpdateModel(newChildModel);
|
||||
var newChildModel = FindAnyObjectByType<ModelManager>().GetById(id);
|
||||
_children[childNum].GetComponent<ChildModelBehaviour>().UpdateModel(newChildModel);
|
||||
}
|
||||
|
||||
public List<int> GetChildrenWithPort(string port)
|
||||
{
|
||||
List<int> list = new List<int>();
|
||||
for (int i = 0; i < Children.Count; i++)
|
||||
for (int i = 0; i < _children.Count; i++)
|
||||
{
|
||||
if (Children[i].GetComponent<ChildModelBehaviour>().ChildModel.port == port)
|
||||
if (_children[i].GetComponent<ChildModelBehaviour>().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<ChildModelBehaviour>();
|
||||
Debug.Log($"{this.name}: {i} name {Children[i].name} - port {cmb.ChildModel.port}");
|
||||
if(cmb.ChildModel.port == port)
|
||||
var cmb = _children[i].GetComponent<ChildModelBehaviour>();
|
||||
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 <b>after</b> cleanup
|
||||
/// </summary>
|
||||
/// <param name="newModel"><c>Model</c> the New Model to spawn ports from</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -11,7 +10,7 @@ public class ModelList
|
||||
public static readonly List<BaseModel> BaseModels = new List<BaseModel>()
|
||||
{
|
||||
new BaseModel(
|
||||
"Fahrrad",
|
||||
"Bike",
|
||||
"bike",
|
||||
Resources.Load<Mesh>("Model/Bicycle/Models/Low-Poly Bicycle"),
|
||||
Resources.Load<Material>($"Model/Universal_Material"),
|
||||
@@ -20,7 +19,6 @@ public class ModelList
|
||||
Vector3.one,
|
||||
new List<Port>
|
||||
{
|
||||
//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<Mesh>("Model/ERLbach/02.01.98.0000-ERLbach_vereinfacht"),
|
||||
Resources.Load<Material>($"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<Port>
|
||||
{
|
||||
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<Mesh>("Plagues/Mesh/Hex"),
|
||||
Resources.Load<Material>($"Model/Universal_Material"),
|
||||
@@ -165,7 +163,7 @@ public class ModelList
|
||||
),
|
||||
new ChildModel(
|
||||
"bikePedalR",
|
||||
"Pedal Rechts",
|
||||
"Pedal (right)",
|
||||
"bikePedalR",
|
||||
Resources.Load<Mesh>("Plagues/Mesh/Hex"),
|
||||
Resources.Load<Material>($"Model/Universal_Material"),
|
||||
@@ -173,7 +171,7 @@ public class ModelList
|
||||
),
|
||||
new ChildModel(
|
||||
"bikePedalL",
|
||||
"Pedal Links",
|
||||
"Pedal (left)",
|
||||
"bikePedalL",
|
||||
Resources.Load<Mesh>("Plagues/Mesh/Hex"),
|
||||
Resources.Load<Material>($"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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ using System.Collections.Generic;
|
||||
|
||||
public class ModelManager : MonoBehaviour
|
||||
{
|
||||
private Dictionary<string, HashSet<ChildModel>> portDict; //port mapped on
|
||||
private Dictionary<string, ChildModel> childModelDict; //childModels by their ID
|
||||
private Dictionary<string, HashSet<ChildModel>> _portDict; //port mapped on
|
||||
private Dictionary<string, ChildModel> _childModelDict; //childModels by their ID
|
||||
|
||||
public List<BaseModel> baseModelList; //available BaseModels
|
||||
private List<BaseModel> _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<string, HashSet<ChildModel>>();
|
||||
childModelDict = new Dictionary<string, ChildModel>();
|
||||
baseModelList = new List<BaseModel>();
|
||||
Debug.Log("ModelManager: " + gameObject.name);
|
||||
_portDict = new Dictionary<string, HashSet<ChildModel>>();
|
||||
_childModelDict = new Dictionary<string, ChildModel>();
|
||||
_baseModelList = new List<BaseModel>();
|
||||
//baseModelSelector = FindFirstObjectByType<BaseModelSelector>();
|
||||
|
||||
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<ChildModel>());
|
||||
_portDict.Add(model.Port, new HashSet<ChildModel>());
|
||||
}
|
||||
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<BaseModel>();
|
||||
baseModelList.Add(baseModel);
|
||||
_baseModelList ??= new List<BaseModel>();
|
||||
_baseModelList.Add(baseModel);
|
||||
}
|
||||
|
||||
public HashSet<ChildModel> getChildModelsForPort(string port)
|
||||
public HashSet<ChildModel> GetChildModelsForPort(string port)
|
||||
{
|
||||
// Überprüfen, ob der Schlüssel im Dictionary vorhanden ist
|
||||
if (portDict.TryGetValue(port, out HashSet<ChildModel> childModels))
|
||||
// Check if key exists in the dictionary
|
||||
if (_portDict.TryGetValue(port, out HashSet<ChildModel> 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<ChildModel>(); // Leeres Set zurückgeben
|
||||
// Warning and return empty set if key not found
|
||||
Debug.LogWarning($"No model found for port {port}.");
|
||||
return new HashSet<ChildModel>();
|
||||
}
|
||||
}
|
||||
|
||||
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<BaseModelBehaviour>();
|
||||
// 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<BaseModelBehaviour>().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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<EventSystem>() == null)
|
||||
{
|
||||
GameObject eventSystemGO = new GameObject("EventSystem");
|
||||
var eventSys = eventSystemGO.AddComponent<EventSystem>();
|
||||
//var inputModule = eventSystemGO.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>();
|
||||
var MetaInputModule = eventSystemGO.AddComponent<OVRInputModule>();
|
||||
GameObject eventSystemGo = new GameObject("EventSystem");
|
||||
eventSystemGo.AddComponent<EventSystem>();
|
||||
//var inputModule = eventSystemGO.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>(); //Put in for keyboard input. Must be commented out on quest
|
||||
eventSystemGo.AddComponent<OVRInputModule>();
|
||||
|
||||
}
|
||||
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>();
|
||||
canvas.renderMode = RenderMode.WorldSpace;
|
||||
GameObject canvasGo = new GameObject("ModelSelectorCanvas");
|
||||
canvasGo.transform.SetParent(gameObject.transform);
|
||||
_canvas = canvasGo.AddComponent<Canvas>();
|
||||
_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<Camera>();
|
||||
canvas.transform.position = centerEye.position + centerEye.forward * 2f;
|
||||
canvas.transform.rotation = Quaternion.LookRotation(canvas.transform.position - centerEye.position);
|
||||
_canvas.worldCamera = centerEye.GetComponent<Camera>();
|
||||
_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<CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasGO.AddComponent<GraphicRaycaster>();
|
||||
canvasGO.AddComponent<OVRRaycaster>();
|
||||
canvasGo.AddComponent<CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasGo.AddComponent<GraphicRaycaster>();
|
||||
canvasGo.AddComponent<OVRRaycaster>();
|
||||
}
|
||||
|
||||
|
||||
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<RectTransform>();
|
||||
var collider = buttonGO.AddComponent<BoxCollider>();
|
||||
GameObject buttonGo = SetupPrefab(baseModel);
|
||||
buttonGo.transform.SetParent(_canvas.transform);
|
||||
RectTransform rt = buttonGo.GetComponent<RectTransform>();
|
||||
var collider = buttonGo.AddComponent<BoxCollider>();
|
||||
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<Button>().onClick.AddListener(() => OnModelButtonClicked(baseModel));
|
||||
startY -= buttonHeight; // Nächster Button weiter unten
|
||||
buttonGo.GetComponent<Button>().onClick.AddListener(() => OnModelButtonClicked(baseModel));
|
||||
startY -= buttonHeight; // Next button below
|
||||
}
|
||||
|
||||
}
|
||||
// Wenn ein Button geklickt wird
|
||||
// When button is clicked
|
||||
public void OnModelButtonClicked(BaseModel model)
|
||||
{
|
||||
Debug.Log($"Ausgewähltes Modell: {model.nameHuman}");
|
||||
Debug.Log($"Selected model: {model.NameHuman}");
|
||||
|
||||
if (modelManager == null)
|
||||
{
|
||||
Debug.LogError("ModelManager ist nicht zugewiesen!");
|
||||
Debug.LogError("ModelManager is not assigned!");
|
||||
return;
|
||||
}
|
||||
modelManager.LoadSelectedModel(model);
|
||||
@@ -112,9 +108,9 @@ public class BaseModelSelector : MonoBehaviour
|
||||
Debug.LogError("ReturnButton is null!");
|
||||
return;
|
||||
}
|
||||
returnButton.Activate(); //aktiviere actimel kräfte
|
||||
returnButton.Activate();
|
||||
|
||||
if (canvas == null)
|
||||
if (_canvas == null)
|
||||
{
|
||||
Debug.LogError("Canvas doesn't exist");
|
||||
return;
|
||||
@@ -124,53 +120,53 @@ public class BaseModelSelector : MonoBehaviour
|
||||
|
||||
public static GameObject SetupPrefab(BaseModel model)
|
||||
{
|
||||
// Hauptobjekt
|
||||
GameObject buttonGO = new GameObject("ModelButton_" + model.nameId);
|
||||
buttonGO.AddComponent<RectTransform>();
|
||||
// Main object
|
||||
GameObject buttonGo = new GameObject("ModelButton_" + model.NameId);
|
||||
buttonGo.AddComponent<RectTransform>();
|
||||
|
||||
var button = buttonGO.AddComponent<Button>();
|
||||
buttonGo.AddComponent<Button>();
|
||||
|
||||
var image = buttonGO.AddComponent<Image>();
|
||||
var image = buttonGo.AddComponent<Image>();
|
||||
|
||||
// Lade individuellen Hintergrund aus Resources/UI/ButtonBackgrounds/
|
||||
// Load background from Resources/UI/ButtonBackgrounds/
|
||||
var backgroundSprite = Resources.Load<Sprite>($"sprites/default");
|
||||
if (backgroundSprite != null)
|
||||
image.sprite = backgroundSprite;
|
||||
else
|
||||
image.color = new Color(0.2f, 0.2f, 0.2f, 0.8f); // Fallback-Farbe
|
||||
image.color = new Color(0.2f, 0.2f, 0.2f, 0.8f); // Fallback-Color
|
||||
|
||||
// Größe
|
||||
RectTransform rt = buttonGO.GetComponent<RectTransform>();
|
||||
// Size
|
||||
RectTransform rt = buttonGo.GetComponent<RectTransform>();
|
||||
rt.sizeDelta = new Vector2(300, 100);
|
||||
|
||||
// === Icon ===
|
||||
GameObject iconGO = new GameObject("Icon");
|
||||
iconGO.transform.SetParent(buttonGO.transform, false);
|
||||
var iconImage = iconGO.AddComponent<Image>();
|
||||
iconImage.sprite = Resources.Load<Sprite>($"sprites/"+model.nameId);
|
||||
GameObject iconGo = new GameObject("Icon");
|
||||
iconGo.transform.SetParent(buttonGo.transform, false);
|
||||
var iconImage = iconGo.AddComponent<Image>();
|
||||
iconImage.sprite = Resources.Load<Sprite>($"sprites/"+model.NameId);
|
||||
|
||||
RectTransform iconRT = iconGO.GetComponent<RectTransform>();
|
||||
RectTransform iconRT = iconGo.GetComponent<RectTransform>();
|
||||
iconRT.anchorMin = new Vector2(0, 0.5f);
|
||||
iconRT.anchorMax = new Vector2(0, 0.5f);
|
||||
iconRT.pivot = new Vector2(0, 0.5f);
|
||||
iconRT.anchoredPosition = new Vector2(10, 0);
|
||||
iconRT.sizeDelta = new Vector2(44, 22);
|
||||
|
||||
// === Titel ===
|
||||
GameObject titleGO = new GameObject("TitleText");
|
||||
titleGO.transform.SetParent(buttonGO.transform, false);
|
||||
var titleText = titleGO.AddComponent<TextMeshProUGUI>();
|
||||
titleText.text = model.nameHuman;
|
||||
// === Title ===
|
||||
GameObject titleGo = new GameObject("TitleText");
|
||||
titleGo.transform.SetParent(buttonGo.transform, false);
|
||||
var titleText = titleGo.AddComponent<TextMeshProUGUI>();
|
||||
titleText.text = model.NameHuman;
|
||||
titleText.fontSize = 24;
|
||||
|
||||
RectTransform titleRT = titleGO.GetComponent<RectTransform>();
|
||||
RectTransform titleRT = titleGo.GetComponent<RectTransform>();
|
||||
titleRT.anchorMin = new Vector2(0, 1);
|
||||
titleRT.anchorMax = new Vector2(1, 1);
|
||||
titleRT.pivot = new Vector2(0, 1);
|
||||
titleRT.anchoredPosition = new Vector2(60, -10);
|
||||
titleRT.sizeDelta = new Vector2(-70, 30);
|
||||
|
||||
return buttonGO;
|
||||
return buttonGo;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
@@ -179,6 +175,3 @@ public class BaseModelSelector : MonoBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -17,17 +15,16 @@ public class ReturnButtonBehaviour : MonoBehaviour
|
||||
private void OnClick()
|
||||
{
|
||||
Debug.Log("Return to Menu clicked");
|
||||
mm.openSelector();
|
||||
mm.OpenSelector();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
//black magic
|
||||
//var cameraTf = GameObject.Find("[BuildingBlock] Camera Rig").transform;
|
||||
//gameObject.transform.position = cameraTf.position + new Vector3(5f,-0.5f,5f);
|
||||
//gameObject.transform.rotation = Quaternion.LookRotation(gameObject.transform.position - cameraTf.position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -103,4 +103,5 @@ public static class MathUtil
|
||||
}
|
||||
return (num2 + 360f) % 360f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ using UnityEngine;
|
||||
/// </summary>
|
||||
public class ModelLoader
|
||||
{
|
||||
public static void LoadChildModelsFromPackedModel(List<ChildModel> appendList, string[] port, string[] nameHuman, string[] nameId, Mesh[] meshes, Material[] mats, List<Port>[] ports, int fromMesh = 0, int toMesh = -1)
|
||||
public static void LoadChildModelsFromPackedModel(List<ChildModel> appendList, string[] port, string[] nameHuman,
|
||||
string[] nameId, Mesh[] meshes, Material[] mats, List<Port>[] 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]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user