Skip to content

Instantly share code, notes, and snippets.

View zhaoguohao's full-sized avatar
🚩
🐬

zhaoguohao

🚩
🐬
  • SkyStar Studio
  • YeShan Planet Earth
View GitHub Profile
@SH42913
SH42913 / in_bench.cs
Last active January 16, 2024 16:28
Benchmarking of in modifier in C#
private const int CallDepth = 300;
public static class MorpehExt
{
public static float DoGetterExt(this in MorpehBaseContext.Component3 c3) => c3.Value1 * c3.Value2;
}
public struct Component1
{
public int Value;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Random = System.Random;
// This source code is used for the video. It obviously requires heavy alterations to be used in a real project.
public class ExampleGrid : MonoBehaviour
{
[SerializeField] private Vector2Int _size;
[SerializeField] private Vector2 _gap;
@zhangjiequan
zhangjiequan / Dump Lua Stack using C or C# In Unity Tolua#
Last active May 31, 2024 13:11
Dump Lua Stack using C/C# In Unity Tolua#
//Call_StackDumper_Example.cs
protected void OpenFP64()
{
luaState.OpenLibs(LuaDLL.luaopen_fp64);
StackDumper.StackDump(luaState);//加这句,dump出当前Lua虚拟栈
luaState.LuaSetField(-3, "fp64");
StackDumper.StackDump(luaState);//加这句,dump出当前Lua虚拟栈
}
@xavierarpa
xavierarpa / unity-generate-uml.yml
Last active September 13, 2023 02:34
C# to UML Diagram
name: Generate UML
on:
push:
branches:
- master
workflow_dispatch:
jobs:
generate-uml:
name: 'Generate UML'
@xavierarpa
xavierarpa / PackageCreator.cs
Last active May 27, 2024 06:35
Folder to package.tgz
#if UNITY_EDITOR
using System.IO;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
public static class PackageCreator
{
public static void CreateTgzPackage(string packagePath, string sourcePath)
{
PackRequest packRequest = Client.Pack(sourcePath, packagePath);
@builder-main
builder-main / AnimatorExtensions
Last active January 17, 2023 05:14 — forked from pazzaar/AnimatorExtensions
Animator rebind function that also maintains some state
public static class AnimatorExtensions
{
public static AnimatorParametersState SaveState(this Animator anim)
{
List<AnimatorStateInfo> animStates = new List<AnimatorStateInfo>();
for (int i = 0; i < anim.layerCount; i++)
{
animStates.Add(anim.GetCurrentAnimatorStateInfo(i));
}
@acoppes
acoppes / TypeValidationAttribute.cs
Created December 30, 2022 19:57
Useful to validate if references to Object or GameObject match specific type in Unity
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class)]
public class TypeValidationAttribute : PropertyAttribute
{
public Type typeToValidate;
public TypeValidationAttribute(Type typeToValidate)
{
this.typeToValidate = typeToValidate;
}
}
@pazzaar
pazzaar / AnimatorExtensions
Last active April 6, 2024 06:02
Animator rebind function that also maintains some state
using System.Collections.Generic;
using UnityEngine;
public static class AnimatorExtensions
{
public static void RebindAndRetainState(this Animator anim)
{
List<AnimatorStateInfo> animStates = new List<AnimatorStateInfo>();
for (int i = 0; i < anim.layerCount; i++)
{
@zhangjiequan
zhangjiequan / UIDissolve.shader
Created August 30, 2022 11:18 — forked from benloong/UIDissolve.shader
Dissolve shader for Unity
Shader "UI/Dissolve"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
@IronWarrior
IronWarrior / MathM.cs
Created August 12, 2022 23:37
Managed implementation of various System.Math functions.
static class MathM
{
public const float PI = (float)System.Math.PI;
public const float TwoPI = PI * 2;
public const float HalfPI = PI * 0.5f;
public static float Sin(float x)
{
float x3 = x * x * x;
float x5 = x3 * x * x;