more functions

This commit is contained in:
Hubert Mattusch 2023-01-27 15:31:25 +01:00
parent 266d199b48
commit 7bbc03cdbf
18 changed files with 196 additions and 39 deletions

View File

@ -0,0 +1,30 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
namespace NEG.Utils.Editor.ComponentsAdditionalItems
{
public static class CanvasScalerDefault
{
[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 );
[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);
private static void SetComponent(MenuCommand command, int width, int height)
{
var scaler = (CanvasScaler)command.context;
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
scaler.matchWidthOrHeight = width > height ? 1f : 0f;
scaler.referenceResolution = new Vector2(width, height);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c7ddebddb1a1c1947be05ac9e96aceb8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,23 +5,8 @@ using NEG.UI.WindowSlot;
namespace NEG.UI.Area
{
public interface IArea : IUiElement
public interface IArea : ISlotsHolder, IUiElement
{
IEnumerable<IWindowSlot> AvailableSlots { get; }
/// <summary>
/// Open window
/// </summary>
/// <param name="window"></param>
/// <param name="data"></param>
void OpenWindow(IWindow window, object data = null);
void CloseAllWindows()
{
foreach (var slot in AvailableSlots)
{
slot.CloseAllWindows();
}
}
void OpenChildWindow(IWindow window, object data = null);
}
}

View File

@ -742,7 +742,7 @@ namespace System.Collections.Generic
int parentIndex = GetParentIndex(nodeIndex);
var parent = nodes[parentIndex];
if (comparer.Compare(node.Priority, parent.Priority) < 0)
if (comparer != null && comparer.Compare(node.Priority, parent.Priority) < 0)
{
nodes[nodeIndex] = parent;
nodeIndex = parentIndex;
@ -828,7 +828,7 @@ namespace System.Collections.Generic
while (++i < childIndexUpperBound)
{
var nextChild = nodes[i];
if (comparer.Compare(nextChild.Priority, minChild.Priority) < 0)
if (comparer != null && comparer.Compare(nextChild.Priority, minChild.Priority) < 0)
{
minChild = nextChild;
minChildIndex = i;
@ -836,7 +836,7 @@ namespace System.Collections.Generic
}
// Heap property is satisfied; insert node in this location.
if (comparer.Compare(node.Priority, minChild.Priority) <= 0) break;
if (comparer != null && comparer.Compare(node.Priority, minChild.Priority) <= 0) break;
// Move the minimal child up by one node and continue recursively from its location.
nodes[nodeIndex] = minChild;

View File

@ -0,0 +1,14 @@
using NEG.UI.UnityUi.Window;
using NEG.UI.Window;
using System;
using UnityEngine;
namespace NEG.UI.Area
{
public class AutoWindowOpen : MonoBehaviour
{
[SerializeField] private MonoWindow window;
private void Start() => window.Open();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e439a77332dc4e3a881348c9506556c6
timeCreated: 1673791915

View File

@ -1,6 +1,7 @@
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;
@ -21,6 +22,14 @@ namespace NEG.UI.Area
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
public void OpenChildWindow(IWindow window, object data = null)
{
foreach (var slot in AvailableSlots)
{
}
}
public virtual void OpenWindow(IWindow window, object data = null)
{
DefaultWindowSlot.AttachWindow(window);

View File

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace NEG.UI.UnityUi.Buttons
{
[RequireComponent(typeof(BaseButton))]
public class ChangeSceneButton : MonoBehaviour
{
[Header("Leave empty to use int value")]
[SerializeField] private string sceneName;
[SerializeField] private int sceneIndex;
private void Awake() => GetComponent<BaseButton>().OnButtonPressed += OnClicked;
private void OnClicked()
{
if (string.IsNullOrEmpty(sceneName))
SceneManager.LoadScene(sceneIndex);
else
SceneManager.LoadScene(sceneName);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 15537f041c9c1204ebf05a5fb7ff6a3d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using NEG.UI.UnityUi.Window;
using NEG.UI.Window;
using UnityEngine;
using UnityEngine.EventSystems;
namespace NEG.UI.UnityUi.Buttons
{
public class CloseWindowOnImageTouch : MonoBehaviour, IPointerDownHandler
{
[SerializeField] private MonoWindow windowToClose;
public void OnPointerDown(PointerEventData eventData) => windowToClose.Close();
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dc1aab636014456da7f768a05d0f143e
timeCreated: 1673909580

View File

@ -7,7 +7,8 @@
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:0c752da273b17c547ae705acf0f2adf2",
"GUID:9e24947de15b9834991c9d8411ea37cf",
"GUID:84651a3751eca9349aac36a66bba901b"
"GUID:84651a3751eca9349aac36a66bba901b",
"GUID:23eed6c2401dca1419d1ebd180e58c5a"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -3,6 +3,7 @@ using NEG.UI.UnityUi.WindowSlot;
using NEG.UI.Window;
using NEG.UI.WindowSlot;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NEG.UI.UnityUi.Window
@ -44,5 +45,8 @@ namespace NEG.UI.UnityUi.Window
if (controller == null)
controller = GetComponent<WindowController>();
}
public IEnumerable<IWindowSlot> AvailableSlots { get; }
public void OpenWindow(IWindow window, object data = null) => throw new NotImplementedException();
}
}

View File

@ -2,14 +2,20 @@
using NEG.UI.Window;
using NEG.UI.WindowSlot;
using UnityEngine;
using TNRD;
namespace NEG.UI.UnityUi.WindowSlot
{
public abstract class MonoWindowSlot : MonoBehaviour, IWindowSlot
{
public IArea ParentArea { get; private set; }
[field: SerializeField] public bool OpenWindowAsMain { get; private set; }
public ISlotsHolder ParentHolder => slotsHolder.Value;
public abstract void AttachWindow(IWindow window);
public abstract void DetachWindow(IWindow window);
public abstract void CloseAllWindows();
[SerializeField] private SerializableInterface<ISlotsHolder> slotsHolder;
}
}

View File

@ -5,10 +5,9 @@ using UnityEngine;
namespace NEG.UI.Window
{
public interface IWindow
public interface IWindow : ISlotsHolder
{
IWindowSlot Parent { get; }
IWindowSlot ChildWindowSlot { get; }
/// <summary>
/// Called internally by slot to open window.
@ -33,20 +32,32 @@ namespace NEG.UI.Window
{
slot.AttachWindow(window);
window.SetData(data);
}
else
UiManager.Instance.CurrentArea.OpenWindow(window, data);
}
public static void Open(this IWindow window, IArea area, object data = null) => area.OpenWindow(window, data);
public static void OpenChildWindow(this IWindow window, IWindow windowToOpen, object data = null)
{
if (window.ChildWindowSlot == null)
{
Debug.LogError("This window doesn't contain area for child windows");
return;
}
//TODO: DO it
//window.ChildWindowArea.OpenWindow(windowToOpen, slot);
UiManager.Instance.CurrentArea.OpenWindow(window, data);
}
public static void Open(this IWindow window, IArea area, object data = null) => area.OpenWindow(window, data);
public static void OpenChild(this IWindow window, IWindow windowToOpen, object data = null)
{
if (windowToOpen == null)
{
Debug.LogError($"Window to open cannot be null");
return;
}
window.OpenWindow(windowToOpen, data);
}
public static void OpenAsChild(this IWindow window, IWindow parentWindow = null, object data = null)
{
if (parentWindow != null)
{
parentWindow.OpenWindow(window);
return;
}
UiManager.Instance.CurrentArea.OpenChildWindow(window, data);
}
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);

View File

@ -0,0 +1,25 @@
using NEG.UI.Window;
using System.Collections.Generic;
namespace NEG.UI.WindowSlot
{
public interface ISlotsHolder
{
IEnumerable<IWindowSlot> AvailableSlots { get; }
/// <summary>
/// Open window
/// </summary>
/// <param name="window"></param>
/// <param name="data"></param>
void OpenWindow(IWindow window, object data = null);
void CloseAllWindows()
{
foreach (var slot in AvailableSlots)
{
slot.CloseAllWindows();
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ace3899aabb0491d80f8b17bd827854b
timeCreated: 1674408955

View File

@ -5,7 +5,8 @@ namespace NEG.UI.WindowSlot
{
public interface IWindowSlot
{
IArea ParentArea { get; }
bool OpenWindowAsMain { get; }
ISlotsHolder ParentHolder { get; }
void AttachWindow(IWindow window);
void DetachWindow(IWindow window);
void CloseAllWindows();