This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//第二个pass专门用来渲染阴影,power参数是颜色加强,因为关闭了实时灯光,模型会显得暗淡,这个参数跟阴影效果没太大关系。 | |
//主要是将光照向量和当前模型的坐标传递给Shader,以便Shader实时计算出当前模型的阴影。 | |
//C# 实现代码: | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerShadow : MonoBehaviour | |
{ | |
public Camera mCamera; | |
public GameObject mLight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//比如 "gameObject.GetComponent<Transform>() ; " 可以通过GameObject直接调用Unity定义好的API "GetComponent" ; | |
//如果已有API满足不了使用需求,还可以利用This关键字进行扩展(专业名词应该是链式编程),当然也不仅限于GameObject。 | |
//比如: | |
//修改Transform.Position的X值: | |
public static void SetPositionX(this Transform t, float newX) | |
{ | |
t.position = new Vector3(newX, t.position.y, t.position.z); | |
} | |
//修改Vector3的Y值: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//首先,我们定义一个PanelBase类,作为所有panel的父类,在这个类里,我们可以给panel定义一套生命周期 | |
//初始化 | |
public virtual void Init(){} | |
//开始面板前 | |
public virtual void OnShowing() { } | |
//显示面板后 | |
public virtual void OnShowed() { } | |
//帧更新 | |
public virtual void Update() { } | |
//关闭前 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//原理:shader里变换UV采样序列帧贴图 | |
//下面是网上摘的一段shader代码: | |
Shader "Custom/NewSurfaceShader" { | |
Properties { | |
_Color ("Main Color", Color) = (1,1,1,1) | |
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} | |
_SizeX ("列", Float) = 4 | |
_SizeY ("行", Float) = 2 | |
_Speed ("播放速度", Float) = 150 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. Matcap的实现(提前了解Matcap的原理) | |
//我们使用了UNITY_MATRIX_IT_MV,即正常矩阵的逆转置进行计算,原因在于直接用ModelView矩阵变换法线时,对于非uniform变换可能导致法线与平面不垂直的问题。 | |
//我们使用一张Matcap,在Matcap中,我们最终采样的是一个法线方向变换到(0,1)区间的结果,实际上有效的区域就只是贴图中心周围的圆形范围内有效。 | |
//而Matcap比较直白的效果就是,在当前视角方向看,Matcap的上下左右方向的颜色就对应模型在当前视角方向对应的法线所指向的上下左右方向。 | |
//shader代码如下: | |
/******************************************************************** | |
FileName: Matcap.shader | |
Description: Matcap效果 | |
history: 4:11:2018 by puppet_master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1.基于图像的边缘检测 | |
//C#代码如下: | |
/******************************************************************** | |
FileName: EdgeEffect.cs | |
Description: 后处理描边效果,使用Roberts和Sobel算子,可调强度&检测距离 | |
history: 11:11:2018 by puppet_master | |
https://blog.csdn.net/puppet_master | |
*********************************************************************/ | |
using UnityEngine; | |
[ExecuteInEditMode] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. 基于颜色差值的双边滤波,也是传说中的磨皮滤镜的实现方式。 | |
//C#关键代码如下: | |
private void OnRenderImage(RenderTexture source, RenderTexture destination) | |
{ | |
var tempRT = RenderTexture.GetTemporary(source.width, source.height, 0, source.format); | |
var blurPass = (int)blurType; | |
filterMaterial.SetFloat("_BilaterFilterFactor", 1.0f - bilaterFilterStrength); | |
filterMaterial.SetVector("_BlurRadius", new Vector4(BlurRadius, 0, 0, 0)); | |
Graphics.Blit(source, tempRT, filterMaterial, blurPass); | |
filterMaterial.SetVector("_BlurRadius", new Vector4(0, BlurRadius, 0, 0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 获取timeLine中的所有track,并进行动态的绑定对象 | |
using UnityEngine; | |
using UnityEngine.Playables; | |
[ExecuteInEditMode] | |
public class TimelineController : MonoBehaviour | |
{ | |
public PlayableDirector playableDirector; | |
private void Start() | |
{ | |
foreach (PlayableBinding item in playableDirector.playableAsset.outputs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//下面就来看看Toggle关联动画事件的实现。 | |
//主要是编辑器部分借鉴使用 SelectableEditor 的代码: | |
using UnityEngine; | |
using UnityEngine.UI; | |
[RequireComponent(typeof(Toggle))] | |
[RequireComponent(typeof(Animator))] | |
public class ToggleAnimatorTrigger : MonoBehaviour | |
{ | |
private const string kDefaultOnAnimName = "On"; | |
private const string kDefaultOffAnimName = "Off"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//由于需要获取显卡信息,但是unity的自带函数,只能输出1个显卡,c#倒是可以但是引用了一个下载的dll System.Management.dll,这个dll放到unity用不了,因为mono不支持,所以先用vs写个外部exe程序: | |
using System; | |
using System.Management; | |
public class Sample | |
{ | |
public static void Main(string[] args) | |
{ | |
string Gname = ""; | |
ManagementObjectSearcher objvide = new ManagementObjectSearcher("select * from Win32_VideoController"); | |
foreach (ManagementObject obj in objvide.Get()) |