Skip to content

Instantly share code, notes, and snippets.

View sassembla's full-sized avatar
😍
be gentle.

Toru sassembla

😍
be gentle.
View GitHub Profile
/*
kill Unity Hub process continuously after UnityEditor is started.
they have no reason to keep living after starting UnityEditor.
To:Unity, please stop UnityHub process until user need to use that. and never use macOS's status bar. please add "quit Hub after UnityEditor startd" option.
or, please design more small UnityInstaller app and UnityProjectViewer app separately.
*/
using System.Diagnostics;
using UnityEditor;
while (true) {
if (A) {
break;
}
if (B) {
break;
}
}
[MenuItem("Window/TakeScreenshotWithCaptureScreenshotAsTexture")]
public static void Menu()
{
var tex = ScreenCapture.CaptureScreenshotAsTexture();
var jpgBytes = tex.EncodeToJPG(10);// 90KB
using (var sw = new StreamWriter("a.jpg"))
{
sw.BaseStream.Write(jpgBytes, 0, jpgBytes.Length);
}
}
@sassembla
sassembla / StopAfterCompileProcess.cs
Created August 28, 2018 01:03
UnityEditorでPlay中にコンパイルが走った時にコンパイル直後にPlayを停めてくれるやつ
using UnityEditor;
using UnityEngine;
public class StopAfterCompileProcess
{
[UnityEditor.Callbacks.DidReloadScripts]
public static void StopAfterCompile()
{
if (EditorApplication.isPlaying)
{
// Text textComponent みたいなものに対して
// TextGenerator generator = new TextGenerator(); みたいなのをグローバルで取得しておいて使い回すことができる
// invalidate first.
generator.Invalidate();
// set content to prefab.
var defaultText = textComponent.text;
textComponent.text = text;
// TMProのコンポーネント TMPro.TextMeshProUGUI textComponentというのがあったとして
textComponent.text = text;
// textComponentに対してwidthをセットする必要がある。高さは無限設定でOK
textComponent.rectTransform.sizeDelta = new Vector2(viewWidth, float.PositiveInfinity);
// このメソッドは、コンポーネントがgameobjectにアタッチされて、かつgameobjectがcanvasに乗っている場合のみ動作する。
var textInfos = textComponent.GetTextInfo(text);
#import "UnityAppController.h"
@interface OverrideAppDelegate : UnityAppController
@end
IMPL_APP_CONTROLLER_SUBCLASS(OverrideAppDelegate)
@sassembla
sassembla / ResourcesController.cs
Created April 6, 2018 07:53
ResourcesController for Autoya.
using System;
using System.Collections;
using AutoyaFramework;
using UnityEngine;
public class ResourcesController
{
public static void LoadAsset<T>(string assetPath, Action<string, T> succeeded, Action<string, int, string, object> failed) where T : UnityEngine.Object
{
var resRequest = Resources.LoadAsync(assetPath);
@sassembla
sassembla / SingletonHolder.cs
Last active October 26, 2020 06:42
automated singleton holder for Unity. auto-initialize on Player boot time and well isolated.
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class SingletonHolder : MonoBehaviour {
private List<Base> instances = new List<Base>();
private static SingletonHolder holderInstance;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void NewSingleton () {
@sassembla
sassembla / XrossPeerUtility.cs
Created April 7, 2016 03:13
C#でいろんなPeerでログをファイルに吐いたり特定の関数で吐いたりするやつ
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
namespace XrossPeerUtility {
public class XrossPeer {
static string logPath = string.Empty;
private static Action<string> logAction;