Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. // MarkerController.js
  2. // Version: 0.0.1
  3. // Event: Lens Initialized
  4. // Description: Controls the marker found and lost behavior.
  5.  
  6. // @input bool advanced = false
  7. // @input Component.MarkerTrackingComponent marker {"showIf": "advanced"}
  8. // @input Component.ScriptComponent crossHintScript {"showIf": "advanced"}
  9. // @input Component.ScriptComponent fadeEffectScript {"showIf": "advanced"}
  10. // @input Component.ScriptComponent hintControllerScript {"showIf": "advanced"}
  11. // @input SceneObject tween
  12. // @input float delayTime = 2
  13. // @input Asset.Material mat
  14. // @input bool captureTexture = false
  15. // @input Component.AnimationMixer animationMixer
  16. // @input string animationOpenName = "Layer0"
  17. // @input string animationCloseName = "Layer0"
  18. // @input Component.ScriptComponent helperFunctions
  19.  
  20. global.touchSystem.touchBlocking = false;
  21.  
  22. var tweening = false; function onTapped(eventData) {
  23. if (!tweening) {
  24. tweening = true; global.tweenManager.startTween(script.tween, "launch", setFalse);
  25. }
  26. }
  27. var event = script.createEvent("TapEvent");
  28. event.bind(onTapped);
  29. function setFalse() {
  30. tweening = false;
  31. }
  32.  
  33. function onLensTurnOnEvent()
  34. {
  35. if(script.fadeEffectScript)
  36. {
  37. if(script.fadeEffectScript.api.resetFadeEffect)
  38. {
  39. script.fadeEffectScript.api.resetFadeEffect();
  40. }
  41. }
  42. if(script.captureTexture)
  43. {
  44. resetAnimation();
  45. }
  46. }
  47. var turnOnEvent = script.createEvent("TurnOnEvent");
  48. turnOnEvent.bind(onLensTurnOnEvent);
  49. var playingParticles = false;
  50. var doorOpenAnimPlaying = false;
  51. var doorOpen = false;
  52.  
  53. script.marker.onMarkerFound = function()
  54. {
  55. global.tweenManager.startTween(script.tween, "move");
  56. var delayedEvent = script.createEvent("DelayedCallbackEvent");
  57. delayedEvent.bind(function(eventData)
  58. {
  59. global.controlTime = getTime();
  60. playingParticles = true;
  61. });
  62.  
  63. playAnimation();
  64.  
  65. delayedEvent.reset(script.delayTime);
  66.  
  67. if(script.hintControllerScript)
  68. {
  69. if(script.hintControllerScript.api.hide)
  70. {
  71. script.hintControllerScript.api.hide();
  72. }
  73. }
  74. else
  75. {
  76. print("MarkerController: Please assign hint controller");
  77. }
  78.  
  79.  
  80. if(script.crossHintScript)
  81. {
  82. if( script.crossHintScript.api.startCrossAnimation)
  83. {
  84. script.crossHintScript.api.startCrossAnimation();
  85. }
  86. }
  87. else
  88. {
  89. print("MarkerController: Please assign cross hint");
  90. }
  91.  
  92. var markerObject = script.marker.getSceneObject();
  93. if(markerObject)
  94. {
  95. for( var i = 0; i < markerObject.getChildrenCount(); i++ )
  96. {
  97. var childObject = markerObject.getChild( i );
  98. for(var j = 0; j < childObject.getComponentCount("Component.ScriptComponent"); j++)
  99. {
  100. var objectsScript = childObject.getComponentByIndex("Component.ScriptComponent" , j);
  101.  
  102. if(objectsScript.api)
  103. {
  104. if(objectsScript.api.onMarkerFound)
  105. {
  106. objectsScript.api.onMarkerFound();
  107. }
  108. }
  109. }
  110. }
  111. }
  112. if(script.fadeEffectScript)
  113. {
  114. if(script.fadeEffectScript.api.startFade)
  115. {
  116. script.fadeEffectScript.api.startFade();
  117. }
  118. }
  119.  
  120. }
  121.  
  122. script.marker.onMarkerLost = function()
  123. {
  124. resetAnimation();
  125. playingParticles = false;
  126.  
  127. if(script.hintControllerScript)
  128. {
  129. if(script.hintControllerScript.api.show)
  130. {
  131. script.hintControllerScript.api.show();
  132. }
  133. }
  134. else
  135. {
  136. print("MarkerController: Please assign hint controller");
  137. }
  138.  
  139. var markerObject = script.marker.getSceneObject();
  140. if(markerObject)
  141. {
  142. for( var i = 0; i < markerObject.getChildrenCount(); i++ )
  143. {
  144. var childObject = markerObject.getChild( i );
  145. for(var j = 0; j < childObject.getComponentCount("Component.ScriptComponent"); j++)
  146. {
  147. var objectsScript = childObject.getComponentByIndex("Component.ScriptComponent" , j);
  148.  
  149. if(objectsScript.api)
  150. {
  151. if(objectsScript.api.onMarkerLost)
  152. {
  153. objectsScript.api.onMarkerLost();
  154. }
  155. }
  156. }
  157. }
  158. }
  159. if(script.fadeEffectScript)
  160. {
  161. if(script.fadeEffectScript.api.resetFadeEffect)
  162. {
  163. script.fadeEffectScript.api.resetFadeEffect();
  164. }
  165. }
  166. }
  167.  
  168. function onUpdate (time)
  169. {
  170. if (playingParticles) {
  171.  
  172. global.animTime = global.controlTime - getTime();
  173. var positiveTime = -animTime * 0.5;
  174.  
  175. script.mat
  176. .mainPass
  177. .externalTimeInput = positiveTime;
  178. }
  179. else{
  180. global.animTime = global.controlTime - getTime();
  181. var positiveTime = -animTime * 0;
  182.  
  183. script.mat
  184. .mainPass
  185. .externalTimeInput = positiveTime;
  186. }
  187. }
  188. var updateEvent = script.createEvent("UpdateEvent");
  189. updateEvent.bind(onUpdate);
  190.  
  191. function playAnimation()
  192. {
  193. if(script.captureTexture)
  194. {
  195. getScreenCapture();
  196. }
  197. if(script.animationMixer)
  198. {
  199. if(doorOpen){
  200. script.animationMixer.start(script.animationCloseName, 0, 1);
  201. doorOpen = false;
  202. }
  203. else{
  204. script.animationMixer.start(script.animationOpenName, 0, 1);
  205. doorOpen = true;
  206. }
  207. doorOpenAnimPlaying = true;
  208. }
  209. else
  210. {
  211. print("MarkerDoorController: Please assign animation mixer component")
  212. }
  213. }
  214.  
  215. function resetAnimation()
  216. {
  217. script.animationMixer.start(script.animationOpenName, 0, 1);
  218. script.animationMixer.pause(script.animationOpenName);
  219. doorOpen = false;
  220. doorOpenAnimPlaying = false;
  221.  
  222. if(script.helperFunctions.api.getScreenCapture)
  223. {
  224. if(script.captureTexture)
  225. {
  226. script.helperFunctions.api.hideScreenCaptureMeshes(doorMeshes);
  227. }
  228. }
  229. else
  230. {
  231. print("MarkerDoorController: Please assign helper script")
  232. }
  233.  
  234. }
  235.  
  236. function getScreenCapture()
  237. {
  238. if(script.helperFunctions.api.getScreenCapture)
  239. {
  240. script.helperFunctions.api.getScreenCapture(doorMeshes);
  241. }
  242. else
  243. {
  244. print("MarkerDoorController: Please assign helper script")
  245. }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement