瀏覽代碼

create new

David `Deltakosh` Catuhe 5 年之前
父節點
當前提交
5d6d36184f

+ 1 - 0
Playground/public/imgs/new.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 55 55"><defs><style>.cls-1{fill:none;}</style></defs><title>newButton</title><g id="Icon_buttons" data-name="Icon buttons"><rect class="cls-1" width="55" height="55"/><path d="M34.9,23.23V37.87H18.65v-20H29.53ZM33.65,36.62V24.12h-5v-5H19.9v17.5ZM29.9,22.87h2.86L29.9,20Z"/></g></svg>

+ 5 - 0
Playground/src/components/commandBarComponent.tsx

@@ -18,10 +18,15 @@ export class CommandBarComponent extends React.Component<ICommandBarComponentPro
         this.props.globalState.onRunRequiredObservable.notifyObservers();
     }
 
+    onNew() {
+        this.props.globalState.onNewRequiredObservable.notifyObservers();
+    }
+
     public render() {
         return (
             <div className={"commands " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")}>
                 <CommandButtonComponent globalState={this.props.globalState} tooltip="Run" icon="play" isActive={true} onClick={()=> this.onPlay()}/>
+                <CommandButtonComponent globalState={this.props.globalState} tooltip="Create new" icon="new" isActive={false} onClick={()=> this.onNew()}/>
             </div>
         );
     }

+ 1 - 0
Playground/src/globalState.ts

@@ -14,6 +14,7 @@ export class GlobalState {
     public mobileDefaultMode = EditionMode.RenderingOnly;
 
     public onRunRequiredObservable = new Observable<void>();
+    public onNewRequiredObservable = new Observable<void>();
     public onErrorObservable = new Observable<string>();    
     public onMobileDefaultModeChangedObservable = new Observable<void>();
 }

+ 15 - 1
Playground/src/tools/monacoManager.ts

@@ -13,7 +13,21 @@ export class MonacoManager {
     // private _templates: string[];
 
     public constructor(public globalState: GlobalState) {
-
+        globalState.onNewRequiredObservable.add(() => {
+            this._editor?.setValue(`// You have to create a function called createScene. This function must return a BABYLON.Scene object
+// You can reference the following variables: scene, canvas
+// You must at least define a camera
+            
+var createScene = function() {
+    var scene = new BABYLON.Scene(engine);
+    var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 2, 12, BABYLON.Vector3.Zero(), scene);
+    camera.attachControl(canvas, true);
+
+    return scene;
+};
+`);
+            globalState.onRunRequiredObservable.notifyObservers();
+        });
     }
     
     public async setupMonacoAsync(hostElement: HTMLDivElement) {