基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class NotificationManager : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
// Content
|
||||
public Sprite icon;
|
||||
public string title = "Notification Title";
|
||||
[TextArea(1, 4)] public string description = "Notification description";
|
||||
|
||||
// Resources
|
||||
public Animator notificationAnimator;
|
||||
public Image iconObj;
|
||||
public TextMeshProUGUI titleObj;
|
||||
public TextMeshProUGUI descriptionObj;
|
||||
|
||||
// Settings
|
||||
public bool enableTimer = true;
|
||||
public float timer = 3f;
|
||||
[SerializeField] private bool useCustomContent = false;
|
||||
public bool closeOnClick = false;
|
||||
public bool useStacking = false;
|
||||
[HideInInspector] public bool isOn;
|
||||
public StartBehaviour startBehaviour = StartBehaviour.Disable;
|
||||
public CloseBehaviour closeBehaviour = CloseBehaviour.Disable;
|
||||
public SlideDirection slideDirection = SlideDirection.Default;
|
||||
|
||||
// Events
|
||||
public UnityEvent onOpen = new UnityEvent();
|
||||
public UnityEvent onClose = new UnityEvent();
|
||||
|
||||
public enum StartBehaviour { None, Disable, Open }
|
||||
public enum CloseBehaviour { None, Disable, Destroy }
|
||||
public enum SlideDirection { Default, Left, Right }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
isOn = false;
|
||||
|
||||
if (!useCustomContent) { UpdateUI(); }
|
||||
if (notificationAnimator == null) { notificationAnimator = gameObject.GetComponent<Animator>(); }
|
||||
if (useStacking)
|
||||
{
|
||||
try { transform.GetComponentInParent<NotificationStacking>().AddToStack(this); }
|
||||
catch { Debug.LogError("<b>[Notification]</b> 'Stacking' is enabled but 'Notification Stacking' cannot be found in parent.", this); }
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (startBehaviour == StartBehaviour.Disable) { gameObject.SetActive(false); }
|
||||
else if (startBehaviour == StartBehaviour.Open) { Open(); }
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
if (isOn)
|
||||
return;
|
||||
|
||||
gameObject.SetActive(true);
|
||||
isOn = true;
|
||||
|
||||
StopCoroutine("StartTimer");
|
||||
StopCoroutine("DisableNotification");
|
||||
|
||||
notificationAnimator.Play("In");
|
||||
onOpen.Invoke();
|
||||
|
||||
if (enableTimer)
|
||||
{
|
||||
StartCoroutine("StartTimer");
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
isOn = false;
|
||||
notificationAnimator.Play("Out");
|
||||
onClose.Invoke();
|
||||
|
||||
StopCoroutine("StartTimer");
|
||||
StopCoroutine("DisableNotification");
|
||||
StartCoroutine("DisableNotification");
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
public void OpenNotification() { Open(); }
|
||||
public void CloseNotification() { Close(); }
|
||||
#endregion
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (iconObj != null) { iconObj.sprite = icon; }
|
||||
if (titleObj != null) { titleObj.text = title; }
|
||||
if (descriptionObj != null) { descriptionObj.text = description; }
|
||||
|
||||
if (slideDirection == SlideDirection.Left)
|
||||
{
|
||||
transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
|
||||
transform.GetChild(0).transform.localScale = new Vector3(-1, transform.GetChild(0).transform.localScale.y, transform.GetChild(0).transform.localScale.z);
|
||||
}
|
||||
|
||||
else if (slideDirection == SlideDirection.Right)
|
||||
{
|
||||
transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
|
||||
transform.GetChild(0).transform.localScale = new Vector3(1, transform.GetChild(0).transform.localScale.y, transform.GetChild(0).transform.localScale.z);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!closeOnClick)
|
||||
return;
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
IEnumerator StartTimer()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(timer);
|
||||
Close();
|
||||
}
|
||||
|
||||
IEnumerator DisableNotification()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
|
||||
if (closeBehaviour == CloseBehaviour.Disable) { gameObject.SetActive(false); isOn = false; }
|
||||
else if (closeBehaviour == CloseBehaviour.Destroy) { Destroy(gameObject); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b4bbdcf873a4164eabf85f0d7820717
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: adf3c8361dd31e1448483775ea241c10, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Notification/NotificationManager.cs
|
||||
uploadId: 628721
|
||||
@@ -0,0 +1,195 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[CustomEditor(typeof(NotificationManager))]
|
||||
public class NotificationManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private NotificationManager ntfTarget;
|
||||
private UIManagerNotification tempUIM;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ntfTarget = (NotificationManager)target;
|
||||
|
||||
try { tempUIM = ntfTarget.GetComponent<UIManagerNotification>(); }
|
||||
catch { }
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = MUIPEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = MUIPEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
MUIPEditorHandler.DrawComponentHeader(customSkin, "Notification Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = 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("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var icon = serializedObject.FindProperty("icon");
|
||||
var title = serializedObject.FindProperty("title");
|
||||
var description = serializedObject.FindProperty("description");
|
||||
var notificationAnimator = serializedObject.FindProperty("notificationAnimator");
|
||||
var iconObj = serializedObject.FindProperty("iconObj");
|
||||
var titleObj = serializedObject.FindProperty("titleObj");
|
||||
var descriptionObj = serializedObject.FindProperty("descriptionObj");
|
||||
var enableTimer = serializedObject.FindProperty("enableTimer");
|
||||
var timer = serializedObject.FindProperty("timer");
|
||||
var useCustomContent = serializedObject.FindProperty("useCustomContent");
|
||||
var closeOnClick = serializedObject.FindProperty("closeOnClick");
|
||||
var useStacking = serializedObject.FindProperty("useStacking");
|
||||
var closeBehaviour = serializedObject.FindProperty("closeBehaviour");
|
||||
var startBehaviour = serializedObject.FindProperty("startBehaviour");
|
||||
var slideDirection = serializedObject.FindProperty("slideDirection");
|
||||
var onOpen = serializedObject.FindProperty("onOpen");
|
||||
var onClose = serializedObject.FindProperty("onClose");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(icon, customSkin, "Icon");
|
||||
|
||||
if (ntfTarget.iconObj != null)
|
||||
ntfTarget.iconObj.sprite = ntfTarget.icon;
|
||||
|
||||
else
|
||||
{
|
||||
if (ntfTarget.iconObj == null)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("'Icon Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
MUIPEditorHandler.DrawProperty(title, customSkin, "Title");
|
||||
|
||||
if (ntfTarget.titleObj != null)
|
||||
ntfTarget.titleObj.text = title.stringValue;
|
||||
|
||||
else
|
||||
{
|
||||
if (ntfTarget.titleObj == null)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("'Title Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Description"), customSkin.FindStyle("Text"), GUILayout.Width(-3));
|
||||
EditorGUILayout.PropertyField(description, new GUIContent(""));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (ntfTarget.descriptionObj != null)
|
||||
ntfTarget.descriptionObj.text = description.stringValue;
|
||||
|
||||
else
|
||||
{
|
||||
if (ntfTarget.descriptionObj == null)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("'Description Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
if (ntfTarget.GetComponent<CanvasGroup>().alpha == 0)
|
||||
{
|
||||
if (GUILayout.Button("Set Visible", customSkin.button))
|
||||
{
|
||||
ntfTarget.GetComponent<CanvasGroup>().alpha = 1;
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Set Invisible", customSkin.button))
|
||||
{
|
||||
ntfTarget.GetComponent<CanvasGroup>().alpha = 0;
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
}
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onOpen, new GUIContent("On Open"), true);
|
||||
EditorGUILayout.PropertyField(onClose, new GUIContent("On Close"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(notificationAnimator, customSkin, "Animator");
|
||||
MUIPEditorHandler.DrawProperty(iconObj, customSkin, "Icon Object");
|
||||
MUIPEditorHandler.DrawProperty(titleObj, customSkin, "Title Object");
|
||||
MUIPEditorHandler.DrawProperty(descriptionObj, customSkin, "Description Object");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
MUIPEditorHandler.DrawProperty(startBehaviour, customSkin, "Start Behaviour");
|
||||
MUIPEditorHandler.DrawProperty(closeBehaviour, customSkin, "Close Behaviour");
|
||||
MUIPEditorHandler.DrawProperty(slideDirection, customSkin, "Slide Direction");
|
||||
useCustomContent.boolValue = MUIPEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content");
|
||||
closeOnClick.boolValue = MUIPEditorHandler.DrawToggle(closeOnClick.boolValue, customSkin, "Close On Click");
|
||||
useStacking.boolValue = MUIPEditorHandler.DrawToggle(useStacking.boolValue, customSkin, "Use Stacking");
|
||||
enableTimer.boolValue = MUIPEditorHandler.DrawToggle(enableTimer.boolValue, customSkin, "Enable Timer");
|
||||
|
||||
if (enableTimer.boolValue == true)
|
||||
MUIPEditorHandler.DrawProperty(timer, customSkin, "Timer");
|
||||
|
||||
MUIPEditorHandler.DrawHeader(customSkin, "UIM Header", 10);
|
||||
|
||||
if (tempUIM != null)
|
||||
{
|
||||
MUIPEditorHandler.DrawUIManagerConnectedHeader();
|
||||
tempUIM.overrideColors = MUIPEditorHandler.DrawToggle(tempUIM.overrideColors, customSkin, "Override Colors");
|
||||
tempUIM.overrideFonts = MUIPEditorHandler.DrawToggle(tempUIM.overrideFonts, customSkin, "Override Fonts");
|
||||
|
||||
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>[Notification 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
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b72fc390a6760374ba76d6ae40841bac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Notification/NotificationManagerEditor.cs
|
||||
uploadId: 628721
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[AddComponentMenu("Modern UI Pack/Notification/Notification Stacking")]
|
||||
public class NotificationStacking : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
public float delay = 1;
|
||||
|
||||
// Helpers
|
||||
List<NotificationManager> notifications = new List<NotificationManager>();
|
||||
int currentNotification = 0;
|
||||
bool enableUpdating = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (notifications.Count == 0)
|
||||
return;
|
||||
|
||||
if (enableUpdating && notifications[currentNotification] != null)
|
||||
{
|
||||
notifications[currentNotification].Open();
|
||||
|
||||
StopCoroutine("StartNotification");
|
||||
StartCoroutine("StartNotification");
|
||||
|
||||
enableUpdating = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddToStack(NotificationManager notif)
|
||||
{
|
||||
notifications.Add(notif);
|
||||
notif.gameObject.SetActive(false);
|
||||
enableUpdating = true;
|
||||
}
|
||||
|
||||
IEnumerator StartNotification()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(notifications[currentNotification].timer + delay);
|
||||
|
||||
Destroy(notifications[currentNotification].gameObject);
|
||||
|
||||
if (currentNotification == notifications.Count - 1)
|
||||
{
|
||||
notifications.Clear();
|
||||
currentNotification = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
currentNotification += 1;
|
||||
enableUpdating = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d6e5a79c713c094fb2ea4246d215d24
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: adf3c8361dd31e1448483775ea241c10, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Notification/NotificationStacking.cs
|
||||
uploadId: 628721
|
||||
Reference in New Issue
Block a user