Browse Source

[fx] Subfx loop refresh

Clément Espeute 2 tháng trước cách đây
mục cha
commit
c65e8d873f
2 tập tin đã thay đổi với 28 bổ sung16 xóa
  1. 20 16
      hrt/prefab/fx/FX.hx
  2. 8 0
      hrt/prefab/fx/SubFX.hx

+ 20 - 16
hrt/prefab/fx/FX.hx

@@ -27,6 +27,7 @@ class FXAnimation extends h3d.scene.Object {
 	function set_loop(v: Bool) {
 		loop = v;
 		initLoop();
+		resetSelf();
 		return loop;
 	}
 
@@ -113,6 +114,9 @@ class FXAnimation extends h3d.scene.Object {
 		loopStart = 0.0;
 		loopEnd = duration;
 
+		if (!loop)
+			return;
+
 		if (events == null)
 			return;
 
@@ -474,22 +478,22 @@ class FXAnimation extends h3d.scene.Object {
 			}
 		}
 
-		var sub = Std.downcast(elt, SubFX);
-		if (sub != null) {
-			var eventLen = out?.length ?? 0;
-			out = initEvents(@:privateAccess sub.resolveRef(), out);
-			var fxAnimation = Std.downcast(sub.refInstance.findFirstLocal3d(), FXAnimation);
-			if (fxAnimation != null) {
-				fxAnimation.events = null;
-			}
-			if (out != null) {
-				// Offset the start time of the events that were added to our array in
-				// init events
-				for (i in eventLen...out.length) {
-					out[i].evt.time += sub.time;
-				}
-			}
-		}
+		// var sub = Std.downcast(elt, SubFX);
+		// if (sub != null) {
+		// 	var eventLen = out?.length ?? 0;
+		// 	out = initEvents(@:privateAccess sub.resolveRef(), out);
+		// 	var fxAnimation = Std.downcast(sub.refInstance.findFirstLocal3d(), FXAnimation);
+		// 	if (fxAnimation != null) {
+		// 		fxAnimation.events = null;
+		// 	}
+		// 	if (out != null) {
+		// 		// Offset the start time of the events that were added to our array in
+		// 		// init events
+		// 		for (i in eventLen...out.length) {
+		// 			out[i].evt.time += sub.time;
+		// 		}
+		// 	}
+		// }
 
 		for(child in elt.children) {
 			out = initEvents(child, out);

+ 8 - 0
hrt/prefab/fx/SubFX.hx

@@ -64,6 +64,14 @@ class SubFX extends Reference implements hrt.prefab.fx.Event.IEvent{
 		};
 	}
 
+	override function updateInstance(?propName:String) {
+		super.updateInstance(propName);
+
+		if (propName == "loop") {
+			postMakeInstance();
+		}
+	}
+
 	#if editor
 
 	override function edit( ctx : hide.prefab.EditContext ) {