This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void OnGUI() | |
{ | |
Matrix4x4 oldMatrix = GUI.matrix; | |
float scale = 2f; | |
int linesCount = 0; | |
float lineHeight = 20f; | |
Rect areaRect = new Rect() | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Print to console": { | |
"prefix": "log", | |
"body": [ | |
"Debug.Log(\"$1\");", | |
], | |
"description": "Log output to console" | |
}, | |
"Print to console a variable": { | |
"prefix": "vlog", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder