├── .gitignore ├── Assets └── Utils │ ├── DirectionsExt.cs │ ├── DirectionsExt.cs.meta │ ├── Editor.meta │ ├── Editor │ ├── FitAnimationsName.cs │ └── FitAnimationsName.cs.meta │ ├── ListExt.cs │ ├── ListExt.cs.meta │ ├── Parent.cs │ ├── Parent.cs.meta │ ├── PoolTool.cs │ ├── PoolTool.cs.meta │ ├── Tools.meta │ ├── Tools │ ├── ExitSceneTool.cs │ └── ExitSceneTool.cs.meta │ ├── TypeIndex.cs │ ├── TypeIndex.cs.meta │ ├── VectorExt.cs │ └── VectorExt.cs.meta ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /Assets/Utils/DirectionsExt.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Utils 4 | { 5 | public static class DirectionsExt 6 | { 7 | public static float Distance(this Transform origin, Transform target) => origin.RawHeading(target).magnitude; 8 | public static float Distance(this Vector3 origin, Transform target) => origin.RawHeading(target).magnitude; 9 | public static float Distance(this Transform origin, Vector3 target) => origin.RawHeading(target).magnitude; 10 | public static float Distance(this Vector3 origin, Vector3 target) => origin.RawHeading(target).magnitude; 11 | 12 | public static Vector3 Heading(this Transform origin, Transform target) => origin.RawHeading(target).normalized; 13 | public static Vector3 Heading(this Vector3 origin, Transform target) => origin.RawHeading(target).normalized; 14 | public static Vector3 Heading(this Transform origin, Vector3 target) => origin.RawHeading(target).normalized; 15 | public static Vector3 Heading(this Vector3 origin, Vector3 target) => origin.RawHeading(target).normalized; 16 | 17 | public static Vector3 RawHeading(this Transform origin, Transform target) => target.position - origin.position; 18 | public static Vector3 RawHeading(this Vector3 origin, Transform target) => target.position - origin; 19 | public static Vector3 RawHeading(this Transform origin, Vector3 target) => target - origin.position; 20 | public static Vector3 RawHeading(this Vector3 origin, Vector3 target) => target - origin; 21 | 22 | public static Vector3 MovementVector(this Transform target, ref Vector3 previousPosition, float sensitivity = 1, bool ignoreY = false) 23 | { 24 | var currentPosition = target.position; 25 | var vector = currentPosition - previousPosition; 26 | var movementVector = Vector3.ClampMagnitude(vector * sensitivity, 1); 27 | if(ignoreY) movementVector.y = 0; 28 | previousPosition = currentPosition; 29 | return movementVector; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Assets/Utils/DirectionsExt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0da29f7eaa964b14928c6477d5c0972a 3 | timeCreated: 1671829939 -------------------------------------------------------------------------------- /Assets/Utils/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a1195afa896a7143bbe95eb06c4e181 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Utils/Editor/FitAnimationsName.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace Utils.Editor 6 | { 7 | public class FitAnimationsName : AssetPostprocessor 8 | { 9 | private void OnPostprocessAnimation(GameObject g, AnimationClip c) => c.name = g.name; 10 | } 11 | } 12 | #endif -------------------------------------------------------------------------------- /Assets/Utils/Editor/FitAnimationsName.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b465b60c85df32e4e88d2d8da66eacd4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Utils/ListExt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using Sirenix.Utilities; 6 | using Random = UnityEngine.Random; 7 | 8 | namespace Utils 9 | { 10 | public static class ListExt 11 | { 12 | public static T PickRandomWithForce(this List objects, Expression> selector) 13 | { 14 | var func = selector.Compile(); 15 | 16 | if (objects.IsNullOrEmpty()) throw new NullReferenceException("list is null or empty"); 17 | 18 | var greatPool = objects.Sum(i => func(i)); 19 | 20 | if (objects.Count == 1) return objects[0]; 21 | if (greatPool == 0) return objects[0]; 22 | 23 | var point = Random.Range(0, greatPool); 24 | 25 | var pickPool = 0f; 26 | foreach (var i in objects) 27 | { 28 | pickPool += func(i); 29 | if (pickPool > point) return i; 30 | } 31 | 32 | throw new NullReferenceException($"Cannot pick object, pool: {greatPool}, elements: {objects.Count}, picked Random: {pickPool}"); 33 | } 34 | 35 | public static T PickRandom(this List list) 36 | { 37 | var listCount = list.Count; 38 | if (listCount == 0) return default; 39 | var randomIndex = UnityEngine.Random.Range(0, listCount); 40 | return list[randomIndex]; 41 | } 42 | 43 | public static T PickRandom(this T[] array) 44 | { 45 | var listCount = array.Length; 46 | if (listCount == 0) return default; 47 | var randomIndex = UnityEngine.Random.Range(0, listCount); 48 | return array[randomIndex]; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Assets/Utils/ListExt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 040d496f86774dd5b674d8d189c4325f 3 | timeCreated: 1671470342 -------------------------------------------------------------------------------- /Assets/Utils/Parent.cs: -------------------------------------------------------------------------------- 1 | using Sirenix.Utilities; 2 | using UnityEngine; 3 | 4 | namespace Utils 5 | { 6 | public class Parent 7 | { 8 | public bool Initialized => !parent.SafeIsUnityNull(); 9 | 10 | private readonly string name; 11 | 12 | private Transform parent; 13 | private Transform parentForThisParent; 14 | 15 | public Parent(string name, Transform spawnUnder = null) 16 | { 17 | this.name = name; 18 | parentForThisParent = spawnUnder; 19 | } 20 | 21 | public Transform Transform => parent.SafeIsUnityNull() ? GetNewParent() : parent; 22 | 23 | private Transform GetNewParent() 24 | { 25 | var newParent = new GameObject(name).transform; 26 | newParent.SetParent(parentForThisParent); 27 | parent = newParent; 28 | return newParent; 29 | } 30 | 31 | public void SetParent(Transform p) => Transform.SetParent(p); 32 | 33 | public static implicit operator Transform(Parent parent) => parent.Transform; 34 | } 35 | } -------------------------------------------------------------------------------- /Assets/Utils/Parent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b79786460aff46f0aff6cfa9bd391a83 3 | timeCreated: 1667046348 -------------------------------------------------------------------------------- /Assets/Utils/PoolTool.cs: -------------------------------------------------------------------------------- 1 | using Lean.Pool; 2 | using UnityEngine; 3 | 4 | namespace Utils 5 | { 6 | public static class PoolTool 7 | { 8 | public static LeanGameObjectPool CreatePoolForPrefab(GameObject prefab, Transform poolParent) 9 | { 10 | var pool = default(LeanGameObjectPool); 11 | if (LeanGameObjectPool.TryFindPoolByPrefab(prefab, ref pool) == false) 12 | { 13 | pool = new GameObject("LeanPool (" + prefab.name + ")").AddComponent(); 14 | pool.Prefab = prefab; 15 | pool.transform.parent = poolParent; 16 | } 17 | return pool; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Assets/Utils/PoolTool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b415d77f3ac84fab865dcee4f22dc533 3 | timeCreated: 1671470307 -------------------------------------------------------------------------------- /Assets/Utils/Tools.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: afe4438e317d0aa48a172e6a69e704aa 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Utils/Tools/ExitSceneTool.cs: -------------------------------------------------------------------------------- 1 | using Movement; 2 | using UnityEngine; 3 | 4 | namespace Tools 5 | { 6 | public class ExitSceneTool : MonoBehaviour 7 | { 8 | #if UNITY_EDITOR 9 | private void Update() 10 | { 11 | if (Input.GetKeyDown(KeyCode.Escape) && Input.GetKeyDown(KeyCode.LeftShift)) 12 | { 13 | Application.Quit(); 14 | UnityEditor.EditorApplication.isPlaying = false; 15 | } 16 | } 17 | #endif 18 | } 19 | } -------------------------------------------------------------------------------- /Assets/Utils/Tools/ExitSceneTool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db67b7ba47064fc296bd945fc887b7b3 3 | timeCreated: 1669562912 -------------------------------------------------------------------------------- /Assets/Utils/TypeIndex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | 4 | namespace Utils 5 | { 6 | public static class TypeIndex 7 | { 8 | public static Type Type { get; } 9 | public static int Index { get; } 10 | 11 | static TypeIndex() 12 | { 13 | Type = typeof(T); 14 | Index = Interlocked.Increment(ref IndexIncrement.Index); 15 | } 16 | } 17 | 18 | public static class IndexIncrement 19 | { 20 | public static int Index; 21 | } 22 | } -------------------------------------------------------------------------------- /Assets/Utils/TypeIndex.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0226d2245794413d8dca5dd31b15d2e5 3 | timeCreated: 1671833429 -------------------------------------------------------------------------------- /Assets/Utils/VectorExt.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Utils 4 | { 5 | public static class VectorExt 6 | { 7 | public static bool IsValueInRange(this Vector2 minMax, float value) => 8 | value <= minMax.y && value >= minMax.x; 9 | 10 | public static bool IsNotInRange(this Vector2 minMax, float value) => 11 | value > minMax.y && value < minMax.x; 12 | 13 | public static float RangedRandom(this Vector2 range) => 14 | Random.Range(range.x, range.y); 15 | 16 | public static float TakeBetween(this Vector2 range, float percent) => 17 | Mathf.Lerp(range.x, range.y, percent); 18 | 19 | public static float TakeBetweenUnclamped(this Vector2 range, float percent) => 20 | Mathf.LerpUnclamped(range.x, range.y, percent); 21 | 22 | public static Vector3 InvertHorizontal(this Vector3 vector) 23 | { 24 | var x = vector.x; 25 | vector.x = vector.z; 26 | vector.z = x; 27 | return vector; 28 | } 29 | 30 | public static float InverseLerp(Vector3 a, Vector3 b, Vector3 value) 31 | { 32 | var ab = b - a; 33 | var av = value - a; 34 | return Vector3.Dot(av, ab) / Vector3.Dot(ab, ab); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Assets/Utils/VectorExt.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92abf923da0e4f5cbfda606250631074 3 | timeCreated: 1671470258 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 SLGerr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityUtils 2 | Utils i use for faster working on my games 3 | 4 | ## Repos that i recommend: 5 | 6 | **Better coding** 7 | - [UniTask](https://github.com/Cysharp/UniTask) - lots of cool Async/await stuff 8 | - [Unity Design Patterns](https://github.com/QianMo/Unity-Design-Pattern) - Must-read 9 | - [ContextStateMachine](https://github.com/MeeXaSiK/ContextStateMachine) 10 | - [More maths](https://github.com/FreyaHolmer/Mathfs) 11 | 12 | **Editor flexibility** 13 | - [Toolbar Extender](https://github.com/marijnz/unity-toolbar-extender) - More Inspector buttons 14 | - [Naughty Attributes](https://github.com/dbrizov/NaughtyAttributes) - Free brother of Odin Inspector 15 | - [Rainbow folders (free)](https://github.com/PhannGor/unity3d-rainbow-folders) - Neat editor folders coloring 16 | - [Replace Auto-compiler with Ctrl+R](https://github.com/AwixStudio/DisableAutoCompiler) 17 | - [Lock Inspector with Ctrl+L](https://github.com/SolidAlloy/EasyShortcutLockInspector) 18 | - [Optional Variables](https://gist.github.com/aarthificial/f2dbb58e4dbafd0a93713a380b9612af) 19 | - [Mulligan ReNamer](https://github.com/redbluegames/unity-mulligan-renamer) - GOAT for project cleanup 20 | - [Dependencies Hunter](https://github.com/AlexeyPerov/Unity-Dependencies-Hunter) - Find any file reference in scenes or prefabs 21 | - [Files Dependency Search](https://github.com/Facepunch/WhatUsesThis) - file referencing but with baking to cache 22 | 23 | **Time saving tools** 24 | - [Facepunch.Steamworks](https://github.com/Facepunch/Facepunch.Steamworks) - out of box steam api integration 25 | - [Just Simple Audio Manager (JSAM)](https://github.com/jackyyang09/Simple-Unity-Audio-Manager) - Convinient handler for game sounds and music 26 | - [File based Player Prefs (FBPP)](https://github.com/richardelms/FileBasedPlayerPrefs) - prefs as file instead of PlayerPrefs 27 | - [Service Locator](https://github.com/Claytonious/Frictionless) - imo GOAT service locator 28 | - [Dev Console](https://github.com/anarkila/DeveloperConsole) - command line from game view or build (Like quantum console) 29 | - [Runtime Editor](https://github.com/yasirkula/UnityRuntimeInspector) - hierarchy view inside game 30 | - [Animator States Codegen](https://github.com/SLiGerr/Animator-Enum-Codegen) - create Enums from all animator controllers inside project 31 | 32 | **Other Stuff** 33 | - [Some shaders](https://github.com/adrian-miasik/unity-shaders) - Urp Supported 34 | 35 | --------------------------------------------------------------------------------