瀏覽代碼

[hide] Added followRef to findFirstLocal2d/3d

Clément Espeute 10 月之前
父節點
當前提交
08e05d7a97
共有 2 個文件被更改,包括 12 次插入8 次删除
  1. 2 2
      hrt/prefab/Material.hx
  2. 10 6
      hrt/prefab/Prefab.hx

+ 2 - 2
hrt/prefab/Material.hx

@@ -197,8 +197,8 @@ class Material extends Prefab {
 	#end
 
 	#if editor
-	override function findFirstLocal3d() {
-		return previewSphere ?? super.findFirstLocal3d();
+	override function findFirstLocal3d(followRefs: Bool = false) {
+		return previewSphere ?? super.findFirstLocal3d(followRefs);
 	}
 	#end
 

+ 10 - 6
hrt/prefab/Prefab.hx

@@ -328,16 +328,16 @@ class Prefab {
 	/**
 		Find the first h2d.Object in this hierarchy, in either this or it's parents
 	**/
-	public function findFirstLocal2d() : h2d.Object {
-		var o2d = findParent(Object2D, (p) -> p.local2d != null, true);
+	public function findFirstLocal2d(followRefs: Bool = false) : h2d.Object {
+		var o2d = findParent(Object2D, (p) -> p.local2d != null, true, followRefs);
 		return o2d != null ? o2d.local2d : shared.root2d;
 	}
 
 	/**
 		Find the first h3d.scene.Object in this hierarchy, in either this or it's parents
 	**/
-	public function findFirstLocal3d() : h3d.scene.Object {
-		var o3d = findParent(Object3D, (p) -> p.local3d != null, true);
+	public function findFirstLocal3d(followRefs: Bool = false) : h3d.scene.Object {
+		var o3d = findParent(Object3D, (p) -> p.local3d != null, true, followRefs);
 		return o3d != null ? o3d.local3d : shared.root3d;
 	}
 
@@ -464,7 +464,7 @@ class Prefab {
 		Find the first prefab in this prefab parent chain that matches the given class `cl`, and optionally the given `filter`.
 		If `includeSelf` is true, then this prefab is checked as well.
 	**/
-	public function findParent<T:Prefab>(?cl:Class<T> ,?filter : (p:T) -> Bool, includeSelf:Bool = false) : Null<T> {
+	public function findParent<T:Prefab>(?cl:Class<T> ,?filter : (p:T) -> Bool, includeSelf:Bool = false, followRefs:Bool = false) : Null<T> {
 		var current = includeSelf ? this : this.parent;
 		while(current != null) {
 			var asCl = cl != null ? Std.downcast(current, cl) : cast current;
@@ -472,7 +472,11 @@ class Prefab {
 				if (filter == null || filter(asCl))
 					return asCl;
 			}
-			current = current.parent;
+			var next = current.parent;
+			if (next == null && followRefs) {
+				next = current.shared.parentPrefab;
+			}
+			current = next;
 		}
 		return null;
 	}