mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 05:09:22 +02:00
add example entity script for change color on hover
This commit is contained in:
parent
4db5986625
commit
2ffe15c833
1 changed files with 38 additions and 0 deletions
38
examples/entityScripts/changeColorOnHover.js
Normal file
38
examples/entityScripts/changeColorOnHover.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
//
|
||||||
|
// changeColorOnHover.js
|
||||||
|
// examples/entityScripts
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 11/1/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// This is an example of an entity script which when assigned to a non-model entity like a box or sphere, will
|
||||||
|
// change the color of the entity when you hover over it. This script uses the JavaScript prototype/class functionality
|
||||||
|
// to construct an object that has methods for hoverEnterEntity and hoverLeaveEntity;
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
(function(){
|
||||||
|
this.oldColor = {};
|
||||||
|
this.oldColorKnown = false;
|
||||||
|
this.storeOldColor = function(entityID) {
|
||||||
|
var oldProperties = Entities.getEntityProperties(entityID);
|
||||||
|
this.oldColor = oldProperties.color;
|
||||||
|
this.oldColorKnown = true;
|
||||||
|
print("storing old color... this.oldColor=" + this.oldColor.red + "," + this.oldColor.green + "," + this.oldColor.blue);
|
||||||
|
};
|
||||||
|
this.hoverEnterEntity = function(entityID, mouseEvent) {
|
||||||
|
if (!this.oldColorKnown) {
|
||||||
|
this.storeOldColor(entityID);
|
||||||
|
}
|
||||||
|
Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
|
||||||
|
};
|
||||||
|
this.hoverLeaveEntity = function(entityID, mouseEvent) {
|
||||||
|
if (this.oldColorKnown) {
|
||||||
|
print("leave restoring old color... this.oldColor="
|
||||||
|
+ this.oldColor.red + "," + this.oldColor.green + "," + this.oldColor.blue);
|
||||||
|
Entities.editEntity(entityID, { color: this.oldColor });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
Loading…
Reference in a new issue