Initial commit

This commit is contained in:
AbstractConcept 2022-09-13 00:36:34 -05:00
commit 3c7cc0c973
8391 changed files with 704313 additions and 0 deletions

View file

@ -0,0 +1,57 @@
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.U2D.Layout
{
internal class DropdownMenu : VisualElement
{
public class DropdownMenuFactory : UxmlFactory<DropdownMenu, DropdownMenuUxmlTraits> {}
public class DropdownMenuUxmlTraits : UxmlTraits {}
/*
private ButtonGroup m_ButtonGroup;
public DropdownMenu()
{
RegisterCallback<FocusOutEvent>(OnFocusOut, Capture.NoCapture);
RegisterCallback<MouseLeaveEvent>(OnMouseLeaveEvent);
}
public void InitialiseWithButtonGroup(ButtonGroup buttonGroup)
{
if (m_ButtonGroup == buttonGroup)
return;
m_ButtonGroup = buttonGroup;
var buttonGroupLocalPosition = parent.WorldToLocal(new Vector2(buttonGroup.worldBound.x, buttonGroup.worldBound.y));
style.positionType = PositionType.Absolute;
style.positionLeft = buttonGroupLocalPosition.x;
style.positionTop = buttonGroupLocalPosition.y;
style.flexDirection = buttonGroup.isHorizontal ? FlexDirection.Row : FlexDirection.Column;
foreach (var element in buttonGroup.elements)
Add(element);
}
private void OnMouseLeaveEvent(MouseLeaveEvent evt)
{
Close();
}
private void OnFocusOut(FocusOutEvent evt)
{
Close();
}
private void Close()
{
foreach (var element in contentContainer.Children())
m_ButtonGroup.elements.Add(element);
this.contentContainer.Clear();
style.width = 0;
style.height = 0;
m_ButtonGroup = null;
}
*/
}
}

View file

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

View file

@ -0,0 +1,97 @@
using UnityEditor.U2D.Animation;
using UnityEngine.UIElements;
namespace UnityEditor.U2D.Layout
{
internal class LayoutOverlay : VisualElement
{
public class LayoutOverlayFactory : UxmlFactory<LayoutOverlay, LayoutOverlayUxmlTraits> {}
public class LayoutOverlayUxmlTraits : UxmlTraits {}
private ScrollableToolbar m_HorizontalToolbar;
private ScrollableToolbar m_VerticalToolbar;
private VisualElement m_HorizontalHolder;
private VisualElement m_LeftOverlay;
private VisualElement m_RightOverlay;
private DropdownMenu m_DropdownOverlay;
public ScrollableToolbar horizontalToolbar
{
get
{
if (m_HorizontalToolbar == null)
m_HorizontalToolbar = this.Q<ScrollableToolbar>("HorizontalToolbar");
return m_HorizontalToolbar;
}
}
public ScrollableToolbar verticalToolbar
{
get
{
if (m_VerticalToolbar == null)
m_VerticalToolbar = this.Q<ScrollableToolbar>("VerticalToolbar");
return m_VerticalToolbar;
}
}
public VisualElement horizontalHolder
{
get
{
if (m_HorizontalHolder == null)
m_HorizontalHolder = this.Q<VisualElement>("HorizontalHolder");
return m_HorizontalHolder;
}
}
public VisualElement leftOverlay
{
get
{
if (m_LeftOverlay == null)
m_LeftOverlay = this.Q<VisualElement>("LeftOverlay");
return m_LeftOverlay;
}
}
public VisualElement rightOverlay
{
get
{
if (m_RightOverlay == null)
m_RightOverlay = this.Q<VisualElement>("RightOverlay");
return m_RightOverlay;
}
}
public DropdownMenu dropdownOverlay
{
get
{
if (m_DropdownOverlay == null)
m_DropdownOverlay = this.Q<DropdownMenu>("DropdownOverlay");
return m_DropdownOverlay;
}
}
public bool hasScrollbar
{
get { return this.ClassListContains("HasScrollbar"); }
set
{
if (value)
this.AddToClassList("HasScrollbar");
else
this.RemoveFromClassList("HasScrollbar");
}
}
public LayoutOverlay()
{
this.StretchToParentSize();
styleSheets.Add(ResourceLoader.Load<StyleSheet>("LayoutOverlay/LayoutOverlayStyle.uss"));
}
}
}

