Skip to content

Instantly share code, notes, and snippets.

View Josef212's full-sized avatar
:shipit:
Subidapdap

Josef21296 Josef212

:shipit:
Subidapdap
View GitHub Profile
public class Helper
{
public static List<T> FindAssetsByType<T>() where T : UnityEngine.Object
{
List<T> assets = new List<T>();
string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
for( int i = 0; i < guids.Length; i++ )
{
string assetPath = AssetDatabase.GUIDToAssetPath( guids[i] );
using UnityEngine;
public static class CameraExtensions
{
public static float GetOrthographicSizeFromWorldWidth(this Camera camera, float width)
{
return width / camera.aspect * 0.5f;
}
public static float GetOrthographicSizeFromWorldHeight(this Camera camera, float height)
using UnityEditor;
public static class CompileAndRun
{
// % Ctrl/Cmd - # Shift - & Alt
[MenuItem("Tools/ReimportAndPlay %&r")] // Ctrl + Alt + R
public static void ReimportAndPlay()
{
AssetDatabase.Refresh();
EditorApplication.EnterPlaymode();
using System.Reflection;
public static class ReflectionExtensions
{
public static T GetFieldValue<T>(this object obj, string fieldName)
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo field = obj.GetType().GetField(fieldName, bindingFlags);
return (T)field?.GetValue(obj);
}
private void OnGUI()
{
Matrix4x4 oldMatrix = GUI.matrix;
float scale = 2f;
int linesCount = 0;
float lineHeight = 20f;
Rect areaRect = new Rect()
{
{
"Print to console": {
"prefix": "log",
"body": [
"Debug.Log(\"$1\");",
],
"description": "Log output to console"
},
"Print to console a variable": {
"prefix": "vlog",
using System.Threading.Tasks;
using UnityEngine;
public static class AsyncExtensions
{
public static Task GetTask(this AsyncOperation asyncOp)
{
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
asyncOp.completed += _ => tcs.SetResult(null);
return tcs.Task;
public class GUIDebug : Monobehaviour
{
public static Bounds GetRectTransformBounds(RectTransform transform)
{
Vector3[] WorldCorners = new Vector3[4];
transform.GetWorldCorners(WorldCorners);
Bounds bounds = new Bounds(WorldCorners[0], Vector3.zero);
for(int i = 1; i < 4; ++i)
{
bounds.Encapsulate(WorldCorners[i]);
public static class ScreenHelper
{
private static System.Reflection.MethodInfo s_getSizeOfMainGameViewMethod = null;
public static bool IsTablet
{
get
{
Vector2 windowSize = GetMainGameViewSize();
float aspectRatio = windowSize.x > windowSize.y ? windowSize.x / windowSize.y : windowSize.y / windowSize.x;
@Josef212
Josef212 / Package
Last active October 24, 2019 09:56
git subtree split --prefix=Path/To/Package/Folder --branch upm
git tag X.Y.Z upm
git push origin upm --tags
# https://docs.unity3d.com/Manual/cus-layout.html
# https://docs.unity3d.com/Manual/upm-manifestPkg.html