Skip to content

Instantly share code, notes, and snippets.

@FriendSea
FriendSea / TreeReferenceInjector.cs
Created June 15, 2023 03:03
木構造にルートや親の参照を注入する。デシリアライズしたオブジェクトとかに使う
using System.Reflection;
public class InjectRootAttribute : Attribute{}
public class InjectParentAttribute : Attribute{}
public static class TreeReferenceInjector {
public static T InjectRoot<T>(this T target, object root = null){
foreach(var info in target.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)){
if(info.FieldType.IsArray){
var array = info.GetValue(target) as object[];
@FriendSea
FriendSea / SerializablePlayerLoop.cs
Created December 27, 2022 03:53
PlayerLoop挿入くん。シリアライズしてEditorからタイミング指定できる。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.LowLevel;
using System.Linq;
static class PlayerLoopInjector
{
static Dictionary<System.Type, System.Action> actions = new Dictionary<System.Type, System.Action>();
@FriendSea
FriendSea / GameObjectPool.cs
Last active December 7, 2022 03:37
クソ雑に使えるオブジェクトプール
using System.Collections.Generic;
using UnityEngine;
namespace FriendSea
{
public static class GameObjectPool
{
static Dictionary<GameObject, GameObject> instance2prefab = new Dictionary<GameObject, GameObject>();
static Dictionary<GameObject, Stack<GameObject>> prefab2pool = new Dictionary<GameObject, Stack<GameObject>>();
@FriendSea
FriendSea / BenderImportMod.cs
Last active November 28, 2022 04:45
.blend のインポート時のFBXエクスポート処理を上書き太郎
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Diagnostics;
public class BenderImportMod
{
static readonly string fileName = "Unity-BlenderToFBX.py";
@FriendSea
FriendSea / SurfaceMeshGenerator.cs
Created November 25, 2022 03:27
C#の式からメッシュ作るくん
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.AssetImporters;
using UnityEditor;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
[ScriptedImporter(0, ".meshgenerator")]
public class SurfaceMeshGenerator : ScriptedImporter
@FriendSea
FriendSea / ShaderBaker.cs
Created November 18, 2022 02:37
Shader焼き込んでTexture2D作るくん
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.AssetImporters;
using UnityEditor;
[ScriptedImporter(0, ".shaderbaker")]
public class ShaderBaker : ScriptedImporter
{
[SerializeField]
@FriendSea
FriendSea / ReorderableEditor.cs
Last active July 28, 2019 06:40
配列ぜんぶReorderableListにする
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
[CustomEditor(typeof(UnityEngine.Object), true)]
[CanEditMultipleObjects]
public class ReorderableEditor : Editor
{
List<ReorderableList> reorderableLists = new List<ReorderableList>();
@FriendSea
FriendSea / CloneComponents.cs
Created February 9, 2019 22:57
An editor tool for unity that clones components from a gameobject to other
using UnityEngine;
using UnityEditor;
public class CloneComponents : ScriptableWizard {
[SerializeField]
GameObject Original;
[SerializeField]
GameObject Target;
private void OnWizardCreate()
@FriendSea
FriendSea / CubeMapRenderer.cs
Last active October 18, 2023 08:58
A wizard to render a scene and create a cubemap image
using UnityEngine;
using UnityEditor;
using System.IO;
public class CubeMapRenderer : ScriptableWizard {
[SerializeField]
Shader TransformShader;
[SerializeField]
Camera RenderCamera;
[SerializeField]