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
//这里只是绘制了球面,如果想绘制球体,只用在渲染时,加入点的法向量即可。 | |
//原理见:https://gameinstitute.qq.com/community/detail/128654 | |
//点的数据结构: | |
class Point | |
{ | |
public: | |
Point(){}; | |
Point(double a,double b,double c):x(a),y(b),z(c){}; | |
public: |
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、深度纹理 | |
//深度纹理并非深度缓冲中的数据,而是通过特定Pass获得: DepthTextureMode.Depth | |
//Unity4.X和Unity5.X版本的实现方式不太一样,Unity4.X通过"RenderType" 标签通过Camera Shader 替换获取; | |
//Unity5通过ShadowCaster Pass获取, 对于自身带有ShadowCaster Pass或者FallBack中含有,并且Render Queue小于等于2500的渲染对象才会出现在深度纹理中. | |
//shader代码: | |
//在Shader中,需提前定义纹理_CameraDepthTexture ,为了兼容不同的平台,Unity ShaderLab提供了UNITY_SAMPLE_DEPTH、SAMPLE_DEPTH_TEXTURE方法解决这个问题。 | |
Pass | |
{ | |
CGPROGRAM |
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
//out | |
//out修饰的参数必须是变量, 在函数体内必需进行赋值, 且必须在参数使用前赋值 | |
//因此在调用函数传参时,out修饰的参数值是用不到的, 可以不对其赋值, 传入函数体后, 要先赋值再使用 | |
void ParameOut(out int value) | |
{ | |
value = 0; | |
} | |
//ref |
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中使用TextMeshPro的文本解决方案,当要生成字库图集时,需要通过插件提供的 【Font Asset Creator】工具,但是每次都需要重新设置选项。 | |
//反编译编辑器查看其代码,照着其实现步骤再实现一遍,注意的是升级插件的话,也要看下实现的代码是否需要改动。另外,自动处理多个字体的部分逻辑如下: | |
public void Update() | |
{ | |
if (this.isProcessing) | |
{ | |
var progress = TMPro_FontPlugin.Check_RenderProgress(); | |
m_FontAssetInfos[m_CurGenerateIndex].genPercent = progress * 100; | |
this.Repaint(); | |
} |
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.给水体添加碰撞体 | |
//需要注意的是要勾选Is Trigger,y方向的范围要控制好,不然可能会出现物体掉到水面一下太多会触发OnTriggerExit()(见脚本部分)。 | |
//2.创建立方体 | |
//创建一个长宽高分别为1,质量为0.5的立方体,预期效果是在水中漂浮一半露出水面。之后可以通过脚本改变大小及质量验证效果。 | |
//3.水的脚本 | |
//水的脚本主要实现OnTriggerEnter和OnTriggerExit两个方法,当其他碰撞体进入水中,触发OnTriggerEnter,将cube中的isInWater置为ture,OnTriggerExit相反。 | |
//4.立方体脚本 | |
//立方体脚本的核心是calFloatage方法,计算立方体下表面与水面高度差,通过公式计算浮力,并通过Rigidbody.AddForce()方法施加浮力。 | |
//进入水中后将阻力系数调高。注意物体完全进入水中后保持h=立方体高度 |
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using UnityEditor; | |
using UnityEngine; | |
public class AnimationKeyframeTangentToConstantWindow : EditorWindow | |
{ | |
public static Action<AnimationClip, AnimationClip> onClipCopyModify; |
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
//主线程阻塞掉,直到信号通知继续执行下面的操作。另外,保证多线程的数量跟处理器数量一致,最大化使用多线程。 | |
#region 多线程执行 | |
private class JobFileTextSearchReplace | |
{ | |
private string m_Path; | |
private List<string> m_Patterns; | |
private string m_ReplaceStr; | |
private bool[] m_SearchRet; | |
public ManualResetEvent doneEvent; | |
public string exception; |
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"QQ/Gradient/Bias" | |
{ | |
Properties | |
{ | |
_Color("Color",Color)=(.5,.5,.5,1) | |
_MainTex("Texture",2D)="white"{} | |
_Gradient("Gradient,x:slope,y:speed,zw:gradual",vector)=(-.1,5,.3,.01) | |
} | |
SubShader | |
{ |
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. 通过法线方向求平面坐标。x=atan(x/z),y=acos(y/r) r为半径; | |
//2. 通过ddx,ddy 偏导数模糊极坐标像素解决极坐标问题。 | |
//3. 通过反射比较真实的扑捉视觉。 | |
Shader"QQ/Sky/Latitude" | |
{ | |
Properties | |
{ | |
_MainTex("Texture",2D)="white"{} |
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
//如何通过Terrain地形数据计算人物位置,比如当地形高度不在0点的时候,设置人物位置会出现问题,需要计算Terrain.activeTerrain.GetPosition().y的值 | |
float height; | |
Vector3 newPos; | |
float halfModelY; | |
float terrainHeight; | |
private void SetModelHight() | |
{ | |
if (GetComponent<MeshFilter>() != null) | |
{ | |
halfModelY = GetComponent<MeshFilter>().sharedMesh.bounds.size.y * transform.lossyScale.y / 2; |