Forráskód Böngészése

added getPrefabByPath

Nicolas Cannasse 5 éve
szülő
commit
3897d089a1
1 módosított fájl, 23 hozzáadás és 0 törlés
  1. 23 0
      hrt/prefab/Prefab.hx

+ 23 - 0
hrt/prefab/Prefab.hx

@@ -261,6 +261,29 @@ class Prefab {
 		return null;
 	}
 
+	/**
+		Search the prefab tree for the prefab matching the given path, returns null if not found
+	**/
+	public function getPrefabByPath( path : String ) {
+		if( path == "" )
+			return this;
+		var parts = path.split(".");
+		var p = this;
+		for( i in 0...parts.length ) {
+			var name = parts[i];
+			var next = null;
+			for( c in p.children )
+				if( c.name == name || (c.name == null && c.getDefaultName() == name) ) {
+					next = c;
+					break;
+				}
+			if( next == null )
+				return null;
+			p = next;
+		}
+		return p;
+	}
+
 	/**
 		Simlar to get() but returns null if not found.
 	**/