usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;public classAntialiasing : MonoBehaviour
{private staticGameObject renderTargetCam;private staticTextureRenderer textureRenderer;private staticRenderTexture renderTexture;public static float scale = 2;privateCamera mainCam;private intscreenX;private intscreenY;private int targetX = 100;private int targetY = 100;private int hideFlagDontShowSave = 61;public boolrestart;private boolrendering;public static RenderTextureFormat Format =RenderTextureFormat.ARGB32;public staticGameObject RenderTargetCamera
{get{returnAntialiasing.renderTargetCam;
}
}public staticRenderTexture RenderTexture
{get{returnAntialiasing.renderTexture;
}
}publicCamera RenderingCamera
{get{return this.mainCam;
}
}private voidOnEnable()
{this.mainCam = base.GetComponent();if (this.mainCam == null)
{
Debug.LogError("Missing Camera on GameObject!");base.enabled = false;return;
}this.hideFlagDontShowSave = 13;this.targetX =Screen.width;this.targetY =Screen.height;//new Shader();
if(Application.isEditor)
{this.restart = true;return;
}this.StartAntialiasing();
}private voidOnDisable()
{this.StopAntialiasing();
}private voidUpdate()
{if (this.screenX != Screen.width || this.screenY !=Screen.height)
{this.restart = true;
}if (this.restart)
{this.Restart();
}
}private voidRestart()
{this.StopAntialiasing();this.StartAntialiasing();this.restart = false;
}private voidOnPreCull()
{if (this.rendering && (this.screenX != Screen.width || this.screenY !=Screen.height))
{this.targetX =Screen.width;this.targetY =Screen.height;this.restart = true;
}if (this.rendering)
{this.mainCam.targetTexture =Antialiasing.renderTexture;
}
}private voidFinishedRendering()
{if (this.rendering)
{this.mainCam.targetTexture = null;
}
}public voidStartAntialiasing()
{if (this.mainCam == null)
{
Debug.LogError("Missing Camera on Object!");return;
}this.screenX =Screen.width;this.screenY =Screen.height;int num = (int)((float)Screen.width *Antialiasing.scale);int num2 = (int)((float)Screen.height *Antialiasing.scale);if (num <= 0)
{
num= 100;
}if (num2 <= 0)
{
num2= 100;
}if (Antialiasing.renderTexture == null || Antialiasing.renderTexture.width != num || Antialiasing.renderTexture.height !=num2)
{if (Antialiasing.renderTexture != null)
{
Antialiasing.renderTexture.Release();
}
Antialiasing.renderTexture= new RenderTexture(num, num2, 2, Antialiasing.Format);
Antialiasing.renderTexture.name= "SSAARenderTarget";
Antialiasing.renderTexture.hideFlags= (HideFlags)this.hideFlagDontShowSave;
}if (Antialiasing.renderTargetCam == null)
{
Antialiasing.renderTargetCam= new GameObject("SSAARenderTargetCamera");
Antialiasing.renderTargetCam.hideFlags= (HideFlags)this.hideFlagDontShowSave;
Camera c= Antialiasing.renderTargetCam.AddComponent();
c.CopyFrom(this.mainCam);
c.cullingMask= 0;
c.targetTexture= null;
c.depth= this.mainCam.depth + 0.5f;
Antialiasing.textureRenderer= Antialiasing.renderTargetCam.AddComponent();
Antialiasing.textureRenderer.hideFlags= (HideFlags)this.hideFlagDontShowSave;
}this.rendering = true;
}public voidStopAntialiasing()
{if (this.mainCam != null && this.mainCam.targetTexture != null)
{this.mainCam.targetTexture = null;
}if (renderTargetCam != null)
{
GameObject.Destroy(renderTargetCam);
}this.rendering = false;
}
}