Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Michsky.MUIP
{
public class WindowDragger : UIBehaviour, IBeginDragHandler, IDragHandler
{
[Header("Resources")]
public RectTransform dragArea;
public RectTransform dragObject;
[Header("Settings")]
public bool topOnDrag = true;
private Vector2 originalLocalPointerPosition;
private Vector3 originalPanelLocalPosition;
public new void Start()
{
if (dragArea == null)
{
try
{
var canvas = (Canvas)GameObject.FindObjectsOfType(typeof(Canvas))[0];
dragArea = canvas.GetComponent<RectTransform>();
}
catch { Debug.LogError("<b>[Movable Window]</b> Drag Area has not been assigned."); }
}
}
private RectTransform DragObjectInternal
{
get
{
if (dragObject == null) { return (transform as RectTransform); }
else { return dragObject; }
}
}
private RectTransform DragAreaInternal
{
get
{
if (dragArea == null)
{
RectTransform canvas = transform as RectTransform;
while (canvas.parent != null && canvas.parent is RectTransform) { canvas = canvas.parent as RectTransform; }
return canvas;
}
else { return dragArea; }
}
}
public void OnBeginDrag(PointerEventData data)
{
originalPanelLocalPosition = DragObjectInternal.localPosition;
RectTransformUtility.ScreenPointToLocalPointInRectangle(DragAreaInternal, data.position, data.pressEventCamera, out originalLocalPointerPosition);
gameObject.transform.SetAsLastSibling();
if (topOnDrag == true) { dragObject.transform.SetAsLastSibling(); }
}
public void OnDrag(PointerEventData data)
{
Vector2 localPointerPosition;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(DragAreaInternal, data.position, data.pressEventCamera, out localPointerPosition))
{
Vector3 offsetToOriginal = localPointerPosition - originalLocalPointerPosition;
DragObjectInternal.localPosition = originalPanelLocalPosition + offsetToOriginal;
}
ClampToArea();
}
private void ClampToArea()
{
Vector3 pos = DragObjectInternal.localPosition;
Vector3 minPosition = DragAreaInternal.rect.min - DragObjectInternal.rect.min;
Vector3 maxPosition = DragAreaInternal.rect.max - DragObjectInternal.rect.max;
pos.x = Mathf.Clamp(DragObjectInternal.localPosition.x, minPosition.x, maxPosition.x);
pos.y = Mathf.Clamp(DragObjectInternal.localPosition.y, minPosition.y, maxPosition.y);
DragObjectInternal.localPosition = pos;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7847a689c7721eb4dba4344e727ab715
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: f87b5805002ec9649bcb1b96d8a16ba9, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,383 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace Michsky.MUIP
{
public class WindowManager : MonoBehaviour
{
// Content
public List<WindowItem> windows = new List<WindowItem>();
// Settings
public int currentWindowIndex = 0;
private int currentButtonIndex = 0;
private int newWindowIndex;
public bool cullWindows = true;
public bool initializeButtons = true;
bool isInitialized = false;
// Events
[System.Serializable] public class WindowChangeEvent : UnityEvent<int> { }
public WindowChangeEvent onWindowChange;
// Hidden vars
private GameObject currentWindow;
private GameObject nextWindow;
private GameObject currentButton;
private GameObject nextButton;
private Animator currentWindowAnimator;
private Animator nextWindowAnimator;
private Animator currentButtonAnimator;
private Animator nextButtonAnimator;
// Animation states
string windowFadeIn = "In";
string windowFadeOut = "Out";
string buttonFadeIn = "Hover to Pressed";
string buttonFadeOut = "Pressed to Normal";
[System.Serializable]
public class WindowItem
{
public string windowName = "My Window";
public GameObject windowObject;
public GameObject buttonObject;
public GameObject firstSelected;
}
void Awake()
{
if (windows.Count == 0)
return;
InitializeWindows();
}
void OnEnable()
{
if (isInitialized == true && nextWindowAnimator == null)
{
currentWindowAnimator.Play(windowFadeIn);
if (currentButtonAnimator != null) { currentButtonAnimator.Play(buttonFadeIn); }
}
else if (isInitialized == true && nextWindowAnimator != null)
{
nextWindowAnimator.Play(windowFadeIn);
if (nextButtonAnimator != null) { nextButtonAnimator.Play(buttonFadeIn); }
}
}
public void InitializeWindows()
{
if (windows[currentWindowIndex].firstSelected != null) { EventSystem.current.firstSelectedGameObject = windows[currentWindowIndex].firstSelected; }
if (windows[currentWindowIndex].buttonObject != null)
{
currentButton = windows[currentWindowIndex].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeIn);
}
currentWindow = windows[currentWindowIndex].windowObject;
currentWindowAnimator = currentWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeIn);
onWindowChange.Invoke(currentWindowIndex);
isInitialized = true;
for (int i = 0; i < windows.Count; i++)
{
if (i != currentWindowIndex && cullWindows == true) { windows[i].windowObject.SetActive(false); }
if (windows[i].buttonObject != null && initializeButtons == true)
{
string tempName = windows[i].windowName;
ButtonManager tempButton = windows[i].buttonObject.GetComponent<ButtonManager>();
if (tempButton != null)
{
tempButton.onClick.RemoveAllListeners();
tempButton.onClick.AddListener(() => OpenPanel(tempName));
}
}
}
}
public void OpenFirstTab()
{
if (currentWindowIndex != 0)
{
currentWindow = windows[currentWindowIndex].windowObject;
currentWindowAnimator = currentWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeOut);
if (windows[currentWindowIndex].buttonObject != null)
{
currentButton = windows[currentWindowIndex].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeOut);
}
currentWindowIndex = 0;
currentButtonIndex = 0;
currentWindow = windows[currentWindowIndex].windowObject;
currentWindowAnimator = currentWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeIn);
if (windows[currentWindowIndex].firstSelected != null) { EventSystem.current.firstSelectedGameObject = windows[currentWindowIndex].firstSelected; }
if (windows[currentButtonIndex].buttonObject != null)
{
currentButton = windows[currentButtonIndex].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeIn);
}
onWindowChange.Invoke(currentWindowIndex);
}
else if (currentWindowIndex == 0)
{
currentWindow = windows[currentWindowIndex].windowObject;
currentWindowAnimator = currentWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeIn);
if (windows[currentWindowIndex].firstSelected != null) { EventSystem.current.firstSelectedGameObject = windows[currentWindowIndex].firstSelected; }
if (windows[currentButtonIndex].buttonObject != null)
{
currentButton = windows[currentButtonIndex].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeIn);
}
}
}
public void OpenWindow(string newWindow)
{
for (int i = 0; i < windows.Count; i++)
{
if (windows[i].windowName == newWindow)
{
newWindowIndex = i;
break;
}
}
if (newWindowIndex != currentWindowIndex)
{
if (cullWindows == true)
StopCoroutine("DisablePreviousWindow");
currentWindow = windows[currentWindowIndex].windowObject;
if (windows[currentWindowIndex].buttonObject != null)
currentButton = windows[currentWindowIndex].buttonObject;
currentWindowIndex = newWindowIndex;
nextWindow = windows[currentWindowIndex].windowObject;
nextWindow.SetActive(true);
currentWindowAnimator = currentWindow.GetComponent<Animator>();
nextWindowAnimator = nextWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeOut);
nextWindowAnimator.Play(windowFadeIn);
if (cullWindows == true)
StartCoroutine("DisablePreviousWindow");
currentButtonIndex = newWindowIndex;
if (windows[currentWindowIndex].firstSelected != null) { EventSystem.current.firstSelectedGameObject = windows[currentWindowIndex].firstSelected; }
if (windows[currentButtonIndex].buttonObject != null)
{
nextButton = windows[currentButtonIndex].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
nextButtonAnimator = nextButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeOut);
nextButtonAnimator.Play(buttonFadeIn);
}
onWindowChange.Invoke(currentWindowIndex);
}
}
// Old method
public void OpenPanel(string newPanel)
{
OpenWindow(newPanel);
}
public void OpenWindowByIndex(int windowIndex)
{
for (int i = 0; i < windows.Count; i++)
{
if (windows[i].windowName == windows[windowIndex].windowName)
{
OpenWindow(windows[windowIndex].windowName);
break;
}
}
}
public void NextWindow()
{
if (currentWindowIndex <= windows.Count - 2)
{
if (cullWindows == true)
StopCoroutine("DisablePreviousWindow");
currentWindow = windows[currentWindowIndex].windowObject;
currentWindow.gameObject.SetActive(true);
if (windows[currentButtonIndex].buttonObject != null)
{
currentButton = windows[currentButtonIndex].buttonObject;
nextButton = windows[currentButtonIndex + 1].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeOut);
}
currentWindowAnimator = currentWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeOut);
currentWindowIndex += 1;
currentButtonIndex += 1;
nextWindow = windows[currentWindowIndex].windowObject;
nextWindow.gameObject.SetActive(true);
nextWindowAnimator = nextWindow.GetComponent<Animator>();
nextWindowAnimator.Play(windowFadeIn);
if (cullWindows == true) { StartCoroutine("DisablePreviousWindow"); }
if (windows[currentWindowIndex].firstSelected != null) { EventSystem.current.firstSelectedGameObject = windows[currentWindowIndex].firstSelected; }
if (nextButton != null)
{
nextButtonAnimator = nextButton.GetComponent<Animator>();
nextButtonAnimator.Play(buttonFadeIn);
}
onWindowChange.Invoke(currentWindowIndex);
}
}
public void PrevWindow()
{
if (currentWindowIndex >= 1)
{
if (cullWindows == true)
StopCoroutine("DisablePreviousWindow");
currentWindow = windows[currentWindowIndex].windowObject;
currentWindow.gameObject.SetActive(true);
if (windows[currentButtonIndex].buttonObject != null)
{
currentButton = windows[currentButtonIndex].buttonObject;
nextButton = windows[currentButtonIndex - 1].buttonObject;
currentButtonAnimator = currentButton.GetComponent<Animator>();
currentButtonAnimator.Play(buttonFadeOut);
}
currentWindowAnimator = currentWindow.GetComponent<Animator>();
currentWindowAnimator.Play(windowFadeOut);
currentWindowIndex -= 1;
currentButtonIndex -= 1;
nextWindow = windows[currentWindowIndex].windowObject;
nextWindow.gameObject.SetActive(true);
nextWindowAnimator = nextWindow.GetComponent<Animator>();
nextWindowAnimator.Play(windowFadeIn);
if (cullWindows == true) { StartCoroutine("DisablePreviousWindow"); }
if (windows[currentWindowIndex].firstSelected != null) { EventSystem.current.firstSelectedGameObject = windows[currentWindowIndex].firstSelected; }
if (nextButton != null)
{
nextButtonAnimator = nextButton.GetComponent<Animator>();
nextButtonAnimator.Play(buttonFadeIn);
}
onWindowChange.Invoke(currentWindowIndex);
}
}
public void ShowCurrentWindow()
{
if (nextWindowAnimator == null) { currentWindowAnimator.Play(windowFadeIn); }
else { nextWindowAnimator.Play(windowFadeIn); }
}
public void HideCurrentWindow()
{
if (nextWindowAnimator == null) { currentWindowAnimator.Play(windowFadeOut); }
else { nextWindowAnimator.Play(windowFadeOut); }
}
public void ShowCurrentButton()
{
if (nextButtonAnimator == null) { currentButtonAnimator.Play(buttonFadeIn); }
else { nextButtonAnimator.Play(buttonFadeIn); }
}
public void HideCurrentButton()
{
if (nextButtonAnimator == null) { currentButtonAnimator.Play(buttonFadeOut); }
else { nextButtonAnimator.Play(buttonFadeOut); }
}
public void AddNewItem()
{
WindowItem window = new WindowItem();
if (windows.Count != 0 && windows[windows.Count - 1].windowObject != null)
{
int tempIndex = windows.Count - 1;
GameObject tempWindow = windows[tempIndex].windowObject.transform.parent.GetChild(tempIndex).gameObject;
GameObject newWindow = Instantiate(tempWindow, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
newWindow.transform.SetParent(windows[tempIndex].windowObject.transform.parent, false);
newWindow.gameObject.name = "New Window " + tempIndex.ToString();
window.windowName = "New Window " + tempIndex.ToString();
window.windowObject = newWindow;
if (windows[tempIndex].buttonObject != null)
{
GameObject tempButton = windows[tempIndex].buttonObject.transform.parent.GetChild(tempIndex).gameObject;
GameObject newButton = Instantiate(tempButton, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
newButton.transform.SetParent(windows[tempIndex].buttonObject.transform.parent, false);
newButton.gameObject.name = "New Window " + tempIndex.ToString();
window.buttonObject = newButton;
}
}
windows.Add(window);
}
IEnumerator DisablePreviousWindow()
{
yield return new WaitForSeconds(0.4f);
for (int i = 0; i < windows.Count; i++)
{
if (i == currentWindowIndex)
continue;
windows[i].windowObject.SetActive(false);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71a9c3d7f141d6240b6653d5c02f9462
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6cf11c0849502024eaa15de7d842e9f4, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Michsky.MUIP
{
[RequireComponent(typeof(Animator))]
public class WindowManagerButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public bool enableMobileMode = false;
[HideInInspector] public Animator buttonAnimator;
void Awake()
{
if (buttonAnimator == null) { buttonAnimator = gameObject.GetComponent<Animator>(); }
if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) { enableMobileMode = true; }
}
public void OnPointerEnter(PointerEventData eventData)
{
if (enableMobileMode == true)
return;
if (!buttonAnimator.GetCurrentAnimatorStateInfo(0).IsName("Hover to Pressed")
&& !buttonAnimator.GetCurrentAnimatorStateInfo(0).IsName("Normal to Pressed"))
buttonAnimator.Play("Normal to Hover");
}
public void OnPointerExit(PointerEventData eventData)
{
if (enableMobileMode == true)
return;
if (!buttonAnimator.GetCurrentAnimatorStateInfo(0).IsName("Hover to Pressed")
&& !buttonAnimator.GetCurrentAnimatorStateInfo(0).IsName("Normal to Pressed"))
buttonAnimator.Play("Hover to Normal");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c84a94b099bc62645a689ebb5655db16
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 98d001ce6b3b53242911dcc3d1415f59, type: 3}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,138 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
namespace Michsky.MUIP
{
[CustomEditor(typeof(WindowManager))]
public class WindowManagerEditor : Editor
{
private GUISkin customSkin;
private WindowManager wmTarget;
private UIManagerWindowManager tempUIM;
private int currentTab;
private void OnEnable()
{
wmTarget = (WindowManager)target;
try { tempUIM = wmTarget.GetComponent<UIManagerWindowManager>(); }
catch { }
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
MUIPEditorHandler.DrawComponentHeader(customSkin, "WM Top Header");
GUIContent[] toolbarTabs = new GUIContent[2];
toolbarTabs[0] = new GUIContent("Content");
toolbarTabs[1] = new GUIContent("Settings");
currentTab = MUIPEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
currentTab = 0;
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
currentTab = 1;
GUILayout.EndHorizontal();
var windows = serializedObject.FindProperty("windows");
var currentWindowIndex = serializedObject.FindProperty("currentWindowIndex");
var cullWindows = serializedObject.FindProperty("cullWindows");
var onWindowChange = serializedObject.FindProperty("onWindowChange");
var initializeButtons = serializedObject.FindProperty("initializeButtons");
switch (currentTab)
{
case 0:
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
if (wmTarget.windows.Count != 0)
{
if (Application.isPlaying == true) { GUI.enabled = false; }
GUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.LabelField(new GUIContent("Selected Window:"), customSkin.FindStyle("Text"), GUILayout.Width(120));
currentWindowIndex.intValue = EditorGUILayout.IntSlider(currentWindowIndex.intValue, 0, wmTarget.windows.Count - 1);
GUILayout.Space(2);
EditorGUILayout.LabelField(new GUIContent(wmTarget.windows[currentWindowIndex.intValue].windowName), customSkin.FindStyle("Text"));
if (Application.isPlaying == false && wmTarget.windows[currentWindowIndex.intValue].windowObject != null)
{
for (int i = 0; i < wmTarget.windows.Count; i++)
{
if (i == currentWindowIndex.intValue)
{
var tempCG = wmTarget.windows[currentWindowIndex.intValue].windowObject.GetComponent<CanvasGroup>();
if (tempCG != null) { tempCG.alpha = 1; }
}
else if (wmTarget.windows[i].windowObject != null)
{
var tempCG = wmTarget.windows[i].windowObject.GetComponent<CanvasGroup>();
if (tempCG != null) { tempCG.alpha = 0; }
}
}
}
GUI.enabled = true;
GUILayout.EndVertical();
}
else { EditorGUILayout.HelpBox("Window List is empty. Create a new item to see more options.", MessageType.Info); }
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(windows, new GUIContent("Window Items"), true);
if (GUILayout.Button("+ Add a new window", customSkin.button))
wmTarget.AddNewItem();
GUILayout.EndVertical();
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
EditorGUILayout.PropertyField(onWindowChange, new GUIContent("On Window Change"), true);
break;
case 1:
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
cullWindows.boolValue = MUIPEditorHandler.DrawToggle(cullWindows.boolValue, customSkin, "Cull Transparent Windows");
initializeButtons.boolValue = MUIPEditorHandler.DrawToggle(initializeButtons.boolValue, customSkin, "Initialize Buttons");
MUIPEditorHandler.DrawHeader(customSkin, "UIM Header", 10);
if (tempUIM != null)
{
MUIPEditorHandler.DrawUIManagerConnectedHeader();
if (GUILayout.Button("Open UI Manager", customSkin.button))
EditorApplication.ExecuteMenuItem("Tools/Modern UI Pack/Show UI Manager");
if (GUILayout.Button("Disable UI Manager Connection", customSkin.button))
{
if (EditorUtility.DisplayDialog("Modern UI Pack", "Are you sure you want to disable UI Manager connection with the object? " +
"This operation cannot be undone.", "Yes", "Cancel"))
{
try { DestroyImmediate(tempUIM); }
catch { Debug.LogError("<b>[Window Manager]</b> Failed to delete UI Manager connection.", this); }
}
}
}
else if (tempUIM == null) { MUIPEditorHandler.DrawUIManagerDisconnectedHeader(); }
break;
}
if (Application.isPlaying == false) { this.Repaint(); }
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

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