音乐效果

This commit is contained in:
SoulliesOfficial
2025-05-21 02:23:25 -04:00
parent 1d176a606b
commit 9a02c62ac4
148 changed files with 243171 additions and 839 deletions

View File

@@ -0,0 +1,41 @@
using System;
using UnityEditor;
using UnityEngine;
using vietlabs.fr2;
public class FR2_DeleteButton
{
public string warningMessage;
public string confirmMessage;
public GUIContent deleteLabel;
public bool hasConfirm;
public bool Draw(Action onConfirmDelete)
{
GUILayout.BeginHorizontal();
{
EditorGUILayout.HelpBox(warningMessage, MessageType.Warning);
GUILayout.BeginVertical();
{
GUILayout.Space(2f);
hasConfirm = GUILayout.Toggle(hasConfirm, confirmMessage);
EditorGUI.BeginDisabledGroup(!hasConfirm);
{
GUI2.BackgroundColor(() =>
{
if (GUILayout.Button(deleteLabel, EditorStyles.miniButton))
{
hasConfirm = false;
onConfirmDelete();
GUIUtility.ExitGUI();
}
}, GUI2.darkRed, 0.8f);
}
EditorGUI.EndDisabledGroup();
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
return false;
}
}

View File

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

View File

@@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public static class FR2_Icon
{
public static GUIContent Lock { get { return TryGet("LockIcon-On"); } }
public static GUIContent Unlock { get { return TryGet("LockIcon"); } }
#if UNITY_2019_3_OR_NEWER
public static GUIContent Refresh { get { return TryGet("d_Refresh@2x"); } }
#else
public static GUIContent Refresh { get { return TryGet("LookDevResetEnv"); } }
#endif
public static GUIContent Selection { get { return TryGet("d_RectTransformBlueprint"); } }
public static GUIContent Details { get { return TryGet("d_UnityEditor.SceneHierarchyWindow"); } }
public static GUIContent Favorite { get { return TryGet("d_Favorite"); } }
public static GUIContent Setting { get { return TryGet("d_SettingsIcon"); } }
public static GUIContent Ignore { get { return TryGet("ShurikenCheckMarkMixed"); } }
public static GUIContent Plus
{
get { return TryGet("ShurikenPlus"); }
}
public static GUIContent Visibility { get { return TryGet("ClothInspector.ViewValue"); } }
#if UNITY_2019_3_OR_NEWER
public static GUIContent Panel { get { return TryGet("VerticalSplit"); } }
#else
public static GUIContent Panel { get { return TryGet("d_LookDevSideBySide"); } }
#endif
public static GUIContent Layout { get { return TryGet("FreeformLayoutGroup Icon"); } }
public static GUIContent Sort { get { return TryGet("AlphabeticalSorting"); } } //d_DefaultSorting
#if UNITY_2019_3_OR_NEWER
public static GUIContent Filter { get { return TryGet("d_ToggleUVOverlay@2x"); } }
#else
public static GUIContent Filter { get { return TryGet("LookDevSplit"); } }
#endif
public static GUIContent Group { get { return TryGet("EditCollider"); } }
public static GUIContent Delete { get { return TryGet("d_TreeEditor.Trash"); } }
public static GUIContent Split { get { return TryGet("VerticalSplit"); } }
public static GUIContent Close { get { return TryGet("LookDevClose"); } }
public static GUIContent Prefab { get { return TryGet("d_Prefab Icon"); } }
public static GUIContent Asset { get { return TryGet("Folder Icon"); } }
public static GUIContent Filesize { get { return TryGet("SavePassive"); } }
public static GUIContent AssetBundle { get { return TryGet("CloudConnect"); } }
public static GUIContent Script { get { return TryGet("dll Script Icon"); } }
public static GUIContent Material { get { return TryGet("d_TreeEditor.Material"); } }
public static GUIContent Scene { get { return TryGet("SceneAsset Icon"); } }
#if UNITY_2017_1_OR_NEWER
public static GUIContent Atlas { get { return TryGet("SpriteAtlas Icon"); } }
#endif
public static GUIContent Folder { get { return TryGet("Project"); } }
public static GUIContent Hierarchy { get { return TryGet("UnityEditor.HierarchyWindow"); } }
private static readonly Dictionary<string, GUIContent> _cache = new Dictionary<string, GUIContent>();
static GUIContent TryGet(string id)
{
GUIContent result;
if (_cache.TryGetValue(id, out result)) return result ?? GUIContent.none;
var icon = EditorGUIUtility.IconContent(id) ?? new GUIContent(Texture2D.whiteTexture);
_cache.Add(id, icon);
return icon;
}
}

View File

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

View File

@@ -0,0 +1,62 @@
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class FR2_SearchView
{
private bool caseSensitive;
private string searchTerm = string.Empty;
public static GUIStyle toolbarSearchField;
public static GUIStyle toolbarSearchFieldCancelButton;
public static GUIStyle toolbarSearchFieldCancelButtonEmpty;
public static void InitSearchStyle()
{
toolbarSearchField = "ToolbarSeachTextFieldPopup";
toolbarSearchFieldCancelButton = "ToolbarSeachCancelButton";
toolbarSearchFieldCancelButtonEmpty = "ToolbarSeachCancelButtonEmpty";
}
public bool DrawLayout()
{
bool dirty = false;
if (toolbarSearchField == null)
{
InitSearchStyle();
}
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
bool v = GUILayout.Toggle(caseSensitive, "Aa", EditorStyles.toolbarButton, GUILayout.Width(24f));
if (v != caseSensitive)
{
caseSensitive = v;
dirty = true;
}
GUILayout.Space(2f);
string value = GUILayout.TextField(searchTerm, toolbarSearchField, GUILayout.Width(140f));
if (searchTerm != value)
{
searchTerm = value;
dirty = true;
}
GUIStyle style = string.IsNullOrEmpty(searchTerm)
? toolbarSearchFieldCancelButtonEmpty
: toolbarSearchFieldCancelButton;
if (GUILayout.Button("Cancel", style))
{
searchTerm = string.Empty;
dirty = true;
}
}
GUILayout.EndHorizontal();
return dirty;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c5c27d8e961e4de6ab683161c6d53584
timeCreated: 1579769248

View File

@@ -0,0 +1,252 @@
//#define FR2_DEBUG
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Experimental.Rendering;
namespace vietlabs.fr2
{
public class FR2_SplitView
{
private const float SPLIT_SIZE = 2f;
private IWindow window;
private bool dirty;
public FR2_SplitView(IWindow w)
{
this.window = w;
}
[Serializable]
public class Info
{
public GUIContent title;
#if FR2_DEBUG
public Color color;
#endif
public Rect rect;
public float normWeight;
public int stIndex;
public bool visible = true;
public float weight = 1f;
public Action<Rect> draw;
public void DoDraw()
{
#if FR2_DEBUG
GUI2.Rect(rect, Color.white, 0.1f);
#endif
var drawRect = rect;
if (title != null)
{
var titleRect = new Rect(rect.x, rect.y, rect.width, 16f);
GUI2.Rect(titleRect, Color.black, 0.2f);
titleRect.xMin += 4f;
GUI.Label(titleRect, title, EditorStyles.boldLabel);
drawRect.yMin += 16f;
}
draw(drawRect);
}
}
public bool isHorz;
public List<Info> splits = new List<Info>();
public bool isVisible
{
get { return _visibleCount > 0; }
}
private int _visibleCount;
private Rect _rect;
public void CalculateWeight()
{
_visibleCount = 0;
var _totalWeight = 0f;
for (var i = 0; i < splits.Count; i++)
{
var info = splits[i];
if (!info.visible) continue;
info.stIndex = _visibleCount;
_totalWeight += info.weight;
_visibleCount++;
}
if (_visibleCount == 0 || _totalWeight == 0)
{
//Debug.LogWarning("Nothing visible!");
return;
}
var cWeight = 0f;
for (var i = 0; i < splits.Count; i++)
{
var info = splits[i];
if (!info.visible) continue;
cWeight += info.weight;
info.normWeight = info.weight / _totalWeight;
}
}
public void Draw(Rect rect)
{
if (rect.width > 0 || rect.height > 0)
{
_rect = rect;
}
if (dirty)
{
dirty = false;
CalculateWeight();
}
var sz = (_visibleCount - 1) * SPLIT_SIZE;
var dx = _rect.x;
var dy = _rect.y;
for (var i = 0; i < splits.Count; i++)
{
var info = splits[i];
if (!info.visible) continue;
var rr = new Rect
(
dx, dy,
isHorz ? (_rect.width - sz) * info.normWeight : _rect.width,
isHorz ? _rect.height : (_rect.height - sz) * info.normWeight
);
if (rr.width > 0 && rr.height > 0)
{
info.rect = rr;
}
if (info.draw != null) info.DoDraw();
if (info.stIndex < _visibleCount - 1)
{
DrawSpliter(i, isHorz ? info.rect.xMax : info.rect.yMax);
}
if (isHorz)
{
dx += info.rect.width + SPLIT_SIZE;
}
else
{
dy += info.rect.height + SPLIT_SIZE;
}
}
}
public void DrawLayout()
{
var rect = StartLayout(isHorz);
{
Draw(rect);
}
EndLayout(isHorz);
}
private int resizeIndex = -1;
void RefreshSpliterPos(int index, float px)
{
var sp1 = splits[index];
var sp2 = splits[index + 1];
var r1 = sp1.rect;
var r2 = sp2.rect;
var w1 = sp1.weight;
var w2 = sp2.weight;
var tt = w1 + w2;
var dd = isHorz ? (r2.xMax - r1.xMin) : (r2.yMax - r1.yMin) - SPLIT_SIZE;
var m = isHorz ? (Event.current.mousePosition.x - r1.x) : (Event.current.mousePosition.y - r1.y);
var pct = Mathf.Min(0.9f, Mathf.Max(0.1f, m / dd));
sp1.weight = tt * pct;
sp2.weight = tt * (1 - pct);
dirty = true;
if (window != null) window.WillRepaint = true;
}
void DrawSpliter(int index, float px)
{
var dRect = _rect;
if (isHorz)
{
dRect.x = px + SPLIT_SIZE;
dRect.width = SPLIT_SIZE;
}
else
{
dRect.y = px;
dRect.height = SPLIT_SIZE;
}
if (Event.current.type == EventType.Repaint || Event.current.type == EventType.MouseMove)
{
GUI2.Rect(dRect, Color.black, 0.4f);
}
var dRect2 = GUI2.Padding(dRect, -2f, -2f);
EditorGUIUtility.AddCursorRect(dRect2, isHorz ? MouseCursor.ResizeHorizontal : MouseCursor.ResizeVertical);
if (Event.current.type == EventType.MouseDown && dRect2.Contains(Event.current.mousePosition))
{
resizeIndex = index;
RefreshSpliterPos(index, px);
}
if (resizeIndex == index)
{
RefreshSpliterPos(index, px);
}
if (Event.current.type == EventType.MouseUp)
{
resizeIndex = -1;
}
}
Rect StartLayout(bool horz)
{
return horz
? EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))
: EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
}
void EndLayout(bool horz)
{
if (horz)
{
EditorGUILayout.EndHorizontal();
}
else
{
EditorGUILayout.EndVertical();
}
}
}
}

View File

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

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace vietlabs.fr2
{
public class DrawCallback
{
public Action BeforeDraw;
public Action AfterDraw;
}
public class FR2_TabView
{
public int current;
public GUIContent[] labels;
public IWindow window;
public Action onTabChange;
public DrawCallback callback;
public bool canDeselectAll; // can there be no active tabs
public FR2_TabView(IWindow w, bool canDeselectAll)
{
this.window = w;
this.canDeselectAll = canDeselectAll;
}
public bool DrawLayout()
{
bool result = false;
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
if (callback != null && callback.BeforeDraw != null) callback.BeforeDraw();
for (var i = 0; i < labels.Length; i++)
{
var isActive = (i == current);
var lb = labels[i];
var clicked = (lb.image != null)
? GUI2.ToolbarToggle(ref isActive, lb.image, Vector2.zero, lb.tooltip)
: GUI2.Toggle(ref isActive, lb, EditorStyles.toolbarButton);
if (!clicked) continue;
current = (!isActive && canDeselectAll) ? -1 : i;
result = true;
if (onTabChange != null) onTabChange();
if (window == null) continue;
window.OnSelectionChange(); // force refresh tabs
window.WillRepaint = true;
}
if (callback != null && callback.AfterDraw != null) callback.AfterDraw();
}
GUILayout.EndHorizontal();
return result;
}
public static FR2_TabView FromEnum(Type enumType, IWindow w, bool canDeselectAll = false)
{
var values = Enum.GetValues(enumType);
var labels = new List<GUIContent>();
foreach (var item in values)
{
labels.Add(new GUIContent(item.ToString()));
}
return new FR2_TabView(w, canDeselectAll) { current = 0, labels = labels.ToArray() };
}
public static GUIContent GetGUIContent(object tex)
{
if (tex is GUIContent) return (GUIContent)tex;
if (tex is Texture) return new GUIContent((Texture)tex);
if (tex is string) return new GUIContent((string)tex);
return GUIContent.none;
}
public static FR2_TabView Create(IWindow w, bool canDeselectAll = false, params object[] titles)
{
var labels = new List<GUIContent>();
foreach (var item in titles)
{
labels.Add(GetGUIContent(item));
}
return new FR2_TabView(w, canDeselectAll) { current = 0, labels = labels.ToArray() };
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ea85064796024a07b975d9ebf1ed2fcc
timeCreated: 1579764674

View File

@@ -0,0 +1,279 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Vector2 = UnityEngine.Vector2;
namespace vietlabs.fr2
{
public interface IDrawer
{
bool Draw(Rect rect);
bool DrawLayout();
}
public static class GUI2
{
public static void Color(Action a, Color c, float? alpha = null)
{
if (a == null) return;
var cColor = GUI.color;
if (alpha != null) c.a = alpha.Value;
GUI.color = c;
a();
GUI.color = cColor;
}
public static void ContentColor(Action a, Color c, float? alpha = null)
{
if (a == null) return;
var cColor = GUI.contentColor;
if (alpha != null) c.a = alpha.Value;
GUI.contentColor = c;
a();
GUI.contentColor = cColor;
}
public static void BackgroundColor(Action a, Color c, float? alpha = null)
{
if (a == null) return;
var cColor = GUI.backgroundColor;
if (alpha != null) c.a = alpha.Value;
GUI.backgroundColor = c;
a();
GUI.backgroundColor = cColor;
}
public static Color Theme(Color proColor, Color indieColor)
{
return EditorGUIUtility.isProSkin ? proColor : indieColor;
}
public static Color Alpha(Color c, float a)
{
c.a = a;
return c;
}
public static void Rect(Rect r, Color c, float? alpha = null)
{
var cColor = GUI.color;
if (alpha != null) c.a = alpha.Value;
GUI.color = c;
GUI.DrawTexture(r, Texture2D.whiteTexture);
GUI.color = cColor;
}
public static UnityEngine.Object[] DropZone(string title, float w, float h)
{
var rect = GUILayoutUtility.GetRect(w, h);
GUI.Box(rect, GUIContent.none, EditorStyles.textArea);
var cx = rect.x + w / 2f;
var cy = rect.y + h / 2f;
var pz = w / 3f; // plus size
var plusRect = new Rect(cx - pz / 2f, (cy - pz / 2f), pz, pz);
GUI2.Color(() => { GUI.DrawTexture(plusRect, FR2_Icon.Plus.image, ScaleMode.ScaleToFit); }, UnityEngine.Color.white, 0.1f);
GUI.Label(rect, title, EditorStyles.wordWrappedMiniLabel);
EventType eventType = Event.current.type;
bool isAccepted = false;
if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (eventType == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
isAccepted = true;
}
Event.current.Use();
}
return isAccepted ? DragAndDrop.objectReferences : null;
}
// public static bool ColorIconButton(Rect r, Texture icon, Vector2? iconOffset, Color? c)
// {
// if (c != null) Rect(r, c.Value);
//
// // align center
// if (iconOffset != null)
// {
// r.x += iconOffset.Value.x;
// r.y += iconOffset.Value.y;
// }
//
// return GUI.Button(r, icon, GUIStyle.none);
// }
public static bool ColorIconButton(Rect r, Texture icon, Color? c)
{
var oColor = GUI.color;
if (c != null) GUI.color = c.Value;
var result = GUI.Button(r, icon, GUIStyle.none);
GUI.color = oColor;
return result;
}
public static bool Toggle(ref bool value, string label, GUIStyle style, params GUILayoutOption[] options)
{
var vv = GUILayout.Toggle(value, label, style, options);
if (vv == value) return false;
value = vv;
return true;
}
public static bool Toggle(ref bool value, Texture2D tex, GUIStyle style, params GUILayoutOption[] options)
{
var vv = GUILayout.Toggle(value, tex, style, options);
if (vv == value) return false;
value = vv;
return true;
}
public static bool Toggle(ref bool value, GUIContent tex, GUIStyle style, params GUILayoutOption[] options)
{
var vv = GUILayout.Toggle(value, tex, style, options);
if (vv == value) return false;
value = vv;
return true;
}
public static bool Toggle(Rect rect, ref bool value, GUIContent tex)
{
var vv = GUI.Toggle(rect, value, tex, GUIStyle.none);
if (vv == value) return false;
value = vv;
return true;
}
public static bool Toggle(Rect rect, ref bool value)
{
var vv = GUI.Toggle(rect, value, GUIContent.none);
if (vv == value) return false;
value = vv;
return true;
}
internal static bool Toggle(bool v, string label, Action<bool> setter)
{
var v1 = GUILayout.Toggle(v, label);
if (v1 == v) return false;
if (setter != null) setter(v1);
return true;
}
internal static Dictionary<string, GUIContent> tooltipCache = new Dictionary<string, GUIContent>();
internal static GUIContent GetTooltip(string tooltip)
{
if (string.IsNullOrEmpty(tooltip)) return GUIContent.none;
GUIContent result;
if (tooltipCache.TryGetValue(tooltip, out result)) return result;
result = new GUIContent(string.Empty, tooltip);
tooltipCache.Add(tooltip, result);
return result;
}
internal static bool ToolbarToggle(ref bool value, Texture icon, Vector2 padding, string tooltip = null)
{
var vv = GUILayout.Toggle(value, GetTooltip(tooltip), EditorStyles.toolbarButton, GUILayout.Width(22f));
if (icon != null)
{
var rect = GUILayoutUtility.GetLastRect();
rect = Padding(rect, padding.x, padding.y);
GUI.DrawTexture(rect, icon, ScaleMode.ScaleToFit);
}
if (vv == value) return false;
value = vv;
return true;
}
// TODO : optimize for performance
public static bool EnumPopup<T>(ref T mode, string label, float labelWidth, GUIStyle style, params GUILayoutOption[] options)
{
var sz = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = labelWidth;
{
var obj = (Enum)(object)mode;
var vv = EditorGUILayout.EnumPopup(label, obj, style, options);
if (Equals(vv, obj))
{
EditorGUIUtility.labelWidth = sz;
return false;
}
mode = (T)(object)vv;
}
EditorGUIUtility.labelWidth = sz;
return true;
}
public static bool EnumPopup<T>(ref T mode, GUIContent icon, GUIStyle style, params GUILayoutOption[] options)
{
var obj = (Enum)(object)mode;
var cRect = GUILayoutUtility.GetRect(16f, 16f);
cRect.xMin -= 2f;
cRect.yMin += 2f;
GUI.Label(cRect, icon);
var vv = EditorGUILayout.EnumPopup(obj, style, options);
if (Equals(vv, obj))
{
return false;
}
mode = (T)(object)vv;
return true;
}
public static Rect Padding(Rect r, float x, float y)
{
return new Rect(r.x + x, r.y + y, r.width - 2 * x, r.height - 2 * y);
}
public static Rect LeftRect(float w, ref Rect rect)
{
rect.x += w;
rect.width -= w;
return new Rect(rect.x - w, rect.y, w, rect.height);
}
public static Rect RightRect(float w, ref Rect rect)
{
rect.width -= w;
return new Rect(rect.x + rect.width, rect.y, w, rect.height);
}
// -----------------------
private static GUIStyle _miniLabelAlignRight;
public static GUIStyle miniLabelAlignRight
{
get
{
return _miniLabelAlignRight ?? (
_miniLabelAlignRight = new GUIStyle(EditorStyles.miniLabel) { alignment = TextAnchor.MiddleRight }
);
}
}
public static Color darkRed = new Color(0.5f, .0f, 0f, 1f);
public static Color darkGreen = new Color(0, .5f, 0f, 1f);
public static Color darkBlue = new Color(0, .0f, 0.5f, 1f);
public static Color lightRed = new Color(1f, 0.5f, 0.5f, 1f);
}
}

View File

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