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

View File

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

View File

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

View File

@@ -12,18 +12,18 @@ public class ExploderModel
public Vector3 initPos;
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.model = model;
this.cmb = cmb;
CalculatePos();
this.tf = tf;
CalculatePos(exploded);
}
public void CalculatePos()
public void CalculatePos(bool exploded = false)
{
tf = cmb.transform;
initPos = tf.localPosition;
goalPos = tf.localPosition + port.ExplodeDirection;
initPos = exploded ? tf.localPosition - port.ExplodeDirection : tf.localPosition;
goalPos = exploded ? tf.localPosition : tf.localPosition + port.ExplodeDirection;
}
}