improve explode stuff

This commit is contained in:
Tim
2025-07-18 00:48:36 +02:00
parent 1aad895df9
commit 625a8b86e0
4 changed files with 40 additions and 35 deletions

View File

@@ -12934,6 +12934,7 @@ MonoBehaviour:
colliderSurface: {fileID: 163506087} colliderSurface: {fileID: 163506087}
interactable: {fileID: 698127119} interactable: {fileID: 698127119}
rayInteractable: {fileID: 698127110} rayInteractable: {fileID: 698127110}
afterBirth: 0
PortSelector: {fileID: 1494770816} PortSelector: {fileID: 1494770816}
Index: -1 Index: -1
--- !u!1 &700047848 --- !u!1 &700047848
@@ -21960,6 +21961,7 @@ MonoBehaviour:
colliderSurface: {fileID: 557957011} colliderSurface: {fileID: 557957011}
interactable: {fileID: 1272917968} interactable: {fileID: 1272917968}
rayInteractable: {fileID: 1272917969} rayInteractable: {fileID: 1272917969}
afterBirth: 0
PortSelector: {fileID: 1494770816} PortSelector: {fileID: 1494770816}
Index: -1 Index: -1
--- !u!114 &1272917968 --- !u!114 &1272917968

View File

@@ -34,6 +34,8 @@ public class ModelBehaviour : MonoBehaviour, IResettable
bool lateInited = false; bool lateInited = false;
public bool afterBirth = false;
public PortSelector PortSelector; public PortSelector PortSelector;
public int Index = -1; public int Index = -1;
@@ -133,6 +135,8 @@ public class ModelBehaviour : MonoBehaviour, IResettable
Debug.Log($"Spawning {gameObject.name}'s ports"); Debug.Log($"Spawning {gameObject.name}'s ports");
SpawnChildPorts(newModel); SpawnChildPorts(newModel);
} }
afterBirth = true;
} }
void LateUpdateModel() void LateUpdateModel()

View File

@@ -62,47 +62,41 @@ public class Exploder : MonoBehaviour, IResettable, IPointerDownHandler
void PopulateModelList() void PopulateModelList()
{ {
models.Clear(); List<ExploderModel> newModels = new List<ExploderModel>();
foreach (Transform child in baseModel.GetComponentsInChildren<Transform>()) foreach (Transform child in baseModel.GetComponentsInChildren<Transform>())
{ {
var cmb = child.GetComponent<ChildModelBehaviour>(); var cmb = child.GetComponent<ChildModelBehaviour>();
if (cmb == null) if (cmb == null)
{ {
continue; //only for basemodel continue; //skip basemodel
} }
Port port = cmb.GetParentPort(); bool skip = false;
models.Add(new ExploderModel(port, cmb.ChildModel, cmb)); foreach (var model in models)
{
if (model.tf == child)
{
if (model.model == cmb.ChildModel) //nothing changed
{
newModels.Add(model);
}
else // model is changed -> its unexploded
{
newModels.Add(new ExploderModel(model.port, cmb.ChildModel, model.cmb, model.tf, false));
}
skip = true;
break;
} }
} }
if (skip)
void UpdateModelList()
{
List<ExploderModel> modelss = new List<ExploderModel>();
foreach (var exploModel in models)
{
if (exploModel.cmb == null)
{
continue; //skip dead ends
}
if (exploModel.model != exploModel.cmb.ChildModel) //update
{
Debug.LogWarning($"Updating Model List from {exploModel.model.NameId} to {exploModel.cmb.ChildModel.NameId}");
// add children + itself
foreach (Transform child in exploModel.cmb.GetComponentsInChildren<Transform>())
{
var cmb = child.GetComponent<ChildModelBehaviour>();
if (cmb == null)
{ {
continue; continue;
} }
//new model altogether -> its unexploded
Port port = cmb.GetParentPort(); Port port = cmb.GetParentPort();
modelss.Add(new ExploderModel(port, cmb.ChildModel, cmb)); newModels.Add(new ExploderModel(port, cmb.ChildModel, cmb, child, false));
} }
continue; models.Clear();
} models = newModels;
modelss.Add(exploModel);
}
models = modelss;
} }
void CleanModelList() void CleanModelList()
@@ -112,6 +106,7 @@ public class Exploder : MonoBehaviour, IResettable, IPointerDownHandler
void ForceSetPos() void ForceSetPos()
{ {
Debug.Log($"ForceSetPos {explode}");
foreach (var exploModel in models) foreach (var exploModel in models)
{ {
exploModel.tf.localPosition = explode ? exploModel.goalPos : exploModel.initPos; exploModel.tf.localPosition = explode ? exploModel.goalPos : exploModel.initPos;
@@ -135,9 +130,13 @@ public class Exploder : MonoBehaviour, IResettable, IPointerDownHandler
public void HandleModelChange() public void HandleModelChange()
{ {
UpdateModelList(); //UpdateModelList();
if (mm.BaseModelBehaviour.afterBirth)
{
PopulateModelList();
ForceSetPos(); ForceSetPos();
} }
}
public void ResetThis() public void ResetThis()
{ {

View File

@@ -12,18 +12,18 @@ public class ExploderModel
public Vector3 initPos; public Vector3 initPos;
public Vector3 goalPos; public Vector3 goalPos;
public ExploderModel(Port port, ChildModel model, ChildModelBehaviour cmb) public ExploderModel(Port port, ChildModel model, ChildModelBehaviour cmb, Transform tf, bool exploded)
{ {
this.port = port; this.port = port;
this.model = model; this.model = model;
this.cmb = cmb; this.cmb = cmb;
CalculatePos(); this.tf = tf;
CalculatePos(exploded);
} }
public void CalculatePos() public void CalculatePos(bool exploded = false)
{ {
tf = cmb.transform; initPos = exploded ? tf.localPosition - port.ExplodeDirection : tf.localPosition;
initPos = tf.localPosition; goalPos = exploded ? tf.localPosition : tf.localPosition + port.ExplodeDirection;
goalPos = tf.localPosition + port.ExplodeDirection;
} }
} }