diff --git a/AutoSceneChanger.cs b/AutoSceneChanger.cs
index c7b60ea..416df6f 100644
--- a/AutoSceneChanger.cs
+++ b/AutoSceneChanger.cs
@@ -1,5 +1,4 @@
using UnityEngine;
-using UnityEngine.SceneManagement;
namespace NEG.Utils
{
@@ -9,5 +8,4 @@ namespace NEG.Utils
private void Start() => SceneManager.LoadScene(1);
#endif
}
-}
-
+}
\ No newline at end of file
diff --git a/Collections/DictionaryExtensions.cs b/Collections/DictionaryExtensions.cs
index aae8985..ea5d2d7 100644
--- a/Collections/DictionaryExtensions.cs
+++ b/Collections/DictionaryExtensions.cs
@@ -5,7 +5,8 @@ namespace NEG.Utils.Collections
public static class DictionaryExtensions
{
///
- /// Adds given value to a dictionary if there was no element at given , replaces element with otherwise.
+ /// Adds given value to a dictionary if there was no element at given , replaces element with
+ /// otherwise.
///
/// true if element was added, false if it was replaced
public static bool AddOrUpdate(this Dictionary dict, K key, V value)
@@ -15,27 +16,23 @@ namespace NEG.Utils.Collections
dict[key] = value;
return false;
}
- else
- {
- dict.Add(key, value);
- return true;
- }
+
+ dict.Add(key, value);
+ return true;
}
///
- /// Gets a value from the dictionary under a specified key or adds it if did not exist and returns .
+ /// Gets a value from the dictionary under a specified key or adds it if did not exist and returns
+ /// .
///
- /// value under a given if it exists, otherwise
+ /// value under a given if it exists, otherwise
public static V GetOrSetToDefault(this Dictionary dict, K key, V defaultValue)
{
- if (dict.TryGetValue(key, out V value))
- {
- return value;
- }
+ if (dict.TryGetValue(key, out var value)) return value;
dict.Add(key, defaultValue);
return defaultValue;
}
}
-}
+}
\ No newline at end of file
diff --git a/CoroutineUtils.cs b/CoroutineUtils.cs
index a91c31c..1bf85ff 100644
--- a/CoroutineUtils.cs
+++ b/CoroutineUtils.cs
@@ -6,41 +6,42 @@ namespace NEG.Utils
{
public static class CoroutineUtils
{
- private static readonly WaitForEndOfFrame WaitForEndOfFrame = new WaitForEndOfFrame();
+ private static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
public static IEnumerator WaitForFrames(int count)
{
- for (int i = 0; i < count; i++)
- {
- yield return null;
- }
+ for (int i = 0; i < count; i++) yield return null;
}
- public static void ActionAfterFrames(this MonoBehaviour mono, int count, Action action)
- {
+ public static void ActionAfterFrames(this MonoBehaviour mono, int count, Action action) =>
mono.StartCoroutine(ActionAfterFrames(count, action));
- }
-
+
public static IEnumerator ActionAfterFrames(int count, Action action)
{
yield return WaitForFrames(count);
action?.Invoke();
}
-
- public static void ActionAfterEndOfFrame(this MonoBehaviour mono, Action action) => mono.StartCoroutine(ActionAtNextFrame(action));
+
+ public static void ActionAfterEndOfFrame(this MonoBehaviour mono, Action action) =>
+ mono.StartCoroutine(ActionAtNextFrame(action));
+
public static IEnumerator ActionAfterEndOfFrame(Action action)
{
yield return WaitForEndOfFrame;
action?.Invoke();
}
- public static void ActionAtNextFrame(this MonoBehaviour mono, Action action) => mono.StartCoroutine(ActionAtNextFrame(action));
+
+ public static void ActionAtNextFrame(this MonoBehaviour mono, Action action) =>
+ mono.StartCoroutine(ActionAtNextFrame(action));
+
public static IEnumerator ActionAtNextFrame(Action action)
{
yield return null;
action?.Invoke();
}
- public static void ActionAfterTime(this MonoBehaviour mono, float time, Action action) => mono.StartCoroutine(ActionAfterTime(time, action));
+ public static void ActionAfterTime(this MonoBehaviour mono, float time, Action action) =>
+ mono.StartCoroutine(ActionAfterTime(time, action));
public static IEnumerator ActionAfterTime(float time, Action action)
{
diff --git a/Editor/BuildingUtils.cs b/Editor/BuildingUtils.cs
index a95774f..cd507f2 100644
--- a/Editor/BuildingUtils.cs
+++ b/Editor/BuildingUtils.cs
@@ -1,8 +1,8 @@
using System.Diagnostics;
using System.Linq;
-using UnityEngine;
using UnityEditor;
-using UnityEditor.Build.Player;
+using UnityEditor.Build;
+using UnityEngine;
using Debug = UnityEngine.Debug;
public static class BuildingUtils
@@ -12,32 +12,32 @@ public static class BuildingUtils
[MenuItem("Tools/PrepareForBuild", priority = -10)]
public static void PrepareForBuild()
{
- var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(
+ var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(
BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
- var args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
+ string[] args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
var argsList = args.ToList();
argsList.Remove(SteamBuildDefine);
PlayerSettings.SetScriptingDefineSymbols(namedBuildTarget, argsList.ToArray());
}
-
+
[MenuItem("Tools/PlatformDefines/Steam", priority = -1)]
public static void SetDefinesForSteam()
{
PrepareForBuild();
-
- var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(
+
+ var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(
BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
- var args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
+ string[] args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
var argsList = args.ToList();
argsList.Add(SteamBuildDefine);
PlayerSettings.SetScriptingDefineSymbols(namedBuildTarget, argsList.ToArray());
}
-
-
+
+
[MenuItem("Tools/Build/Steam/Release")]
public static void SteamRelease()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
IncreaseBuildNumber();
@@ -48,21 +48,21 @@ public static class BuildingUtils
[MenuItem("Tools/Build/Steam/Development")]
public static void SteamDevelopment()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
-
+
IncreaseBuildNumber();
BuildDevelopment();
UploadSteam();
}
-
-
+
+
[MenuItem("Tools/Build/Steam/Demo")]
public static void SteamDemo()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
-
+
IncreaseBuildNumber();
BuildDemo();
UploadSteam(true);
@@ -71,7 +71,7 @@ public static class BuildingUtils
[MenuItem("Tools/Build/All Release")]
public static void BuildRelease()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
BuildWindowsRelease();
BuildLinuxRelease();
@@ -80,24 +80,24 @@ public static class BuildingUtils
[MenuItem("Tools/Build/All Development")]
public static void BuildDevelopment()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
BuildWindowsDevelopment();
}
-
+
[MenuItem("Tools/Build/All Demo")]
public static void BuildDemo()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
- BuildWindows(true, new[] {"DEMO"});
- BuildLinux(true, new[] {"DEMO"});
+ BuildWindows(true, new[] { "DEMO" });
+ BuildLinux(true, new[] { "DEMO" });
}
[MenuItem("Tools/Build/Platform/Windows/x64-Development")]
public static void BuildWindowsDevelopment()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
BuildWindows(false);
}
@@ -105,19 +105,19 @@ public static class BuildingUtils
[MenuItem("Tools/Build/Platform/Windows/x64-Release")]
public static void BuildWindowsRelease()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
BuildWindows(true);
}
-
+
[MenuItem("Tools/Build/Platform/Linux/x64-Release")]
public static void BuildLinuxRelease()
{
- if(!CanBuild())
+ if (!CanBuild())
return;
BuildLinux(true);
}
-
+
[MenuItem("Tools/Build/Platform/Android/GooglePlay")]
public static void BuildGooglePlay()
@@ -125,13 +125,11 @@ public static class BuildingUtils
IncreaseBuildNumber();
PlayerSettings.Android.bundleVersionCode++;
EditorUserBuildSettings.buildAppBundle = true;
-
+
var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] };
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
- {
buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path;
- }
-
+
buildPlayerOptions.target = BuildTarget.Android;
buildPlayerOptions.options = BuildOptions.None;
buildPlayerOptions.locationPathName = Application.dataPath +
@@ -143,9 +141,7 @@ public static class BuildingUtils
{
var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] };
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
- {
buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path;
- }
buildPlayerOptions.extraScriptingDefines = additionalDefines;
@@ -155,14 +151,12 @@ public static class BuildingUtils
$"/../../{Application.productName}-Steam/ContentBuilder/content/windows/{Application.productName}.exe";
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
-
+
private static void BuildLinux(bool release, string[] additionalDefines = default)
{
var buildPlayerOptions = new BuildPlayerOptions { scenes = new string[EditorBuildSettings.scenes.Length] };
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
- {
buildPlayerOptions.scenes[i] = EditorBuildSettings.scenes[i].path;
- }
buildPlayerOptions.extraScriptingDefines = additionalDefines;
@@ -175,28 +169,29 @@ public static class BuildingUtils
private static void IncreaseBuildNumber()
{
- string[] versionParts = PlayerSettings.bundleVersion.Split('.');
- if (versionParts.Length != 3 || !int.TryParse(versionParts[2], out int version)) {
+ string[] versionParts = PlayerSettings.bundleVersion.Split('.');
+ if (versionParts.Length != 3 || !int.TryParse(versionParts[2], out int version))
+ {
Debug.LogError("IncreaseBuildNumber failed to update version " + PlayerSettings.bundleVersion);
return;
}
+
versionParts[2] = (version + 1).ToString();
PlayerSettings.bundleVersion = string.Join(".", versionParts);
}
private static void UploadSteam(bool demo = false)
{
- string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat";
+ string command =
+ $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_build.bat";
if (demo)
- {
- command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_demo.bat";
- }
+ command =
+ $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && push_demo.bat";
var processInfo = new ProcessStartInfo("cmd.exe", $"/c {command}")
- {
- CreateNoWindow = true,
- UseShellExecute = false
- };
+ {
+ CreateNoWindow = true, UseShellExecute = false
+ };
var process = Process.Start(processInfo);
process.WaitForExit();
Debug.Log(process.ExitCode);
@@ -207,17 +202,18 @@ public static class BuildingUtils
{
if (CanBuildUtil())
return true;
- Debug.LogError("Cannot build with defines set in project, please use PrepareForBuild and wait for scripts recompilation");
+ Debug.LogError(
+ "Cannot build with defines set in project, please use PrepareForBuild and wait for scripts recompilation");
return false;
}
private static bool CanBuildUtil()
{
- var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(
+ var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(
BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
- var args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
+ string[] args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
var argsList = args.ToList();
-
+
if (argsList.Contains(SteamBuildDefine))
return false;
diff --git a/Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs b/Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs
index a6cb782..a459bab 100644
--- a/Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs
+++ b/Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs
@@ -8,14 +8,19 @@ namespace NEG.Utils.Editor.ComponentsAdditionalItems
{
[MenuItem("CONTEXT/CanvasScaler/Full HD horizontal", false, 2000)]
public static void SetFullHdHorizontal(MenuCommand command) => SetComponent(command, 1920, 1080);
+
[MenuItem("CONTEXT/CanvasScaler/Full HD vertical", false, 2000)]
public static void SetFullHdVertical(MenuCommand command) => SetComponent(command, 1080, 1920);
+
[MenuItem("CONTEXT/CanvasScaler/Full 2k horizontal", false, 2000)]
- public static void Set2KHorizontal(MenuCommand command) => SetComponent(command, 2560, 1440 );
+ public static void Set2KHorizontal(MenuCommand command) => SetComponent(command, 2560, 1440);
+
[MenuItem("CONTEXT/CanvasScaler/Full 2k vertical", false, 2000)]
public static void Set2KVertical(MenuCommand command) => SetComponent(command, 1440, 2560);
+
[MenuItem("CONTEXT/CanvasScaler/Full 4k horizontal", false, 2000)]
public static void Set4KHorizontal(MenuCommand command) => SetComponent(command, 3840, 2160);
+
[MenuItem("CONTEXT/CanvasScaler/Full 4k vertical", false, 2000)]
public static void Set4KVertical(MenuCommand command) => SetComponent(command, 2160, 3840);
diff --git a/Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs b/Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs
index a24a86c..53ff6a4 100644
--- a/Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs
+++ b/Editor/EditorMultipleInstances/Editor/EditorInstanceCreator.cs
@@ -11,61 +11,57 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
-using UnityEngine;
using UnityEditor;
+using UnityEngine;
+using Debug = UnityEngine.Debug;
namespace TheGamedevGuru
{
public class EditorInstanceCreator : EditorWindow
{
- string _projectInstanceName;
- string _extraSubdirectories;
- bool _includeProjectSettings = true;
+ private string _extraSubdirectories;
+ private bool _includeProjectSettings = true;
+ private string _projectInstanceName;
- [MenuItem("Window/The Gamedev Guru/Editor Instance Creator")]
- static void Init()
- {
- ((EditorInstanceCreator)EditorWindow.GetWindow(typeof(EditorInstanceCreator))).Show();
- }
-
- void OnGUI()
+ private void OnGUI()
{
if (string.IsNullOrEmpty(_projectInstanceName))
- {
_projectInstanceName = PlayerSettings.productName + "_Slave_1";
- }
-
+
EditorGUILayout.Separator();
EditorGUILayout.LabelField("The Gamedev Guru - Project Instance Creator");
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Slave Project Name");
_projectInstanceName = EditorGUILayout.TextField("", _projectInstanceName);
EditorGUILayout.Separator();
-
+
EditorGUILayout.LabelField("Include Project Settings? (Recommended)");
_includeProjectSettings = EditorGUILayout.Toggle("", _includeProjectSettings);
EditorGUILayout.Separator();
-
+
EditorGUILayout.LabelField("Extra Subdirectories? (Separate by comma)");
_extraSubdirectories = EditorGUILayout.TextField("", _extraSubdirectories);
EditorGUILayout.Separator();
if (GUILayout.Button("Create"))
- {
CreateProjectInstance(_projectInstanceName, _includeProjectSettings, _extraSubdirectories);
- }
-
+
if (GUILayout.Button("Help"))
- {
Application.OpenURL("https://thegamedev.guru/multiple-unity-editor-instances-within-a-single-project/");
- }
}
- static void CreateProjectInstance(string projectInstanceName, bool includeProjectSettings, string extraSubdirectories)
+ [MenuItem("Window/The Gamedev Guru/Editor Instance Creator")]
+ private static void Init() => ((EditorInstanceCreator)GetWindow(typeof(EditorInstanceCreator))).Show();
+
+ private static void CreateProjectInstance(string projectInstanceName, bool includeProjectSettings,
+ string extraSubdirectories)
{
- var targetDirectory = Path.Combine(Directory.GetCurrentDirectory(), ".." + Path.DirectorySeparatorChar, projectInstanceName);
+ string targetDirectory = Path.Combine(Directory.GetCurrentDirectory(), ".." + Path.DirectorySeparatorChar,
+ projectInstanceName);
Debug.Log(targetDirectory);
if (Directory.Exists(targetDirectory))
{
@@ -75,29 +71,21 @@ namespace TheGamedevGuru
Directory.CreateDirectory(targetDirectory);
- List subdirectories = new List{"Assets", "Packages"};
- if (includeProjectSettings)
- {
- subdirectories.Add("ProjectSettings");
- }
+ var subdirectories = new List { "Assets", "Packages" };
+ if (includeProjectSettings) subdirectories.Add("ProjectSettings");
- foreach (var extraSubdirectory in extraSubdirectories.Split(','))
- {
+ foreach (string extraSubdirectory in extraSubdirectories.Split(','))
subdirectories.Add(extraSubdirectory.Trim());
- }
- foreach (var subdirectory in subdirectories)
- {
- System.Diagnostics.Process.Start("CMD.exe",GetLinkCommand(subdirectory, targetDirectory));
- }
+ foreach (string subdirectory in subdirectories)
+ Process.Start("CMD.exe", GetLinkCommand(subdirectory, targetDirectory));
EditorUtility.RevealInFinder(targetDirectory + Path.DirectorySeparatorChar + "Assets");
- EditorUtility.DisplayDialog("Done!", $"Done! Feel free to add it as an existing project at: {targetDirectory}", "Ok :)");
+ EditorUtility.DisplayDialog("Done!",
+ $"Done! Feel free to add it as an existing project at: {targetDirectory}", "Ok :)");
}
- static string GetLinkCommand(string subdirectory, string targetDirectory)
- {
- return $"/c mklink /J \"{targetDirectory}{Path.DirectorySeparatorChar}{subdirectory}\" \"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}{subdirectory}\"";
- }
+ private static string GetLinkCommand(string subdirectory, string targetDirectory) =>
+ $"/c mklink /J \"{targetDirectory}{Path.DirectorySeparatorChar}{subdirectory}\" \"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}{subdirectory}\"";
}
-}
+}
\ No newline at end of file
diff --git a/Editor/EditorUtils.cs b/Editor/EditorUtils.cs
index 9300f6d..55eeb55 100644
--- a/Editor/EditorUtils.cs
+++ b/Editor/EditorUtils.cs
@@ -9,7 +9,18 @@ namespace NegUtils.Editor
public class AssetPath
{
- public string Path
+ private readonly string filter;
+
+ private string path;
+
+
+ public AssetPath(string filter)
+ {
+ this.filter = filter;
+ TryFindPath();
+ }
+
+ public string Path
{
get
{
@@ -20,16 +31,6 @@ namespace NegUtils.Editor
}
}
- private string path;
- private readonly string filter;
-
-
- public AssetPath(string filter)
- {
- this.filter = filter;
- TryFindPath();
- }
-
private void TryFindPath()
{
string[] candidates = AssetDatabase.FindAssets(filter);
diff --git a/Editor/GUIDToAssetPath.cs b/Editor/GUIDToAssetPath.cs
index f4e5aae..4dabd33 100644
--- a/Editor/GUIDToAssetPath.cs
+++ b/Editor/GUIDToAssetPath.cs
@@ -1,23 +1,18 @@
using UnityEditor;
using UnityEngine;
-
+
public class GUIDToAssetPath : EditorWindow
{
- string guid = "";
- string path = "";
- [MenuItem("Tools/GUIDToAssetPath")]
- static void CreateWindow()
- {
- GUIDToAssetPath window = (GUIDToAssetPath)EditorWindow.GetWindowWithRect(typeof(GUIDToAssetPath), new Rect(0, 0, 400, 120));
- }
-
- void OnGUI()
+ private string guid = "";
+ private string path = "";
+
+ private void OnGUI()
{
GUILayout.Label("Enter guid");
guid = GUILayout.TextField(guid);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
- if (GUILayout.Button("Get Asset Path",GUILayout.Width(120)))
+ if (GUILayout.Button("Get Asset Path", GUILayout.Width(120)))
path = GetAssetPath(guid);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
@@ -29,10 +24,17 @@ public class GUIDToAssetPath : EditorWindow
GUILayout.EndHorizontal();
GUILayout.Label(path);
}
- static string GetAssetPath(string guid)
+
+ [MenuItem("Tools/GUIDToAssetPath")]
+ private static void CreateWindow()
+ {
+ var window = (GUIDToAssetPath)GetWindowWithRect(typeof(GUIDToAssetPath), new Rect(0, 0, 400, 120));
+ }
+
+ private static string GetAssetPath(string guid)
{
guid = guid.Replace("-", "");
-
+
string p = AssetDatabase.GUIDToAssetPath(guid);
Debug.Log(p);
if (p.Length == 0) p = "not found";
diff --git a/Editor/MonoBehaviourExtensions.cs b/Editor/MonoBehaviourExtensions.cs
index fb4464d..0e52560 100644
--- a/Editor/MonoBehaviourExtensions.cs
+++ b/Editor/MonoBehaviourExtensions.cs
@@ -1,6 +1,6 @@
using System.IO;
-using UnityEngine;
using UnityEditor;
+using UnityEngine;
namespace NEG.Utils.Editor
{
@@ -9,33 +9,33 @@ namespace NEG.Utils.Editor
[MenuItem("CONTEXT/MonoBehaviour/Change Script")]
public static void ChangeScript(MenuCommand command)
{
- if (command.context == null)
+ if (command.context == null)
return;
-
+
var monoBehaviour = command.context as MonoBehaviour;
var monoScript = MonoScript.FromMonoBehaviour(monoBehaviour);
-
+
string scriptPath = AssetDatabase.GetAssetPath(monoScript);
string directoryPath = new FileInfo(scriptPath).Directory?.FullName;
-
+
// Allow the user to select which script to replace with
string newScriptPath = EditorUtility.OpenFilePanel("Select replacement script", directoryPath, "cs");
-
+
// Don't log anything if they cancelled the window
if (string.IsNullOrEmpty(newScriptPath)) return;
// Load the selected asset
string relativePath = "Assets\\" + Path.GetRelativePath(Application.dataPath, newScriptPath);
var chosenTextAsset = AssetDatabase.LoadAssetAtPath(relativePath);
-
+
if (chosenTextAsset == null)
{
Debug.LogWarning($"Selected script couldn't be loaded ({relativePath})");
return;
}
-
+
Undo.RegisterCompleteObjectUndo(command.context, "Changing component script");
-
+
var so = new SerializedObject(monoBehaviour);
var scriptProperty = so.FindProperty("m_Script");
so.Update();
diff --git a/Editor/NEG.Utils.Editor.asmdef b/Editor/NEG.Utils.Editor.asmdef
index 60746f0..b11b4e4 100644
--- a/Editor/NEG.Utils.Editor.asmdef
+++ b/Editor/NEG.Utils.Editor.asmdef
@@ -1,18 +1,18 @@
{
- "name": "NEG.Utils.Editor",
- "rootNamespace": "",
- "references": [
- "GUID:3c4294719a93e3c4e831a9ff0c261e8a"
- ],
- "includePlatforms": [
- "Editor"
- ],
- "excludePlatforms": [],
- "allowUnsafeCode": false,
- "overrideReferences": false,
- "precompiledReferences": [],
- "autoReferenced": true,
- "defineConstraints": [],
- "versionDefines": [],
- "noEngineReferences": false
+ "name": "NEG.Utils.Editor",
+ "rootNamespace": "",
+ "references": [
+ "GUID:3c4294719a93e3c4e831a9ff0c261e8a"
+ ],
+ "includePlatforms": [
+ "Editor"
+ ],
+ "excludePlatforms": [],
+ "allowUnsafeCode": false,
+ "overrideReferences": false,
+ "precompiledReferences": [],
+ "autoReferenced": true,
+ "defineConstraints": [],
+ "versionDefines": [],
+ "noEngineReferences": false
}
\ No newline at end of file
diff --git a/Editor/ReadOnlyAttribute.cs b/Editor/ReadOnlyAttribute.cs
index 956c85b..4ce718d 100644
--- a/Editor/ReadOnlyAttribute.cs
+++ b/Editor/ReadOnlyAttribute.cs
@@ -3,10 +3,12 @@ using UnityEngine;
namespace NegUtils.Editor
{
- public class ReadOnlyAttribute : PropertyAttribute { }
-
+ public class ReadOnlyAttribute : PropertyAttribute
+ {
+ }
+
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
- public class ReadOnlyPropertyDrawer : PropertyDrawer
+ public class ReadOnlyPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
@@ -15,9 +17,7 @@ namespace NegUtils.Editor
GUI.enabled = true;
}
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
- {
- return EditorGUI.GetPropertyHeight(property, label, true);
- }
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label) =>
+ EditorGUI.GetPropertyHeight(property, label, true);
}
}
\ No newline at end of file
diff --git a/Editor/RequireInterfaceDrawer.cs b/Editor/RequireInterfaceDrawer.cs
index 5535ce5..e54c75c 100644
--- a/Editor/RequireInterfaceDrawer.cs
+++ b/Editor/RequireInterfaceDrawer.cs
@@ -1,5 +1,6 @@
-using UnityEngine;
using UnityEditor;
+using UnityEngine;
+
///
/// Drawer for the RequireInterface attribute.
///
@@ -10,7 +11,7 @@ namespace NEG.Utils
public class RequireInterfaceDrawer : PropertyDrawer
{
///
- /// Overrides GUI drawing for the attribute.
+ /// Overrides GUI drawing for the attribute.
///
/// Position.
/// Property.
@@ -21,11 +22,12 @@ namespace NEG.Utils
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
// Get attribute parameters.
- var requiredAttribute = this.attribute as RequireInterfaceAttribute;
+ var requiredAttribute = attribute as RequireInterfaceAttribute;
// Begin drawing property field.
EditorGUI.BeginProperty(position, label, property);
// Draw property field.
- property.objectReferenceValue = EditorGUI.ObjectField(position, label, property.objectReferenceValue, requiredAttribute.requiredType, true);
+ property.objectReferenceValue = EditorGUI.ObjectField(position, label, property.objectReferenceValue,
+ requiredAttribute.requiredType, true);
// Finish drawing property field.
EditorGUI.EndProperty();
}
diff --git a/Editor/ScreenshotMaker.cs b/Editor/ScreenshotMaker.cs
index 7304f1c..d133c52 100644
--- a/Editor/ScreenshotMaker.cs
+++ b/Editor/ScreenshotMaker.cs
@@ -1,5 +1,4 @@
-using System.IO;
-using UnityEditor;
+using UnityEditor;
using UnityEngine;
namespace NEG.Editor
@@ -14,8 +13,6 @@ namespace NEG.Editor
return;
ScreenCapture.CaptureScreenshot(path);
-
}
-
}
}
\ No newline at end of file
diff --git a/Editor/SerializationExtentions.cs b/Editor/SerializationExtentions.cs
index 2e37ad4..c4ff416 100644
--- a/Editor/SerializationExtentions.cs
+++ b/Editor/SerializationExtentions.cs
@@ -1,20 +1,15 @@
-using System;
using UnityEditor;
namespace NEG.Utils.Serialization
{
public static class SerializationExtentions
{
- public static SerializedProperty FindAutoProperty(this SerializedObject @this, string name)
- {
- return @this.FindProperty(GetBackingFieldName(name));
- }
+ public static SerializedProperty FindAutoProperty(this SerializedObject @this, string name) =>
+ @this.FindProperty(GetBackingFieldName(name));
+
+ public static SerializedProperty FindAutoPropertyRelative(this SerializedProperty @this, string name) =>
+ @this.FindPropertyRelative(GetBackingFieldName(name));
- public static SerializedProperty FindAutoPropertyRelative(this SerializedProperty @this, string name)
- {
- return @this.FindPropertyRelative(GetBackingFieldName(name));
- }
-
public static string GetBackingFieldName(string name)
{
#if NET_STANDARD || NET_STANDARD_2_1
@@ -29,4 +24,4 @@ namespace NEG.Utils.Serialization
#endif
}
}
-}
+}
\ No newline at end of file
diff --git a/Editor/ToolsWindowBase.cs b/Editor/ToolsWindowBase.cs
index 6248f15..78be03b 100644
--- a/Editor/ToolsWindowBase.cs
+++ b/Editor/ToolsWindowBase.cs
@@ -1,5 +1,4 @@
-using System;
-using System.IO;
+using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
@@ -11,12 +10,33 @@ namespace NegUtils.Editor
public class ToolsWindowBase : EditorWindow
{
private const int UnitySceneExtensionLength = 6;
-
+
static ToolsWindowBase()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
+ protected virtual void OnGUI()
+ {
+ if (GUILayout.Button("Select Scene"))
+ ShowScenesList(GUILayoutUtility.GetLastRect());
+
+ bool startFromSceneIndex0 = EditorPrefs.GetBool("StartFromSceneIndex0");
+ bool newVal = GUILayout.Toggle(startFromSceneIndex0, "Start from scene with index 0 on start");
+ if (newVal != startFromSceneIndex0) EditorPrefs.SetBool("StartFromSceneIndex0", newVal);
+
+ if (!startFromSceneIndex0)
+ return;
+
+ bool goToCurrentScene = EditorPrefs.GetBool("GoToCurrentSceneAfterPlay");
+ newVal = GUILayout.Toggle(goToCurrentScene, "Go to current scene after play");
+ if (newVal != goToCurrentScene) EditorPrefs.SetBool("GoToCurrentSceneAfterPlay", newVal);
+
+ bool goToFirstScene = EditorPrefs.GetBool("GoToFirstSceneAfterPlay");
+ newVal = GUILayout.Toggle(goToFirstScene, "Go to scene with index 1 after play");
+ if (newVal != goToFirstScene) EditorPrefs.SetBool("GoToFirstSceneAfterPlay", newVal);
+ }
+
[MenuItem("Tools/Show Tools Window")]
private static void ShowWindow()
{
@@ -24,44 +44,14 @@ namespace NegUtils.Editor
window.Show();
}
- protected virtual void OnGUI()
- {
- if (GUILayout.Button("Select Scene"))
- ShowScenesList(GUILayoutUtility.GetLastRect());
-
- bool startFromSceneIndex0 = EditorPrefs.GetBool("StartFromSceneIndex0");
- bool newVal = GUILayout.Toggle(startFromSceneIndex0, "Start from scene with index 0 on start");
- if (newVal != startFromSceneIndex0)
- {
- EditorPrefs.SetBool("StartFromSceneIndex0", newVal);
- }
-
- if (!startFromSceneIndex0)
- return;
-
- bool goToCurrentScene = EditorPrefs.GetBool("GoToCurrentSceneAfterPlay");
- newVal = GUILayout.Toggle(goToCurrentScene, "Go to current scene after play");
- if (newVal != goToCurrentScene)
- {
- EditorPrefs.SetBool("GoToCurrentSceneAfterPlay", newVal);
- }
-
- bool goToFirstScene = EditorPrefs.GetBool("GoToFirstSceneAfterPlay");
- newVal = GUILayout.Toggle(goToFirstScene, "Go to scene with index 1 after play");
- if (newVal != goToFirstScene)
- {
- EditorPrefs.SetBool("GoToFirstSceneAfterPlay", newVal);
- }
- }
-
private static void ShowScenesList(Rect position)
{
var menu = new GenericMenu();
-
+
string path = Application.dataPath + "/Scenes/Production";
-
+
AddFiles(path, path, menu);
-
+
menu.DropDown(position);
}
@@ -71,21 +61,22 @@ namespace NegUtils.Editor
for (int i = 0; i < fileInfo.Length; i++)
{
string s = fileInfo[i];
- menu.AddItem(new GUIContent(s.Remove(0, basePath.Length + 1).Remove(s.Length - basePath.Length - UnitySceneExtensionLength - 1 ,UnitySceneExtensionLength).Replace('\\', '/')), false, () => {
- LoadScene(s);
- });
-
- if(i == fileInfo.Length) continue;
+ menu.AddItem(
+ new GUIContent(s.Remove(0, basePath.Length + 1)
+ .Remove(s.Length - basePath.Length - UnitySceneExtensionLength - 1, UnitySceneExtensionLength)
+ .Replace('\\', '/')), false, () =>
+ {
+ LoadScene(s);
+ });
+
+ if (i == fileInfo.Length) continue;
menu.AddSeparator("");
}
string[] dirInfo = Directory.GetDirectories(path);
- foreach (string dir in dirInfo)
- {
- AddFiles(dir, basePath, menu);
- }
+ foreach (string dir in dirInfo) AddFiles(dir, basePath, menu);
}
-
+
private static void LoadScene(string path)
{
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
@@ -94,11 +85,11 @@ namespace NegUtils.Editor
private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
- switch(state)
+ switch (state)
{
case PlayModeStateChange.ExitingEditMode:
{
- if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
+ if (!EditorPrefs.GetBool("StartFromSceneIndex0"))
return;
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
EditorPrefs.SetString("LastOpenedScenePath", EditorSceneManager.GetSceneManagerSetup()[0].path);
@@ -107,7 +98,7 @@ namespace NegUtils.Editor
break;
case PlayModeStateChange.EnteredPlayMode:
{
- if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
+ if (!EditorPrefs.GetBool("StartFromSceneIndex0"))
return;
if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay"))
@@ -119,13 +110,12 @@ namespace NegUtils.Editor
break;
case PlayModeStateChange.EnteredEditMode:
{
- if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
+ if (!EditorPrefs.GetBool("StartFromSceneIndex0"))
return;
EditorSceneManager.OpenScene(EditorPrefs.GetString("LastOpenedScenePath"));
}
break;
}
-
}
}
}
\ No newline at end of file
diff --git a/Editor/TsvImporter.cs b/Editor/TsvImporter.cs
index 77299f5..b580d43 100644
--- a/Editor/TsvImporter.cs
+++ b/Editor/TsvImporter.cs
@@ -1,9 +1,7 @@
using System.IO;
-using UnityEditor;
using UnityEditor.AssetImporters;
-using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
-
+
[ScriptedImporter(1, "tsv")]
public class TsvImporter : ScriptedImporter
{
@@ -13,4 +11,4 @@ public class TsvImporter : ScriptedImporter
ctx.AddObjectToAsset(Path.GetFileNameWithoutExtension(ctx.assetPath), textAsset);
ctx.SetMainObject(textAsset);
}
-}
+}
\ No newline at end of file
diff --git a/KeyBasedFactory.cs b/KeyBasedFactory.cs
index c4d4d5f..8ff9c46 100644
--- a/KeyBasedFactory.cs
+++ b/KeyBasedFactory.cs
@@ -7,8 +7,7 @@ namespace NEG.Utils
{
public class KeyBasedFactory
{
- [PublicAPI]
- protected Dictionary data;
+ [PublicAPI] protected Dictionary data;
public KeyBasedFactory()
{
@@ -18,10 +17,10 @@ namespace NEG.Utils
public void FireRegistration()
{
ScanAssembly(typeof(T2).Assembly);
-
- if(typeof(T2).Assembly.GetType().Assembly == typeof(T2).Assembly)
+
+ if (typeof(T2).Assembly.GetType().Assembly == typeof(T2).Assembly)
return;
-
+
ScanAssembly(typeof(T2).Assembly.GetType().Assembly);
}
@@ -32,12 +31,8 @@ namespace NEG.Utils
var methodFields =
type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
for (int i = 0; i < methodFields.Length; i++)
- {
if (Attribute.GetCustomAttribute(methodFields[i], typeof(FactoryRegistration)) != null)
- {
methodFields[i].Invoke(null, Array.Empty