2
0
Эх сурвалжийг харах

make sure we use correct scene when loading resources from prefab Context

ncannasse 7 жил өмнө
parent
commit
40508fbeaf

+ 3 - 2
hide/comp/SceneEditor.hx

@@ -116,6 +116,7 @@ class SceneEditor {
 		var sceneEl = new Element('<div class="scene"></div>');
 		scene = new hide.comp.Scene(view.props, null, sceneEl);
 		scene.onReady = onSceneReady;
+		@:privateAccess context.scene = scene;
 
 		view.keys.register("copy", onCopy);
 		view.keys.register("paste", onPaste);
@@ -232,7 +233,7 @@ class SceneEditor {
 				{ label : "Duplicate", enabled : current != null, click : duplicate.bind(false) },
 				{ label : "Reference", enabled : current != null, click : function() createRef(current, current.parent) },
 			];
-			
+
 			if(current != null && current.to(Object3D) != null) {
 				menuItems = menuItems.concat([
 					{ label : "Select all", click : selectAll },
@@ -1067,7 +1068,7 @@ class SceneEditor {
 	}
 
 	function autoName(p : PrefabElement) {
-		
+
 		var uniqueName = false;
 		var layer = p.getParent(hide.prefab.l3d.Layer);
 		if(layer != null) {

+ 12 - 3
hide/prefab/Context.hx

@@ -45,6 +45,9 @@ class Context {
 	public var shared : ContextShared;
 	public var custom : Dynamic;
 	public var isRef : Bool = false;
+	#if editor
+	var scene : hide.comp.Scene;
+	#end
 
 	public function new() {
 	}
@@ -76,6 +79,12 @@ class Context {
 		return c;
 	}
 
+	#if editor
+	function getScene() {
+		return scene;
+	}
+	#end
+
 	public dynamic function onError( e : Dynamic ) {
 		#if editor
 		js.Browser.window.alert(e);
@@ -86,7 +95,7 @@ class Context {
 
 	public function loadModel( path : String ) {
 		#if editor
-		return hide.comp.Scene.getCurrent().loadModel(path);
+		return getScene().loadModel(path);
 		#else
 		return @:privateAccess shared.cache.loadModel(hxd.res.Loader.currentInstance.load(path).toModel());
 		#end
@@ -94,7 +103,7 @@ class Context {
 
 	public function loadAnimation( path : String ) {
 		#if editor
-		return hide.comp.Scene.getCurrent().loadAnimation(path);
+		return getScene().loadAnimation(path);
 		#else
 		return @:privateAccess shared.cache.loadAnimation(hxd.res.Loader.currentInstance.load(path).toModel());
 		#end
@@ -102,7 +111,7 @@ class Context {
 
 	public function loadTexture( path : String ) {
 		#if editor
-		return hide.comp.Scene.getCurrent().loadTexture("",path);
+		return getScene().loadTexture("",path);
 		#else
 		return @:privateAccess shared.cache.loadTexture(null, path);
 		#end