Created
March 24, 2017 00:40
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var teleport; | |
var portalDestination; | |
var animationURL; | |
var position; | |
function playSound(entityID) { | |
print("playing teleport sound"); | |
if (teleport.downloaded) { | |
if(!position) { | |
getProps(entityID); | |
} | |
Audio.playSound(teleport, { position: position, volume: 0.40, localOnly: true }); | |
} | |
}; | |
function getProps(entityID) { | |
var properties = Entities.getEntityProperties(entityID); | |
if (properties) { | |
animationURL = properties.modelURL; | |
position = properties.position; | |
try { portalDestination=JSON.parse(properties.userData).portalDestination; } catch(e) { | |
portalDestination = properties.userData; | |
} | |
} | |
}; | |
this.preload = function(entityID) { | |
print("loading teleport script"); | |
teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw"); | |
getProps(entityID); | |
}; | |
this.enterEntity = function(entityID) { | |
// get latest props in case we changed the destination | |
getProps(entityID); | |
print("enterEntity() .... The portal destination is " + portalDestination); | |
if (portalDestination.length > 0) { | |
print("Teleporting to hifi://" + portalDestination); | |
Window.location = "hifi://" + portalDestination; | |
} | |
}; | |
this.leaveEntity = function(entityID) { | |
print("leaveEntity() called ...."); | |
if (!animationURL) { | |
getProps(entityID); | |
} | |
Entities.editEntity(entityID, { | |
animation: { url: animationURL, currentFrame: 1, running: false } | |
}); | |
playSound(entityID); | |
}; | |
this.hoverEnterEntity = function(entityID) { | |
print("hoverEnterEntity() called ...."); | |
if (!animationURL) { | |
getProps(entityID); | |
} | |
Entities.editEntity(entityID, { | |
animation: { url: animationURL, fps: 24, firstFrame: 1, lastFrame: 25, currentFrame: 1, running: true, hold: true } | |
}); | |
}; | |
this.unload = function() { | |
print("unloading teleport script"); | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment