diff --git a/ProjectObsidian/Components/Radiant UI/Data Feeds/Feeds/ComponentsDataFeed.cs b/ProjectObsidian/Components/Radiant UI/Data Feeds/Feeds/ComponentsDataFeed.cs index 1b3faf2..d0b1576 100644 --- a/ProjectObsidian/Components/Radiant UI/Data Feeds/Feeds/ComponentsDataFeed.cs +++ b/ProjectObsidian/Components/Radiant UI/Data Feeds/Feeds/ComponentsDataFeed.cs @@ -120,9 +120,9 @@ private void Unsubscribe(Slot s) s.ComponentRemoved -= OnSlotComponentRemoved; } - protected override void OnAwake() + protected override void OnStart() { - base.OnAwake(); + base.OnStart(); _lastSlot = TargetSlot.Target; if (_lastSlot != null) { diff --git a/ProjectObsidian/Components/Utility/IsValidGenericTypeDriver.cs b/ProjectObsidian/Components/Utility/IsValidGenericTypeDriver.cs new file mode 100644 index 0000000..1f63e89 --- /dev/null +++ b/ProjectObsidian/Components/Utility/IsValidGenericTypeDriver.cs @@ -0,0 +1,28 @@ +using Elements.Core; +using FrooxEngine; +using System; +using System.Linq; + +namespace Obsidian; + +[Category(new string[] { "Obsidian/Utility" })] +public class IsValidGenericTypeDriver : Component +{ + public readonly SyncType Type; + + public readonly FieldDrive Target; + + protected override void OnChanges() + { + base.OnChanges(); + if (!Target.IsLinkValid) return; + if (Type.Value == null || !Type.Value.IsGenericType) + { + Target.Target.Value = false; + } + else + { + Target.Target.Value = Type.Value.IsValidGenericType(validForInstantiation: true); + } + } +} \ No newline at end of file diff --git a/ProjectObsidian/Components/Utility/StringToTypeDriver.cs b/ProjectObsidian/Components/Utility/StringToTypeDriver.cs new file mode 100644 index 0000000..ce2c61a --- /dev/null +++ b/ProjectObsidian/Components/Utility/StringToTypeDriver.cs @@ -0,0 +1,36 @@ +using Elements.Core; +using FrooxEngine; +using System; + +namespace Obsidian; + +[Category(new string[] { "Obsidian/Utility" })] +public class StringToTypeDriver : Component +{ + public readonly Sync Text; + + public readonly FieldDrive Target; + + protected override void OnChanges() + { + base.OnChanges(); + if (!Target.IsLinkValid) return; + if (string.IsNullOrWhiteSpace(Text.Value)) + { + Target.Target.Value = null; + } + else + { + try + { + var parsedType = WorkerManager.ParseNiceType(Text.Value); + Target.Target.Value = parsedType; + } + catch (Exception ex) + { + UniLog.Warning("Exception when parsing type from string:\n" + ex.ToString()); + Target.Target.Value = null; + } + } + } +} \ No newline at end of file