unity android 开启抗锯齿,unity抗锯齿效果

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;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值