Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MarkerController.js
- // Version: 0.0.1
- // Event: Lens Initialized
- // Description: Controls the marker found and lost behavior.
- // @input bool advanced = false
- // @input Component.MarkerTrackingComponent marker {"showIf": "advanced"}
- // @input Component.ScriptComponent crossHintScript {"showIf": "advanced"}
- // @input Component.ScriptComponent fadeEffectScript {"showIf": "advanced"}
- // @input Component.ScriptComponent hintControllerScript {"showIf": "advanced"}
- // @input SceneObject tween
- // @input float delayTime = 2
- // @input Asset.Material mat
- // @input bool captureTexture = false
- // @input Component.AnimationMixer animationMixer
- // @input string animationOpenName = "Layer0"
- // @input string animationCloseName = "Layer0"
- // @input Component.ScriptComponent helperFunctions
- global.touchSystem.touchBlocking = false;
- var tweening = false; function onTapped(eventData) {
- if (!tweening) {
- tweening = true; global.tweenManager.startTween(script.tween, "launch", setFalse);
- }
- }
- var event = script.createEvent("TapEvent");
- event.bind(onTapped);
- function setFalse() {
- tweening = false;
- }
- function onLensTurnOnEvent()
- {
- if(script.fadeEffectScript)
- {
- if(script.fadeEffectScript.api.resetFadeEffect)
- {
- script.fadeEffectScript.api.resetFadeEffect();
- }
- }
- if(script.captureTexture)
- {
- resetAnimation();
- }
- }
- var turnOnEvent = script.createEvent("TurnOnEvent");
- turnOnEvent.bind(onLensTurnOnEvent);
- var playingParticles = false;
- var doorOpenAnimPlaying = false;
- var doorOpen = false;
- script.marker.onMarkerFound = function()
- {
- global.tweenManager.startTween(script.tween, "move");
- var delayedEvent = script.createEvent("DelayedCallbackEvent");
- delayedEvent.bind(function(eventData)
- {
- global.controlTime = getTime();
- playingParticles = true;
- });
- playAnimation();
- delayedEvent.reset(script.delayTime);
- if(script.hintControllerScript)
- {
- if(script.hintControllerScript.api.hide)
- {
- script.hintControllerScript.api.hide();
- }
- }
- else
- {
- print("MarkerController: Please assign hint controller");
- }
- if(script.crossHintScript)
- {
- if( script.crossHintScript.api.startCrossAnimation)
- {
- script.crossHintScript.api.startCrossAnimation();
- }
- }
- else
- {
- print("MarkerController: Please assign cross hint");
- }
- var markerObject = script.marker.getSceneObject();
- if(markerObject)
- {
- for( var i = 0; i < markerObject.getChildrenCount(); i++ )
- {
- var childObject = markerObject.getChild( i );
- for(var j = 0; j < childObject.getComponentCount("Component.ScriptComponent"); j++)
- {
- var objectsScript = childObject.getComponentByIndex("Component.ScriptComponent" , j);
- if(objectsScript.api)
- {
- if(objectsScript.api.onMarkerFound)
- {
- objectsScript.api.onMarkerFound();
- }
- }
- }
- }
- }
- if(script.fadeEffectScript)
- {
- if(script.fadeEffectScript.api.startFade)
- {
- script.fadeEffectScript.api.startFade();
- }
- }
- }
- script.marker.onMarkerLost = function()
- {
- resetAnimation();
- playingParticles = false;
- if(script.hintControllerScript)
- {
- if(script.hintControllerScript.api.show)
- {
- script.hintControllerScript.api.show();
- }
- }
- else
- {
- print("MarkerController: Please assign hint controller");
- }
- var markerObject = script.marker.getSceneObject();
- if(markerObject)
- {
- for( var i = 0; i < markerObject.getChildrenCount(); i++ )
- {
- var childObject = markerObject.getChild( i );
- for(var j = 0; j < childObject.getComponentCount("Component.ScriptComponent"); j++)
- {
- var objectsScript = childObject.getComponentByIndex("Component.ScriptComponent" , j);
- if(objectsScript.api)
- {
- if(objectsScript.api.onMarkerLost)
- {
- objectsScript.api.onMarkerLost();
- }
- }
- }
- }
- }
- if(script.fadeEffectScript)
- {
- if(script.fadeEffectScript.api.resetFadeEffect)
- {
- script.fadeEffectScript.api.resetFadeEffect();
- }
- }
- }
- function onUpdate (time)
- {
- if (playingParticles) {
- global.animTime = global.controlTime - getTime();
- var positiveTime = -animTime * 0.5;
- script.mat
- .mainPass
- .externalTimeInput = positiveTime;
- }
- else{
- global.animTime = global.controlTime - getTime();
- var positiveTime = -animTime * 0;
- script.mat
- .mainPass
- .externalTimeInput = positiveTime;
- }
- }
- var updateEvent = script.createEvent("UpdateEvent");
- updateEvent.bind(onUpdate);
- function playAnimation()
- {
- if(script.captureTexture)
- {
- getScreenCapture();
- }
- if(script.animationMixer)
- {
- if(doorOpen){
- script.animationMixer.start(script.animationCloseName, 0, 1);
- doorOpen = false;
- }
- else{
- script.animationMixer.start(script.animationOpenName, 0, 1);
- doorOpen = true;
- }
- doorOpenAnimPlaying = true;
- }
- else
- {
- print("MarkerDoorController: Please assign animation mixer component")
- }
- }
- function resetAnimation()
- {
- script.animationMixer.start(script.animationOpenName, 0, 1);
- script.animationMixer.pause(script.animationOpenName);
- doorOpen = false;
- doorOpenAnimPlaying = false;
- if(script.helperFunctions.api.getScreenCapture)
- {
- if(script.captureTexture)
- {
- script.helperFunctions.api.hideScreenCaptureMeshes(doorMeshes);
- }
- }
- else
- {
- print("MarkerDoorController: Please assign helper script")
- }
- }
- function getScreenCapture()
- {
- if(script.helperFunctions.api.getScreenCapture)
- {
- script.helperFunctions.api.getScreenCapture(doorMeshes);
- }
- else
- {
- print("MarkerDoorController: Please assign helper script")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement