从旧版中移植,Prefab未确认

This commit is contained in:
2025-07-24 15:41:28 +08:00
parent 86842492ea
commit 43b824b722
300 changed files with 101926 additions and 14 deletions

View File

@@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Convention.Workflow
{
}

View File

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

View File

@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Convention.WindowsUI;
using Convention.WindowsUI.Variant;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Convention.Workflow
{
[Serializable, ArgPackage]
public class EndNodeInfo : NodeInfo
{
protected override NodeInfo CreateTemplate()
{
return new EndNodeInfo();
}
}
public class EndNode : Node, INodeSlotLinkable
{
internal static List<EndNode> AllEndNodes = new();
// ContextBehaviour
public object end_result;
protected override void Start()
{
base.Start();
end_result = null;
AllEndNodes.Add(this);
var context = gameObject.GetOrAddComponent<BehaviourContextManager>();
context.OnPointerClickEvent = BehaviourContextManager.InitializeContextSingleEvent(context.OnPointerClickEvent, PointerRightClickAndOpenMenu);
}
protected override void OnDestroy()
{
base.OnDestroy();
AllEndNodes.Remove(this);
}
private Dictionary<string, PropertiesWindow.ItemEntry> m_dynamicSlots = new();
public override void PointerRightClickAndOpenMenu(PointerEventData pointer)
{
if (pointer.button == PointerEventData.InputButton.Right)
{
List<SharedModule.CallbackData> callbacks = new()
{
new (WorkflowManager.Transformer("Create New Slot"), x =>
{
SharedModule.instance.SingleEditString(
WorkflowManager.Transformer("SlotName"),
WorkflowManager.Transformer("SlotName"),
y => AddSlot(y,"string"));
}),
new (WorkflowManager.Transformer("Delete"), x =>
{
WorkflowManager.instance.DestroyNode(this);
})
};
SharedModule.instance.OpenCustomMenu(WorkflowManager.instance.UIFocusObject, callbacks.ToArray());
}
}
public bool AddSlot(string name, string typeIndicator)
{
if (this.m_Inmapping.ContainsKey(name))
return false;
var entry = CreateGraphNodeInSlots(1)[0];
RectTransform curEntryRect = entry.ref_value.transform as RectTransform;
this.m_Inmapping[name] = entry.ref_value.GetComponent<NodeSlot>();
this.m_Inmapping[name].SetupFromInfo(new NodeSlotInfo()
{
parentNode = this,
slotName = name,
typeIndicator = typeIndicator,
IsInmappingSlot = true
});
m_dynamicSlots.Add(name, entry);
this.rectTransform.sizeDelta = new Vector2(this.rectTransform.sizeDelta.x, this.rectTransform.sizeDelta.y + curEntryRect.rect.height);
ConventionUtility.CreateSteps().Wait(1f, () =>
{
foreach (var (key, slot) in this.m_Inmapping)
{
slot.SetDirty();
}
}).Invoke();
return true;
}
public bool RemoveSlot(string name)
{
if (this.m_Inmapping.ContainsKey(name) == false)
return false;
this.m_Inmapping.Remove(name);
RectTransform curEntryRect = m_dynamicSlots[name].ref_value.transform as RectTransform;
this.rectTransform.sizeDelta = new Vector2(this.rectTransform.sizeDelta.x, this.rectTransform.sizeDelta.y - curEntryRect.rect.height);
m_dynamicSlots[name].Release();
m_dynamicSlots.Remove(name);
ConventionUtility.CreateSteps().Next(() =>
{
foreach (var (key, slot) in this.m_Inmapping)
{
slot.SetDirty();
}
}).Invoke();
return true;
}
public bool LinkTo([In, Opt] NodeSlot other)
{
if (Linkable(other))
{
AddSlot(other.info.slotName, other.info.typeIndicator);
var slot = m_dynamicSlots[other.info.slotName].ref_value.GetComponent<NodeSlot>();
if (slot.Linkable(other))
{
slot.LinkTo(other);
return true;
}
}
return false;
}
public bool Linkable([In] NodeSlot other)
{
return other != null && other.info.IsInmappingSlot == false;
}
[return: ReturnMayNull]
public GameObject GetExtensionModule(string slotName)
{
if (this.m_Inmapping.ContainsKey(slotName))
{
return this.m_Inmapping[slotName].ExtensionModule;
}
return null;
}
[return: ReturnMayNull]
public T GetExtensionModule<T>(string slotName) where T : Component
{
if (this.m_Inmapping.ContainsKey(slotName))
{
var go = this.m_Inmapping[slotName].ExtensionModule;
if (go != null)
{
return ConventionUtility.SeekComponent<T>(go);
}
}
return null;
}
public List<string> GetAllInslotNames()
{
return m_Inmapping.Keys.ToList();
}
public bool ContainsInslot(string slotName)
{
return m_Inmapping.ContainsKey(slotName);
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Convention.WindowsUI;
using Convention.WindowsUI.Variant;
using UnityEngine;
namespace Convention.Workflow
{
[Serializable, ArgPackage]
public class ResourceNodeInfo : StartNodeInfo
{
[NonSerialized] private string l_resource = WorkflowManager.Transformer(nameof(resource));
[InspectorDraw(InspectorDrawType.Text, true, true, nameGenerater: nameof(l_resource))]
public string resource = "unknown";
public ResourceNodeInfo() : this("") { }
public ResourceNodeInfo(string resource, string outmappingName = "value")
{
this.resource = resource;
this.outmapping = new()
{
{
outmappingName, new NodeSlotInfo()
{
slotName = outmappingName,
typeIndicator = "string",
IsInmappingSlot = false,
}
}
};
this.inmapping = new();
this.title = "Resource";
}
protected override NodeInfo CreateTemplate()
{
return new ResourceNodeInfo();
}
protected override void CloneValues([In] NodeInfo clonen)
{
((ResourceNodeInfo)clonen).resource = this.resource;
base.CloneValues(clonen);
}
}
public class ResourceNode : StartNode, IText
{
[Resources, OnlyNotNullMode] public ModernUIInputField InputField;
[Content, OnlyPlayMode] public bool isEditing = false;
public ResourceNodeInfo MyResourceNodeInfo => this.info as ResourceNodeInfo;
public string text { get => ((IText)this.InputField).text; set => ((IText)this.InputField).text = value; }
protected override void Start()
{
base.Start();
InputField.InputFieldSource.Source.onSelect.AddListener(_ => isEditing = true);
InputField.InputFieldSource.Source.onEndEdit.AddListener(str =>
{
MyResourceNodeInfo.resource = str;
isEditing = false;
});
}
private void LateUpdate()
{
if (info != null && this.isEditing == false && RectTransformExtension.IsVisible(this.rectTransform))
{
this.text = this.MyResourceNodeInfo.resource;
}
}
}
}

View File

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

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Convention.WindowsUI;
using Convention.WindowsUI.Variant;
using UnityEngine;
namespace Convention.Workflow
{
public class SelectorNodeInfo : StartNodeInfo
{
public virtual IEnumerable<string> EnumNamesGenerater()
{
return new List<string>()
{
WorkflowManager.Transformer("unknown")
};
}
[NonSerialized] private string l_select = WorkflowManager.Transformer(nameof(select));
[InspectorDraw(InspectorDrawType.Enum, true, false, nameGenerater: nameof(l_select), enumGenerater: nameof(EnumNamesGenerater))]
public string select = "";
public SelectorNodeInfo() : this("") { }
public SelectorNodeInfo(string select, string outputName = "select")
{
this.select = select;
this.outmapping = new()
{
{
outputName, new NodeSlotInfo()
{
slotName = outputName,
typeIndicator="string",
IsInmappingSlot=false
}
}
};
this.inmapping = new();
this.title = "Selector";
}
protected override NodeInfo CreateTemplate()
{
return new SelectorNodeInfo();
}
protected override void CloneValues([In] NodeInfo clonen)
{
var info = (SelectorNodeInfo)clonen;
info.select = select;
info.outmapping = new(outmapping);
base.CloneValues(clonen);
}
}
public class SelectorNode : StartNode
{
[Resources, OnlyNotNullMode,SerializeField] private ModernUIDropdown DropDown;
public SelectorNodeInfo MySelectorInfo => info as SelectorNodeInfo;
protected override void Start()
{
base.Start();
DropDown.AddListener(x => MySelectorInfo.select = x);
}
protected virtual void RebuildDropDown(ModernUIDropdown dropdown, SelectorNodeInfo info)
{
foreach (var name in info.EnumNamesGenerater())
{
dropdown.CreateOption(name);
}
dropdown.RefreshImmediate();
if (string.IsNullOrEmpty(info.select) == false)
dropdown.Select(info.select);
}
protected override void WhenSetup(NodeInfo info)
{
RebuildDropDown(DropDown, info as SelectorNodeInfo);
base.WhenSetup(info);
}
}
}

View File

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

View File

@@ -0,0 +1,73 @@
using System.Linq;
using Convention.WindowsUI;
using Convention.WindowsUI.Variant;
using UnityEngine;
namespace Convention.Workflow
{
public class TextNodeInfo : StartNodeInfo
{
private string l_text => WorkflowManager.Transformer(nameof(text));
[InspectorDraw(InspectorDrawType.Text, nameGenerater: nameof(l_text))]
public string text;
public TextNodeInfo() : this("") { }
public TextNodeInfo(string text, string outmappingName = "text")
{
this.text = text;
this.outmapping = new()
{
{
outmappingName, new NodeSlotInfo()
{
slotName = outmappingName,
typeIndicator = "string",
IsInmappingSlot = false,
}
}
};
this.inmapping = new();
this.title = "Text";
}
protected override NodeInfo CreateTemplate()
{
return new TextNodeInfo();
}
protected override void CloneValues([In] NodeInfo clonen)
{
((TextNodeInfo)clonen).text = text;
base.CloneValues(clonen);
}
}
public class TextNode : StartNode, IText
{
[Resources, OnlyNotNullMode] public ModernUIInputField InputField;
[Content, OnlyPlayMode] public bool isEditing = false;
public TextNodeInfo MyTextNodeInfo => this.info as TextNodeInfo;
public string text { get => ((IText)this.InputField).text; set => ((IText)this.InputField).text = value; }
protected override void Start()
{
base.Start();
InputField.InputFieldSource.Source.onSelect.AddListener(_ => isEditing = true);
InputField.InputFieldSource.Source.onEndEdit.AddListener(str =>
{
MyTextNodeInfo.text = str;
isEditing = false;
});
}
private void LateUpdate()
{
if (info != null && this.isEditing == false && RectTransformExtension.IsVisible(this.rectTransform))
{
this.text = this.MyTextNodeInfo.text;
}
}
}
}

View File

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

View File

@@ -0,0 +1,96 @@
using System;
using System.Linq;
using Convention.WindowsUI;
using Convention.WindowsUI.Variant;
using UnityEngine;
namespace Convention.Workflow
{
public class ValueNodeInfo : StartNodeInfo
{
[NonSerialized] private string l_value = WorkflowManager.Transformer(nameof(value));
[InspectorDraw(InspectorDrawType.Text, true, true, nameGenerater: nameof(l_value))]
public float value = 0;
[NonSerialized] private string l_min = WorkflowManager.Transformer(nameof(min));
[InspectorDraw(InspectorDrawType.Auto, true, true, nameGenerater: nameof(l_min))]
public float min = 0;
[NonSerialized]private string l_max = WorkflowManager.Transformer(nameof(max));
[InspectorDraw(InspectorDrawType.Auto, true, true, nameGenerater: nameof(l_max))]
public float max = 1;
public ValueNodeInfo() : this(0) { }
public ValueNodeInfo(float value, string outmappingName = "value")
{
this.value = value;
this.outmapping = new()
{
{
outmappingName, new NodeSlotInfo()
{
slotName = outmappingName,
typeIndicator = "float",
IsInmappingSlot = false,
}
}
};
this.inmapping = new();
this.title = "Value";
}
protected override NodeInfo CreateTemplate()
{
return new ValueNodeInfo();
}
protected override void CloneValues([In] NodeInfo clonen)
{
var info = ((ValueNodeInfo)clonen);
info.value = value;
info.min = min;
info.max = max;
base.CloneValues(clonen);
}
}
public class ValueNode : StartNode, IText
{
[Resources, OnlyNotNullMode] public ModernUIInputField InputField;
[Resources, OnlyNotNullMode] public ModernUIFillBar RangeBar;
[Content, OnlyPlayMode] public bool isEditing = false;
public ValueNodeInfo MyValueNodeInfo => this.info as ValueNodeInfo;
public string text { get => ((IText)this.InputField).text; set => ((IText)this.InputField).text = value; }
protected override void Start()
{
base.Start();
InputField.InputFieldSource.Source.onSelect.AddListener(_ => isEditing = true);
InputField.InputFieldSource.Source.onEndEdit.AddListener(str =>
{
if (float.TryParse(str, out float value))
MyValueNodeInfo.value = value;
else
MyValueNodeInfo.value = 0;
isEditing = false;
});
}
protected override void WhenSetup(NodeInfo info)
{
base.WhenSetup(info);
RangeBar.minValue = MyValueNodeInfo.min;
RangeBar.maxValue = MyValueNodeInfo.max;
RangeBar.SetValue(MyValueNodeInfo.value);
}
private void LateUpdate()
{
if (info != null && this.isEditing == false && RectTransformExtension.IsVisible(this.rectTransform))
{
RangeBar.minValue = MyValueNodeInfo.min;
RangeBar.maxValue = MyValueNodeInfo.max;
RangeBar.SetValue(MyValueNodeInfo.value);
}
}
}
}

View File

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