Skip to content

Instantly share code, notes, and snippets.

View SunGuangdong's full-sized avatar

sunguangdong SunGuangdong

View GitHub Profile
@adammyhre
adammyhre / ArenaAllocator.cs
Created June 8, 2025 07:18
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) {
@adammyhre
adammyhre / AbilityData.cs
Created May 25, 2025 10:34
Modular Ability Effects
using System;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "AbilityData", menuName = "ScriptableObjects/AbilityData")]
class AbilityData : ScriptableObject {
public string label;
public AnimationClip animationClip;
[Range(0.1f, 4f)] public float castTime = 2f;
@adammyhre
adammyhre / AnimationController.cs
Created May 25, 2025 10:13
Animation Controller
using ImprovedTimers;
using UnityEngine;
namespace AdvancedController {
[RequireComponent(typeof(PlayerController))]
public class AnimationController : MonoBehaviour {
PlayerController controller;
Animator animator;
CountdownTimer animationTimer;
@JohnnyTurbo
JohnnyTurbo / CameraTargetSingleton.cs
Created March 12, 2025 14:32
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()
{
Shader "Custom/VoronoiWater" {
Properties {
_CellSize ("Cell Size", Range(0, 10)) = 2
_CellSizeSubtract ("Cell Size Subtract", Range(0, 10)) = 2
_CellSubtractFactor ("Cell Subtract Factor", Range(0, 10)) = 1
_WindDirection ("Wind Direction", Vector) = (1, 0, 0)
_WindFactor ("Wind Factor", Range(0, 10)) = 1
_BorderColor ("Border Color", Color) = (0,0,0,1)
_SurfaceNoise("Surface Noise", 2D) = "white" {}
_SurfaceNoiseScroll("Surface Noise Scroll", Vector) = (0.03, 0.03, 0, 0)
@adammyhre
adammyhre / AnyValue.cs
Created January 19, 2025 08:11
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
@baobao
baobao / DownSamplingRenderFeature.cs
Created December 25, 2024 10:58
RenderGraph版URP拡張サンプルコード
using UnityEngine.Rendering.Universal;
public class DownSamplingRenderFeature : ScriptableRendererFeature
{
DownSamplingRenderPass _renderPass;
public override void Create()
{
// パスの作成
_renderPass = new DownSamplingRenderPass
//FontEngineProxy
//Copyright (c) 2024 tsukasa TSUCHIYA(T2/t_tutiya)
//This software is released under the MIT License.
//http://opensource.org/licenses/mit-license.php
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.TextCore;
using UnityEngine.TextCore.LowLevel;
@thammin
thammin / RiveView.cs
Created December 9, 2024 03:05
A simple rive view that draw to full screen RawImage.
using Rive;
using UnityEngine;
using UnityEngine.UI;
public class RiveView : MonoBehaviour
{
public Asset asset;
public RawImage rawImage;
public AudioSource audioSource;
@adammyhre
adammyhre / Either.cs
Created December 1, 2024 12:29
Monads, Nullables, and the Power of Optionals in Unity
using System;
using System.Collections.Generic;
public struct Either<TLeft, TRight> {
readonly TLeft left;
readonly TRight right;
readonly bool isRight;
Either(TLeft left, TRight right, bool isRight) {
this.left = left;