more functions
This commit is contained in:
parent
266d199b48
commit
7bbc03cdbf
30
Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs
Normal file
30
Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs.meta
Normal file
11
Editor/ComponentsAdditionalItems/CanvasScalerDefault.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c7ddebddb1a1c1947be05ac9e96aceb8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -5,23 +5,8 @@ using NEG.UI.WindowSlot;
|
|||||||
|
|
||||||
namespace NEG.UI.Area
|
namespace NEG.UI.Area
|
||||||
{
|
{
|
||||||
public interface IArea : IUiElement
|
public interface IArea : ISlotsHolder, IUiElement
|
||||||
{
|
{
|
||||||
IEnumerable<IWindowSlot> AvailableSlots { get; }
|
void OpenChildWindow(IWindow window, object data = null);
|
||||||
|
|
||||||
/// <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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -742,7 +742,7 @@ namespace System.Collections.Generic
|
|||||||
int parentIndex = GetParentIndex(nodeIndex);
|
int parentIndex = GetParentIndex(nodeIndex);
|
||||||
var parent = nodes[parentIndex];
|
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;
|
nodes[nodeIndex] = parent;
|
||||||
nodeIndex = parentIndex;
|
nodeIndex = parentIndex;
|
||||||
@ -828,7 +828,7 @@ namespace System.Collections.Generic
|
|||||||
while (++i < childIndexUpperBound)
|
while (++i < childIndexUpperBound)
|
||||||
{
|
{
|
||||||
var nextChild = nodes[i];
|
var nextChild = nodes[i];
|
||||||
if (comparer.Compare(nextChild.Priority, minChild.Priority) < 0)
|
if (comparer != null && comparer.Compare(nextChild.Priority, minChild.Priority) < 0)
|
||||||
{
|
{
|
||||||
minChild = nextChild;
|
minChild = nextChild;
|
||||||
minChildIndex = i;
|
minChildIndex = i;
|
||||||
@ -836,7 +836,7 @@ namespace System.Collections.Generic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Heap property is satisfied; insert node in this location.
|
// 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.
|
// Move the minimal child up by one node and continue recursively from its location.
|
||||||
nodes[nodeIndex] = minChild;
|
nodes[nodeIndex] = minChild;
|
||||||
|
|||||||
14
NEG/UI/UnityUi/Area/AutoWindowOpen.cs
Normal file
14
NEG/UI/UnityUi/Area/AutoWindowOpen.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
3
NEG/UI/UnityUi/Area/AutoWindowOpen.cs.meta
Normal file
3
NEG/UI/UnityUi/Area/AutoWindowOpen.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e439a77332dc4e3a881348c9506556c6
|
||||||
|
timeCreated: 1673791915
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using NEG.UI.Popup;
|
using NEG.UI.Popup;
|
||||||
|
using NEG.UI.UnityUi.Window;
|
||||||
using NEG.UI.UnityUi.WindowSlot;
|
using NEG.UI.UnityUi.WindowSlot;
|
||||||
using NEG.UI.Window;
|
using NEG.UI.Window;
|
||||||
using NEG.UI.WindowSlot;
|
using NEG.UI.WindowSlot;
|
||||||
@ -17,10 +18,18 @@ namespace NEG.UI.Area
|
|||||||
|
|
||||||
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
[SerializeField] private List<MonoWindowSlot> windowSlots;
|
||||||
|
|
||||||
[SerializeField] private Queue<IPopup> currentPopups = new();
|
[SerializeField] private Queue<IPopup> currentPopups = new();
|
||||||
|
|
||||||
public virtual void SetEnabled(bool setEnabled) => gameObject.SetActive(setEnabled);
|
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)
|
public virtual void OpenWindow(IWindow window, object data = null)
|
||||||
{
|
{
|
||||||
DefaultWindowSlot.AttachWindow(window);
|
DefaultWindowSlot.AttachWindow(window);
|
||||||
|
|||||||
26
NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs
Normal file
26
NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs.meta
Normal file
11
NEG/UI/UnityUi/Buttons/ChangeSceneButton.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 15537f041c9c1204ebf05a5fb7ff6a3d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
14
NEG/UI/UnityUi/Buttons/CloseWindowOnImageTouch.cs
Normal file
14
NEG/UI/UnityUi/Buttons/CloseWindowOnImageTouch.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
3
NEG/UI/UnityUi/Buttons/CloseWindowOnImageTouch.cs.meta
Normal file
3
NEG/UI/UnityUi/Buttons/CloseWindowOnImageTouch.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dc1aab636014456da7f768a05d0f143e
|
||||||
|
timeCreated: 1673909580
|
||||||
@ -7,7 +7,8 @@
|
|||||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||||
"GUID:0c752da273b17c547ae705acf0f2adf2",
|
"GUID:0c752da273b17c547ae705acf0f2adf2",
|
||||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||||
"GUID:84651a3751eca9349aac36a66bba901b"
|
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||||
|
"GUID:23eed6c2401dca1419d1ebd180e58c5a"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using NEG.UI.UnityUi.WindowSlot;
|
|||||||
using NEG.UI.Window;
|
using NEG.UI.Window;
|
||||||
using NEG.UI.WindowSlot;
|
using NEG.UI.WindowSlot;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NEG.UI.UnityUi.Window
|
namespace NEG.UI.UnityUi.Window
|
||||||
@ -44,5 +45,8 @@ namespace NEG.UI.UnityUi.Window
|
|||||||
if (controller == null)
|
if (controller == null)
|
||||||
controller = GetComponent<WindowController>();
|
controller = GetComponent<WindowController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IWindowSlot> AvailableSlots { get; }
|
||||||
|
public void OpenWindow(IWindow window, object data = null) => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,14 +2,20 @@
|
|||||||
using NEG.UI.Window;
|
using NEG.UI.Window;
|
||||||
using NEG.UI.WindowSlot;
|
using NEG.UI.WindowSlot;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using TNRD;
|
||||||
|
|
||||||
namespace NEG.UI.UnityUi.WindowSlot
|
namespace NEG.UI.UnityUi.WindowSlot
|
||||||
{
|
{
|
||||||
public abstract class MonoWindowSlot : MonoBehaviour, IWindowSlot
|
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 AttachWindow(IWindow window);
|
||||||
public abstract void DetachWindow(IWindow window);
|
public abstract void DetachWindow(IWindow window);
|
||||||
public abstract void CloseAllWindows();
|
public abstract void CloseAllWindows();
|
||||||
|
|
||||||
|
[SerializeField] private SerializableInterface<ISlotsHolder> slotsHolder;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,11 +5,10 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace NEG.UI.Window
|
namespace NEG.UI.Window
|
||||||
{
|
{
|
||||||
public interface IWindow
|
public interface IWindow : ISlotsHolder
|
||||||
{
|
{
|
||||||
IWindowSlot Parent { get; }
|
IWindowSlot Parent { get; }
|
||||||
IWindowSlot ChildWindowSlot { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called internally by slot to open window.
|
/// Called internally by slot to open window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,20 +32,32 @@ namespace NEG.UI.Window
|
|||||||
{
|
{
|
||||||
slot.AttachWindow(window);
|
slot.AttachWindow(window);
|
||||||
window.SetData(data);
|
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;
|
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);
|
public static void Close(this IWindow window) => window.Parent.DetachWindow(window);
|
||||||
|
|||||||
25
NEG/UI/WindowSlot/ISlotsHolder.cs
Normal file
25
NEG/UI/WindowSlot/ISlotsHolder.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
NEG/UI/WindowSlot/ISlotsHolder.cs.meta
Normal file
3
NEG/UI/WindowSlot/ISlotsHolder.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ace3899aabb0491d80f8b17bd827854b
|
||||||
|
timeCreated: 1674408955
|
||||||
@ -5,7 +5,8 @@ namespace NEG.UI.WindowSlot
|
|||||||
{
|
{
|
||||||
public interface IWindowSlot
|
public interface IWindowSlot
|
||||||
{
|
{
|
||||||
IArea ParentArea { get; }
|
bool OpenWindowAsMain { get; }
|
||||||
|
ISlotsHolder ParentHolder { get; }
|
||||||
void AttachWindow(IWindow window);
|
void AttachWindow(IWindow window);
|
||||||
void DetachWindow(IWindow window);
|
void DetachWindow(IWindow window);
|
||||||
void CloseAllWindows();
|
void CloseAllWindows();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user