更改文件架构

This commit is contained in:
CortexCore
2023-06-07 18:38:07 +08:00
parent 93292b1a59
commit ed84166723
720 changed files with 297 additions and 65 deletions

View File

@@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Events;
namespace BITKit
{
public struct NewSubMenu
{
public string name;
public Vector2 position;
public IEnumerable<SubAction> actions;
}
public struct SubAction
{
public string name;
public UnityAction action;
}
public class SubMenu : BITBehavior
{
[Header(Constant.Header.Components)]
public UIDocument document;
Label label;
VisualElement context;
VisualElement root;
void Start()
{
Data.AddListener<IEnumerable<SubAction>>(OnAction);
Data.AddListener<NewSubMenu>(OnContextMenu);
root = document.rootVisualElement;
label = root.Q<Label>("Label");
context = root.Q("Context");
SetActive(false);
root.RegisterCallback<PointerLeaveEvent>(x =>
{
SetActive(false);
});
}
void OnContextMenu(NewSubMenu contextMenu)
{
label.text = contextMenu.name;
OnAction(contextMenu.actions);
root.style.left = contextMenu.position.x - 4f;
root.style.top = contextMenu.position.y - 4f;
}
void OnAction(IEnumerable<SubAction> actions)
{
SetActive(true);
actions.ForEach(x =>
{
var button = new Button();
button.text = x.name;
button.clicked += () =>
{
x.action.Invoke();
SetActive(false);
};
context.Add(button);
});
}
public override void SetActive(bool active)
{
if (active)
{
}
else
{
context.Clear();
}
document.rootVisualElement.SetActive(active);
}
}
}

View File

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