Explode Model

This commit is contained in:
lachs218
2025-05-21 23:09:31 +02:00
parent 6fdfc6af30
commit 07425c1672
15 changed files with 990 additions and 282 deletions

View File

@@ -0,0 +1,19 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: efa1458c2bc55e04b872c61942be2866, type: 3}
m_Name: OVROverlayCanvasSettings
m_EditorClassIdentifier:
_transparentImposterShader: {fileID: 0}
_opaqueImposterShader: {fileID: 0}
MaxSimultaneousCanvases: 1
CanvasRenderLayer: 31
CanvasLayer: -1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cbb9a7449d589c14298d9bcdf4862fcf
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -113,26 +113,26 @@ public class ModelList
new Port(Definitions.PORT_ERLBACH_71, new Vector3(0f, 0f, 0f), "idErlbachPart71", false),
new Port(Definitions.PORT_ERLBACH_72, new Vector3(0f, 0f, 0f), "idErlbachPart72", false),
new Port(Definitions.PORT_ERLBACH_73, new Vector3(0f, 0f, 0f), "idErlbachPart73", false),
new Port(Definitions.PORT_ERLBACH_BasePlate, new Vector3(0f, 0f, 0f), "idErlbachPart74"),
new Port(Definitions.PORT_ERLBACH_FrontAxe, new Vector3(0f, 0f, 0f), "idErlbachPart75"),
new Port(Definitions.PORT_ERLBACH_BatteriePack, new Vector3(0f, 0f, 0f), "idErlbachPart76"),
new Port(Definitions.PORT_ERLBACH_BasePlate, new Vector3(0f, 0f, 0f), "idErlbachPart74",true, new Vector3(0f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_FrontAxe, new Vector3(0f, 0f, 0f), "idErlbachPart75",true, new Vector3(1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_BatteriePack, new Vector3(0f, 0f, 0f), "idErlbachPart76",true, new Vector3(0f,0f,1f)),
new Port(Definitions.PORT_ERLBACH_77, new Vector3(0f, 0f, 0f), "idErlbachPart77", false),
new Port(Definitions.PORT_ERLBACH_78, new Vector3(0f, 0f, 0f), "idErlbachPart78", false),
new Port(Definitions.PORT_ERLBACH_79, new Vector3(0f, 0f, 0f), "idErlbachPart79", false),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_LH"),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_LV"),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_RH"),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_RV"),
new Port(Definitions.PORT_ERLBACH_Body, new Vector3(0f, 0f, 0f), "idErlbachPart84"),
new Port(Definitions.PORT_ERLBACH_Bumper, new Vector3(0f, 0f, 0f), "idErlbachPart85"),
new Port(Definitions.PORT_ERLBACH_FrontBumper, new Vector3(0f, 0f, 0f), "idErlbachPart86"),
new Port(Definitions.PORT_ERLBACH_Number, new Vector3(0f, 0f, 0f), "idErlbachPart87"),
new Port(Definitions.PORT_ERLBACH_LicensePlate, new Vector3(0f, 0f, 0f), "idErlbachPart88"),
new Port(Definitions.PORT_ERLBACH_LicensePlateContent, new Vector3(0f, 0f, 0f), "idErlbachPart89"),
new Port(Definitions.PORT_ERLBACH_Grill, new Vector3(0f, 0f, 0f), "idErlbachPart90"),
new Port(Definitions.PORT_ERLBACH_Refelctor_H, new Vector3(0f, 0f, 0f), "idErlbachPart91"),
new Port(Definitions.PORT_ERLBACH_Headlight_V_Cover, new Vector3(0f, 0f, 0f), "idErlbachPart92"),
new Port(Definitions.PORT_ERLBACH_Headlight_V, new Vector3(0f, 0f, 0f), "idErlbachPart93")
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_LH", true, new Vector3(0f,-1f,0f)),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_LV",true, new Vector3(0f,-1f,0f)),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_RH",true, new Vector3(0f,1f,0f)),
new Port(Definitions.PORT_ERLBACH_Wheel, new Vector3(0f, 0f, 0f), "idErlbachWheel_RV",true, new Vector3(0f,1f,0f)),
new Port(Definitions.PORT_ERLBACH_Body, new Vector3(0f, 0f, 0f), "idErlbachPart84",true, new Vector3(0f,0f,1f)),
new Port(Definitions.PORT_ERLBACH_Bumper, new Vector3(0f, 0f, 0f), "idErlbachPart85",true, new Vector3(1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_FrontBumper, new Vector3(0f, 0f, 0f), "idErlbachPart86",true, new Vector3(-1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_Number, new Vector3(0f, 0f, 0f), "idErlbachPart87",true, new Vector3(1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_LicensePlate, new Vector3(0f, 0f, 0f), "idErlbachPart88",true, new Vector3(1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_LicensePlateContent, new Vector3(0f, 0f, 0f), "idErlbachPart89",true, new Vector3(1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_Grill, new Vector3(0f, 0f, 0f), "idErlbachPart90",true, new Vector3(-1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_Refelctor_H, new Vector3(0f, 0f, 0f), "idErlbachPart91",true, new Vector3(1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_Headlight_V_Cover, new Vector3(0f, 0f, 0f), "idErlbachPart92",true, new Vector3(-1f,0f,0f)),
new Port(Definitions.PORT_ERLBACH_Headlight_V, new Vector3(0f, 0f, 0f), "idErlbachPart93",true, new Vector3(-1f,0f,0f))
}
)
};
@@ -177,6 +177,14 @@ public class ModelList
Resources.Load<Mesh>("Plagues/Mesh/Hex"),
Resources.Load<Material>($"Material/Default"),
null
),
new ChildModel(
Definitions.PORT_ERLBACH_Wheel,
"Wheel",
"rad20",
Resources.Load<Mesh>($"Model/ERLbach/02.01.05.0000-Rad_5Speichen"),
Resources.Load<Material>($"Material/Default"),
null
)
};

View File

@@ -17,6 +17,7 @@ public class ModelManager : MonoBehaviour
}
public BaseModelBehaviour BaseModelBehaviour;
public BaseModelSelector baseModelSelector;
public List<Vector3> childPositions = new List<Vector3>();
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
@@ -153,5 +154,22 @@ public class ModelManager : MonoBehaviour
tw.Write(BaseModelBehaviour.ExportJson());
tw.Close();
}
public Port GetPortForChildModel(ChildModel childModel)
{
foreach (var port in BaseModel.Ports)
{
var childModels = GetChildModelsForPort(port.PortID);
if (childModels.Contains(childModel))
{
if (port.DefaultId == childModel.NameId)
{
return port;
}
}
}
Debug.LogWarning($"Kein Port für das ChildModel {childModel.NameId} gefunden.");
return null;
}
}

