12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100 |
- using System;
- using System.Reflection;
- using UnityEngine;
- [RequireComponent(typeof(Camera))]
- [ExecuteInEditMode]
- public class AMCameraFade : MonoBehaviour
- {
- public static Texture2D blankTexture
- {
- get
- {
- if (!AMCameraFade._blankTexture)
- {
- AMCameraFade._blankTexture = AMCameraFade.getBlankTexture();
- }
- return AMCameraFade._blankTexture;
- }
- }
- public static Material matIris
- {
- get
- {
- if (AMCameraFade._matIris == null)
- {
- AMCameraFade._matIris = AMCameraFade.getMaterialIris();
- }
- return AMCameraFade._matIris;
- }
- }
- [HideInInspector]
- private RenderTexture tex
- {
- get
- {
- return this.getRenderTexture();
- }
- }
- private void Awake()
- {
- if (Application.isPlaying && this.preview)
- {
- this.destroy();
- }
- else
- {
- Camera component = base.GetComponent<Camera>();
- component.clearFlags = CameraClearFlags.Nothing;
- component.cullingMask = 0;
- component.depth = -1f;
- this.keepAliveAwake = true;
- }
- }
- private void OnGUI()
- {
- if (this.isReset || (!this.hasColorTex && ((!this.useRenderTexture && !this.tex2d) || (this.useRenderTexture && !this.renderTextureCamera))))
- {
- return;
- }
- GUI.depth = -9999999;
- if (this.hasColorBG)
- {
- GUI.color = new Color(this.colorBG.r, this.colorBG.g, this.colorBG.b, 1f);
- GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), AMCameraFade.blankTexture);
- }
- if (this.hasColorTex)
- {
- GUI.color = new Color(this.colorTex.r, this.colorTex.g, this.colorTex.b, 1f);
- }
- else
- {
- GUI.color = Color.white;
- }
- 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);
- if (!Application.isPlaying)
- {
- float num = 0f;
- bool flag = false;
- if ((float)this.height > 0f)
- {
- num = (float)this.width / (float)this.height;
- }
- else
- {
- flag = true;
- }
- this.width = Screen.width;
- this.height = Screen.height;
- float num2 = (float)this.width / (float)this.height;
- if (flag || (num > 0f && num2.ToString("N1") != num.ToString("N1")))
- {
- this.doForceUpdate(false);
- }
- if (!this.isReset && this.placeholder)
- {
- GUI.color = Color.black;
- GUI.DrawTexture(new Rect(0f, (float)Screen.height - 25f, (float)Screen.width, 25f), this.tex);
- GUI.color = Color.white;
- 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.");
- }
- }
- }
- private void Update()
- {
- if (this.deleteMe)
- {
- Debug.Log("Animator: Deleted AMCameraFade" + ((!this.preview) ? string.Empty : "Preview"));
- }
- if (!Application.isPlaying)
- {
- if (this.deleteMe)
- {
- this.destroyImmediate();
- }
- else if (this.updateTexture)
- {
- this.doForceUpdate(true);
- }
- return;
- }
- if (this.preview || this.deleteMe || (!this.keepAliveAwake && !this.keepAliveColor && this.keepAlives <= 0 && !this.keepAlivePreview))
- {
- this.destroy();
- }
- }
- private void doForceUpdate(bool showMsg = false)
- {
- if (this.useRenderTexture)
- {
- this.shouldUpdateRenderTexture = true;
- }
- else
- {
- AMCameraFade.doShouldUpdateStill();
- }
- this.updateTexture = false;
- if (showMsg)
- {
- Debug.Log("Animator: Updated AMCameraFade" + ((!this.preview) ? string.Empty : "Preview") + " Texture");
- }
- }
- public void destroyImmediate()
- {
- AMTween.Stop(base.gameObject);
- if (this._tex)
- {
- if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this._tex)
- {
- this.renderTextureCamera.targetTexture = null;
- }
- UnityEngine.Object.DestroyImmediate(this._tex);
- }
- AMCameraFade._cf = null;
- UnityEngine.Object.DestroyImmediate(base.gameObject);
- }
- public void destroy()
- {
- AMTween.Stop(base.gameObject);
- if (this._tex)
- {
- if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this._tex)
- {
- this.renderTextureCamera.targetTexture = null;
- }
- UnityEngine.Object.Destroy(this._tex);
- }
- AMCameraFade._cf = null;
- UnityEngine.Object.Destroy(base.gameObject);
- }
- public static void processCameraFade(Rect rect, Texture tex, int mode, float value, float percent, float[] r, Texture2D _irisShape, Event editorEvent)
- {
- if (_irisShape != null && AMCameraFade.matIris.GetTexture("_Mask") != _irisShape)
- {
- AMCameraFade.matIris.SetTexture("_Mask", _irisShape);
- }
- switch (mode)
- {
- case 1:
- if (((r.Length < 1) ? 0f : r[0]) == 0f)
- {
- AMCameraFade.processVenetianBlindsVertical(rect, tex, value, (r.Length < 2) ? 5 : ((int)r[1]));
- }
- else
- {
- AMCameraFade.processVenetianBlindsHorizontal(rect, tex, value, (int)r[1]);
- }
- return;
- case 2:
- {
- bool flag = ((r.Length < 2) ? 0f : r[1]) == 0f;
- float num = (r.Length < 3) ? 0.5f : Mathf.Clamp(r[2], 0f, 1f);
- if (r.Length < 1 || r[0] == 0f)
- {
- if (flag)
- {
- AMCameraFade.processDoorsVerticalOpen(rect, tex, value, num);
- }
- else
- {
- AMCameraFade.processDoorsVerticalClose(rect, tex, value, num);
- }
- }
- else if (flag)
- {
- AMCameraFade.processDoorsHorizontalOpen(rect, tex, value, num);
- }
- else
- {
- AMCameraFade.processDoorsHorizontalClose(rect, tex, value, num);
- }
- return;
- }
- case 3:
- if (((r.Length < 1) ? 0f : r[0]) == 0f)
- {
- 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));
- }
- else
- {
- 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));
- }
- return;
- case 4:
- 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);
- return;
- case 6:
- 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);
- return;
- case 7:
- 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);
- return;
- case 8:
- AMCameraFade.processLinearWipe(rect, tex, value, (r.Length < 1) ? 0 : ((int)r[0]), (r.Length < 2) ? 0.25f : r[1], _irisShape, editorEvent);
- return;
- case 9:
- 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);
- return;
- case 10:
- 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);
- return;
- }
- AMCameraFade.processAlpha(rect, tex, value);
- }
- public void setupMaterials()
- {
- switch (this.mode)
- {
- case 4:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- AMCameraFade.matIris.SetMatrix("_MatrixTex", Matrix4x4.zero);
- AMCameraFade.matIris.SetTexture("_Mask", this.irisShape);
- break;
- }
- }
- public static bool needsTexture(int mode)
- {
- switch (mode)
- {
- case 4:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- return true;
- }
- return false;
- }
- public static void processAlpha(Rect rect, Texture tex, float value)
- {
- GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, value);
- GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex);
- }
- public static void processDoorsVerticalOpen(Rect rect, Texture tex, float value, float focalX)
- {
- float num = rect.width * focalX * value;
- float num2 = (rect.width - rect.width * focalX) * value;
- float num3 = 0f;
- float num4 = rect.width - num2;
- float num5 = focalX * value;
- float num6 = (1f - focalX) * value;
- float x = 0f;
- float x2 = 1f - num6;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num3, rect.y, num, rect.height), tex, new Rect(x, 0f, num5, 1f));
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num4, rect.y, num2, rect.height), tex, new Rect(x2, 0f, num6, 1f));
- }
- public static void processDoorsVerticalClose(Rect rect, Texture tex, float value, float focalX)
- {
- float num = rect.width * focalX * value;
- float num2 = (rect.width - rect.width * focalX) * value;
- float num3 = rect.width * focalX - num;
- float num4 = rect.width * focalX;
- float num5 = focalX * value;
- float num6 = (1f - focalX) * value;
- float x = focalX - num5;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num3, rect.y, num, rect.height), tex, new Rect(x, 0f, num5, 1f));
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num4, rect.y, num2, rect.height), tex, new Rect(focalX, 0f, num6, 1f));
- }
- public static void processDoorsHorizontalOpen(Rect rect, Texture tex, float value, float focalY)
- {
- float num = rect.height * focalY * value;
- float num2 = (rect.height - rect.height * focalY) * value;
- float num3 = 0f;
- float num4 = rect.height - num2;
- float num5 = focalY * value;
- float num6 = (1f - focalY) * value;
- float y = 1f - focalY * value;
- float y2 = 0f;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num3, rect.width, num), tex, new Rect(0f, y, 1f, num5));
- GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num4, rect.width, num2), tex, new Rect(0f, y2, 1f, num6));
- }
- public static void processDoorsHorizontalClose(Rect rect, Texture tex, float value, float focalY)
- {
- float num = rect.height * focalY * value;
- float num2 = (rect.height - rect.height * focalY) * value;
- float num3 = rect.height * focalY - num;
- float num4 = rect.height * focalY;
- float num5 = focalY * value;
- float num6 = (1f - focalY) * value;
- float y = 1f - focalY;
- float y2 = 1f - focalY - num6;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num3, rect.width, num), tex, new Rect(0f, y, 1f, num5));
- GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num4, rect.width, num2), tex, new Rect(0f, y2, 1f, num6));
- }
- public static void processVenetianBlindsVertical(Rect rect, Texture tex, float value, int resolution)
- {
- for (int i = 0; i < resolution; i++)
- {
- float num = rect.width / (float)resolution * (float)i + (1f - value) * (rect.width / (float)resolution) / 2f;
- float num2 = rect.width / (float)resolution * value;
- float x = 1f / (float)resolution * (float)i + (1f - value) * (1f / (float)resolution) / 2f;
- float num3 = 1f / (float)resolution * value;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y, num2, rect.height), tex, new Rect(x, 0f, num3, 1f));
- }
- }
- public static void processVenetianBlindsHorizontal(Rect rect, Texture tex, float value, int resolution)
- {
- for (int i = 0; i < resolution; i++)
- {
- float num = rect.height - rect.height / (float)resolution * (float)(i + 1) + (1f - value) * (rect.height / (float)resolution) / 2f;
- float num2 = rect.height / (float)resolution * value;
- float y = 1f / (float)resolution * (float)i + (1f - value) * (1f / (float)resolution) / 2f;
- float num3 = 1f / (float)resolution * value;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x, rect.y + num, rect.width, num2), tex, new Rect(0f, y, 1f, num3));
- }
- }
- public static void processIrisBoxGrow(Rect rect, Texture tex, float value, float focalX, float focalY)
- {
- float num = rect.width * focalX * value;
- float num2 = rect.height * focalY * value;
- float num3 = rect.width * (1f - value);
- float num4 = rect.height * (1f - value);
- float x = focalX * value;
- float y = (1f - focalY) * value;
- float num5 = 1f - value;
- float num6 = 1f - value;
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y + num2, num3, num4), tex, new Rect(x, y, num5, num6));
- }
- public static void processIrisBoxShrink(Rect rect, Texture tex, float value, float focalX, float focalY)
- {
- float num = rect.width * focalX * (1f - value);
- float num2 = rect.height * focalY * (1f - value);
- float num3 = rect.width * value;
- float num4 = rect.height * value;
- float x = focalX * (1f - value);
- float y = (1f - focalY) * (1f - value);
- GUI.DrawTextureWithTexCoords(new Rect(rect.x + num, rect.y + num2, num3, num4), tex, new Rect(x, y, value, value));
- }
- public static void processIrisRound(Rect rect, Texture tex, bool shrink, float value, float maxScale, float focalX, float focalY, Texture2D irisShape, Event editorEvent)
- {
- AMCameraFade.processIrisShape(rect, tex, shrink, value, 1f, focalX, focalY, irisShape, maxScale, 0.5f, 0.5f, 0, true, editorEvent);
- }
- 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)
- {
- if (editorEvent.type.Equals(EventType.Repaint))
- {
- focalY = 1f - focalY;
- float num = ((!shrink) ? (1f - value) : value) * maxScale;
- if (num <= 0.01f)
- {
- num = 0f;
- }
- if ((double)num <= 0.04)
- {
- AMCameraFade.matIris.SetFloat("_Cutoff", 0.8f);
- }
- else
- {
- AMCameraFade.matIris.SetFloat("_Cutoff", 0.1f);
- }
- float num2 = rect.width / rect.height;
- Vector2 vector = new Vector2(0f, 0f);
- vector.x = focalX - num / 2f / num2;
- vector.y = focalY - 0.5f * num;
- Vector3 s = new Vector3(1f / num * num2, 1f / num, 1f);
- Vector3 pos = new Vector3(-1f * vector.x * s.x, -1f * vector.y * s.y, 0f);
- float num3 = ((!shrink) ? 1f : 0f) - value;
- pivotY = 1f - pivotY;
- pivotX = pivotX / 2f + 0.25f;
- pivotY = pivotY / 2f + 0.25f;
- Vector2 vector2 = new Vector2(pivotX + (0.5f - pivotX) * num3, pivotY + (0.5f - pivotY) * num3);
- Matrix4x4 rhs = Matrix4x4.TRS(-vector2, Quaternion.identity, Vector3.one);
- float num4 = (float)rotateAmount * 5f;
- if (easeRotation)
- {
- num4 *= num3;
- }
- else
- {
- num4 *= percent;
- }
- Quaternion q = Quaternion.Euler(0f, 0f, num4);
- Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
- Matrix4x4 lhs = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one);
- Matrix4x4 rhs3 = Matrix4x4.TRS(pos, Quaternion.identity, s);
- AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
- AMCameraFade.matIris.color = GUI.color;
- Graphics.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex, AMCameraFade.matIris);
- }
- }
- public static void processLinearWipe(Rect rect, Texture tex, float value, int angle, float padding, Texture2D irisShape, Event editorEvent)
- {
- AMCameraFade.processShapeWipe(rect, tex, value, irisShape, angle, 1f, padding, 0f, 0f, editorEvent);
- }
- public static void processShapeWipe(Rect rect, Texture tex, float value, Texture shape, int angle, float scale, float padding, float offsetStart, float offsetEnd, Event editorEvent)
- {
- if (editorEvent.type.Equals(EventType.Repaint))
- {
- int num = angle + 90;
- float num2 = rect.width / rect.height;
- Vector3 s = new Vector3(1f / scale * num2, 1f / scale, 1f);
- Vector2 vector = AMCameraFade.getPositionAtAngle(num, padding);
- Vector2 a = AMCameraFade.getPositionAtAngle((num + 180) % 360, padding);
- Vector2 normalized = (a - vector).normalized;
- vector += -normalized * offsetEnd;
- a += -normalized * offsetStart;
- Vector2 vector2 = new Vector2(0.5f, 0.5f);
- Vector2 vector3 = new Vector2(a.x - vector.x, a.y - vector.y);
- Vector2 vector4 = new Vector2(0f, 0f);
- vector4.x = vector.x + vector3.x * value;
- vector4.y = vector.y + vector3.y * value;
- Vector2 v = new Vector3(-vector4.x * s.x + 0.5f, -vector4.y * s.y + 0.5f);
- Matrix4x4 rhs = Matrix4x4.TRS(-vector2, Quaternion.identity, Vector3.one);
- Quaternion q = Quaternion.Euler(0f, 0f, (float)(num - 90));
- Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
- Matrix4x4 lhs = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one);
- Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
- AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
- if (AMCameraFade.matIris.color != GUI.color)
- {
- AMCameraFade.matIris.color = GUI.color;
- }
- Graphics.DrawTexture(new Rect(rect.x, rect.y, rect.width, rect.height), tex, AMCameraFade.matIris);
- }
- }
- public static void processRadialWipe(Rect rect, Texture tex, float value, bool clockwise, int startingAngle, float focalX, float focalY, Event editorEvent)
- {
- if (value <= 0f)
- {
- return;
- }
- if (value >= 1f)
- {
- GUI.DrawTexture(rect, tex);
- return;
- }
- if (editorEvent.type.Equals(EventType.Repaint))
- {
- if (!clockwise)
- {
- startingAngle = (startingAngle + 180) % 360;
- }
- AMCameraFade.matIris.SetFloat("_Cutoff", 0f);
- float num = 1f;
- float num2 = (float)(startingAngle + 90) + 360f * (1f - value) * ((!clockwise) ? -1f : 1f);
- float num3 = rect.width / rect.height;
- Vector3 s = new Vector3(1f / num * num3, 1f / num, 1f);
- Vector2 vector = new Vector2(0.5f, 0.5f);
- Vector2 vector2 = new Vector2(focalX, 1f - focalY);
- Vector2 v = new Vector3(-vector2.x * s.x + 0.5f, -vector2.y * s.y + 0.5f);
- Matrix4x4 rhs = Matrix4x4.TRS(-vector, Quaternion.identity, Vector3.one);
- Quaternion q = Quaternion.Euler(0f, 0f, num2 - 90f);
- Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
- Matrix4x4 lhs = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one);
- Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
- AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
- if (AMCameraFade.matIris.color != GUI.color)
- {
- AMCameraFade.matIris.color = GUI.color;
- }
- Rect rect2 = new Rect(0f, 0f, 1f, 1f);
- Rect rect3 = new Rect(0f, 0f, 1f, 1f);
- Rect rect4 = new Rect(rect);
- bool flag = value > 0.5f;
- if ((float)startingAngle == 0f)
- {
- rect3.width = focalX;
- rect4.width = rect.width * focalX;
- }
- else if ((float)startingAngle == 90f)
- {
- rect3.y = 1f - focalY;
- rect3.height = focalY;
- rect4.height = rect.height * focalY;
- }
- else if ((float)startingAngle == 180f)
- {
- rect3.x = focalX;
- rect3.width = 1f - focalX;
- rect4.x = rect.x + rect.width * focalX;
- rect4.width = rect.width * (1f - focalX);
- }
- else if ((float)startingAngle == 270f)
- {
- rect3.height = 1f - focalY;
- rect4.y = rect.y + rect.height * focalY;
- rect4.height = rect.height * (1f - focalY);
- }
- Graphics.DrawTexture(flag ? rect : rect4, tex, flag ? rect2 : rect3, 0, 0, 0, 0, AMCameraFade.matIris);
- if (flag)
- {
- GUI.DrawTextureWithTexCoords(rect4, tex, rect3);
- }
- }
- }
- public static void processWedgeWipe(Rect rect, Texture tex, float value, int startingAngle, float focalX, float focalY, Event editorEvent)
- {
- if (value <= 0f)
- {
- return;
- }
- if (value >= 1f)
- {
- GUI.DrawTexture(rect, tex);
- return;
- }
- if (editorEvent.type.Equals(EventType.Repaint))
- {
- AMCameraFade.matIris.SetFloat("_Cutoff", 0f);
- float num = 1f;
- float num2 = (float)(startingAngle + 90) + 360f * (0.5f - value / 2f);
- float num3 = rect.width / rect.height;
- Vector3 s = new Vector3(1f / num * num3, 1f / num, 1f);
- Vector2 vector = new Vector2(0.5f, 0.5f);
- Vector2 vector2 = new Vector2(focalX, 1f - focalY);
- Vector2 v = new Vector3(-vector2.x * s.x + 0.5f, -vector2.y * s.y + 0.5f);
- Matrix4x4 rhs = Matrix4x4.TRS(-vector, Quaternion.identity, Vector3.one);
- Quaternion q = Quaternion.Euler(0f, 0f, num2 - 90f);
- Matrix4x4 rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
- Matrix4x4 lhs = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one);
- Matrix4x4 rhs3 = Matrix4x4.TRS(v, Quaternion.identity, s);
- AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
- if (AMCameraFade.matIris.color != GUI.color)
- {
- AMCameraFade.matIris.color = GUI.color;
- }
- Rect sourceRect = new Rect(0f, 0f, 1f, 1f);
- Rect screenRect = new Rect(rect);
- Rect sourceRect2 = new Rect(0f, 0f, 1f, 1f);
- Rect screenRect2 = new Rect(rect);
- if ((float)startingAngle == 0f)
- {
- sourceRect.width = focalX;
- screenRect.width = rect.width * focalX;
- sourceRect2.x = focalX;
- sourceRect2.width = 1f - focalX;
- screenRect2.x = rect.x + rect.width * focalX;
- screenRect2.width = rect.width - screenRect.width;
- }
- else if ((float)startingAngle == 90f)
- {
- sourceRect.height = focalY;
- sourceRect.y = 1f - focalY;
- screenRect.height = rect.height * focalY;
- sourceRect2.height = 1f - sourceRect.height;
- screenRect2.y = rect.y + rect.height * focalY;
- screenRect2.height = rect.height - screenRect.height;
- }
- else if ((float)startingAngle == 180f)
- {
- sourceRect.x = focalX;
- sourceRect.width = 1f - focalX;
- screenRect.x = rect.x + rect.width * focalX;
- screenRect.width = rect.width * (1f - focalX);
- sourceRect2.width = focalX;
- screenRect2.width = rect.width * focalX;
- }
- else if ((float)startingAngle == 270f)
- {
- sourceRect.height = 1f - focalY;
- screenRect.y = rect.y + rect.height * focalY;
- screenRect.height = rect.height * (1f - focalY);
- sourceRect2.height = focalY;
- sourceRect2.y = 1f - focalY;
- screenRect2.height = rect.height * focalY;
- }
- Graphics.DrawTexture(screenRect2, tex, sourceRect2, 0, 0, 0, 0, AMCameraFade.matIris);
- startingAngle = (startingAngle + 180) % 360;
- num2 = (float)(startingAngle + 90) + 360f * (0.5f - value / 2f) * -1f;
- q = Quaternion.Euler(0f, 0f, num2 - 90f);
- rhs2 = Matrix4x4.TRS(Vector3.zero, q, Vector3.one);
- AMCameraFade.matIris.SetMatrix("_Matrix", lhs * rhs2 * rhs * rhs3);
- Graphics.DrawTexture(screenRect, tex, sourceRect, 0, 0, 0, 0, AMCameraFade.matIris);
- }
- }
- private static Texture2D getBlankTexture()
- {
- Texture2D texture2D = (Texture2D)Resources.Load("am_blank_texture");
- if (!texture2D)
- {
- texture2D = new Texture2D(1, 1);
- texture2D.SetPixel(0, 0, Color.white);
- texture2D.Apply();
- }
- return texture2D;
- }
- private static Material getMaterialIris()
- {
- Material material = (Material)Resources.Load("AMIrisShapeMaterial");
- if (!material)
- {
- 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}}}");
- }
- return material;
- }
- private static Material getMaterialRadial()
- {
- return (Material)Resources.Load("AMRadialWipeMaterial");
- }
- public static AMCameraFade getCameraFade(bool preview = false)
- {
- if (AMCameraFade._cf)
- {
- AMCameraFade._cf.preview = preview;
- return AMCameraFade._cf;
- }
- AMCameraFade amcameraFade = null;
- GameObject gameObject = GameObject.Find("AMCamera" + ((!preview) ? "Fade" : "FadePreview"));
- if (gameObject)
- {
- amcameraFade = (AMCameraFade)gameObject.GetComponent(typeof(AMCameraFade));
- }
- if (!amcameraFade)
- {
- amcameraFade = (AMCameraFade)new GameObject("AMCamera" + ((!preview) ? "Fade" : "FadePreview"), new Type[]
- {
- typeof(AMCameraFade)
- }).GetComponent(typeof(AMCameraFade));
- }
- AMCameraFade._cf = amcameraFade;
- AMCameraFade._cf.preview = preview;
- return AMCameraFade._cf;
- }
- public void setupRenderTexture(Camera camera)
- {
- if (this.renderTextureCamera != camera)
- {
- if (this.renderTextureCamera && this.renderTextureCamera.targetTexture == this.tex)
- {
- this.renderTextureCamera.targetTexture = null;
- }
- camera.targetTexture = this.tex;
- this.renderTextureCamera = camera;
- camera.Render();
- }
- this.useRenderTexture = true;
- this.colorTex = Color.white;
- this.hasColorTex = false;
- this.placeholder = false;
- }
- public bool isRenderTextureSetupFor(Camera camera)
- {
- return this.tex && camera.targetTexture == this.tex;
- }
- public static void reset()
- {
- if (AMCameraFade._cf != null)
- {
- AMCameraFade._cf.isReset = true;
- AMCameraFade._cf.value = 0f;
- if (AMCameraFade._cf.renderTextureCamera)
- {
- if (AMCameraFade._cf.renderTextureCamera.targetTexture == AMCameraFade._cf.tex)
- {
- AMCameraFade._cf.renderTextureCamera.targetTexture = null;
- }
- AMCameraFade._cf.renderTextureCamera = null;
- }
- }
- }
- public static void clearRenderTexture()
- {
- if (AMCameraFade._cf != null)
- {
- AMCameraFade._cf.clearTexture();
- }
- }
- public static void destroyAndReload(bool isPreview)
- {
- if (AMCameraFade._cf != null)
- {
- AMCameraFade._cf.destroyImmediate();
- }
- AMCameraFade._cf = null;
- AMCameraFade.getCameraFade(isPreview);
- }
- public static void destroyImmediateInstance()
- {
- if (AMCameraFade._cf != null)
- {
- AMCameraFade._cf.destroyImmediate();
- }
- }
- public static bool hasInstance()
- {
- return AMCameraFade._cf != null;
- }
- public static bool isPreview()
- {
- return AMCameraFade._cf != null && AMCameraFade._cf.preview;
- }
- public static void doShouldUpdateStill()
- {
- if (AMCameraFade._cf)
- {
- AMCameraFade._cf.cachedStillFrame = 0;
- AMCameraFade._cf.shouldUpdateStill = true;
- }
- }
- public static Vector2 getPositionAtAngle(int a, float padding)
- {
- a = (a % 360 + 360) % 360;
- Vector2 result = new Vector2(0f, 0f);
- float num = 0f - padding;
- float num2 = 1f + padding;
- float num3 = 0f - padding;
- float num4 = 1f + padding;
- float num5 = num2 - num;
- float num6 = num4 - num3;
- if (a >= 0 && a <= 45)
- {
- result.x = (float)a / 45f * (num5 / 2f) + num5 / 2f;
- result.y = num4;
- }
- else if (a <= 90)
- {
- result.x = num2;
- result.y = (1f - ((float)a - 45f) / 45f) * (num6 / 2f) + num6 / 2f;
- }
- else if (a <= 135)
- {
- result.x = num2;
- result.y = (1f - ((float)a - 90f) / 45f) * (num6 / 2f);
- }
- else if (a <= 180)
- {
- result.x = (1f - ((float)a - 135f) / 45f) * (num5 / 2f) + num5 / 2f;
- result.y = num3;
- }
- else if (a <= 225)
- {
- result.x = (1f - ((float)a - 180f) / 45f) * (num5 / 2f);
- result.y = num3;
- }
- else if (a <= 270)
- {
- result.x = num;
- result.y = ((float)a - 225f) / 45f * (num6 / 2f);
- }
- else if (a <= 315)
- {
- result.x = num;
- result.y = ((float)a - 270f) / 45f * (num6 / 2f) + num6 / 2f;
- }
- else if (a <= 360)
- {
- result.x = ((float)a - 315f) / 45f * (num5 / 2f);
- result.y = num4;
- }
- return result;
- }
- public void repaint()
- {
- this.OnGUI();
- }
- public void incrementKeepAlives()
- {
- this.keepAlives++;
- this.keepAliveAwake = false;
- }
- public void clearTexture()
- {
- if (this.renderTextureCamera)
- {
- this.renderTextureCamera.targetTexture = null;
- this.renderTextureCamera = null;
- }
- }
- public void clearTexture2D()
- {
- if (this.tex2d)
- {
- UnityEngine.Object.Destroy(this.tex2d);
- this.tex2d = null;
- }
- }
- private RenderTexture getRenderTexture()
- {
- if (!this.shouldUpdateRenderTexture && this._tex)
- {
- return this._tex;
- }
- this.shouldUpdateRenderTexture = false;
- if (Application.isPlaying)
- {
- if (this._tex)
- {
- UnityEngine.Object.Destroy(this._tex);
- }
- this.width = Screen.width;
- this.height = Screen.height;
- }
- else
- {
- if (this._tex)
- {
- UnityEngine.Object.DestroyImmediate(this._tex);
- }
- if (this.width > 0)
- {
- if (this.height > 0)
- {
- goto IL_E3;
- }
- }
- try
- {
- Rect mainGameViewPosition = AMCameraFade.GetMainGameViewPosition();
- this.width = (int)mainGameViewPosition.width;
- this.height = (int)mainGameViewPosition.height;
- }
- catch
- {
- this.width = 200;
- this.height = 100;
- this.shouldUpdateRenderTexture = true;
- }
- }
- IL_E3:
- this._tex = new RenderTexture(this.width, this.height, 24);
- return this._tex;
- }
- public static object GetMainGameView()
- {
- Type type = Type.GetType("UnityEditor.GameView,UnityEditor");
- MethodInfo method = type.GetMethod("GetMainGameView", BindingFlags.Static | BindingFlags.NonPublic);
- return method.Invoke(null, null);
- }
- public static Rect GetMainGameViewPosition()
- {
- object mainGameView = AMCameraFade.GetMainGameView();
- return (Rect)mainGameView.GetType().GetProperty("position").GetValue(mainGameView, null);
- }
- private static AMCameraFade _cf;
- private static Texture2D _blankTexture;
- private static Material _matIris;
- public bool deleteMe;
- public bool updateTexture;
- [HideInInspector]
- public int keepAlives;
- [HideInInspector]
- public bool keepAliveColor;
- [HideInInspector]
- public bool keepAlivePreview;
- [HideInInspector]
- public bool keepAliveAwake = true;
- [HideInInspector]
- public int mode;
- [HideInInspector]
- public float percent;
- public float value;
- [HideInInspector]
- public bool useRenderTexture;
- [HideInInspector]
- public Texture2D tex2d;
- [HideInInspector]
- public RenderTexture _tex;
- [HideInInspector]
- public float[] r;
- [HideInInspector]
- public Camera renderTextureCamera;
- [HideInInspector]
- public bool hasColorTex;
- [HideInInspector]
- public bool hasColorBG;
- [HideInInspector]
- public Color colorTex;
- [HideInInspector]
- public Color colorBG;
- [HideInInspector]
- public int width;
- [HideInInspector]
- public int height;
- [HideInInspector]
- public bool placeholder;
- [HideInInspector]
- public Texture2D irisShape;
- [HideInInspector]
- public Texture background;
- [HideInInspector]
- public int cachedStillFrame;
- [HideInInspector]
- public bool isReset;
- [HideInInspector]
- public bool shouldUpdateStill;
- [HideInInspector]
- public bool shouldUpdateRenderTexture;
- [HideInInspector]
- public bool preview;
- public static class Defaults
- {
- public static class Doors
- {
- public const float layout = 0f;
- public const float type = 0f;
- public const float focalXorY = 0.5f;
- }
- public static class VenetianBlinds
- {
- public const float layout = 0f;
- public const int numberOfBlinds = 5;
- }
- public static class IrisBox
- {
- public const float type = 0f;
- public const float focalX = 0.5f;
- public const float focalY = 0.5f;
- }
- public static class IrisRound
- {
- public const float type = 0f;
- public const float maxScale = 2.5f;
- public const float focalX = 0.5f;
- public const float focalY = 0.5f;
- }
- public static class IrisShape
- {
- public const float type = 0f;
- public const float maxScale = 6f;
- public const int rotateAmount = 50;
- public const float easeRotation = 0f;
- public const float focalX = 0.5f;
- public const float focalY = 0.5f;
- public const float pivotX = 0.5f;
- public const float pivotY = 0.5f;
- }
- public static class ShapeWipe
- {
- public const int angle = 0;
- public const float scale = 6f;
- public const float padding = 0f;
- public const float offsetStart = 3f;
- public const float offsetEnd = -3f;
- }
- public static class LinearWipe
- {
- public const int angle = 0;
- public const float padding = 0.25f;
- }
- public static class RadialWipe
- {
- public const float direction = 0f;
- public const int startingAngle = 0;
- public const float focalX = 0.5f;
- public const float focalY = 0.5f;
- }
- public static class WedgeWipe
- {
- public const int startingAngle = 0;
- public const float focalX = 0.5f;
- public const float focalY = 0.5f;
- }
- }
- }
|