Compare commits
1 Commits
main
...
mo/localiz
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ae01f763c |
@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace NEG.Utils
|
||||
{
|
||||
@ -8,4 +9,5 @@ namespace NEG.Utils
|
||||
private void Start() => SceneManager.LoadScene(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,8 +5,7 @@ namespace NEG.Utils.Collections
|
||||
public static class DictionaryExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds given value to a dictionary if there was no element at given <paramref name="key" />, replaces element with
|
||||
/// <paramref name="value"> otherwise.
|
||||
/// Adds given value to a dictionary if there was no element at given <paramref name="key"/>, replaces element with <paramref name="value"> otherwise.
|
||||
/// </summary>
|
||||
/// <returns>true if element was added, false if it was replaced</returns>
|
||||
public static bool AddOrUpdate<K, V>(this Dictionary<K, V> dict, K key, V value)
|
||||
@ -16,23 +15,27 @@ namespace NEG.Utils.Collections
|
||||
dict[key] = value;
|
||||
return false;
|
||||
}
|
||||
|
||||
dict.Add(key, value);
|
||||
return true;
|
||||
else
|
||||
{
|
||||
dict.Add(key, value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value from the dictionary under a specified key or adds it if did not exist and returns
|
||||
/// <paramref name="defaultValue" />.
|
||||
/// Gets a value from the dictionary under a specified key or adds it if did not exist and returns <paramref name="defaultValue"/>.
|
||||
/// </summary>
|
||||
/// <returns>value under a given <paramref name="key" /> if it exists, <paramref name="defaultValue" /> otherwise</returns>
|
||||
/// <returns>value under a given <paramref name="key"/> if it exists, <paramref name="defaultValue"/> otherwise</returns>
|
||||
public static V GetOrSetToDefault<K, V>(this Dictionary<K, V> dict, K key, V defaultValue)
|
||||
{
|
||||
if (dict.TryGetValue(key, out var value)) return value;
|
||||
if (dict.TryGetValue(key, out V value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
dict.Add(key, defaultValue);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,42 +6,40 @@ namespace NEG.Utils
|
||||
{
|
||||
public static class CoroutineUtils
|
||||
{
|
||||
private static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
||||
private static readonly WaitForEndOfFrame WaitForEndOfFrame = new WaitForEndOfFrame();
|
||||
|
||||
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 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)
|
||||
{
|
||||
|
||||
@ -1,45 +1,13 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
public static class BuildingUtils
|
||||
{
|
||||
private const string SteamBuildDefine = "STEAM_BUILD";
|
||||
|
||||
[MenuItem("Tools/PrepareForBuild", priority = -10)]
|
||||
public static void PrepareForBuild()
|
||||
{
|
||||
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(
|
||||
BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
|
||||
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 = NamedBuildTarget.FromBuildTargetGroup(
|
||||
BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
|
||||
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())
|
||||
return;
|
||||
|
||||
IncreaseBuildNumber();
|
||||
BuildRelease();
|
||||
UploadSteam();
|
||||
@ -48,102 +16,38 @@ public static class BuildingUtils
|
||||
[MenuItem("Tools/Build/Steam/Development")]
|
||||
public static void SteamDevelopment()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
|
||||
IncreaseBuildNumber();
|
||||
BuildDevelopment();
|
||||
UploadSteam();
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Tools/Build/Steam/Demo")]
|
||||
public static void SteamDemo()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
|
||||
IncreaseBuildNumber();
|
||||
BuildDemo();
|
||||
UploadSteam(true);
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Build/All Release")]
|
||||
public static void BuildRelease()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
BuildWindowsRelease();
|
||||
BuildLinuxRelease();
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Build/All Development")]
|
||||
public static void BuildDevelopment()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
BuildWindowsDevelopment();
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Build/All Demo")]
|
||||
public static void BuildDemo()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
BuildWindows(true, new[] { "DEMO" });
|
||||
BuildLinux(true, new[] { "DEMO" });
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Build/Platform/Windows/x64-Development")]
|
||||
public static void BuildWindowsDevelopment()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
BuildWindows(false);
|
||||
}
|
||||
public static void BuildWindowsDevelopment() => BuildWindows(false);
|
||||
|
||||
[MenuItem("Tools/Build/Platform/Windows/x64-Release")]
|
||||
public static void BuildWindowsRelease()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
BuildWindows(true);
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Build/Platform/Linux/x64-Release")]
|
||||
public static void BuildLinuxRelease()
|
||||
{
|
||||
if (!CanBuild())
|
||||
return;
|
||||
BuildLinux(true);
|
||||
}
|
||||
public static void BuildWindowsRelease() => BuildWindows(true);
|
||||
|
||||
|
||||
[MenuItem("Tools/Build/Platform/Android/GooglePlay")]
|
||||
public static void BuildGooglePlay()
|
||||
{
|
||||
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 +
|
||||
$"/../../{Application.productName}-GooglePlay/{Application.productName}.aab";
|
||||
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
}
|
||||
|
||||
private static void BuildWindows(bool release, string[] additionalDefines = default)
|
||||
private static void BuildWindows(bool release)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
|
||||
buildPlayerOptions.options = release ? BuildOptions.None : BuildOptions.Development;
|
||||
@ -152,73 +56,29 @@ public static class BuildingUtils
|
||||
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;
|
||||
|
||||
buildPlayerOptions.target = BuildTarget.StandaloneLinux64;
|
||||
buildPlayerOptions.options = release ? BuildOptions.None : BuildOptions.Development;
|
||||
buildPlayerOptions.locationPathName = Application.dataPath +
|
||||
$"/../../{Application.productName}-Steam/ContentBuilder/content/linux/{Application.productName}.x86_64";
|
||||
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
}
|
||||
|
||||
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)
|
||||
private static void UploadSteam()
|
||||
{
|
||||
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";
|
||||
}
|
||||
string command = $"cd {Application.dataPath}/../../{Application.productName}-Steam/ContentBuilder && run_build.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);
|
||||
process.Close();
|
||||
}
|
||||
|
||||
private static bool CanBuild()
|
||||
{
|
||||
if (CanBuildUtil())
|
||||
return true;
|
||||
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 = NamedBuildTarget.FromBuildTargetGroup(
|
||||
BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
|
||||
string[] args = PlayerSettings.GetAdditionalCompilerArguments(namedBuildTarget);
|
||||
var argsList = args.ToList();
|
||||
|
||||
if (argsList.Contains(SteamBuildDefine))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -8,19 +8,14 @@ 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);
|
||||
|
||||
|
||||
@ -11,57 +11,61 @@
|
||||
// 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 UnityEditor;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TheGamedevGuru
|
||||
{
|
||||
public class EditorInstanceCreator : EditorWindow
|
||||
{
|
||||
private string _extraSubdirectories;
|
||||
private bool _includeProjectSettings = true;
|
||||
private string _projectInstanceName;
|
||||
string _projectInstanceName;
|
||||
string _extraSubdirectories;
|
||||
bool _includeProjectSettings = true;
|
||||
|
||||
private void OnGUI()
|
||||
[MenuItem("Window/The Gamedev Guru/Editor Instance Creator")]
|
||||
static void Init()
|
||||
{
|
||||
((EditorInstanceCreator)EditorWindow.GetWindow(typeof(EditorInstanceCreator))).Show();
|
||||
}
|
||||
|
||||
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/");
|
||||
}
|
||||
}
|
||||
|
||||
[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)
|
||||
static void CreateProjectInstance(string projectInstanceName, bool includeProjectSettings, string extraSubdirectories)
|
||||
{
|
||||
string targetDirectory = Path.Combine(Directory.GetCurrentDirectory(), ".." + Path.DirectorySeparatorChar,
|
||||
projectInstanceName);
|
||||
var targetDirectory = Path.Combine(Directory.GetCurrentDirectory(), ".." + Path.DirectorySeparatorChar, projectInstanceName);
|
||||
Debug.Log(targetDirectory);
|
||||
if (Directory.Exists(targetDirectory))
|
||||
{
|
||||
@ -71,21 +75,29 @@ namespace TheGamedevGuru
|
||||
|
||||
Directory.CreateDirectory(targetDirectory);
|
||||
|
||||
var subdirectories = new List<string> { "Assets", "Packages" };
|
||||
if (includeProjectSettings) subdirectories.Add("ProjectSettings");
|
||||
List<string> subdirectories = new List<string>{"Assets", "Packages"};
|
||||
if (includeProjectSettings)
|
||||
{
|
||||
subdirectories.Add("ProjectSettings");
|
||||
}
|
||||
|
||||
foreach (string extraSubdirectory in extraSubdirectories.Split(','))
|
||||
foreach (var extraSubdirectory in extraSubdirectories.Split(','))
|
||||
{
|
||||
subdirectories.Add(extraSubdirectory.Trim());
|
||||
}
|
||||
|
||||
foreach (string subdirectory in subdirectories)
|
||||
Process.Start("CMD.exe", GetLinkCommand(subdirectory, targetDirectory));
|
||||
foreach (var subdirectory in subdirectories)
|
||||
{
|
||||
System.Diagnostics.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 :)");
|
||||
}
|
||||
|
||||
private static string GetLinkCommand(string subdirectory, string targetDirectory) =>
|
||||
$"/c mklink /J \"{targetDirectory}{Path.DirectorySeparatorChar}{subdirectory}\" \"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}{subdirectory}\"";
|
||||
static string GetLinkCommand(string subdirectory, string targetDirectory)
|
||||
{
|
||||
return $"/c mklink /J \"{targetDirectory}{Path.DirectorySeparatorChar}{subdirectory}\" \"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}{subdirectory}\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace NegUtils.Editor
|
||||
{
|
||||
public class EditorUtils
|
||||
{
|
||||
}
|
||||
|
||||
public class AssetPath
|
||||
{
|
||||
private readonly string filter;
|
||||
|
||||
private string path;
|
||||
|
||||
|
||||
public AssetPath(string filter)
|
||||
{
|
||||
this.filter = filter;
|
||||
TryFindPath();
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (path != null)
|
||||
return path;
|
||||
TryFindPath();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
private void TryFindPath()
|
||||
{
|
||||
string[] candidates = AssetDatabase.FindAssets(filter);
|
||||
if (candidates.Length == 0)
|
||||
throw new Exception("Missing layout asset!");
|
||||
path = AssetDatabase.GUIDToAssetPath(candidates[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4848b69c1024df8ad6f76cfd4415d01
|
||||
timeCreated: 1698258811
|
||||
@ -1,18 +1,23 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class GUIDToAssetPath : EditorWindow
|
||||
{
|
||||
private string guid = "";
|
||||
private string path = "";
|
||||
|
||||
private void OnGUI()
|
||||
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()
|
||||
{
|
||||
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();
|
||||
@ -24,17 +29,10 @@ public class GUIDToAssetPath : EditorWindow
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Label(path);
|
||||
}
|
||||
|
||||
[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)
|
||||
static string GetAssetPath(string guid)
|
||||
{
|
||||
guid = guid.Replace("-", "");
|
||||
|
||||
|
||||
string p = AssetDatabase.GUIDToAssetPath(guid);
|
||||
Debug.Log(p);
|
||||
if (p.Length == 0) p = "not found";
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.Utils.Editor
|
||||
{
|
||||
public static class MonoBehaviourExtensions
|
||||
{
|
||||
[MenuItem("CONTEXT/MonoBehaviour/Change Script")]
|
||||
public static void ChangeScript(MenuCommand command)
|
||||
{
|
||||
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<TextAsset>(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();
|
||||
scriptProperty.objectReferenceValue = chosenTextAsset;
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0501eedeaf1d4dcf8c4d0f1b7a0c1761
|
||||
timeCreated: 1684519404
|
||||
@ -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
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.Utils.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
||||
public class ReadOnlyPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) =>
|
||||
EditorGUI.GetPropertyHeight(property, label, true);
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f837bac3a7b40528454a9fb9a46d0be
|
||||
timeCreated: 1699371332
|
||||
@ -1,6 +1,5 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEditor;
|
||||
/// <summary>
|
||||
/// Drawer for the RequireInterface attribute.
|
||||
/// </summary>
|
||||
@ -11,7 +10,7 @@ namespace NEG.Utils
|
||||
public class RequireInterfaceDrawer : PropertyDrawer
|
||||
{
|
||||
/// <summary>
|
||||
/// Overrides GUI drawing for the attribute.
|
||||
/// Overrides GUI drawing for the attribute.
|
||||
/// </summary>
|
||||
/// <param name="position">Position.</param>
|
||||
/// <param name="property">Property.</param>
|
||||
@ -22,12 +21,11 @@ namespace NEG.Utils
|
||||
if (property.propertyType == SerializedPropertyType.ObjectReference)
|
||||
{
|
||||
// Get attribute parameters.
|
||||
var requiredAttribute = attribute as RequireInterfaceAttribute;
|
||||
var requiredAttribute = this.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();
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.Editor
|
||||
{
|
||||
public static class ScreenshotMaker
|
||||
{
|
||||
[MenuItem("CONTEXT/Camera/Save view")]
|
||||
public static void Capture(MenuCommand command)
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel("Save screenshot", "", "screen.png", "png");
|
||||
if (path.Length == 0)
|
||||
return;
|
||||
|
||||
ScreenCapture.CaptureScreenshot(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dba407e8e8740a1bed3ee5fa833b13c
|
||||
timeCreated: 1687881092
|
||||
@ -1,16 +1,21 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace NEG.Utils.Serialization
|
||||
{
|
||||
public static class SerializationExtentions
|
||||
{
|
||||
public static SerializedProperty FindAutoProperty(this SerializedObject @this, string name) =>
|
||||
@this.FindProperty(GetBackingFieldName(name));
|
||||
public static SerializedProperty FindAutoProperty(this SerializedObject @this, string name)
|
||||
{
|
||||
return @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)
|
||||
private static string GetBackingFieldName(string name)
|
||||
{
|
||||
#if NET_STANDARD || NET_STANDARD_2_1
|
||||
return string.Create(1/*<*/ + name.Length + 16/*>k__BackingField*/, name, static (span, name) =>
|
||||
@ -24,4 +29,4 @@ namespace NEG.Utils.Serialization
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
@ -9,34 +10,11 @@ namespace NegUtils.Editor
|
||||
[InitializeOnLoad]
|
||||
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()
|
||||
{
|
||||
@ -44,39 +22,47 @@ 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)
|
||||
{
|
||||
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";
|
||||
|
||||
AddFiles(path, path, menu);
|
||||
|
||||
menu.DropDown(position);
|
||||
}
|
||||
|
||||
private static void AddFiles(string path, string basePath, GenericMenu menu)
|
||||
{
|
||||
string path = Application.dataPath + "/Scenes/Production";
|
||||
string[] fileInfo = Directory.GetFiles(path, "*.unity");
|
||||
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;
|
||||
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("");
|
||||
}
|
||||
|
||||
string[] dirInfo = Directory.GetDirectories(path);
|
||||
foreach (string dir in dirInfo) AddFiles(dir, basePath, menu);
|
||||
menu.DropDown(position);
|
||||
}
|
||||
|
||||
|
||||
private static void LoadScene(string path)
|
||||
{
|
||||
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
|
||||
@ -85,11 +71,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);
|
||||
@ -98,26 +84,25 @@ namespace NegUtils.Editor
|
||||
break;
|
||||
case PlayModeStateChange.EnteredPlayMode:
|
||||
{
|
||||
if (!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
return;
|
||||
|
||||
if (EditorPrefs.GetBool("GoToCurrentSceneAfterPlay"))
|
||||
{
|
||||
EditorSceneManager.LoadSceneInPlayMode(EditorPrefs.GetString("LastOpenedScenePath"),
|
||||
new LoadSceneParameters(LoadSceneMode.Single));
|
||||
}
|
||||
else if (EditorPrefs.GetBool("GoToFirstSceneAfterPlay"))
|
||||
else
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
break;
|
||||
case PlayModeStateChange.EnteredEditMode:
|
||||
{
|
||||
if (!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
if(!EditorPrefs.GetBool("StartFromSceneIndex0"))
|
||||
return;
|
||||
EditorSceneManager.OpenScene(EditorPrefs.GetString("LastOpenedScenePath"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
using System.IO;
|
||||
using UnityEditor.AssetImporters;
|
||||
using UnityEngine;
|
||||
|
||||
[ScriptedImporter(1, "tsv")]
|
||||
public class TsvImporter : ScriptedImporter
|
||||
{
|
||||
public override void OnImportAsset(AssetImportContext ctx)
|
||||
{
|
||||
var textAsset = new TextAsset(File.ReadAllText(ctx.assetPath));
|
||||
ctx.AddObjectToAsset(Path.GetFileNameWithoutExtension(ctx.assetPath), textAsset);
|
||||
ctx.SetMainObject(textAsset);
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3f8438db4084014bab0a063e4675d3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,50 +0,0 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NEG.Utils
|
||||
{
|
||||
public class KeyBasedFactory<T1, T2>
|
||||
{
|
||||
[PublicAPI] protected Dictionary<T1, Type> data;
|
||||
|
||||
public KeyBasedFactory()
|
||||
{
|
||||
data = new Dictionary<T1, Type>();
|
||||
}
|
||||
|
||||
public void FireRegistration()
|
||||
{
|
||||
ScanAssembly(typeof(T2).Assembly);
|
||||
|
||||
if (typeof(T2).Assembly.GetType().Assembly == typeof(T2).Assembly)
|
||||
return;
|
||||
|
||||
ScanAssembly(typeof(T2).Assembly.GetType().Assembly);
|
||||
}
|
||||
|
||||
private static void ScanAssembly(Assembly assembly)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
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<object>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Register(T1 key, Type type) => data.Add(key, type);
|
||||
|
||||
public T2 CreateInstance(T1 key, params object[] args) => (T2)Activator.CreateInstance(data[key], args);
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class FactoryRegistration : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e0d3df1ddd34209bfb7262b4e51abfe
|
||||
timeCreated: 1683917310
|
||||
@ -1,16 +1,16 @@
|
||||
{
|
||||
"name": "NEG.Utils",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
"name": "NEG.Utils",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a807a09d7c00be478bf44636c2cc89f
|
||||
guid: e37f36b09b24be54ea4e03cc602bbd59
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
18
NEG/Localization/Language.cs
Normal file
18
NEG/Localization/Language.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using JetBrains.Annotations;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BEG.Localization
|
||||
{
|
||||
public class Language
|
||||
{
|
||||
[PublicAPI]
|
||||
public readonly string Name;
|
||||
|
||||
private Dictionary<string, ITranslation> translations = new ();
|
||||
|
||||
public ITranslation GetTranslation(string key) => translations[key];
|
||||
public void AddTranslation(ITranslation translation) => translations.Add(translation.Key, translation);
|
||||
|
||||
public ITranslation this[string key] => GetTranslation(key);
|
||||
}
|
||||
}
|
||||
3
NEG/Localization/Language.cs.meta
Normal file
3
NEG/Localization/Language.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2755a88e374448688202c15c2d67777c
|
||||
timeCreated: 1675712587
|
||||
63
NEG/Localization/LocalizationContext.cs
Normal file
63
NEG/Localization/LocalizationContext.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BEG.Localization
|
||||
{
|
||||
public class LocalizationContext
|
||||
{
|
||||
public interface IParam
|
||||
{
|
||||
[PublicAPI] public event Action OnValueChanged;
|
||||
}
|
||||
|
||||
public class Param<T>: IParam
|
||||
{
|
||||
public event Action OnValueChanged;
|
||||
|
||||
[PublicAPI]
|
||||
public T Value
|
||||
{
|
||||
get => value;
|
||||
set
|
||||
{
|
||||
OnValueChanged?.Invoke();
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
[NotNull] private readonly Func<T, string> formatter;
|
||||
private T value;
|
||||
|
||||
public Param(T value, Func<T, string> formatter)
|
||||
{
|
||||
this.formatter = formatter ?? (v => v.ToString());
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override string ToString() => formatter(value);
|
||||
}
|
||||
|
||||
private Dictionary<string, IParam> parameters = new ();
|
||||
|
||||
public void SetParam(string name, IParam param)
|
||||
{
|
||||
if (parameters.ContainsKey(name))
|
||||
parameters[name] = param;
|
||||
else
|
||||
parameters.Add(name, param);
|
||||
}
|
||||
|
||||
public void RemoveParam(string name) => parameters.Remove(name);
|
||||
public IParam GetParam(string name) => parameters[name];
|
||||
|
||||
public void ClearParams() => parameters.Clear();
|
||||
|
||||
public IParam this[string name]
|
||||
{
|
||||
get => GetParam(name);
|
||||
set => SetParam(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
NEG/Localization/LocalizationContext.cs.meta
Normal file
3
NEG/Localization/LocalizationContext.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19a01d756a5548e7ab1e357fee9dc8b6
|
||||
timeCreated: 1675712674
|
||||
49
NEG/Localization/LocalizationManager.cs
Normal file
49
NEG/Localization/LocalizationManager.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BEG.Localization
|
||||
{
|
||||
public class LocalizationManager
|
||||
{
|
||||
public event Action OnLanguageChanged;
|
||||
|
||||
public string CurrentLanguage
|
||||
{
|
||||
get => currentLanguage?.Name ?? "";
|
||||
set
|
||||
{
|
||||
currentLanguage = languages[value];
|
||||
OnLanguageChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public readonly LocalizationContext GlobalContext = new ();
|
||||
|
||||
private readonly Dictionary<string, Language> languages = new ();
|
||||
private Language currentLanguage;
|
||||
|
||||
[PublicAPI]
|
||||
public void AddLanguage(Language language) => languages.Add(language.Name, language);
|
||||
|
||||
[PublicAPI]
|
||||
public ITranslation GetTranslation(string key) =>
|
||||
currentLanguage.GetTranslation(key);
|
||||
|
||||
[PublicAPI] public Action Translate(string key, Action<string> action, params LocalizationContext[] contexts)
|
||||
{
|
||||
void Update()
|
||||
{
|
||||
if (currentLanguage == null) return;
|
||||
|
||||
var translation = currentLanguage.GetTranslation(key);
|
||||
translation.Get(action, currentLanguage, contexts);
|
||||
}
|
||||
|
||||
Update();
|
||||
OnLanguageChanged += Update;
|
||||
|
||||
return () => OnLanguageChanged -= Update;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
NEG/Localization/LocalizationManager.cs.meta
Normal file
3
NEG/Localization/LocalizationManager.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1544626d93fa411ea713f77d68a831ae
|
||||
timeCreated: 1675712650
|
||||
26
NEG/Localization/Translation.cs
Normal file
26
NEG/Localization/Translation.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
|
||||
namespace BEG.Localization
|
||||
{
|
||||
public interface ITranslation
|
||||
{
|
||||
[PublicAPI] string Key { get; }
|
||||
|
||||
[PublicAPI] void Get(Action<string> action, Language language, params LocalizationContext[] contexts);
|
||||
}
|
||||
|
||||
public class SimpleTranslation: ITranslation
|
||||
{
|
||||
public string Key { get; }
|
||||
public void Get(Action<string> action, Language language, params LocalizationContext[] contexts) => action?.Invoke(value);
|
||||
|
||||
private readonly string value;
|
||||
|
||||
public SimpleTranslation(string key, string value)
|
||||
{
|
||||
Key = key;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
NEG/Localization/Translation.cs.meta
Normal file
3
NEG/Localization/Translation.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64ea16abf71b4c36ac03e0b14ef33e1f
|
||||
timeCreated: 1675712656
|
||||
@ -1,11 +1,9 @@
|
||||
using NEG.UI.WindowSlot;
|
||||
using NegUtils.NEG.UI;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public interface IArea : ISlotsHolder, IControllable
|
||||
public interface IArea : ISlotsHolder, IUiElement
|
||||
{
|
||||
void Open();
|
||||
void Close();
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace NegUtils.NEG.UI
|
||||
{
|
||||
public interface IControllable
|
||||
{
|
||||
event Action<object> OnOpened;
|
||||
event Action OnClosed;
|
||||
event Action<BackUsed> OnBackUsed;
|
||||
|
||||
public void TryUseBack(ref BackUsed backUsed);
|
||||
|
||||
public class BackUsed
|
||||
{
|
||||
public bool Used { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 175798310e4048eda768cf40e6ee6de3
|
||||
timeCreated: 1686596400
|
||||
@ -1,7 +0,0 @@
|
||||
namespace NegUtils.NEG.UI
|
||||
{
|
||||
public interface IController
|
||||
{
|
||||
IControllable Controllable { get; }
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b88f4a93020a4bc6bde40e0438d296a9
|
||||
timeCreated: 1686595825
|
||||
11
NEG/UI/IUiElement.cs
Normal file
11
NEG/UI/IUiElement.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace NEG.UI
|
||||
{
|
||||
public interface IUiElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets only visible state of element
|
||||
/// </summary>
|
||||
/// <param name="setEnabled"></param>
|
||||
void SetEnabled(bool setEnabled);
|
||||
}
|
||||
}
|
||||
3
NEG/UI/IUiElement.cs.meta
Normal file
3
NEG/UI/IUiElement.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 296bf6969a6347f8aea788a7bdd086af
|
||||
timeCreated: 1670693177
|
||||
@ -1,16 +1,14 @@
|
||||
{
|
||||
"name": "NEG.UI",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:3c4294719a93e3c4e831a9ff0c261e8a"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
"name": "NEG.UI",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -5,14 +5,13 @@ namespace NEG.UI.Popup
|
||||
{
|
||||
public class DefaultPopupData : PopupData
|
||||
{
|
||||
private readonly string content;
|
||||
private readonly IDefaultPopup defaultPopup;
|
||||
private readonly List<(string, Action)> options;
|
||||
|
||||
private readonly string title;
|
||||
private readonly string content;
|
||||
private readonly List<(string, Action)> options;
|
||||
|
||||
public DefaultPopupData(IDefaultPopup popup, string title, string content, List<(string, Action)> options) :
|
||||
base(popup)
|
||||
public DefaultPopupData(IDefaultPopup popup, string title, string content, List<(string, Action)> options) : base(popup)
|
||||
{
|
||||
defaultPopup = popup;
|
||||
this.title = title;
|
||||
|
||||
@ -6,14 +6,11 @@ namespace NEG.UI.Popup
|
||||
public interface IDefaultPopup : IPopup
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets content based on provided data.
|
||||
/// Sets content based on provided data.
|
||||
/// </summary>
|
||||
/// <param name="title">popup title</param>
|
||||
/// <param name="content">popup content</param>
|
||||
/// <param name="options">
|
||||
/// list of tuples (name, action on click), to set buttons. Do not pass here popup closing logic,
|
||||
/// implementing class should do it
|
||||
/// </param>
|
||||
/// <param name="options">list of tuples (name, action on click), to set buttons. Do not pass here popup closing logic, implementing class should do it</param>
|
||||
public void SetContent(string title, string content, List<(string name, Action action)> options);
|
||||
}
|
||||
}
|
||||
@ -7,18 +7,18 @@ namespace NEG.UI.Popup
|
||||
public interface IPopup
|
||||
{
|
||||
/// <summary>
|
||||
/// Event to fire when popup is closed
|
||||
/// Event to fire when popup is closed
|
||||
/// </summary>
|
||||
event Action<PopupData> OnPopupClosed;
|
||||
|
||||
/// <summary>
|
||||
/// Show popup
|
||||
/// Show popup
|
||||
/// </summary>
|
||||
/// <param name="data">data assigned to popup, used to give info that popup is closed</param>
|
||||
public void Show(PopupData data);
|
||||
|
||||
/// <summary>
|
||||
/// Close popup or mark as closed if not visible
|
||||
/// Close popup or mark as closed if not visible
|
||||
/// </summary>
|
||||
/// <param name="silent">if true hide visually, without firing callbacks to properly close</param>
|
||||
void Close(bool silent = false);
|
||||
|
||||
@ -6,25 +6,8 @@ namespace NEG.UI.Popup
|
||||
[PublicAPI]
|
||||
public class PopupData
|
||||
{
|
||||
private readonly IPopup popup;
|
||||
|
||||
/// <summary>
|
||||
/// PopupData constructor.
|
||||
/// </summary>
|
||||
/// <param name="popup">attached to this data, can be used by different data instances</param>
|
||||
public PopupData(IPopup popup)
|
||||
{
|
||||
this.popup = popup;
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this data is still valid. If set to false, popup will not show.
|
||||
/// </summary>
|
||||
public bool IsValid { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Event that is fired on closing popup.
|
||||
/// Event that is fired on closing popup.
|
||||
/// </summary>
|
||||
public event Action<PopupData> PopupClosedEvent
|
||||
{
|
||||
@ -33,22 +16,35 @@ namespace NEG.UI.Popup
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show popup and pass needed data.
|
||||
/// Is this data is still valid. If set to false, popup will not show.
|
||||
/// </summary>
|
||||
public virtual void Show() => popup.Show(this);
|
||||
public bool IsValid { get; protected set; }
|
||||
|
||||
private readonly IPopup popup;
|
||||
|
||||
/// <summary>
|
||||
/// Hide popup. Close visuals without firing events;
|
||||
/// PopupData constructor.
|
||||
/// </summary>
|
||||
/// <param name="popup">attached to this data, can be used by different data instances</param>
|
||||
public PopupData(IPopup popup)
|
||||
{
|
||||
this.popup = popup;
|
||||
IsValid = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show popup and pass needed data.
|
||||
/// </summary>
|
||||
public virtual void Show() => popup.Show(this);
|
||||
|
||||
/// <summary>
|
||||
/// Hide popup. Close visuals without firing events;
|
||||
/// </summary>
|
||||
public virtual void Hide() => popup.Close(true);
|
||||
|
||||
/// <summary>
|
||||
/// Invalidate popup, <see cref="UiManager" /> will automatically skip this popup
|
||||
/// Invalidate popup, <see cref="UiManager"/> will automatically skip this popup
|
||||
/// </summary>
|
||||
public virtual void Invalidate()
|
||||
{
|
||||
IsValid = false;
|
||||
UiManager.Instance.RefreshPopups();
|
||||
}
|
||||
public virtual void Invalidate() => IsValid = false;
|
||||
}
|
||||
}
|
||||
@ -248,10 +248,8 @@ namespace System.Collections.Generic
|
||||
public PriorityQueue(int initialCapacity, IComparer<TPriority>? comparer)
|
||||
{
|
||||
if (initialCapacity < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(initialCapacity), initialCapacity, SR.ArgumentOutOfRange_NeedNonNegNum);
|
||||
}
|
||||
|
||||
_nodes = new (TElement, TPriority)[initialCapacity];
|
||||
_comparer = InitializeComparer(comparer);
|
||||
@ -491,7 +489,7 @@ namespace System.Collections.Generic
|
||||
{
|
||||
int i = 0;
|
||||
(TElement, TPriority)[] nodes = _nodes;
|
||||
foreach (var (element, priority) in items)
|
||||
foreach ((var element, var priority) in items)
|
||||
{
|
||||
if (nodes.Length == i)
|
||||
{
|
||||
@ -510,8 +508,9 @@ namespace System.Collections.Generic
|
||||
if (_size > 1) Heapify();
|
||||
}
|
||||
else
|
||||
foreach (var (element, priority) in items)
|
||||
Enqueue(element, priority);
|
||||
{
|
||||
foreach ((var element, var priority) in items) Enqueue(element, priority);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -555,8 +554,9 @@ namespace System.Collections.Generic
|
||||
if (i > 1) Heapify();
|
||||
}
|
||||
else
|
||||
foreach (var element in elements)
|
||||
Enqueue(element, priority);
|
||||
{
|
||||
foreach (var element in elements) Enqueue(element, priority);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -684,15 +684,11 @@ namespace System.Collections.Generic
|
||||
int lastParentWithChildren = GetParentIndex(_size - 1);
|
||||
|
||||
if (_comparer == null)
|
||||
{
|
||||
for (int index = lastParentWithChildren; index >= 0; --index)
|
||||
MoveDownDefaultComparer(nodes[index], index);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int index = lastParentWithChildren; index >= 0; --index)
|
||||
MoveDownCustomComparer(nodes[index], index);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -719,7 +715,9 @@ namespace System.Collections.Generic
|
||||
nodeIndex = parentIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nodes[nodeIndex] = node;
|
||||
@ -750,7 +748,9 @@ namespace System.Collections.Generic
|
||||
nodeIndex = parentIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nodes[nodeIndex] = node;
|
||||
@ -894,10 +894,8 @@ namespace System.Collections.Generic
|
||||
if (array.GetLowerBound(0) != 0) throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array));
|
||||
|
||||
if (index < 0 || index > array.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index), index,
|
||||
SR.ArgumentOutOfRange_IndexMustBeLessOrEqual);
|
||||
}
|
||||
|
||||
if (array.Length - index < _queue._size) throw new ArgumentException(SR.Argument_InvalidOffLen);
|
||||
|
||||
|
||||
@ -2,28 +2,47 @@ using JetBrains.Annotations;
|
||||
using NEG.UI.Area;
|
||||
using NEG.UI.Popup;
|
||||
using NEG.UI.Window;
|
||||
using NegUtils.NEG.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI
|
||||
{
|
||||
[PublicAPI]
|
||||
public abstract class UiManager : IDisposable
|
||||
public abstract class UiManager
|
||||
{
|
||||
public static UiManager Instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current area shown on screen.
|
||||
/// </summary>
|
||||
public IArea CurrentArea
|
||||
{
|
||||
get => currentArea;
|
||||
set
|
||||
{
|
||||
currentArea?.SetEnabled(false);
|
||||
|
||||
currentArea = value;
|
||||
|
||||
currentArea?.SetEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current window that is considered main (focused, lastly opened). Can be null.
|
||||
/// </summary>
|
||||
public IWindow CurrentMainWindow { get; protected set; }
|
||||
|
||||
private IArea currentArea;
|
||||
protected IDefaultPopup currentDefaultPopup;
|
||||
private (PopupData data, int priority) currentShownPopup;
|
||||
protected IDefaultPopup currentDefaultPopup;
|
||||
|
||||
private PriorityQueue<PopupData, int> popupsToShow = new();
|
||||
|
||||
//TODO: localize
|
||||
private string localizedYes = "Yes", localizedNo = "No", localizedOk = "Ok";
|
||||
|
||||
private List<IWindow> mainWindows;
|
||||
|
||||
private PriorityQueue<PopupData, int> popupsToShow = new();
|
||||
|
||||
protected UiManager(IArea startArea)
|
||||
{
|
||||
if (Instance != null)
|
||||
@ -35,39 +54,10 @@ namespace NEG.UI
|
||||
Instance = this;
|
||||
|
||||
CurrentArea = startArea;
|
||||
mainWindows = new List<IWindow>();
|
||||
}
|
||||
|
||||
public static UiManager Instance { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current area shown on screen.
|
||||
/// </summary>
|
||||
public IArea CurrentArea
|
||||
{
|
||||
get => currentArea;
|
||||
set
|
||||
{
|
||||
currentArea?.Close();
|
||||
|
||||
currentArea = value;
|
||||
|
||||
currentArea?.Open();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Current window that is considered main (focused, lastly opened). Can be null.
|
||||
/// </summary>
|
||||
public IWindow CurrentMainWindow => mainWindows.LastOrDefault();
|
||||
|
||||
public PopupData CurrentPopup => currentShownPopup.data;
|
||||
|
||||
public virtual void Dispose() => Instance = null;
|
||||
|
||||
/// <summary>
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later.
|
||||
/// It will be closed after pressing ok button.
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later. It will be closed after pressing ok button.
|
||||
/// </summary>
|
||||
/// <param name="title">popup title</param>
|
||||
/// <param name="content">popup content</param>
|
||||
@ -76,18 +66,16 @@ namespace NEG.UI
|
||||
/// <param name="priority">priority of popup (lower number -> show first)</param>
|
||||
/// <param name="forceShow">force show current popup only if currently shown has lower priority</param>
|
||||
/// <returns>data for created popup, can be used to invalidate popup (will not show)</returns>
|
||||
public PopupData ShowOkPopup(string title, string content, string okText = null, Action okPressed = null,
|
||||
int priority = 0, bool forceShow = false)
|
||||
public PopupData ShowOkPopup(string title, string content, string okText = null, Action okPressed = null, int priority = 0, bool forceShow = false)
|
||||
{
|
||||
var data = new DefaultPopupData(currentDefaultPopup, title, content,
|
||||
new List<(string, Action)> { (okText ?? localizedOk, okPressed) });
|
||||
new List<(string, Action)>() { (okText ?? localizedOk, okPressed) });
|
||||
ShowPopup(data, priority, forceShow);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later.
|
||||
/// It will be closed after pressing yes or no button.
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later. It will be closed after pressing yes or no button.
|
||||
/// </summary>
|
||||
/// <param name="title">popup title</param>
|
||||
/// <param name="content">popup content</param>
|
||||
@ -98,21 +86,16 @@ namespace NEG.UI
|
||||
/// <param name="priority">priority of popup (lower number -> show first)</param>
|
||||
/// <param name="forceShow">force show current popup only if currently shown has lower priority</param>
|
||||
/// <returns>data for created popup, can be used to invalidate popup (will not show)</returns>
|
||||
public PopupData ShowYesNoPopup(string title, string content, string yesText = null, string noText = null,
|
||||
Action yesPressed = null, Action noPressed = null, int priority = 0, bool forceShow = false)
|
||||
public PopupData ShowYesNoPopup(string title, string content, string yesText = null, string noText = null, Action yesPressed = null, Action noPressed = null, int priority = 0, bool forceShow = false)
|
||||
{
|
||||
var data = new DefaultPopupData(currentDefaultPopup, title, content,
|
||||
new List<(string, Action)>
|
||||
{
|
||||
(yesText ?? localizedYes, yesPressed), (noText ?? localizedNo, noPressed)
|
||||
});
|
||||
new List<(string, Action)>() { (yesText ?? localizedYes, yesPressed), (noText ?? localizedNo, noPressed) });
|
||||
ShowPopup(data, priority, forceShow);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later.
|
||||
/// It will be closed after pressing any button.
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later. It will be closed after pressing any button.
|
||||
/// </summary>
|
||||
/// <param name="title">popup title</param>
|
||||
/// <param name="content">popup content</param>
|
||||
@ -120,16 +103,15 @@ namespace NEG.UI
|
||||
/// <param name="priority">priority of popup (lower number -> show first)</param>
|
||||
/// <param name="forceShow">force show current popup only if currently shown has lower priority</param>
|
||||
/// <returns>data for created popup, can be used to invalidate popup (will not show)</returns>
|
||||
public PopupData ShowPopup(string title, string content, List<(string, Action)> actions, int priority = 0,
|
||||
bool forceShow = false)
|
||||
public PopupData ShowPopup(string title, string content, List<(string, Action)> actions, int priority = 0, bool forceShow = false)
|
||||
{
|
||||
var data = new DefaultPopupData(currentDefaultPopup, title, content, actions);
|
||||
ShowPopup(data, priority, forceShow);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later.
|
||||
/// Show popup if there is non other currently shown. Otherwise add current popup to ordered queue and show it later.
|
||||
/// </summary>
|
||||
/// <param name="data">popup data object</param>
|
||||
/// <param name="priority">priority of popup (lower number -> show first)</param>
|
||||
@ -139,72 +121,35 @@ namespace NEG.UI
|
||||
popupsToShow.Enqueue(data, priority);
|
||||
UpdatePopupsState(forceShow, priority, data);
|
||||
}
|
||||
|
||||
public void UseBack()
|
||||
{
|
||||
IControllable.BackUsed backUsed = new();
|
||||
|
||||
CurrentMainWindow?.TryUseBack(ref backUsed);
|
||||
if (backUsed.Used)
|
||||
return;
|
||||
CurrentArea.TryUseBack(ref backUsed);
|
||||
}
|
||||
|
||||
|
||||
public void RefreshPopups()
|
||||
{
|
||||
if (currentShownPopup.data is { IsValid: true })
|
||||
return;
|
||||
UpdatePopupsState(false);
|
||||
}
|
||||
|
||||
public void SetMainWindow(IWindow window) => mainWindows.Add(window);
|
||||
|
||||
public void MainWindowClosed(IWindow window) => mainWindows.Remove(window);
|
||||
|
||||
public void OnWindowClosed(IWindow window) => MainWindowClosed(window);
|
||||
|
||||
//TODO: select new main window
|
||||
|
||||
protected void PopupClosed(PopupData data)
|
||||
{
|
||||
if (currentShownPopup.data != data)
|
||||
//Debug.LogError("Popup was not shown");
|
||||
{
|
||||
Debug.LogError("Popup was not shown");
|
||||
return;
|
||||
}
|
||||
UpdatePopupsState(false);
|
||||
}
|
||||
|
||||
|
||||
protected void SetDefaultPopup(IDefaultPopup popup) => currentDefaultPopup = popup;
|
||||
|
||||
|
||||
protected virtual void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null)
|
||||
private void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null)
|
||||
{
|
||||
if (forceShow)
|
||||
{
|
||||
if (currentShownPopup.data != null && currentShownPopup.priority >= priority)
|
||||
if(currentShownPopup.priority <= priority)
|
||||
return;
|
||||
|
||||
|
||||
popupsToShow.Enqueue(currentShownPopup.data, currentShownPopup.priority);
|
||||
ShowPopup(data, priority);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!popupsToShow.TryDequeue(out var d, out int p))
|
||||
return;
|
||||
|
||||
while (popupsToShow.TryDequeue(out var d, out int p))
|
||||
{
|
||||
if (d == null)
|
||||
continue;
|
||||
if (!d.IsValid)
|
||||
continue;
|
||||
if (d == currentShownPopup.data)
|
||||
continue;
|
||||
ShowPopup(d, p);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentShownPopup.data == null)
|
||||
return;
|
||||
currentShownPopup.data.PopupClosedEvent -= PopupClosed;
|
||||
currentShownPopup.data.Hide();
|
||||
currentShownPopup.data = null;
|
||||
ShowPopup(d, p);
|
||||
}
|
||||
|
||||
private void ShowPopup(PopupData data, int priority)
|
||||
@ -214,10 +159,11 @@ namespace NEG.UI
|
||||
currentShownPopup.data.PopupClosedEvent -= PopupClosed;
|
||||
currentShownPopup.data.Hide();
|
||||
}
|
||||
|
||||
currentShownPopup = (data, priority);
|
||||
data.Show();
|
||||
data.PopupClosedEvent += PopupClosed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.Window;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public class AutoOpenWindowWhenNoOther : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private MonoWindow window;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (UiManager.Instance.CurrentMainWindow == null)
|
||||
window.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 473c065573984067a824ebf3b605c3ab
|
||||
timeCreated: 1695048071
|
||||
@ -1,14 +1,15 @@
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.Window;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
[Tooltip("Automatically open attached window on start")]
|
||||
[Tooltip(tooltip: "Automatically open attached window on start")]
|
||||
public class AutoWindowOpen : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private MonoWindow window;
|
||||
|
||||
|
||||
private void Start() => window.Open();
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
using NEG.UI.UnityUi;
|
||||
using NEG.UI.Window;
|
||||
using NegUtils.NEG.UI;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public class CloseMainWindowOnBack : MonoController
|
||||
{
|
||||
protected override void OnBackUsed(IControllable.BackUsed backUsed)
|
||||
{
|
||||
base.OnBackUsed(backUsed);
|
||||
UiManager.Instance.CurrentMainWindow?.Close();
|
||||
backUsed.Used = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ec2bf64cda740a1849d024d4f163a01
|
||||
timeCreated: 1686598066
|
||||
@ -1,19 +1,30 @@
|
||||
using NEG.UI.UnityUi.WindowSlot;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using NEG.UI.Popup;
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.UnityUi.WindowSlot;
|
||||
using NEG.UI.Window;
|
||||
using NEG.UI.WindowSlot;
|
||||
using NegUtils.NEG.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.Area
|
||||
{
|
||||
public class MonoArea : MonoBehaviour, IArea
|
||||
{
|
||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
||||
|
||||
[SerializeField] private bool setAsDefaultArea;
|
||||
|
||||
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||
public IWindowSlot DefaultWindowSlot => windowSlots[0];
|
||||
|
||||
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
||||
|
||||
public virtual void OpenWindow(IWindow window, object data = null)
|
||||
{
|
||||
DefaultWindowSlot.AttachWindow(window);
|
||||
window.SetData(data);
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
@ -21,40 +32,10 @@ namespace NEG.UI.Area
|
||||
UiManager.Instance.CurrentArea = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (!setAsDefaultArea)
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (UiManager.Instance == null)
|
||||
return;
|
||||
if (ReferenceEquals(UiManager.Instance.CurrentArea, this))
|
||||
UiManager.Instance.CurrentArea = null;
|
||||
}
|
||||
|
||||
public event Action<object> OnOpened;
|
||||
public event Action OnClosed;
|
||||
public event Action<IControllable.BackUsed> OnBackUsed;
|
||||
|
||||
public IEnumerable<IWindowSlot> AvailableSlots => windowSlots;
|
||||
|
||||
public void Open()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
OnOpened?.Invoke(null);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
OnClosed?.Invoke();
|
||||
}
|
||||
|
||||
public void OpenWindow(IWindow window, object data = null) => DefaultWindowSlot.AttachWindow(window, data);
|
||||
|
||||
public void TryUseBack(ref IControllable.BackUsed backUsed) => OnBackUsed?.Invoke(backUsed);
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: 39eb59ca1ef60934abb3f0c64169be65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 10
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
timeCreated: 1670707479
|
||||
@ -1,104 +1,78 @@
|
||||
using KBCore.Refs;
|
||||
using NEG.UI.UnityUi.Buttons.Behaviours;
|
||||
using NEG.UI.UnityUi.Buttons.Settings;
|
||||
using FMOD.Studio;
|
||||
using FMODUnity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
[DefaultExecutionOrder(-1)]
|
||||
[RequireComponent(typeof(Button))]
|
||||
[RequireComponent(typeof(ButtonSerializeFields))]
|
||||
public class BaseButton : MonoBehaviour, ISelectHandler, IDeselectHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public delegate void SelectionHandler(bool isSilent);
|
||||
public event Action OnButtonPressed;
|
||||
|
||||
public bool Interactable { get => serializeFields.Button.interactable; set => serializeFields.Button.interactable = value; }
|
||||
|
||||
[SerializeField]
|
||||
protected ButtonSerializeFields serializeFields;
|
||||
|
||||
[SerializeField] [Self(Flag.Optional)] private Button button;
|
||||
private bool isHovered;
|
||||
|
||||
[SerializeField] [Child(Flag.Optional)]
|
||||
private TMP_Text text;
|
||||
|
||||
[SerializeField] [Child(Flag.Optional)]
|
||||
private Image icon;
|
||||
|
||||
[SerializeField] private ButtonSettings groupButtonSettings;
|
||||
|
||||
private readonly Dictionary<string, ButtonElementBehaviour> behaviours = new();
|
||||
|
||||
public bool Interactable { get => button.interactable; set => button.interactable = value; }
|
||||
|
||||
public TMP_Text Text => text;
|
||||
|
||||
protected virtual void Awake()
|
||||
public virtual void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
button.onClick.AddListener(OnClicked);
|
||||
if (groupButtonSettings == null)
|
||||
MonoUiManager.Instance.DefaultUiSettings.Apply(this);
|
||||
else
|
||||
groupButtonSettings.Apply(this);
|
||||
if (serializeFields.Text)
|
||||
serializeFields.Text.color = serializeFields.SelectedTextColor;
|
||||
}
|
||||
|
||||
private void Start() => OnDeselect(null);
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (serializeFields.Text)
|
||||
serializeFields.Text.color = serializeFields.DeselectedTextColor;
|
||||
}
|
||||
|
||||
private void OnValidate() => this.ValidateRefs();
|
||||
|
||||
public void OnDeselect(BaseEventData eventData) => OnDeselected?.Invoke(eventData is SilentEventData);
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData) => EventSystem.current.SetSelectedGameObject(gameObject);
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHovered = true;
|
||||
if (serializeFields.Text)
|
||||
serializeFields.Text.color = serializeFields.SelectedTextColor;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (EventSystem.current.currentSelectedGameObject == gameObject)
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
isHovered = false;
|
||||
if (serializeFields.Text)
|
||||
serializeFields.Text.color = serializeFields.DeselectedTextColor;
|
||||
}
|
||||
|
||||
public virtual void OnSelect(BaseEventData eventData) => OnSelected?.Invoke(eventData is SilentEventData);
|
||||
|
||||
/// <summary>
|
||||
/// is silent
|
||||
/// </summary>
|
||||
public event SelectionHandler OnSelected;
|
||||
|
||||
public event SelectionHandler OnDeselected;
|
||||
public event Action OnButtonPressed;
|
||||
|
||||
public void SetText(string txt)
|
||||
public void SetText(string text)
|
||||
{
|
||||
if (text == null)
|
||||
if(serializeFields == null)
|
||||
return;
|
||||
text.text = txt;
|
||||
if(serializeFields.Text == null)
|
||||
return;
|
||||
serializeFields.Text.text = text;
|
||||
}
|
||||
|
||||
public void AddOrOverrideSetting(SettingData data)
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (behaviours.TryGetValue(data.Key, out var setting))
|
||||
{
|
||||
setting.ChangeData(data);
|
||||
return;
|
||||
}
|
||||
|
||||
behaviours.Add(data.Key, MonoUiManager.Instance.BehavioursFactory.CreateInstance(data.Key, this, data));
|
||||
if(serializeFields == null)
|
||||
serializeFields = GetComponent<ButtonSerializeFields>();
|
||||
serializeFields.Button.onClick.AddListener(OnClicked);
|
||||
OnDeselect(null);
|
||||
}
|
||||
|
||||
public void RemoveSetting(string key)
|
||||
private void OnValidate()
|
||||
{
|
||||
if (!behaviours.TryGetValue(key, out var setting))
|
||||
{
|
||||
Debug.LogError($"Behaviour with key {key} was not found");
|
||||
return;
|
||||
}
|
||||
|
||||
setting.Dispose();
|
||||
behaviours.Remove(key);
|
||||
if(serializeFields == null)
|
||||
serializeFields = GetComponent<ButtonSerializeFields>();
|
||||
}
|
||||
|
||||
protected virtual void OnClicked()
|
||||
{
|
||||
OnDeselect(null);
|
||||
isHovered = false;
|
||||
OnButtonPressed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a250ef2d0c34e7396a16fc5eddbdb01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -1
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
timeCreated: 1670777213
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 953c3353e3af44258625fe607ede632b
|
||||
timeCreated: 1683915598
|
||||
@ -1,21 +0,0 @@
|
||||
using NEG.UI.UnityUi.Buttons.Settings;
|
||||
using System;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Behaviours
|
||||
{
|
||||
public abstract class ButtonElementBehaviour : IDisposable
|
||||
{
|
||||
protected readonly BaseButton button;
|
||||
protected SettingData baseData;
|
||||
|
||||
public ButtonElementBehaviour(BaseButton baseButton, SettingData settingData)
|
||||
{
|
||||
button = baseButton;
|
||||
baseData = settingData;
|
||||
}
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public virtual void ChangeData(SettingData newData) => baseData = newData;
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5e3decad6424cb288eff3e6f7e0d28e
|
||||
timeCreated: 1683919740
|
||||
@ -1,41 +0,0 @@
|
||||
using NEG.UI.UnityUi.Buttons.Settings;
|
||||
using NEG.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Behaviours
|
||||
{
|
||||
public class ChangeTextColorBehaviour : ButtonElementBehaviour
|
||||
{
|
||||
private ColorData data;
|
||||
|
||||
public ChangeTextColorBehaviour(BaseButton baseButton, ColorData data) : base(baseButton, data)
|
||||
{
|
||||
if (baseButton.Text == null)
|
||||
return;
|
||||
|
||||
baseButton.OnSelected += OnButtonSelected;
|
||||
baseButton.OnDeselected += OnButtonDeselected;
|
||||
ChangeData(data);
|
||||
}
|
||||
|
||||
public override void ChangeData(SettingData newData)
|
||||
{
|
||||
base.ChangeData(newData);
|
||||
Debug.Assert(newData is ColorData, "newData is not ColorData");
|
||||
data = (ColorData)newData;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
button.OnSelected -= OnButtonSelected;
|
||||
button.OnDeselected -= OnButtonDeselected;
|
||||
}
|
||||
|
||||
[FactoryRegistration]
|
||||
private static void RegisterInFactory() =>
|
||||
MonoUiManager.Instance.BehavioursFactory.Register("ChangeTextColor", typeof(ChangeTextColorBehaviour));
|
||||
|
||||
private void OnButtonSelected(bool _) => button.Text.color = data.SelectedColor;
|
||||
private void OnButtonDeselected(bool _) => button.Text.color = data.DeselectedColor;
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2079225d6e34001ae85f74a0a418d68
|
||||
timeCreated: 1683919878
|
||||
@ -1,21 +0,0 @@
|
||||
#if FMOD
|
||||
namespace NEG.UI.UnityUi.Buttons.Behaviours
|
||||
{
|
||||
public class SimpleSoundBehaviour : ButtonElementBehaviour
|
||||
{
|
||||
public SimpleSoundBehaviour(BaseButton baseButton, FmodSoundData data) : base(baseButton, data)
|
||||
{
|
||||
//TODO: use silnet to not play sound
|
||||
}
|
||||
|
||||
[FactoryRegistration]
|
||||
private static void RegisterInFactory() =>
|
||||
MonoUiManager.Instance.BehavioursFactory.Register("SimpleSound", typeof(SimpleSoundBehaviour));
|
||||
|
||||
public override void ChangeData(SettingData newData) => throw new System.NotImplementedException();
|
||||
|
||||
public override void Dispose() => throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d75c0d86eeab47a1a6340f0b03b83de0
|
||||
timeCreated: 1684002680
|
||||
15
NEG/UI/UnityUi/Buttons/ButtonReaction.cs
Normal file
15
NEG/UI/UnityUi/Buttons/ButtonReaction.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
[RequireComponent(typeof(BaseButton))]
|
||||
public abstract class ButtonReaction : MonoBehaviour
|
||||
{
|
||||
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
|
||||
|
||||
private void OnDestroy() => GetComponent<BaseButton>().OnButtonPressed -= OnClicked;
|
||||
|
||||
protected abstract void OnClicked();
|
||||
}
|
||||
}
|
||||
33
NEG/UI/UnityUi/Buttons/ButtonSerializeFields.cs
Normal file
33
NEG/UI/UnityUi/Buttons/ButtonSerializeFields.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using FMODUnity;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
public class ButtonSerializeFields : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField]
|
||||
public Button Button { get; private set; }
|
||||
[field: SerializeField]
|
||||
public TMP_Text Text { get; private set; }
|
||||
[field: SerializeField]
|
||||
public Color SelectedTextColor { get; private set; }
|
||||
[field: SerializeField]
|
||||
public Color DeselectedTextColor { get; private set; }
|
||||
[field: SerializeField]
|
||||
public EventReference HoverEventRef { get; private set; }
|
||||
[field: SerializeField]
|
||||
public EventReference ClickEventRef { get; private set; }
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if(Button == null)
|
||||
Button = GetComponent<Button>();
|
||||
if (Text == null)
|
||||
Text = GetComponentInChildren<TMP_Text>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3
NEG/UI/UnityUi/Buttons/ButtonSerializeFields.cs.meta
Normal file
3
NEG/UI/UnityUi/Buttons/ButtonSerializeFields.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f8c6cf4cf18463c86ec1165c61c79b2
|
||||
timeCreated: 1670777232
|
||||
@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
[RequireComponent(typeof(BaseButton))]
|
||||
public class ChangeScene : ButtonReaction
|
||||
public class ChangeSceneButton : ButtonReaction
|
||||
{
|
||||
[Header("Leave empty to use int value")] [SerializeField]
|
||||
private string sceneName;
|
||||
[Header("Leave empty to use int value")]
|
||||
[SerializeField] private string sceneName;
|
||||
|
||||
[SerializeField] private int sceneIndex;
|
||||
|
||||
@ -19,4 +22,4 @@ namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
public class CloseAllWindows : ButtonReaction
|
||||
{
|
||||
@ -1,21 +1,22 @@
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.Window;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
[RequireComponent(typeof(BaseButton))]
|
||||
public class CloseWindow : ButtonReaction
|
||||
{
|
||||
[SerializeField] private MonoWindow windowToClose;
|
||||
|
||||
protected override void OnClicked() => windowToClose.Close();
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (windowToClose != null)
|
||||
if(windowToClose != null)
|
||||
return;
|
||||
windowToClose = GetComponentInParent<MonoWindow>();
|
||||
}
|
||||
|
||||
protected override void OnClicked() => windowToClose.Close();
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ namespace NEG.UI.UnityUi.Buttons
|
||||
public class CloseWindowOnImageTouch : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
[SerializeField] private MonoWindow windowToClose;
|
||||
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) => windowToClose.Close();
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
public class CustomNavigationButton : Button
|
||||
{
|
||||
[SerializeField] [HideInInspector] private OverridableNavigation upOverride;
|
||||
[SerializeField] private OverridableNavigation downOverride;
|
||||
[SerializeField] private OverridableNavigation leftOverride;
|
||||
[SerializeField] private OverridableNavigation rightOverride;
|
||||
|
||||
|
||||
public override void OnMove(AxisEventData eventData)
|
||||
{
|
||||
switch (eventData.moveDir)
|
||||
{
|
||||
case MoveDirection.Left:
|
||||
if (TryNavigate(eventData, leftOverride))
|
||||
return;
|
||||
break;
|
||||
case MoveDirection.Up:
|
||||
if (TryNavigate(eventData, upOverride))
|
||||
return;
|
||||
break;
|
||||
case MoveDirection.Right:
|
||||
if (TryNavigate(eventData, rightOverride))
|
||||
return;
|
||||
break;
|
||||
case MoveDirection.Down:
|
||||
if (TryNavigate(eventData, downOverride))
|
||||
return;
|
||||
break;
|
||||
case MoveDirection.None:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
base.OnMove(eventData);
|
||||
}
|
||||
|
||||
public static bool TryNavigate(BaseEventData eventData, OverridableNavigation overrideNavigation)
|
||||
{
|
||||
if (!overrideNavigation.Override)
|
||||
return false;
|
||||
|
||||
if (overrideNavigation.Selectable == null || !overrideNavigation.Selectable.IsActive())
|
||||
return true;
|
||||
|
||||
eventData.selectedObject = overrideNavigation.Selectable.gameObject;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class OverridableNavigation
|
||||
{
|
||||
[field: SerializeField] public bool Override { get; private set; }
|
||||
[field: SerializeField] public Selectable Selectable { get; private set; }
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9b5ca8863c240f792232d6e276d8d56
|
||||
timeCreated: 1684520970
|
||||
@ -1,17 +1,18 @@
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.UnityUi.WindowSlot;
|
||||
using NEG.UI.Window;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using NEG.UI.Window;
|
||||
using NEG.UI.WindowSlot;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
[RequireComponent(typeof(BaseButton))]
|
||||
public class OpenWindow : ButtonReaction
|
||||
{
|
||||
[SerializeField] private MonoWindow window;
|
||||
|
||||
[Header("Open on default area slot if empty")] [SerializeField]
|
||||
private MonoWindowSlot slot;
|
||||
[Header("Open on default area slot if empty")]
|
||||
[SerializeField] private MonoWindowSlot slot;
|
||||
|
||||
protected override void OnClicked() => window.Open(slot);
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccaf0d2f63be41f6956471dcd9c210d9
|
||||
timeCreated: 1709465582
|
||||
@ -1,19 +0,0 @@
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons
|
||||
{
|
||||
[RequireComponent(typeof(BaseButton))]
|
||||
public abstract class ButtonReaction : MonoBehaviour
|
||||
{
|
||||
[SerializeField] [Self(Flag.Optional)] protected BaseButton button;
|
||||
|
||||
protected virtual void Awake() => button.OnButtonPressed += OnClicked;
|
||||
|
||||
protected virtual void OnDestroy() => button.OnButtonPressed -= OnClicked;
|
||||
|
||||
private void OnValidate() => this.ValidateRefs();
|
||||
|
||||
protected abstract void OnClicked();
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
{
|
||||
public class ExitGame : ButtonReaction
|
||||
{
|
||||
protected override void OnClicked()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.isPlaying = false;
|
||||
#endif
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 185f765a5bf7487ab85a7d95fc0ef2c7
|
||||
timeCreated: 1709473462
|
||||
@ -1,13 +0,0 @@
|
||||
using NEG.UI.UnityUi.Window;
|
||||
using NEG.UI.Window;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Reactions
|
||||
{
|
||||
public class OpenAsCurrentMainChild : ButtonReaction
|
||||
{
|
||||
[SerializeField] private MonoWindow windowToOpen;
|
||||
|
||||
protected override void OnClicked() => UiManager.Instance.CurrentMainWindow.OpenAsChild(windowToOpen);
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 049e222140c94fc28fb36bca4aaddba4
|
||||
timeCreated: 1686595194
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d25aba738e174616bcab9bf2d52a3ed1
|
||||
timeCreated: 1683398272
|
||||
@ -1,23 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Settings
|
||||
{
|
||||
public class ButtonSettings : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<SettingData> settingDatas = new();
|
||||
|
||||
public void Apply(BaseButton button)
|
||||
{
|
||||
foreach (var setting in settingDatas) setting.Apply(button);
|
||||
}
|
||||
|
||||
[ContextMenu("Refresh")]
|
||||
public void Refresh()
|
||||
{
|
||||
settingDatas.Clear();
|
||||
var components = GetComponents<SettingData>();
|
||||
foreach (var data in components) settingDatas.Add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5292008faae496ab9028ad1faa0a3ba
|
||||
timeCreated: 1683398713
|
||||
@ -1,10 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Settings
|
||||
{
|
||||
public class ColorData : SettingData
|
||||
{
|
||||
[field: SerializeField] public Color SelectedColor { get; private set; } = Color.black;
|
||||
[field: SerializeField] public Color DeselectedColor { get; private set; } = Color.black;
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cec5286cd31b4819981e244b1adb977e
|
||||
timeCreated: 1684001181
|
||||
@ -1,14 +0,0 @@
|
||||
#if FMOD
|
||||
using FMODUnity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Settings
|
||||
{
|
||||
public class FmodSoundData : SettingData
|
||||
{
|
||||
[field: SerializeField] public EventReference SelectedSound { get; private set; }
|
||||
[field: SerializeField] public EventReference ClickedSound { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e6a7b10c07d40408ee9492c931e3ec9
|
||||
timeCreated: 1684001979
|
||||
@ -1,7 +0,0 @@
|
||||
namespace NEG.UI.UnityUi.Buttons.Settings
|
||||
{
|
||||
public class RemoveFeature : SettingData
|
||||
{
|
||||
public override void Apply(BaseButton button) => button.RemoveSetting(Key);
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b44cdc2e0164ebdb8f6da348d653e77
|
||||
timeCreated: 1684001264
|
||||
@ -1,26 +0,0 @@
|
||||
using KBCore.Refs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Settings
|
||||
{
|
||||
public abstract class SettingData : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField] public string Key { get; private set; }
|
||||
[SerializeField] [Self(Flag.Optional)] private BaseButton attachedButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (attachedButton != null)
|
||||
Apply(attachedButton);
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
this.ValidateRefs();
|
||||
if (attachedButton == null && TryGetComponent(out ButtonSettings settings))
|
||||
settings.Refresh();
|
||||
}
|
||||
|
||||
public virtual void Apply(BaseButton button) => button.AddOrOverrideSetting(this);
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49b3fccda2b4485193eada1b3611ea40
|
||||
timeCreated: 1684001079
|
||||
@ -1,10 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NEG.UI.UnityUi.Buttons.Settings
|
||||
{
|
||||
public class SpriteData : SettingData
|
||||
{
|
||||
[field: SerializeField] public Sprite SelectedSprite { get; private set; }
|
||||
[field: SerializeField] public Sprite DeselectedSprite { get; private set; }
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aeba07ffa68b4674bc7025ba4f328562
|
||||
timeCreated: 1684001906
|
||||
@ -5,11 +5,22 @@ using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NEG.UI.UnityUi
|
||||
{
|
||||
[PublicAPI]
|
||||
public class CarouselList : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Current option
|
||||
/// </summary>
|
||||
public string CurrentOption { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current selected option id
|
||||
/// </summary>
|
||||
public int CurrentOptionId { get; private set; }
|
||||
|
||||
[SerializeField] private BaseButton nextButton;
|
||||
[SerializeField] private BaseButton prevButton;
|
||||
[SerializeField] private TMP_Text currentOptionText;
|
||||
@ -17,31 +28,7 @@ namespace NEG.UI.UnityUi
|
||||
private List<string> options;
|
||||
|
||||
/// <summary>
|
||||
/// Current option
|
||||
/// </summary>
|
||||
public string CurrentOption { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current selected option id
|
||||
/// </summary>
|
||||
public int CurrentOptionId { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
nextButton.OnButtonPressed += SelectNextOption;
|
||||
prevButton.OnButtonPressed += SelectPrevOption;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
nextButton.OnButtonPressed -= SelectNextOption;
|
||||
prevButton.OnButtonPressed -= SelectPrevOption;
|
||||
}
|
||||
|
||||
public event Action<int> OnSelectedItemChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Sets new options list, automatically first will be selected.
|
||||
/// Sets new options list, automatically first will be selected.
|
||||
/// </summary>
|
||||
/// <param name="options">list of options names</param>
|
||||
public void SetOptions(List<string> options)
|
||||
@ -52,9 +39,9 @@ namespace NEG.UI.UnityUi
|
||||
|
||||
public void SelectNextOption() => ChangeOption(true);
|
||||
public void SelectPrevOption() => ChangeOption(false);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Selects option with provided id.
|
||||
/// Selects option with provided id.
|
||||
/// </summary>
|
||||
/// <param name="option">option number</param>
|
||||
public void SelectOption(int option)
|
||||
@ -64,15 +51,13 @@ namespace NEG.UI.UnityUi
|
||||
Debug.LogError("Invalid option number");
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentOptionId = option;
|
||||
CurrentOption = options[option];
|
||||
currentOptionText.text = CurrentOption;
|
||||
OnSelectedItemChanged?.Invoke(CurrentOptionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select option with provided value. Use with caution, better use <see cref="SelectOption(int)" />.
|
||||
/// Select option with provided value. Use with caution, better use <see cref="SelectOption(int)"/>.
|
||||
/// </summary>
|
||||
/// <param name="option">option value to select</param>
|
||||
public void SelectOption(string option)
|
||||
@ -89,11 +74,22 @@ namespace NEG.UI.UnityUi
|
||||
Debug.LogError($"Option {option} not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SelectOption(index);
|
||||
}
|
||||
|
||||
private void ChangeOption(bool next) =>
|
||||
SelectOption((CurrentOptionId + (next ? 1 : -1) + options.Count) % options.Count);
|
||||
private void Awake()
|
||||
{
|
||||
nextButton.OnButtonPressed += SelectNextOption;
|
||||
prevButton.OnButtonPressed += SelectPrevOption;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
nextButton.OnButtonPressed -= SelectNextOption;
|
||||
prevButton.OnButtonPressed -= SelectPrevOption;
|
||||
}
|
||||
|
||||
private void ChangeOption(bool next) => SelectOption((CurrentOptionId + (next ? 1 : -1) + options.Count) % options.Count);
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
using NEG.UI.UnityUi.Buttons;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace NEG.UI.UnityUi.Editor
|
||||
{
|
||||
public static class ButtonsExtensions
|
||||
{
|
||||
[MenuItem("CONTEXT/Button/Change To Navigation Button")]
|
||||
public static void ChangeScript(MenuCommand command)
|
||||
{
|
||||
if (command.context == null)
|
||||
return;
|
||||
|
||||
var button = command.context as Button;
|
||||
var go = new GameObject();
|
||||
var sourceScriptAsset = MonoScript.FromMonoBehaviour(go.AddComponent<CustomNavigationButton>());
|
||||
string relativePath = AssetDatabase.GetAssetPath(sourceScriptAsset);
|
||||
Object.DestroyImmediate(go);
|
||||
|
||||
var chosenTextAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(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(button);
|
||||
var scriptProperty = so.FindProperty("m_Script");
|
||||
so.Update();
|
||||
scriptProperty.objectReferenceValue = chosenTextAsset;
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b09e744f7ec6704c95ec273584a964f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user