From f98941e80f0998de8464d0ba946cdb4c1c568d44 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 12:52:05 -0800 Subject: [PATCH] switching between particle entities --- examples/edit.js | 9 +++++++-- examples/particle_explorer/particleExplorer.js | 2 -- examples/particle_explorer/particleExplorerTool.js | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 8221461451..a571269a61 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1881,12 +1881,17 @@ var showMenuItem = propertyMenu.addMenuItem("Show in Marketplace"); propertiesTool = PropertiesTool(); var particleExplorerTool = ParticleExplorerTool(); +var selectedParticleEntity = 0; entityListTool.webView.eventBridge.webEventReceived.connect(function(data) { var data = JSON.parse(data); if (data.type == "selectionUpdate") { var ids = data.entityIds; if(ids.length === 1) { - if (Entities.getEntityProperties(ids[0], "type").type === "ParticleEffect") { + if (Entities.getEntityProperties(ids[0], "type").type === "ParticleEffect" ) { + if (JSON.stringify(selectedParticleEntity) !== JSON.stringify(ids[0])) { + // We already had a particle entity selected, so destroy that one and create the new one + particleExplorerTool.destroyWebView(); + } // Now we want to activate the partice explorer panel! particleExplorerTool.createWebView(); var properties = Entities.getEntityProperties(ids[0]); @@ -1898,7 +1903,7 @@ entityListTool.webView.eventBridge.webEventReceived.connect(function(data) { Script.setTimeout(function() { // Wait for event bridge on web side to open particleExplorerTool.webView.eventBridge.emitScriptEvent(JSON.stringify(data)); - }, 3000) + }, 2000) } else { particleExplorerTool.destroyWebView(); diff --git a/examples/particle_explorer/particleExplorer.js b/examples/particle_explorer/particleExplorer.js index 8bec19646a..7749c93120 100644 --- a/examples/particle_explorer/particleExplorer.js +++ b/examples/particle_explorer/particleExplorer.js @@ -338,9 +338,7 @@ function writeVec3ToInterface(obj) { } function listenForSettingsUpdates() { - console.log("EBL LISTENING FOR EVENTS ON PARTICLE GUI WEB SIDE!") EventBridge.scriptEventReceived.connect(function(data) { - console.log("EBL RECIEVED EVENT!! ON WEB SIDE - " + JSON.stringify(data)); data = JSON.parse(data); if (data.messageType === 'particle_settings') { _.each(data.currentProperties, function(value, key) { diff --git a/examples/particle_explorer/particleExplorerTool.js b/examples/particle_explorer/particleExplorerTool.js index 118ef94542..03979b6cfa 100644 --- a/examples/particle_explorer/particleExplorerTool.js +++ b/examples/particle_explorer/particleExplorerTool.js @@ -2,7 +2,7 @@ // particleExplorerTool.js // // Created by Eric Levin on 2/15/16 -// Copyright 2015 High Fidelity, Inc. +// Copyright 2016 High Fidelity, Inc. // Adds particleExplorer tool to the edit panel when a user selects a particle entity from the edit tool window // This is an example of a new, easy way to do two way bindings between dynamically created GUI and in-world entities. // @@ -31,6 +31,9 @@ ParticleExplorerTool = function() { that.destroyWebView = function() { + if (!that.webView) { + return; + } that.webView.close(); that.webView = null; }