Browse Source

Editor only (#196)

A prefab in tree can be marked as EditorOnly. It will only be maked when editing the current prefab but not when used elsewhere (in an other prefab/l3d or in game)
Jed974 4 năm trước cách đây
mục cha
commit
1f993fd0ff
4 tập tin đã thay đổi với 43 bổ sung0 xóa
  1. 7 0
      bin/style.css
  2. 8 0
      bin/style.less
  3. 20 0
      hide/comp/SceneEditor.hx
  4. 8 0
      hrt/prefab/Prefab.hx

+ 7 - 0
bin/style.css

@@ -1705,6 +1705,13 @@ body.hide-subview .lm_controls {
 .jstree .filtered {
   display: none;
 }
+.jstree .editorOnly {
+  color: #02aeda !important;
+}
+.jstree .editorOnly i,
+.jstree .editorOnly a {
+  color: #02aeda;
+}
 .jstree .hidden {
   color: #555 !important;
 }

+ 8 - 0
bin/style.less

@@ -1940,6 +1940,14 @@ body.hide-subview {
 		display: none;
 	}
 
+	.editorOnly {
+		color: rgb(2, 174, 218) !important;
+
+		i, a {
+			color: rgb(2, 174, 218);
+		}
+	}
+
 	.hidden {
 		color: #555 !important;
 

+ 20 - 0
hide/comp/SceneEditor.hx

@@ -503,6 +503,7 @@ class SceneEditor {
 
 			if( current != null ) {
 				menuItems.push({ label : "Enable", checked : current.enabled, stayOpen : true, click : function() setEnabled(curEdit.elements, !current.enabled) });
+				menuItems.push({ label : "Editor only", checked : current.editorOnly, stayOpen : true, click : function() setEditorOnly(curEdit.elements, !current.editorOnly) });
 			}
 
 			if( isObj ) {
@@ -1204,6 +1205,7 @@ class SceneEditor {
 			el.toggleClass("disabled", !p.enabled || !obj3d.visible);
 			el.toggleClass("hidden", isHidden(obj3d));
 			el.toggleClass("locked", p.locked);
+			el.toggleClass("editorOnly", p.editorOnly);
 
 			var visTog = el.find(".visibility-toggle").first();
 			if(visTog.length == 0) {
@@ -1907,6 +1909,24 @@ class SceneEditor {
 		}));
 	}
 
+	public function setEditorOnly(elements : Array<PrefabElement>, enable: Bool) {
+		var old = [for(e in elements) e.editorOnly];
+		function apply(on) {
+			for(i in 0...elements.length) {
+				elements[i].editorOnly = on ? enable : old[i];
+				onPrefabChange(elements[i]);
+			}
+			refreshScene();
+		}
+		apply(true);
+		undo.change(Custom(function(undo) {
+			if(undo)
+				apply(false);
+			else
+				apply(true);
+		}));
+	}
+
 	public function isHidden(e: PrefabElement) {
 		if(e == null)
 			return false;

+ 8 - 0
hrt/prefab/Prefab.hx

@@ -36,6 +36,11 @@ class Prefab {
 	**/
 	@:s public var enabled : Bool = true;
 
+	/**
+		Tells if the prefab will create an instance when used in an other prefab or in game. Also apply to this prefab children.
+	**/
+	@:s public var editorOnly : Bool = false;
+
 	/**
 		Prevent the prefab from being selected in Hide. Also apply to this prefab children.
 	**/
@@ -260,6 +265,9 @@ class Prefab {
 			ctx = new Context();
 			ctx.init();
 		}
+		var fromRef = #if editor ctx.shared.parent != null #else true #end;
+		if (fromRef && editorOnly)
+			return ctx;
 		ctx = makeInstance(ctx);
 		for( c in children )
 			makeChildren(ctx, c);