Add tools
This commit is contained in:
parent
1318e8fea4
commit
5f65b80b8d
13
AutoSceneChanger.cs
Normal file
13
AutoSceneChanger.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace NEG.Utils
|
||||
{
|
||||
public class AutoSceneChanger : MonoBehaviour
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
private void Start() => SceneManager.LoadScene(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
11
AutoSceneChanger.cs.meta
Normal file
11
AutoSceneChanger.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eac2f9a681087504998bbeb40cd8516a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Editor/ComponentsAdditionalItems.meta
Normal file
8
Editor/ComponentsAdditionalItems.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d683d64cc04efcf479b41c84b51cf7fe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,22 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace NEG.Utils.Editor.ComponentsAdditionalItems
|
||||
{
|
||||
public static class RectTransformSetBasedOnImage
|
||||
{
|
||||
[MenuItem("CONTEXT/RectTransform/Set as inside of Image", false, 2000)]
|
||||
public static void SetFillBasedOnImage(MenuCommand command)
|
||||
{
|
||||
var transform = (RectTransform)command.context;
|
||||
if (!transform.TryGetComponent(out Image image))
|
||||
return;
|
||||
|
||||
transform.anchorMin = Vector2.zero;
|
||||
transform.anchorMax = Vector2.one;
|
||||
transform.offsetMin = new Vector2(-image.sprite.border.x, -image.sprite.border.y);
|
||||
transform.offsetMax = new Vector2(image.sprite.border.z, image.sprite.border.w);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 614a58a9665e7cf4182834f1fb3c0096
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
107
Editor/ToolsWindowBase.cs
Normal file
107
Editor/ToolsWindowBase.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace NegUtils.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class ToolsWindowBase : EditorWindow
|
||||
{
|
||||
static ToolsWindowBase()
|
||||
{
|
||||
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Show Tools Window")]
|
||||
private static void ShowWindow()
|
||||
{
|
||||
var window = GetWindow<ToolsWindowBase>();
|
||||
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)
|
||||
{
|
||||
bool goToCurrentScene = EditorPrefs.GetBool("GoToCurrentSceneAfterPlay");
|
||||
newVal = GUILayout.Toggle(goToCurrentScene, "Go to current scene after play");
|
||||
if (newVal != goToCurrentScene)
|
||||
{
|
||||
EditorPrefs.SetBool("GoToCurrentSceneAfterPlay", newVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowScenesList(Rect position)
|
||||
{
|
||||
var menu = new GenericMenu();
|
||||
|
||||
string path = Application.dataPath + "/Scenes/Production";
|
||||
string[] fileInfo = Directory.GetFiles(path, "*.unity");
|
||||
|
||||
foreach (string item in fileInfo)
|
||||
{
|
||||
string s = item;
|
||||
menu.AddItem(new GUIContent(s.Remove(0, path.Length + 1).Remove(s.Length - path.Length - 7 ,6)), false, () => {
|
||||
LoadScene(s);
|
||||
});
|
||||
menu.AddSeparator("");
|
||||
}
|
||||
menu.DropDown(position);
|
||||
}
|
||||
|
||||
private static void LoadScene(string path)
|
||||
{
|
||||
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
||||
EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
|
||||
}
|
||||
|
||||
private static void OnPlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case PlayModeStateChange.ExitingEditMode:
|
||||
{
|
||||
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
return;
|
||||
EditorPrefs.SetString("LastOpenedScenePath", EditorSceneManager.GetSceneManagerSetup()[0].path);
|
||||
EditorSceneManager.OpenScene(EditorBuildSettings.scenes[0].path);
|
||||
}
|
||||
break;
|
||||
case PlayModeStateChange.EnteredPlayMode:
|
||||
{
|
||||
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
return;
|
||||
|
||||
if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay"))
|
||||
EditorSceneManager.LoadSceneInPlayMode(EditorPrefs.GetString("LastOpenedScenePath"),
|
||||
new LoadSceneParameters(LoadSceneMode.Single));
|
||||
else
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
break;
|
||||
case PlayModeStateChange.EnteredEditMode:
|
||||
{
|
||||
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
return;
|
||||
EditorSceneManager.OpenScene(EditorPrefs.GetString("LastOpenedScenePath"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/ToolsWindowBase.cs.meta
Normal file
3
Editor/ToolsWindowBase.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76faf7fadf7c40d88dec1a8ee4da5cb6
|
||||
timeCreated: 1671500708
|
||||
Loading…
x
Reference in New Issue
Block a user