Unity C# 学习笔记
GeometryUtility
Unsafe | Native
- 开启Unsafe
- Project Setting/Player
- .asmdef
- Unity.Burst
- Unity.Mathematics
- 获取native指针
- NativeArray.GetUnsafePtr()
- NativeArray.GetUnsafeReadOnlyPtr()
1
2
3
4
5
6
7
8
9
10
11
12using Unity.Collections.LowLevel.Unsafe;
struct SpheresSoA
{
[ReadOnly] public NativeArray<float> centerX;
public unsafe int HitSpheres(ref Ray r, float tMin, float tMax, ref Hit outHit)
{
float4* ptrCenterX = (float4*) centerX.GetUnsafeReadOnlyPtr();
float4 sCenterX = *ptrCenterX;
}
}
SerializedObject | ScriptObject | Reflection
- Type
- typeof(class)
- object.GetType()
- Asset Load
- const string assetPath = “Assets/Settings/Universal Render Pipeline Asset.asset”;
- var pipelineAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, typeof(RenderPipelineAsset)) as RenderPipelineAsset;
- SerializedObject
- 支持Undo
- 支持多个编辑
- Property
- FindProperty
- SerializedProperty
- Next
- NextVisible
- intValue
- you can Shift+Right Click on property names in the Inspector to see their paths
- Shift+右键获取属性路径
- ApplyModifiedProperties
- 序列化对象 SerializedObject
- ScriptableObject
Command Buffer
- Unity的CommandBuffer基础
- https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.html
- Camera.AddCommandBuffer
- Light.AddCommandBuffer
- Graphics.ExecuteCommandBuffer
- BuiltinRenderTextureType
- https://docs.unity3d.com/ScriptReference/Rendering.BuiltinRenderTextureType.html
- Blit(BuiltinRenderTextureType.CurrentActive,id)
- CurrentActive
- Depth
Unity技巧
- 方法属性加Button
- Unity小窍门100条!!!(上)
- FormerlySerializedAs()
- 重命名显示
- RuntimeInitializeOnLoadMethod
- [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
- 无需创建空物体就能执行代码
- 在运行游戏(Play)就会立即执行该函数,而不需要继承MonoBehavior并挂接在物体身上。
- [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
Extension
1 |
|
Mono
- OnValidate() 属性变化时调用
UnityEvent
- 支持UI事件函数编辑
- using UnityEngine.Events;
- public UnityEvent onClick;
Custom Package
- package.json
- name “com.xxx.core”
- displayName “xxx”
- version “0.0.1”
- 解决csproj生成问题,使用最新Vscode Editor Package1.2.5插件
- Asmdef
- 模块化打包成dll
Build Player
- Compiling from command line
- https://stackoverflow.com/questions/45081576/how-can-i-compile-a-unity3d-game-project-from-command-line-into-webgl
- https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildPlayer.html
1
Unity.exe -quit -batchmode -projectPath "%cd%" -executeMethod "Builder.BuildAll" -logfile "editor.log"
1
2
3
4
5
6
7
8
9
10
11public class Builder : MonoBehaviour {
public static void BuildAll()
{
BuildPipeline.BuildPlayer(
new[] {"Test.unity"},
"Build/Win/App.exe",
BuildTarget.StandaloneWindows64,
BuildOptions.None);
}
}
C# Native Command
- App Command Line
- string[] args = System.Environment.GetCommandLineArgs();
- How to start Unity application from command prompt with initial arguments?
- How to run external programs
1 |
|
DLL
Unity C# 学习笔记
https://automask.github.io/wild/2021/10/26/log/P_Unity_Csharp/