AMCameraFade.cs 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. using System;
  2. using System.Reflection;
  3. using UnityEngine;
  4. [RequireComponent(typeof(Camera))]
  5. [ExecuteInEditMode]
  6. public class AMCameraFade : MonoBehaviour
  7. {
  8. public static Texture2D blankTexture
  9. {
  10. get
  11. {
  12. if (!AMCameraFade._blankTexture)
  13. {
  14. AMCameraFade._blankTexture = AMCameraFade.getBlankTexture();
  15. }
  16. return AMCameraFade._blankTexture;
  17. }
  18. }
  19. public static Material matIris
  20. {
  21. get
  22. {
  23. if (AMCameraFade._matIris == null)
  24. {
  25. AMCameraFade._matIris = AMCameraFade.getMaterialIris();
  26. }
  27. return AMCameraFade._matIris;
  28. }
  29. }
  30. [HideInInspector]
  31. private RenderTexture tex
  32. {
  33. get
  34. {
  35. return this.getRenderTexture();
  36. }
  37. }
  38. private void Awake()
  39. {
  40. if (Application.isPlaying && this.preview)
  41. {
  42. this.destroy();
  43. }
  44. else
  45. {
  46. Camera component = base.GetComponent<Camera>();
  47. component.clearFlags = CameraClearFlags.Nothing;
  48. component.cullingMask = 0;
  49. component.depth = -1f;
  50. this.keepAliveAwake = true;
  51. }
  52. }
  53. private void OnGUI()
  54. {
  55. if (this.isReset || (!this.hasColorTex && ((!this.useRenderTexture && !this.tex2d) || (this.useRenderTexture && !this.renderTextureCamera))))
  56. {
  57. return;
  58. }
  59. GUI.depth = -9999999;
  60. if (this.hasColorBG)
  61. {
  62. GUI.color = new Color(this.colorBG.r, this.colorBG.g, this.colorBG.b, 1f);
  63. GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), AMCameraFade.blankTexture);
  64. }
  65. if (this.hasColorTex)
  66. {
  67. GUI.color = new Color(this.colorTex.r, this.colorTex.g, this.colorTex.b, 1f);
  68. }
  69. else
  70. {
  71. GUI.color = Color.white;
  72. }
  73. AMCameraFade.processCameraFade(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (!this.hasColorTex) ? ((!this.useRenderTexture) ? this.tex2d : this.tex) : AMCameraFade.blankTexture, this.mode, this.value, this.percent, this.r, this.irisShape, Event.current);
  74. if (!Application.isPlaying)
  75. {
  76. float num = 0f;
  77. bool flag = false;
  78. if ((float)this.height > 0f)
  79. {
  80. num = (float)this.width / (float)this.height;
  81. }
  82. else
  83. {
  84. flag = true;
  85. }
  86. this.width = Screen.width;
  87. this.height = Screen.height;
  88. float num2 = (float)this.width / (float)this.height;
  89. if (flag || (num > 0f && num2.ToString("N1") != num.ToString("N1")))
  90. {
  91. this.doForceUpdate(false);
  92. }
  93. if (!this.isReset && this.placeholder)
  94. {
  95. GUI.color = Color.black;
  96. GUI.DrawTexture(new Rect(0f, (float)Screen.height - 25f, (float)Screen.width, 25f), this.tex);
  97. GUI.color = Color.white;
  98. GUI.Label(new Rect(5f, (float)Screen.height - 20f - 2f, (float)Screen.width - 10f, 20f), "This is a placeholder. Transitions can only be previewed with a Unity Pro license.");
  99. }
  100. }
  101. }
  102. private void Update()
  103. {
  104. if (this.deleteMe)
  105. {
  106. Debug.Log("Animator: Deleted AMCameraFade" + ((!this.preview) ? string.Empty : "Preview"));
  107. }
  108. if (!Application.isPlaying)
  109. {
  110. if (this.deleteMe)
  111. {
  112. this.destroyImmediate();
  113. }
  114. else if (this.updateTexture)
  115. {
  116. this.doForceUpdate(true);
  117. }
  118. return;
  119. }
  120. if (this.preview || this.deleteMe || (!this.keepAliveAwake && !this.keepAliveColor && this.keepAlives <= 0 && !this.keepAlivePreview))
  121. {
  122. this.destroy();
  123. }
  124. }
  125. private void doForceUpdate(bool showMsg = false)
  126. {
  127. if (this.useRenderTexture)
  128. {
  129. this.shouldUpdateRenderTexture = true;
  130. }
  131. else
  132. {
  133. AMCameraFade.doShouldUpdateStill();
  134. }
  135. this.updateTexture = false;
  136. if (showMsg)
  137. {
  138. Debug.Log("Animator: Updated AMCameraFade" + ((!this.preview) ? string.Empty : "Preview") + " Texture");
  139. }
  140. }
  141. public void destroyImmediate()
  142. {
  143. AMTween.Stop(base.gameObject);
  144. if (this._tex)
  145. {
  146. if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this._tex)
  147. {
  148. this.renderTextureCamera.targetTexture = null;
  149. }
  150. UnityEngine.Object.DestroyImmediate(this._tex);
  151. }
  152. AMCameraFade._cf = null;
  153. UnityEngine.Object.DestroyImmediate(base.gameObject);
  154. }
  155. public void destroy()
  156. {
  157. AMTween.Stop(base.gameObject);
  158. if (this._tex)
  159. {
  160. if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this._tex)
  161. {
  162. this.renderTextureCamera.targetTexture = null;
  163. }
  164. UnityEngine.Object.Destroy(this._tex);
  165. }
  166. AMCameraFade._cf = null;
  167. UnityEngine.Object.Destroy(base.gameObject);
  168. }
  169. public static void processCameraFade(Rect rect, Texture tex, int mode, float value, float percent, float[] r, Texture2D _irisShape, Event editorEvent)
  170. {
  171. if (_irisShape != null && AMCameraFade.matIris.GetTexture("_Mask") != _irisShape)
  172. {
  173. AMCameraFade.matIris.SetTexture("_Mask", _irisShape);
  174. }
  175. switch (mode)
  176. {
  177. case 1:
  178. if (((r.Length < 1) ? 0f : r[0]) == 0f)
  179. {
  180. AMCameraFade.processVenetianBlindsVertical(rect, tex, value, (r.Length < 2) ? 5 : ((int)r[1]));
  181. }
  182. else
  183. {
  184. AMCameraFade.processVenetianBlindsHorizontal(rect, tex, value, (int)r[1]);
  185. }
  186. return;
  187. case 2:
  188. {
  189. bool flag = ((r.Length < 2) ? 0f : r[1]) == 0f;
  190. float num = (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f);
  191. if (r.Length < 1 || r[0] == 0f)
  192. {
  193. if (flag)
  194. {
  195. AMCameraFade.processDoorsVerticalOpen(rect, tex, value, num);
  196. }
  197. else
  198. {
  199. AMCameraFade.processDoorsVerticalClose(rect, tex, value, num);
  200. }
  201. }
  202. else if (flag)
  203. {
  204. AMCameraFade.processDoorsHorizontalOpen(rect, tex, value, num);
  205. }
  206. else
  207. {
  208. AMCameraFade.processDoorsHorizontalClose(rect, tex, value, num);
  209. }
  210. return;
  211. }
  212. case 3:
  213. if (((r.Length < 1) ? 0f : r[0]) == 0f)
  214. {
  215. AMCameraFade.processIrisBoxShrink(rect, tex, value, (r.Length < 2) ? 0.5f : Mathf.Clamp(r[1], 0f, 1f), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f));
  216. }
  217. else
  218. {
  219. AMCameraFade.processIrisBoxGrow(rect, tex, value, (r.Length < 2) ? 0.5f : Mathf.Clamp(r[1], 0f, 1f), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f));
  220. }
  221. return;
  222. case 4:
  223. AMCameraFade.processIrisRound(rect, tex, ((r.Length < 1) ? 0f : r[0]) == 0f, value, (r.Length < 2) ? 2.5f : r[1], (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f), (r.Length < 4) ? 0.5f : Mathf.Clamp(r[3], 0f, 1f), _irisShape, editorEvent);
  224. return;
  225. case 6:
  226. AMCameraFade.processIrisShape(rect, tex, ((r.Length < 1) ? 0f : r[0]) == 0f, value, percent, (r.Length < 5) ? 0.5f : Mathf.Clamp(r[4], 0f, 1f), (r.Length < 6) ? 0.5f : Mathf.Clamp(r[5], 0f, 1f), _irisShape, (r.Length < 2 || r[1] <= 0f) ? 6f : r[1], (r.Length < 7) ? 0.5f : r[6], (r.Length < 8) ? 0.5f : r[7], (r.Length < 3) ? 50 : ((int)r[2]), ((r.Length < 4) ? 0f : r[3]) == 1f, editorEvent);
  227. return;
  228. case 7:
  229. AMCameraFade.processShapeWipe(rect, tex, value, _irisShape, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 6f : r[1], (r.Length < 3) ? 0f : r[2], (r.Length < 4) ? 3f : r[3], (r.Length < 5) ? -3f : r[4], editorEvent);
  230. return;
  231. case 8:
  232. AMCameraFade.processLinearWipe(rect, tex, value, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 0.25f : r[1], _irisShape, editorEvent);
  233. return;
  234. case 9:
  235. AMCameraFade.processRadialWipe(rect, tex, value, ((r.Length < 1) ? 0f : r[0]) == 0f, (r.Length < 2) ? 0 : ((int)r[1]), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f), (r.Length < 4) ? 0.5f : Mathf.Clamp(r[3], 0f, 1f), editorEvent);
  236. return;
  237. case 10:
  238. AMCameraFade.processWedgeWipe(rect, tex, value, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 0.5f : Mathf.Clamp(r[1], 0f, 1f), (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f), editorEvent);
  239. return;
  240. }
  241. AMCameraFade.processAlpha(rect, tex, value);
  242. }
  243. public void setupMaterials()
  244. {
  245. switch (this.mode)
  246. {
  247. case 4:
  248. case 6:
  249. case 7:
  250. case 8:
  251. case 9:
  252. case 10:
  253. AMCameraFade.matIris.SetMatrix("_MatrixTex", Matrix4x4.zero);
  254. AMCameraFade.matIris.SetTexture("_Mask", this.irisShape);
  255. break;
  256. }
  257. }
  258. public static bool needsTexture(int mode)
  259. {
  260. switch (mode)
  261. {
  262. case 4:
  263. case 6:
  264. case 7:
  265. case 8:
  266. case 9:
  267. case 10:
  268. return true;
  269. }
  270. return false;
  271. }
  272. public static void processAlpha(Rect rect, Texture tex, float value)
  273. {
  274. GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, value);
  275. GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex);
  276. }
  277. public static void processDoorsVerticalOpen(Rect rect, Texture tex, float value, float focalX)
  278. {
  279. float num = rect.width * focalX * value;
  280. float num2 = (rect.width - rect.width * focalX) * value;
  281. float num3 = 0f;
  282. float num4 = rect.width - num2;
  283. float num5 = focalX * value;
  284. float num6 = (1f - focalX) * value;
  285. float x = 0f;
  286. float x2 = 1f - num6;
  287. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num3, rect.y, num, rect.height), tex, new Rect(x, 0f, num5, 1f));
  288. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num4, rect.y, num2, rect.height), tex, new Rect(x2, 0f, num6, 1f));
  289. }
  290. public static void processDoorsVerticalClose(Rect rect, Texture tex, float value, float focalX)
  291. {
  292. float num = rect.width * focalX * value;
  293. float num2 = (rect.width - rect.width * focalX) * value;
  294. float num3 = rect.width * focalX - num;
  295. float num4 = rect.width * focalX;
  296. float num5 = focalX * value;
  297. float num6 = (1f - focalX) * value;
  298. float x = focalX - num5;
  299. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num3, rect.y, num, rect.height), tex, new Rect(x, 0f, num5, 1f));
  300. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num4, rect.y, num2, rect.height), tex, new Rect(focalX, 0f, num6, 1f));
  301. }
  302. public static void processDoorsHorizontalOpen(Rect rect, Texture tex, float value, float focalY)
  303. {
  304. float num = rect.height * focalY * value;
  305. float num2 = (rect.height - rect.height * focalY) * value;
  306. float num3 = 0f;
  307. float num4 = rect.height - num2;
  308. float num5 = focalY * value;
  309. float num6 = (1f - focalY) * value;
  310. float y = 1f - focalY * value;
  311. float y2 = 0f;
  312. GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num3, rect.width, num), tex, new Rect(0f, y, 1f, num5));
  313. GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num4, rect.width, num2), tex, new Rect(0f, y2, 1f, num6));
  314. }
  315. public static void processDoorsHorizontalClose(Rect rect, Texture tex, float value, float focalY)
  316. {
  317. float num = rect.height * focalY * value;
  318. float num2 = (rect.height - rect.height * focalY) * value;
  319. float num3 = rect.height * focalY - num;
  320. float num4 = rect.height * focalY;
  321. float num5 = focalY * value;
  322. float num6 = (1f - focalY) * value;
  323. float y = 1f - focalY;
  324. float y2 = 1f - focalY - num6;
  325. GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num3, rect.width, num), tex, new Rect(0f, y, 1f, num5));
  326. GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num4, rect.width, num2), tex, new Rect(0f, y2, 1f, num6));
  327. }
  328. public static void processVenetianBlindsVertical(Rect rect, Texture tex, float value, int resolution)
  329. {
  330. for (int i = 0; i < resolution; i++)
  331. {
  332. float num = rect.width / (float)resolution * (float)i + (1f - value) * (rect.width / (float)resolution) / 2f;
  333. float num2 = rect.width / (float)resolution * value;
  334. float x = 1f / (float)resolution * (float)i + (1f - value) * (1f / (float)resolution) / 2f;
  335. float num3 = 1f / (float)resolution * value;
  336. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y, num2, rect.height), tex, new Rect(x, 0f, num3, 1f));
  337. }
  338. }
  339. public static void processVenetianBlindsHorizontal(Rect rect, Texture tex, float value, int resolution)
  340. {
  341. for (int i = 0; i < resolution; i++)
  342. {
  343. float num = rect.height - rect.height / (float)resolution * (float)(i + 1) + (1f - value) * (rect.height / (float)resolution) / 2f;
  344. float num2 = rect.height / (float)resolution * value;
  345. float y = 1f / (float)resolution * (float)i + (1f - value) * (1f / (float)resolution) / 2f;
  346. float num3 = 1f / (float)resolution * value;
  347. GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num, rect.width, num2), tex, new Rect(0f, y, 1f, num3));
  348. }
  349. }
  350. public static void processIrisBoxGrow(Rect rect, Texture tex, float value, float focalX, float focalY)
  351. {
  352. float num = rect.width * focalX * value;
  353. float num2 = rect.height * focalY * value;
  354. float num3 = rect.width * (1f - value);
  355. float num4 = rect.height * (1f - value);
  356. float x = focalX * value;
  357. float y = (1f - focalY) * value;
  358. float num5 = 1f - value;
  359. float num6 = 1f - value;
  360. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y + num2, num3, num4), tex, new Rect(x, y, num5, num6));
  361. }
  362. public static void processIrisBoxShrink(Rect rect, Texture tex, float value, float focalX, float focalY)
  363. {
  364. float num = rect.width * focalX * (1f - value);
  365. float num2 = rect.height * focalY * (1f - value);
  366. float num3 = rect.width * value;
  367. float num4 = rect.height * value;
  368. float x = focalX * (1f - value);
  369. float y = (1f - focalY) * (1f - value);
  370. GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y + num2, num3, num4), tex, new Rect(x, y, value, value));
  371. }
  372. public static void processIrisRound(Rect rect, Texture tex, bool shrink, float value, float maxScale, float focalX, float focalY, Texture2D irisShape, Event editorEvent)
  373. {
  374. AMCameraFade.processIrisShape(rect, tex, shrink, value, 1f, focalX, focalY, irisShape, maxScale, 0.5f, 0.5f, 0, true, editorEvent);
  375. }
  376. public static void processIrisShape(Rect rect, Texture tex, bool shrink, float value, float percent, float focalX, float focalY, Texture shape, float maxScale, float pivotX, float pivotY, int rotateAmount, bool easeRotation, Event editorEvent)
  377. {
  378. if (editorEvent.type.Equals(EventType.Repaint))
  379. {
  380. focalY = 1f - focalY;
  381. float num = ((!shrink) ? (1f - value) : value) * maxScale;
  382. if (num <= 0.01f)
  383. {
  384. num = 0f;
  385. }
  386. if ((double)num <= 0.04)
  387. {
  388. AMCameraFade.matIris.SetFloat("_Cutoff", 0.8f);
  389. }
  390. else
  391. {
  392. AMCameraFade.matIris.SetFloat("_Cutoff", 0.1f);
  393. }
  394. float num2 = rect.width / rect.height;
  395. Vector2 vector = new Vector2(0f, 0f);
  396. vector.x = focalX - num / 2f / num2;
  397. vector.y = focalY - 0.5f * num;
  398. Vector3 s = new Vector3(1f / num * num2, 1f / num, 1f);
  399. Vector3 pos = new Vector3(-1f * vector.x * s.x, -1f * vector.y * s.y, 0f);
  400. float num3 = ((!shrink) ? 1f : 0f) - value;
  401. pivotY = 1f - pivotY;
  402. pivotX = pivotX / 2f + 0.25f;
  403. pivotY = pivotY / 2f + 0.25f;
  404. Vector2 vector2 = new Vector2(pivotX + (0.5f - pivotX) * num3, pivotY + (0.5f - pivotY) * num3);
  405. Matrix4x4 rhs = Matrix4x4.TRS(-vector2, Quaternion.identity, Vector3.one);
  406. float num4 = (float)rotateAmount * 5f;
  407. if (easeRotation)
  408. {
  409. num4 *= num3;
  410. }
  411. else
  412. {
  413. num4 *= percent;
  414. }
  415. Quaternion q = Quaternion.Euler(0f, 0f, num4);
  416. Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
  417. Matrix4x4 lhs = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one);
  418. Matrix4x4 rhs3 = Matrix4x4.TRS(pos, Quaternion.identity, s);
  419. AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
  420. AMCameraFade.matIris.color = GUI.color;
  421. Graphics.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex, AMCameraFade.matIris);
  422. }
  423. }
  424. public static void processLinearWipe(Rect rect, Texture tex, float value, int angle, float padding, Texture2D irisShape, Event editorEvent)
  425. {
  426. AMCameraFade.processShapeWipe(rect, tex, value, irisShape, angle, 1f, padding, 0f, 0f, editorEvent);
  427. }
  428. public static void processShapeWipe(Rect rect, Texture tex, float value, Texture shape, int angle, float scale, float padding, float offsetStart, float offsetEnd, Event editorEvent)
  429. {
  430. if (editorEvent.type.Equals(EventType.Repaint))
  431. {
  432. int num = angle + 90;
  433. float num2 = rect.width / rect.height;
  434. Vector3 s = new Vector3(1f / scale * num2, 1f / scale, 1f);
  435. Vector2 vector = AMCameraFade.getPositionAtAngle(num, padding);
  436. Vector2 a = AMCameraFade.getPositionAtAngle((num + 180) % 360, padding);
  437. Vector2 normalized = (a - vector).normalized;
  438. vector += -normalized * offsetEnd;
  439. a += -normalized * offsetStart;
  440. Vector2 vector2 = new Vector2(0.5f, 0.5f);
  441. Vector2 vector3 = new Vector2(a.x - vector.x, a.y - vector.y);
  442. Vector2 vector4 = new Vector2(0f, 0f);
  443. vector4.x = vector.x + vector3.x * value;
  444. vector4.y = vector.y + vector3.y * value;
  445. Vector2 v = new Vector3(-vector4.x * s.x + 0.5f, -vector4.y * s.y + 0.5f);
  446. Matrix4x4 rhs = Matrix4x4.TRS(-vector2, Quaternion.identity, Vector3.one);
  447. Quaternion q = Quaternion.Euler(0f, 0f, (float)(num - 90));
  448. Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
  449. Matrix4x4 lhs = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one);
  450. Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
  451. AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
  452. if (AMCameraFade.matIris.color != GUI.color)
  453. {
  454. AMCameraFade.matIris.color = GUI.color;
  455. }
  456. Graphics.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex, AMCameraFade.matIris);
  457. }
  458. }
  459. public static void processRadialWipe(Rect rect, Texture tex, float value, bool clockwise, int startingAngle, float focalX, float focalY, Event editorEvent)
  460. {
  461. if (value <= 0f)
  462. {
  463. return;
  464. }
  465. if (value >= 1f)
  466. {
  467. GUI.DrawTexture(rect, tex);
  468. return;
  469. }
  470. if (editorEvent.type.Equals(EventType.Repaint))
  471. {
  472. if (!clockwise)
  473. {
  474. startingAngle = (startingAngle + 180) % 360;
  475. }
  476. AMCameraFade.matIris.SetFloat("_Cutoff", 0f);
  477. float num = 1f;
  478. float num2 = (float)(startingAngle + 90) + 360f * (1f - value) * ((!clockwise) ? -1f : 1f);
  479. float num3 = rect.width / rect.height;
  480. Vector3 s = new Vector3(1f / num * num3, 1f / num, 1f);
  481. Vector2 vector = new Vector2(0.5f, 0.5f);
  482. Vector2 vector2 = new Vector2(focalX, 1f - focalY);
  483. Vector2 v = new Vector3(-vector2.x * s.x + 0.5f, -vector2.y * s.y + 0.5f);
  484. Matrix4x4 rhs = Matrix4x4.TRS(-vector, Quaternion.identity, Vector3.one);
  485. Quaternion q = Quaternion.Euler(0f, 0f, num2 - 90f);
  486. Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
  487. Matrix4x4 lhs = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one);
  488. Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
  489. AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
  490. if (AMCameraFade.matIris.color != GUI.color)
  491. {
  492. AMCameraFade.matIris.color = GUI.color;
  493. }
  494. Rect rect2 = new Rect(0f, 0f, 1f, 1f);
  495. Rect rect3 = new Rect(0f, 0f, 1f, 1f);
  496. Rect rect4 = new Rect(rect);
  497. bool flag = value > 0.5f;
  498. if ((float)startingAngle == 0f)
  499. {
  500. rect3.width = focalX;
  501. rect4.width = rect.width * focalX;
  502. }
  503. else if ((float)startingAngle == 90f)
  504. {
  505. rect3.y = 1f - focalY;
  506. rect3.height = focalY;
  507. rect4.height = rect.height * focalY;
  508. }
  509. else if ((float)startingAngle == 180f)
  510. {
  511. rect3.x = focalX;
  512. rect3.width = 1f - focalX;
  513. rect4.x = rect.x + rect.width * focalX;
  514. rect4.width = rect.width * (1f - focalX);
  515. }
  516. else if ((float)startingAngle == 270f)
  517. {
  518. rect3.height = 1f - focalY;
  519. rect4.y = rect.y + rect.height * focalY;
  520. rect4.height = rect.height * (1f - focalY);
  521. }
  522. Graphics.DrawTexture(flag ? rect : rect4, tex, flag ? rect2 : rect3, 0, 0, 0, 0, AMCameraFade.matIris);
  523. if (flag)
  524. {
  525. GUI.DrawTextureWithTexCoords(rect4, tex, rect3);
  526. }
  527. }
  528. }
  529. public static void processWedgeWipe(Rect rect, Texture tex, float value, int startingAngle, float focalX, float focalY, Event editorEvent)
  530. {
  531. if (value <= 0f)
  532. {
  533. return;
  534. }
  535. if (value >= 1f)
  536. {
  537. GUI.DrawTexture(rect, tex);
  538. return;
  539. }
  540. if (editorEvent.type.Equals(EventType.Repaint))
  541. {
  542. AMCameraFade.matIris.SetFloat("_Cutoff", 0f);
  543. float num = 1f;
  544. float num2 = (float)(startingAngle + 90) + 360f * (0.5f - value / 2f);
  545. float num3 = rect.width / rect.height;
  546. Vector3 s = new Vector3(1f / num * num3, 1f / num, 1f);
  547. Vector2 vector = new Vector2(0.5f, 0.5f);
  548. Vector2 vector2 = new Vector2(focalX, 1f - focalY);
  549. Vector2 v = new Vector3(-vector2.x * s.x + 0.5f, -vector2.y * s.y + 0.5f);
  550. Matrix4x4 rhs = Matrix4x4.TRS(-vector, Quaternion.identity, Vector3.one);
  551. Quaternion q = Quaternion.Euler(0f, 0f, num2 - 90f);
  552. Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
  553. Matrix4x4 lhs = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one);
  554. Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
  555. AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
  556. if (AMCameraFade.matIris.color != GUI.color)
  557. {
  558. AMCameraFade.matIris.color = GUI.color;
  559. }
  560. Rect sourceRect = new Rect(0f, 0f, 1f, 1f);
  561. Rect screenRect = new Rect(rect);
  562. Rect sourceRect2 = new Rect(0f, 0f, 1f, 1f);
  563. Rect screenRect2 = new Rect(rect);
  564. if ((float)startingAngle == 0f)
  565. {
  566. sourceRect.width = focalX;
  567. screenRect.width = rect.width * focalX;
  568. sourceRect2.x = focalX;
  569. sourceRect2.width = 1f - focalX;
  570. screenRect2.x = rect.x + rect.width * focalX;
  571. screenRect2.width = rect.width - screenRect.width;
  572. }
  573. else if ((float)startingAngle == 90f)
  574. {
  575. sourceRect.height = focalY;
  576. sourceRect.y = 1f - focalY;
  577. screenRect.height = rect.height * focalY;
  578. sourceRect2.height = 1f - sourceRect.height;
  579. screenRect2.y = rect.y + rect.height * focalY;
  580. screenRect2.height = rect.height - screenRect.height;
  581. }
  582. else if ((float)startingAngle == 180f)
  583. {
  584. sourceRect.x = focalX;
  585. sourceRect.width = 1f - focalX;
  586. screenRect.x = rect.x + rect.width * focalX;
  587. screenRect.width = rect.width * (1f - focalX);
  588. sourceRect2.width = focalX;
  589. screenRect2.width = rect.width * focalX;
  590. }
  591. else if ((float)startingAngle == 270f)
  592. {
  593. sourceRect.height = 1f - focalY;
  594. screenRect.y = rect.y + rect.height * focalY;
  595. screenRect.height = rect.height * (1f - focalY);
  596. sourceRect2.height = focalY;
  597. sourceRect2.y = 1f - focalY;
  598. screenRect2.height = rect.height * focalY;
  599. }
  600. Graphics.DrawTexture(screenRect2, tex, sourceRect2, 0, 0, 0, 0, AMCameraFade.matIris);
  601. startingAngle = (startingAngle + 180) % 360;
  602. num2 = (float)(startingAngle + 90) + 360f * (0.5f - value / 2f) * -1f;
  603. q = Quaternion.Euler(0f, 0f, num2 - 90f);
  604. rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
  605. AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
  606. Graphics.DrawTexture(screenRect, tex, sourceRect, 0, 0, 0, 0, AMCameraFade.matIris);
  607. }
  608. }
  609. private static Texture2D getBlankTexture()
  610. {
  611. Texture2D texture2D = (Texture2D)Resources.Load("am_blank_texture");
  612. if (!texture2D)
  613. {
  614. texture2D = new Texture2D(1, 1);
  615. texture2D.SetPixel(0, 0, Color.white);
  616. texture2D.Apply();
  617. }
  618. return texture2D;
  619. }
  620. private static Material getMaterialIris()
  621. {
  622. Material material = (Material)Resources.Load("AMIrisShapeMaterial");
  623. if (!material)
  624. {
  625. material = new Material("Shader \"Animator/AMIrisShape\" {Properties {\t_MainTex (\"Base (RGB)\", 2D) = \"white\" {}\t_Mask (\"Culling Mask\", 2D) = \"white\" {}\t_Cutoff (\"Alpha cutoff\", Range (0,1)) = 0.1 \t_Color (\"Main Color\", Color) = (1,1,1,1) }SubShader {\tTags {\"Queue\"=\"Background\"}\tLighting Off\tZWrite Off\tBlend SrcAlpha OneMinusSrcAlpha\tAlphaTest GEqual [_Cutoff]\tPass {\t\tSetTexture [_Mask] { matrix [_Matrix] combine texture }\t\tSetTexture [_MainTex] { ConstantColor [_Color] matrix[_TexMatrix] combine texture * constant, previous }\t}}}");
  626. }
  627. return material;
  628. }
  629. private static Material getMaterialRadial()
  630. {
  631. return (Material)Resources.Load("AMRadialWipeMaterial");
  632. }
  633. public static AMCameraFade getCameraFade(bool preview = false)
  634. {
  635. if (AMCameraFade._cf)
  636. {
  637. AMCameraFade._cf.preview = preview;
  638. return AMCameraFade._cf;
  639. }
  640. AMCameraFade amcameraFade = null;
  641. GameObject gameObject = GameObject.Find("AMCamera" + ((!preview) ? "Fade" : "FadePreview"));
  642. if (gameObject)
  643. {
  644. amcameraFade = (AMCameraFade)gameObject.GetComponent(typeof(AMCameraFade));
  645. }
  646. if (!amcameraFade)
  647. {
  648. amcameraFade = (AMCameraFade)new GameObject("AMCamera" + ((!preview) ? "Fade" : "FadePreview"), new Type[]
  649. {
  650. typeof(AMCameraFade)
  651. }).GetComponent(typeof(AMCameraFade));
  652. }
  653. AMCameraFade._cf = amcameraFade;
  654. AMCameraFade._cf.preview = preview;
  655. return AMCameraFade._cf;
  656. }
  657. public void setupRenderTexture(Camera camera)
  658. {
  659. if (this.renderTextureCamera != camera)
  660. {
  661. if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this.tex)
  662. {
  663. this.renderTextureCamera.targetTexture = null;
  664. }
  665. camera.targetTexture = this.tex;
  666. this.renderTextureCamera = camera;
  667. camera.Render();
  668. }
  669. this.useRenderTexture = true;
  670. this.colorTex = Color.white;
  671. this.hasColorTex = false;
  672. this.placeholder = false;
  673. }
  674. public bool isRenderTextureSetupFor(Camera camera)
  675. {
  676. return this.tex && camera.targetTexture == this.tex;
  677. }
  678. public static void reset()
  679. {
  680. if (AMCameraFade._cf != null)
  681. {
  682. AMCameraFade._cf.isReset = true;
  683. AMCameraFade._cf.value = 0f;
  684. if (AMCameraFade._cf.renderTextureCamera)
  685. {
  686. if (AMCameraFade._cf.renderTextureCamera.targetTexture == AMCameraFade._cf.tex)
  687. {
  688. AMCameraFade._cf.renderTextureCamera.targetTexture = null;
  689. }
  690. AMCameraFade._cf.renderTextureCamera = null;
  691. }
  692. }
  693. }
  694. public static void clearRenderTexture()
  695. {
  696. if (AMCameraFade._cf != null)
  697. {
  698. AMCameraFade._cf.clearTexture();
  699. }
  700. }
  701. public static void destroyAndReload(bool isPreview)
  702. {
  703. if (AMCameraFade._cf != null)
  704. {
  705. AMCameraFade._cf.destroyImmediate();
  706. }
  707. AMCameraFade._cf = null;
  708. AMCameraFade.getCameraFade(isPreview);
  709. }
  710. public static void destroyImmediateInstance()
  711. {
  712. if (AMCameraFade._cf != null)
  713. {
  714. AMCameraFade._cf.destroyImmediate();
  715. }
  716. }
  717. public static bool hasInstance()
  718. {
  719. return AMCameraFade._cf != null;
  720. }
  721. public static bool isPreview()
  722. {
  723. return AMCameraFade._cf != null && AMCameraFade._cf.preview;
  724. }
  725. public static void doShouldUpdateStill()
  726. {
  727. if (AMCameraFade._cf)
  728. {
  729. AMCameraFade._cf.cachedStillFrame = 0;
  730. AMCameraFade._cf.shouldUpdateStill = true;
  731. }
  732. }
  733. public static Vector2 getPositionAtAngle(int a, float padding)
  734. {
  735. a = (a % 360 + 360) % 360;
  736. Vector2 result = new Vector2(0f, 0f);
  737. float num = 0f - padding;
  738. float num2 = 1f + padding;
  739. float num3 = 0f - padding;
  740. float num4 = 1f + padding;
  741. float num5 = num2 - num;
  742. float num6 = num4 - num3;
  743. if (a >= 0 && a <= 45)
  744. {
  745. result.x = (float)a / 45f * (num5 / 2f) + num5 / 2f;
  746. result.y = num4;
  747. }
  748. else if (a <= 90)
  749. {
  750. result.x = num2;
  751. result.y = (1f - ((float)a - 45f) / 45f) * (num6 / 2f) + num6 / 2f;
  752. }
  753. else if (a <= 135)
  754. {
  755. result.x = num2;
  756. result.y = (1f - ((float)a - 90f) / 45f) * (num6 / 2f);
  757. }
  758. else if (a <= 180)
  759. {
  760. result.x = (1f - ((float)a - 135f) / 45f) * (num5 / 2f) + num5 / 2f;
  761. result.y = num3;
  762. }
  763. else if (a <= 225)
  764. {
  765. result.x = (1f - ((float)a - 180f) / 45f) * (num5 / 2f);
  766. result.y = num3;
  767. }
  768. else if (a <= 270)
  769. {
  770. result.x = num;
  771. result.y = ((float)a - 225f) / 45f * (num6 / 2f);
  772. }
  773. else if (a <= 315)
  774. {
  775. result.x = num;
  776. result.y = ((float)a - 270f) / 45f * (num6 / 2f) + num6 / 2f;
  777. }
  778. else if (a <= 360)
  779. {
  780. result.x = ((float)a - 315f) / 45f * (num5 / 2f);
  781. result.y = num4;
  782. }
  783. return result;
  784. }
  785. public void repaint()
  786. {
  787. this.OnGUI();
  788. }
  789. public void incrementKeepAlives()
  790. {
  791. this.keepAlives++;
  792. this.keepAliveAwake = false;
  793. }
  794. public void clearTexture()
  795. {
  796. if (this.renderTextureCamera)
  797. {
  798. this.renderTextureCamera.targetTexture = null;
  799. this.renderTextureCamera = null;
  800. }
  801. }
  802. public void clearTexture2D()
  803. {
  804. if (this.tex2d)
  805. {
  806. UnityEngine.Object.Destroy(this.tex2d);
  807. this.tex2d = null;
  808. }
  809. }
  810. private RenderTexture getRenderTexture()
  811. {
  812. if (!this.shouldUpdateRenderTexture && this._tex)
  813. {
  814. return this._tex;
  815. }
  816. this.shouldUpdateRenderTexture = false;
  817. if (Application.isPlaying)
  818. {
  819. if (this._tex)
  820. {
  821. UnityEngine.Object.Destroy(this._tex);
  822. }
  823. this.width = Screen.width;
  824. this.height = Screen.height;
  825. }
  826. else
  827. {
  828. if (this._tex)
  829. {
  830. UnityEngine.Object.DestroyImmediate(this._tex);
  831. }
  832. if (this.width > 0)
  833. {
  834. if (this.height > 0)
  835. {
  836. goto IL_E3;
  837. }
  838. }
  839. try
  840. {
  841. Rect mainGameViewPosition = AMCameraFade.GetMainGameViewPosition();
  842. this.width = (int)mainGameViewPosition.width;
  843. this.height = (int)mainGameViewPosition.height;
  844. }
  845. catch
  846. {
  847. this.width = 200;
  848. this.height = 100;
  849. this.shouldUpdateRenderTexture = true;
  850. }
  851. }
  852. IL_E3:
  853. this._tex = new RenderTexture(this.width, this.height, 24);
  854. return this._tex;
  855. }
  856. public static object GetMainGameView()
  857. {
  858. Type type = Type.GetType("UnityEditor.GameView,UnityEditor");
  859. MethodInfo method = type.GetMethod("GetMainGameView", BindingFlags.Static | BindingFlags.NonPublic);
  860. return method.Invoke(null, null);
  861. }
  862. public static Rect GetMainGameViewPosition()
  863. {
  864. object mainGameView = AMCameraFade.GetMainGameView();
  865. return (Rect)mainGameView.GetType().GetProperty("position").GetValue(mainGameView, null);
  866. }
  867. private static AMCameraFade _cf;
  868. private static Texture2D _blankTexture;
  869. private static Material _matIris;
  870. public bool deleteMe;
  871. public bool updateTexture;
  872. [HideInInspector]
  873. public int keepAlives;
  874. [HideInInspector]
  875. public bool keepAliveColor;
  876. [HideInInspector]
  877. public bool keepAlivePreview;
  878. [HideInInspector]
  879. public bool keepAliveAwake = true;
  880. [HideInInspector]
  881. public int mode;
  882. [HideInInspector]
  883. public float percent;
  884. public float value;
  885. [HideInInspector]
  886. public bool useRenderTexture;
  887. [HideInInspector]
  888. public Texture2D tex2d;
  889. [HideInInspector]
  890. public RenderTexture _tex;
  891. [HideInInspector]
  892. public float[] r;
  893. [HideInInspector]
  894. public Camera renderTextureCamera;
  895. [HideInInspector]
  896. public bool hasColorTex;
  897. [HideInInspector]
  898. public bool hasColorBG;
  899. [HideInInspector]
  900. public Color colorTex;
  901. [HideInInspector]
  902. public Color colorBG;
  903. [HideInInspector]
  904. public int width;
  905. [HideInInspector]
  906. public int height;
  907. [HideInInspector]
  908. public bool placeholder;
  909. [HideInInspector]
  910. public Texture2D irisShape;
  911. [HideInInspector]
  912. public Texture background;
  913. [HideInInspector]
  914. public int cachedStillFrame;
  915. [HideInInspector]
  916. public bool isReset;
  917. [HideInInspector]
  918. public bool shouldUpdateStill;
  919. [HideInInspector]
  920. public bool shouldUpdateRenderTexture;
  921. [HideInInspector]
  922. public bool preview;
  923. public static class Defaults
  924. {
  925. public static class Doors
  926. {
  927. public const float layout = 0f;
  928. public const float type = 0f;
  929. public const float focalXorY = 0.5f;
  930. }
  931. public static class VenetianBlinds
  932. {
  933. public const float layout = 0f;
  934. public const int numberOfBlinds = 5;
  935. }
  936. public static class IrisBox
  937. {
  938. public const float type = 0f;
  939. public const float focalX = 0.5f;
  940. public const float focalY = 0.5f;
  941. }
  942. public static class IrisRound
  943. {
  944. public const float type = 0f;
  945. public const float maxScale = 2.5f;
  946. public const float focalX = 0.5f;
  947. public const float focalY = 0.5f;
  948. }
  949. public static class IrisShape
  950. {
  951. public const float type = 0f;
  952. public const float maxScale = 6f;
  953. public const int rotateAmount = 50;
  954. public const float easeRotation = 0f;
  955. public const float focalX = 0.5f;
  956. public const float focalY = 0.5f;
  957. public const float pivotX = 0.5f;
  958. public const float pivotY = 0.5f;
  959. }
  960. public static class ShapeWipe
  961. {
  962. public const int angle = 0;
  963. public const float scale = 6f;
  964. public const float padding = 0f;
  965. public const float offsetStart = 3f;
  966. public const float offsetEnd = -3f;
  967. }
  968. public static class LinearWipe
  969. {
  970. public const int angle = 0;
  971. public const float padding = 0.25f;
  972. }
  973. public static class RadialWipe
  974. {
  975. public const float direction = 0f;
  976. public const int startingAngle = 0;
  977. public const float focalX = 0.5f;
  978. public const float focalY = 0.5f;
  979. }
  980. public static class WedgeWipe
  981. {
  982. public const int startingAngle = 0;
  983. public const float focalX = 0.5f;
  984. public const float focalY = 0.5f;
  985. }
  986. }
  987. }