// physButton.js (function(){ var _this; var ringID; var ringAction = null; var buttonAction = null; var buttonSpring = null; var pressDepth; var physButton = function() { _this = this; }; physButton.prototype = { preload: function(entityID) { _this.entityID = entityID; _this.getButtonData(); var actionList = Entities.getActionIDs(_this.entityID); if(actionList.length <= 1){ console.log("adding Actions"); buttonAction = Entities.addAction("slider", ringID, { axis: { x: 0, y: 1, z: 0 }, point: {x:0, y:0, z: 0}, otherEntityID: _this.entityID, otherPoint: { x: 0, y: 1, z: 0 }, otherAxis: { x: 0, y: 1, z: 0 }, linearLow: -1, linearHigh: 1 }); //Entities.editEntity(ringID, {locked: true}); buttonSpring = Entities.addAction("tractor", _this.entityID, { targetPosition: { x: 0, y: 100, z: 0}, LinearTimeScale: 0, otherID: ringID }); }else{ for ( i = 0; i < actionList.length; i++ ){ try{ Entities.deleteAction(_this.entityID, actionList[i]); console.log("actionID deleted"); } catch (e){ print("Error deleting ActionID"); return; } } } }, getButtonData: function() { buttonProperties = Entities.getEntityProperties(_this.entityID, ["position", "userData"]); if (!buttonProperties.userData || buttonProperties.userData === "{}") { print("Button ", _this.entityID, " is missing user data."); //Script.clearInterval(intervalID); return; } try { buttonUserData = JSON.parse(buttonProperties.userData); ringID = buttonUserData.ringID; baseID = buttonUserData.baseID; soundURL = SoundCache.getSound(buttonUserData.soundURL); pressDepth = buttonUserData.pressDepth; soundVolume = !isNaN(buttonUserData.soundVolume) ? buttonUserData.soundVolume : 0.0; soundLocal = buttonUserData.isLocal ? buttonUserData.isLocal : false; // verify that settings are legit } catch (e) { print("Error in retrieving physButton Data"); return; } }, playSound: function() { if (injector) { injector.stop(); } if (soundURL && soundURL.downloaded) { injector = Audio.playSound(soundURL, { position: soundPosition, volume: soundVolume, loop: soundLoop, localOnly: soundLocal }); } else { print("soundURL not downloaded!"); return; } }, collisionWithEntity: function(entityID, baseID, collision){ _this.playSound(); }, unload: function(){ var actionList = Entities.getActionIDs(_this.entityID); for ( i = 0; i < actionList.length; i++ ){ try{ Entities.deleteAction(_this.entityID, actionList[i]); console.log("actionID deleted"); } catch (e){ print("Error deleting ActionID"); return; } } Entities.deleteAction(ringID,ringAction); Entities.deleteAction(_this.entityID, buttonAction); } // var switchBaseID = Entities.findEntitiesByName("Visual_Object_Mark_scram-base", worldOriginPos, radius); // console.log("HELLOOOOOOO ",switchBaseID); }; return new physButton; });