View file

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

View file

@ -0,0 +1,35 @@
using System;
using UnityEditor.U2D.Animation;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.U2D.Layout
{
internal static class LayoutOverlayUtility
{
public static Button CreateButton(string name, Action clickEvent, string tooltip = null, string text = null, string imageResourcePath = null, string stylesheetPath = null)
{
Button button = new Button(clickEvent);
button.name = name;
button.tooltip = tooltip;
if (!String.IsNullOrEmpty(text))
button.text = text;
if (!String.IsNullOrEmpty(imageResourcePath))
{
var texture = ResourceLoader.Load<Texture>(imageResourcePath);
if (texture != null)
{
Image image = new Image();
image.image = texture;
button.Add(image);
}
}
if (!String.IsNullOrEmpty(stylesheetPath))
button.styleSheets.Add(ResourceLoader.Load<StyleSheet>(stylesheetPath));
return button;
}
}
}

View file

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

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8356cf4cb497279418c30e5fcdfe82b8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,146 @@
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.U2D.Layout
{
internal interface IDraggable
{
bool IsMovableNow();
void UpdatePresenterPosition();
}
internal class Draggable : MouseManipulator
{
private Vector2 m_Start;
protected bool m_Active;
public Vector2 panSpeed { get; set; }
public bool clampToParentEdges { get; set; }
public Draggable(bool clampToParentEdges = false)
{
activators.Add(new ManipulatorActivationFilter {button = MouseButton.LeftMouse});
panSpeed = Vector2.one;
this.clampToParentEdges = clampToParentEdges;
m_Active = false;
}
protected Rect CalculatePosition(float x, float y, float width, float height)
{
var rect = new Rect(x, y, width, height);
if (clampToParentEdges)
{
if (rect.x < 0f)
rect.x = 0f;
else if (rect.xMax > target.parent.layout.width)
rect.x = target.parent.layout.width - rect.width;
if (rect.y < 0f)
rect.y = 0f;
else if (rect.yMax > target.parent.layout.height)
rect.y = target.parent.layout.height - rect.height;
// Reset size, we never intended to change them in the first place
rect.width = width;
rect.height = height;
}
return rect;
}
protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback<MouseDownEvent>(OnMouseDown);
target.RegisterCallback<MouseMoveEvent>(OnMouseMove);
target.RegisterCallback<MouseUpEvent>(OnMouseUp);
}
protected override void UnregisterCallbacksFromTarget()
{
target.UnregisterCallback<MouseDownEvent>(OnMouseDown);
target.UnregisterCallback<MouseMoveEvent>(OnMouseMove);
target.UnregisterCallback<MouseUpEvent>(OnMouseUp);
}
protected void OnMouseDown(MouseDownEvent e)
{
if (m_Active)
{
e.StopImmediatePropagation();
return;
}
/*
IDraggable ce = e.target as IDraggable;
if (ce == null || !ce.IsMovableNow())
{
return;
}
*/
if (CanStartManipulation(e))
{
m_Start = e.localMousePosition;
m_Active = true;
target.CaptureMouse();
e.StopPropagation();
}
}
protected void OnMouseMove(MouseMoveEvent e)
{
/*
IDraggable ce = e.target as IDraggable;
if (ce == null || !ce.IsMovableNow())
{
return;
}
*/
if (m_Active)
{
Vector2 diff = e.localMousePosition - m_Start;
Rect rect = CalculatePosition(target.layout.x + diff.x, target.layout.y + diff.y, target.layout.width, target.layout.height);
if (target.style.position == Position.Relative)
{
target.style.left = rect.xMin;
target.style.top = rect.yMin;
target.style.right = rect.xMax;
target.style.bottom = rect.yMax;
}
else if (target.style.position == Position.Absolute)
{
target.style.left = rect.x;
target.style.top = rect.y;
}
e.StopPropagation();
}
}
protected void OnMouseUp(MouseUpEvent e)
{
/*
IDraggable ce = e.target as IDraggable;
if (ce == null || !ce.IsMovableNow())
{
return;
}
*/
if (m_Active)
{
if (CanStopManipulation(e))
{
//ce.UpdatePresenterPosition();
m_Active = false;
target.ReleaseMouse();
e.StopPropagation();
}
}
}
}
}