View File

@@ -8,6 +8,7 @@ public class Port
public readonly string PortID; // port name
public readonly string DefaultId; //the default ChildModel to apply on initialization
public readonly bool Chooseable; //whether the Port will be rendered in GUI
public readonly Vector3 direction;
public void Apply(Transform target)
@@ -17,7 +18,7 @@ public class Port
target.localScale = _scale;
}
public Port(string name, Vector3 position, string defaultId, bool chooseable = true)
public Port(string name, Vector3 position, string defaultId, bool chooseable = true, Vector3 direction = default)
{
PortID = name;
this._position = position;
@@ -25,9 +26,11 @@ public class Port
this._scale = new Vector3(1f,1f,1f);
this.DefaultId = defaultId;
this.Chooseable = chooseable;
this.direction = direction;
}
public Port(string portID, Vector3 position, Quaternion rotation, Vector3 scale, string defaultId, bool chooseable = true)
public Port(string portID, Vector3 position, Quaternion rotation, Vector3 scale, string defaultId, bool chooseable = true,Vector3 direction = default)
{
this.PortID = portID;
this._position = position;
@@ -35,8 +38,10 @@ public class Port
this._scale = scale;
this.DefaultId = defaultId;
this.Chooseable = chooseable;
this.direction = direction;
}
public Port(string portID, Vector3 position, Quaternion rotation, string defaultId, bool chooseable = true)
public Port(string portID, Vector3 position, Quaternion rotation, string defaultId, bool chooseable = true, Vector3 direction = default)
{
this.PortID = portID;
this._position = position;
@@ -44,6 +49,11 @@ public class Port
this._scale = new Vector3(1f,1f,1f);
this.DefaultId = defaultId;
this.Chooseable = chooseable;
this.direction = direction;
}
public Vector3 GetPosition()
{
return _position;
}
}

View File

