armory/Sources/armory/logicnode/CanvasGetPositionNode.hx
2019-12-19 23:54:08 +01:00

29 lines
703 B
Haxe

package armory.logicnode;
import iron.Scene;
import armory.trait.internal.CanvasScript;
class CanvasGetPositionNode extends LogicNode {
var canvas: CanvasScript;
public function new(tree: LogicTree) {
super(tree);
}
#if arm_ui
override function get(from: Int) {
if (canvas == null) canvas = Scene.active.getTrait(CanvasScript);
if (canvas == null) canvas = Scene.active.camera.getTrait(CanvasScript);
if (canvas == null || !canvas.ready) return null;
// This Try/Catch hacks around an issue where the handles are
// not created yet, even though canvas.ready is true.
try {
return canvas.getHandle(inputs[0].get()).position;
}
catch (e: Dynamic) { return null; }
}
#end
}