View file

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

View file

@ -0,0 +1,134 @@
using System.Collections.Generic;
using UnityEditor.U2D.Animation;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.U2D.Layout
{
internal class ScrollableToolbar : VisualElement
{
public class ScrollableToolbarFactory : UxmlFactory<ScrollableToolbar, ScrollableToolbarUxmlTraits> {}
public class ScrollableToolbarUxmlTraits : UxmlTraits
{
UxmlBoolAttributeDescription m_IsHorizontal;
public ScrollableToolbarUxmlTraits()
{
m_IsHorizontal = new UxmlBoolAttributeDescription { name = "isHorizontal" };
}
public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
{
get { yield break; }
}
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc);
ScrollableToolbar toolbar = ((ScrollableToolbar)ve);
toolbar.isHorizontal = m_IsHorizontal.GetValueFromBag(bag, cc);
}
}
private ScrollView m_ScrollView;
private bool m_IsHorizontal;
public bool isHorizontal
{
get { return m_IsHorizontal; }
set
{
if (m_IsHorizontal != value)
{
m_IsHorizontal = value;
SetupScrolling();
}
}
}
public ScrollableToolbar() : this(false)
{
}
public ScrollableToolbar(bool isHorizontal)
{
m_ScrollView = new ScrollView() {name = "ScrollView"};;
m_ScrollView.StretchToParentSize();
hierarchy.Add(m_ScrollView);
m_IsHorizontal = isHorizontal;
SetupScrolling();
styleSheets.Add(ResourceLoader.Load<StyleSheet>("LayoutOverlay/ScrollableToolbar.uss"));
// TODO: Add onto current ScrollView internal WheelEvent
m_ScrollView.RegisterCallback<WheelEvent>(OnScrollWheel);
pickingMode = PickingMode.Ignore;
m_ScrollView.pickingMode = PickingMode.Ignore;
m_ScrollView.contentViewport.pickingMode = PickingMode.Ignore;
m_ScrollView.contentContainer.pickingMode = PickingMode.Ignore;
}
public void AddToContainer(VisualElement element)
{
m_ScrollView.contentContainer.Add(element);
}
public void Collapse(bool collapse)
{
if (collapse)
AddToClassList("Collapse");
else
RemoveFromClassList("Collapse");
}
private void SetupScrolling()
{
if (isHorizontal)
{
m_ScrollView.style.flexDirection = FlexDirection.Row;
m_ScrollView.contentViewport.style.marginLeft = 10;
m_ScrollView.contentViewport.style.marginRight = 10;
m_ScrollView.contentViewport.style.marginTop = 0;
m_ScrollView.contentViewport.style.marginBottom = 0;
m_ScrollView.contentContainer.style.flexDirection = FlexDirection.Row;
m_ScrollView.contentContainer.style.flexGrow = 1f;
}
else
{
m_ScrollView.style.flexDirection = FlexDirection.Column;
m_ScrollView.contentViewport.style.marginLeft = 0;
m_ScrollView.contentViewport.style.marginRight = 0;
m_ScrollView.contentViewport.style.marginTop = 10;
m_ScrollView.contentViewport.style.marginBottom = 10;
m_ScrollView.contentContainer.style.flexDirection = FlexDirection.Column;
m_ScrollView.contentContainer.style.flexGrow = 1f;
}
}
void OnScrollWheel(WheelEvent evt)
{
/*
// Handled by ScrollView
if (!isHorizontal && m_ScrollView.contentContainer.layout.height - layout.height > 0)
{
if (evt.delta.y < 0)
m_ScrollView.verticalScroller.ScrollPageUp();
else if (evt.delta.y > 0)
m_ScrollView.verticalScroller.ScrollPageDown();
}
*/
if (isHorizontal && m_ScrollView.contentContainer.layout.width - layout.width > 0)
{
// TODO: Does not provide delta.x for sidescrolling mouse wheel. Use delta.y for now.
if (evt.delta.y < 0)
m_ScrollView.horizontalScroller.ScrollPageUp();
else if (evt.delta.y > 0)
m_ScrollView.horizontalScroller.ScrollPageDown();
}
evt.StopPropagation();
}
}
}

View file

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