Skip to content

Instantly share code, notes, and snippets.

View SunGuangdong's full-sized avatar

sunguangdong SunGuangdong

View GitHub Profile
@SunGuangdong
SunGuangdong / AllocCounter.cs
Created October 27, 2025 04:24 — forked from adammyhre/AllocCounter.cs
Allocation Analyzer
using System;
using UnityEngine.Profiling;
// See UnityEngine.TestTools.Constraints.AllocatingGCMemoryConstraint
// and https://maingauche.games/devlog/20230504-counting-allocations-in-unity/
public class AllocCounter {
UnityEngine.Profiling.Recorder rec;
public AllocCounter() {
rec = Recorder.Get("GC.Alloc");
@SunGuangdong
SunGuangdong / .editorconfig
Created October 11, 2025 16:12 — forked from Isshi-777/.editorconfig
自分用の.editorconfig(Unity+C#)
root = true
############################################
# 既定は“ほぼ無効”(外部アセット含む全域)
############################################
[*.cs]
dotnet_analyzer_diagnostic.severity = silent
############################################
# 自作コードだけ有効化(ホワイトリスト)

.NET Blog Performance Improvements で Peanut Butterと呼ばれる類の小手先の定数倍高速化まとめ(羅列) 個人的なメモをpublicにしただけなのであんまり信用しない方が。長文部分はだいたいわかってないで書いてる(数年前の自分・・・)
ランタイムやライブラリの進化で無意味になることがあります。
整えてないので見にくい。

原則

  • コピーを作らない
  • スタック上で完結させる(==アロケーションを避ける)Sapn<T>stackallocは強い。ただしスタック領域は狭い。
  • 仮想メソッドは遅い
  • ボックス化はもっと遅い
@SunGuangdong
SunGuangdong / NonAllocStringSplitter.cs
Created June 11, 2025 11:22 — forked from sator-imaging/NonAllocStringSplitter.cs
Non-Alloc String Splitter for C# / .NET
/** Non-Alloc String Splitter for C# / .NET
** (c) 2024 https://github.com/sator-imaging
** Licensed under the MIT License
How to Use
==========
```cs
var result = new NonAllocStringSplitter("ABC DEF", ' ');
_ = result.Count; // 2
_ = result.Value0; // ABC
@SunGuangdong
SunGuangdong / ArenaAllocator.cs
Created June 9, 2025 03:50 — forked from adammyhre/ArenaAllocator.cs
Unity Memory Arena
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
public unsafe class ArenaAllocator : IDisposable {
byte* buffer; // 'buffer' is a pointer to a byte (i.e., byte*)
int offset;
readonly int capacity;
public ArenaAllocator(int sizeInBytes) {
using UnityEngine;
using System.Collections;
public class NetworkInterpolatedTransform : MonoBehaviour
{
public double interpolationBackTime = 0.1;
internal struct State
{
internal double timestamp;

Unity-Best-Practice

Some useful tips that I find useful while learning Unity.

Disclaimer: These tips are not absolute. Some of them might be actually bad in some situations, in light of the fact that I am still struggling to learn unity right now.

Scripting

1. use attribute to attach additional behavior to the methods and variables you create

@SunGuangdong
SunGuangdong / EasingFunctions.cs
Created May 7, 2025 01:54 — forked from cjddmut/EasingFunctions.cs
Easing Functions for Unity3D
/*
* Created by C.J. Kimberlin
*
* The MIT License (MIT)
*
* Copyright (c) 2019
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@SunGuangdong
SunGuangdong / CameraTargetSingleton.cs
Created March 16, 2025 02:04 — forked from JohnnyTurbo/CameraTargetSingleton.cs
Scripts from tutorial: Tutorial: SURVIVORS-LIKE w/ Unity DOTS & ECS - https://youtu.be/cc5l66FwpQ4
using UnityEngine;
namespace TMG.Survivors
{
public class CameraTargetSingleton : MonoBehaviour
{
public static CameraTargetSingleton Instance;
public void Awake()
{
@SunGuangdong
SunGuangdong / AnyValue.cs
Created January 31, 2025 14:03 — forked from adammyhre/AnyValue.cs
Serialized Callback System
using System;
using UnityEngine;
public enum ValueType { Int, Float, Bool, String, Vector3 }
[Serializable]
public struct AnyValue {
public ValueType type;
// Storage for different types of values