83 lines
No EOL
2.2 KiB
JavaScript
83 lines
No EOL
2.2 KiB
JavaScript
(function(){
|
|
var _this = this;
|
|
var _activeColor;
|
|
var _activeTrigger;
|
|
|
|
_this.preload = function(entityID){
|
|
_this.entityID = entityID;
|
|
_activeColor = "red";
|
|
_activeTrigger = "clickDownOnEntity";
|
|
}
|
|
|
|
_this.clickDownOnEntity = function(entityID, event)
|
|
{
|
|
if(_activeTrigger === "clickDownOnEntity")
|
|
{
|
|
changeColor(_activeColor);
|
|
}
|
|
}
|
|
|
|
_this.hoverOverEntity = function(entityID, event)
|
|
{
|
|
if(_activeTrigger === "enterEntity")
|
|
{
|
|
changeColor(_activeColor);
|
|
}
|
|
}
|
|
|
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
var button = tablet.addButton({
|
|
text: "COLORS"
|
|
});
|
|
|
|
function clicked(){
|
|
tablet.gotoWebScreen("https://hifi-content.s3.amazonaws.com/liv/scriptEditor.html")
|
|
}
|
|
|
|
button.clicked.connect(clicked);
|
|
|
|
// The web events send the results of the different options from the UI
|
|
function onWebEventReceived(event)
|
|
{
|
|
print("Web Event: " + event);
|
|
if(typeof event === "string"){
|
|
event = JSON.parse(event);
|
|
}
|
|
|
|
if(event.type === "click")
|
|
{
|
|
_activeColor = event.data;
|
|
}
|
|
|
|
else if(event.type === "dropdown")
|
|
{
|
|
_activeTrigger = event.data;
|
|
}
|
|
}
|
|
|
|
|
|
// This is the main function call that uses the behaviors
|
|
function changeColor(color){
|
|
switch(color)
|
|
{
|
|
case "red":
|
|
Entities.editEntity(_this.entityID, { color: { red: 255, green: 0, blue: 0 } });
|
|
break;
|
|
case "green":
|
|
Entities.editEntity(_this.entityID, { color: { red: 0, green: 255, blue: 0 } });
|
|
break;
|
|
case "blue":
|
|
Entities.editEntity(_this.entityID, { color: { red: 0, green: 0, blue: 255 } });
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
tablet.webEventReceived.connect(onWebEventReceived);
|
|
|
|
function cleanup() {
|
|
tablet.removeButton(button);
|
|
}
|
|
Script.scriptEnding.connect(cleanup);
|
|
|
|
}) |