@@ -1,47 +0,0 @@
using UnityEngine;
public class ExplodeBike : MonoBehaviour
{
[System.Serializable]
public class BikePart
{
public Transform part;
public Vector3 explodeDirection;
}
public BikePart[] bikeParts;
public float explosionDistance = 2f;
public float explosionSpeed = 2f;
private bool _isExploding = false;
private Vector3[] _originalPositions;
void Start()
{
_originalPositions = new Vector3[bikeParts.Length];
for (int i = 0; i < bikeParts.Length; i++)
{
_originalPositions[i] = bikeParts[i].part.localPosition;
}
}
void Update()
{
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);
}
}
}
public void Explode()
{
_isExploding = true;
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 70b47230a8a0a8a459511d787cd6a722

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class ExplodeModel : MonoBehaviour
{
public ModelManager mm;
public GameObject go;
public GameObject unexplodeButton;
private float y;
private float z;
private float x;
void Start()
{
GetComponent<Button>().onClick.AddListener(Explode);
}
private void Explode()
{
y = 0;
z = 0;
x = 0;
mm.childPositions.Clear();
foreach (Transform child in go.transform)
{
mm.childPositions.Add(child.localPosition);
var childModelBehaviour = child.GetComponent<ChildModelBehaviour>();
Port port = mm.GetPortForChildModel(childModelBehaviour.ChildModel);
if (port.direction != Vector3.zero)
{
Vector3 richtung = Richtung(port.direction);
Debug.Log("Richtung Pos" + richtung*10);
child.localPosition = richtung*10;
}
}
gameObject.SetActive(false);
unexplodeButton.SetActive(true);
}
private Vector3 Richtung(Vector3 direction)
{
float dx = direction.x;
float dy = direction.y;
float dz = direction.z;
Debug.Log("Vector Richtung "+direction);
if (dx != 0)
{
if (dx > 0)
{
this.x++;
return new Vector3(0f + x, 0f, 0f);
}
else if (dx < 0)
{
this.x++;
return new Vector3(0f - x, 0f, 0f);
}
}
else if (dy != 0)
{
if (dy > 0)
{
y = 4;
return new Vector3(0f, 0f + y, 0f);
}
else if (dy < 0)
{
y = 4;
Debug.Log("Y Pos" + y);
var vector = new Vector3(0f, 0f - y, 0f);
Debug.Log("Vector Richtung " + vector);
return vector;
}
}
else if (dz != 0)
{
if (dz > 0)
{
z+=5;
return new Vector3(0f, 0f, 0f + z);
}
else if (dz < 0)
{
z+=5;
return new Vector3(0f, 0f, 0f - z);
}
}
return default;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3bf62feee29a7fb41b8ec04cfa1231ad

View File

@@ -0,0 +1,27 @@
using UnityEngine;
using UnityEngine.UI;
public class UnExplode : MonoBehaviour
{
public GameObject go;
public GameObject explodeBUtton;
public ModelManager mm;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
GetComponent<Button>().onClick.AddListener(unexplode);
}
private void unexplode()
{
explodeBUtton.SetActive(true);
gameObject.SetActive(false);
int i = 0;
foreach (Transform child in go.transform)
{
child.localPosition = mm.childPositions[i];
i++;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 148fd3ba1bc1c7745bd89a67b61c8834

View File

@@ -13,20 +13,18 @@ public class BaseModelSelector : MonoBehaviour
public ModelManager modelManager; // <-- to be put in inspector
public GameObject unexplodeButton;
public GameObject ContentUi;
public ReturnButtonBehaviour returnButton;
public GameObject _canvasButtons;
void Start()
{
_canvasButtons.SetActive(false);
SetupEventSystem();
SetupCanvas();
CreatePrefabButtons();
if(returnButton == null)
{
returnButton = FindAnyObjectByType<ReturnButtonBehaviour>();
}
}
void SetupEventSystem()
@@ -35,15 +33,13 @@ public class BaseModelSelector : MonoBehaviour
{
GameObject eventSystemGo = new GameObject("EventSystem");
eventSystemGo.AddComponent<EventSystem>();
//eventSystemGo.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>(); //Put in for keyboard input. Must be commented out on quest
eventSystemGo.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>(); //Put in for keyboard input. Must be commented out on quest
eventSystemGo.AddComponent<OVRInputModule>();
}
else
{
Debug.Log("EventSystem already exists - new one will not be created.");
}
}
void SetupCanvas()
@@ -88,8 +84,8 @@ public class BaseModelSelector : MonoBehaviour
buttonGo.transform.localRotation = Quaternion.identity;
// Setup Collider correctly
//collider.size = new Vector3(rt.sizeDelta.x * rt.localScale.x, rt.sizeDelta.y * rt.localScale.y, 1f);
//collider.center = Vector3.zero;
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; // Next button below
@@ -115,12 +111,12 @@ public class BaseModelSelector : MonoBehaviour
}
portSelector.GenerateButtons();
if (returnButton == null)
if (_canvasButtons == null)
{
Debug.LogError("ReturnButton is null!");
Debug.LogError("CanvasButtonis null!");
return;
}
returnButton.Activate();
_canvasButtons.SetActive(true);
if (_canvas == null)
{
@@ -135,6 +131,11 @@ public class BaseModelSelector : MonoBehaviour
return;
}
ContentUi.SetActive(true);
if (unexplodeButton == null)
{
Debug.LogError("UnexplodeButton is null!");
}
unexplodeButton.SetActive(false);
}
public static GameObject SetupPrefab(BaseModel model)

View File

@@ -6,10 +6,12 @@ public class ReturnButtonBehaviour : MonoBehaviour
public BaseModelSelector bms;
public ModelManager mm;
public GameObject ContentUi;
public GameObject _canvasButtons;
public GameObject explodeButton;
public GameObject unexplodeButton;
void Start()
{
gameObject.SetActive(false);
GetComponent<Button>().onClick.AddListener(OnClick);
}
@@ -17,7 +19,9 @@ public class ReturnButtonBehaviour : MonoBehaviour
{
Debug.Log("Return to Menu clicked");
mm.OpenSelector();
gameObject.SetActive(false);
explodeButton.SetActive(true);
unexplodeButton.SetActive(false);
_canvasButtons.SetActive(false);
ContentUi.SetActive(false);
}

View File