Skip to content

Instantly share code, notes, and snippets.

View SunGuangdong's full-sized avatar

sunguangdong SunGuangdong

View GitHub Profile

.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
@SunGuangdong
SunGuangdong / DownSamplingRenderFeature.cs
Created January 1, 2025 10:00 — forked from baobao/DownSamplingRenderFeature.cs
RenderGraph版URP拡張サンプルコード
using UnityEngine.Rendering.Universal;
public class DownSamplingRenderFeature : ScriptableRendererFeature
{
DownSamplingRenderPass _renderPass;
public override void Create()
{
// パスの作成
_renderPass = new DownSamplingRenderPass
@SunGuangdong
SunGuangdong / DamageCalculator.cs
Created December 15, 2024 13:26 — forked from adammyhre/DamageCalculator.cs
Expression Trees in Unity Examples
using System;
using System.Linq.Expressions;
using UnityEngine;
public class DamageCalculator : MonoBehaviour {
void Start() {
Func<int, int, int> damageExpression = CreateDamageEvaluator();
int damage = damageExpression(10, 2);
Debug.Log($"Calculated Damage: {damage}");