From 608821b50b0896c682202f1652d83bf92a5bd45f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Mar 2016 17:06:49 -0700 Subject: [PATCH] simple baton --- .../virtualBaton/batonSimpleEntityScript.js | 64 +++++++++++++++++++ .../virtualBaton/batonSimpleEntitySpawner.js | 31 +++++++++ 2 files changed, 95 insertions(+) create mode 100644 examples/entityScripts/virtualBaton/batonSimpleEntityScript.js create mode 100644 examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js diff --git a/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js b/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js new file mode 100644 index 0000000000..77b75b9914 --- /dev/null +++ b/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js @@ -0,0 +1,64 @@ +(function() { + Script.include("../../libraries/virtualBaton.js"); + + var _this = this; + + + this.startUpdate = function() { + Entities.editEntity(_this.batonDebugModel, {visible: true}); + + } + + this.maybeClaim = function() { + if (_this.isBatonOwner === true) { + _this.soundIntervalConnected = false; + } + Entities.editEntity(_this.batonDebugModel, {visible: false}); + baton.claim(_this.startUpdate, _this.maybeClaim); + } + + this.preload = function(entityID) { + _this.entityID = entityID + _this.batonDebugModel = Entities.addEntity({ + type: "Box", + color: { + red: 200, + green: 10, + blue: 200 + }, + position: Vec3.sum(MyAvatar.position, { + x: 0, + y: 1, + z: 0 + }), + dimensions: { + x: 0.5, + y: 1, + z: 0 + }, + parentID: MyAvatar.sessionUUID, + visible: false + }); + _this.colorsToCycle = [{ + red: 200, + green: 0, + blue: 0 + }, { + red: 0, + green: 200, + blue: 0 + }, { + red: 0, + green: 0, + blue: 200 + }]; + baton = virtualBaton({ + batonName: "batonSimpleEntityScript:" + _this.entityID + }); + _this.isBatonOwner = false; + _this.maybeClaim(); + + print("EBL Preload!!"); + } + +}); \ No newline at end of file diff --git a/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js b/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js new file mode 100644 index 0000000000..e48ef77e8f --- /dev/null +++ b/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js @@ -0,0 +1,31 @@ + var orientation = Camera.getOrientation(); + orientation = Quat.safeEulerAngles(orientation); + orientation.x = 0; + orientation = Quat.fromVec3Degrees(orientation); + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); + + // Math.random ensures no caching of script + var SCRIPT_URL = Script.resolvePath("batonSimpleEntityScript.js?v1" + Math.random()); + + var myEntity = Entities.addEntity({ + type: "Box", + color: { + red: 200, + green: 10, + blue: 10 + }, + position: center, + dimensions: { + x: 0.1, + y: 0.1, + z: 0.1 + }, + script: SCRIPT_URL + }); + + + function cleanup() { + Entities.deleteEntity(myEntity); + } + + Script.scriptEnding.connect(cleanup); \ No newline at end of file