更改文件架构

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,20 @@
{
"name": "BITKit.UX.Quest",
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b5274363baca5454aaf4284ab7fbef6f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using BITKit.SubSystems.Quest;
using UnityEngine.UIElements;
using System.Threading.Tasks;
namespace BITKit.UX
{
public class UXQuest : UXElement<VisualElement>
{
[Header(Constant.Header.Settings)]
public bool clearAfterCompleted;
[Header(Constant.Header.Reference)]
[SerializeReference, SubclassSelector] public References completeClassName;
[Header(Constant.Header.Prefabs)]
public VisualTreeAsset visualTreeAsset;
[Header(Constant.Header.InternalVariables)]
public Dictionary<string, UXContainer> dictionary = new();
public override void OnStart()
{
base.OnStart();
QuestSystem.OnQuestCreated += OnQuestCreated;
QuestSystem.OnQuestCompleted += OnQuestCompleted;
QuestSystem.OnQuestCanceled += OnQuestCancened;
visualElement.Clear();
}
void OnDestroy()
{
QuestSystem.OnQuestCreated -= OnQuestCreated;
QuestSystem.OnQuestCompleted -= OnQuestCompleted;
QuestSystem.OnQuestCanceled -= OnQuestCancened;
}
void OnQuestCreated(QuestSystem.Info quest)
{
BIT4Log.Log<UXQuest>($"已创建任务:{quest.name}");
if (dictionary.TryGetValue(quest.name, out var container))
{
container.visualElement.RemoveFromClassList(completeClassName);
}
else
{
container = new(visualTreeAsset.CloneTree());
dictionary.Add(quest.name, container);
}
container.titleLabel.text = quest.name;
container.descriptionLabel.text = quest.description;
visualElement.Add(container);
}
void OnQuestCancened(QuestSystem.Info quest)
{
BIT4Log.Log<UXQuest>($"已取消任务:{quest.name}");
if (dictionary.TryGetValue(quest.name, out var container))
{
visualElement.Remove(container);
dictionary.Remove(quest.name);
}
}
async void OnQuestCompleted(QuestSystem.Info quest)
{
BIT4Log.Log<UXQuest>($"已完成任务:{quest.name}");
if (dictionary.TryGetValue(quest.name, out var container))
{
container.visualElement.AddToClassList(completeClassName);
container.titleLabel.text = $"已完成:{quest.name}";
container.visualElement.tabIndex = 256;
if (clearAfterCompleted)
{
dictionary.Remove(quest.name);
try
{
await Task.Delay(8096, cancellationToken);
}
catch (System.OperationCanceledException) { }
catch (System.Exception)
{
visualElement.Remove(container);
throw;
}
}
}
}
}
}

View File

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