From 264e73376de73e719d4d9f704d21f40a8422ac07 Mon Sep 17 00:00:00 2001 From: Paul-Walcher <paulwalcher12@gmail.com> Date: Mon, 30 Dec 2024 18:46:54 +0100 Subject: [PATCH] SphereGadget --- .../GadgetDataContainerGadgetCollection.asset | 5 +-- .../Gadgets/SphereGadgetData.asset | 26 +++++++++++++++ .../Gadgets/SphereGadgetData.asset.meta | 8 +++++ .../FactHandling/FactAdder.cs | 6 ++++ .../InteractionEngine/Gadgets/Gadget.cs | 3 ++ .../InteractionEngine/Gadgets/SphereGadget.cs | 32 +++++++++++++++++++ .../Gadgets/SphereGadget.cs.meta | 11 +++++++ 7 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset create mode 100644 Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset.meta create mode 100644 Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs create mode 100644 Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs.meta diff --git a/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset b/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset index 47177f03..9542b6a6 100644 --- a/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset +++ b/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset @@ -27,8 +27,8 @@ MonoBehaviour: - {fileID: 21300000, guid: d456617ba2282854d9570dcebcc2b279, type: 3} - {fileID: 21300000, guid: e35797aede3d7bd449ca9195a409b0cc, type: 3} - {fileID: 21300000, guid: 9831128faf2531e4cba52f58894091be, type: 3} - - {fileID: 21300000, guid: e706f1d2fb068e342b1c80c357d84b40, type: 3} - GadgetType: ffffffff00000000010000000200000003000000040000000500000006000000070000000800000009000000 + - {fileID: 21300000, guid: 13f4e064448182b49ba38b5035a1f45a, type: 3} + GadgetType: ffffffff000000000100000002000000030000000400000005000000060000000700000008000000090000000a000000 GadgetData: - {fileID: 11400000, guid: 7431ff31b707d2a4082b65b61e15e5df, type: 2} - {fileID: 11400000, guid: c149a1e468d3b3b48a0732c2e0811856, type: 2} @@ -41,3 +41,4 @@ MonoBehaviour: - {fileID: 11400000, guid: 06736b134e21b50488990025c33c9c2e, type: 2} - {fileID: 11400000, guid: 6bc4e283502549d428d3c9ce74e91757, type: 2} - {fileID: 11400000, guid: 35d3197399dc8374280464a237271ac5, type: 2} + - {fileID: 11400000, guid: 23a852b1469eeba4ebacccac54ec0f59, type: 2} diff --git a/Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset b/Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset new file mode 100644 index 00000000..26f90847 --- /dev/null +++ b/Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset @@ -0,0 +1,26 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 262a3c8caea4a7741b65ef20c568f5c2, type: 3} + m_Name: SphereGadgetData + m_EditorClassIdentifier: Assembly-CSharp::DataContainerGadgetInit + Rank: 11 + MaxRange: 10 + MaxHeight: 10 + UiName: Sphere Gadget + MaterialIndx: 0 + ButtonIndx: 11 + LayerHitMask: + serializedVersion: 2 + m_Bits: 1637393 + SecondaryLayerMask: + serializedVersion: 2 + m_Bits: 0 diff --git a/Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset.meta b/Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset.meta new file mode 100644 index 00000000..f9a037d0 --- /dev/null +++ b/Assets/ScriptableObjects/Gadgets/SphereGadgetData.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 23a852b1469eeba4ebacccac54ec0f59 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/InteractionEngine/FactHandling/FactAdder.cs b/Assets/Scripts/InteractionEngine/FactHandling/FactAdder.cs index 778b0ff9..ed7e288f 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/FactAdder.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/FactAdder.cs @@ -54,6 +54,12 @@ public static PointFact AddPointFact(Vector3 point, Vector3 normal, bool sameste , out _, samestep, gadget, scroll_label); } + public static SphereFact AddSphereFact(string pid1, string pid2, bool samestep = false, Gadget gadget = null, string scroll_label = null){ + + return (SphereFact)AddFactIfNotFound( + new SphereFact(pid1, pid2), out _, samestep, gadget, scroll_label); + } + /// \copybrief FactManager <summary></summary> /// <param name="pid"><see cref="Fact.Id"/> of <see cref="PointFact"/> which lies on <paramref name="lid"/></param> /// <param name="lid"><see cref="Fact.Id"/> of <see cref="LineFact"/> on which <paramref name="pid"/> lies</param> diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs b/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs index ec1cfc14..9ab1093a 100644 --- a/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs +++ b/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs @@ -20,6 +20,7 @@ [JsonSubtypes.KnownSubType(typeof(PoleTool), "PoleTool")] [JsonSubtypes.KnownSubType(typeof(Remover), "Remover")] [JsonSubtypes.KnownSubType(typeof(EqualCircleGadget), "EqualCircles")] +[JsonSubtypes.KnownSubType(typeof(SphereGadget), "SphereGadget")] [JsonSubtypes.FallBackSubType(typeof(UndefinedGadget))] public abstract class Gadget { @@ -47,6 +48,7 @@ public enum GadgetIDs Remover = 7, EqualCircles = 8, MiddlePoint = 9, + SphereGadget = 10, } @@ -62,6 +64,7 @@ public enum GadgetIDs {typeof(Remover) , GadgetIDs.Remover }, {typeof(EqualCircleGadget) , GadgetIDs.EqualCircles }, {typeof(TestMiddlePoint) , GadgetIDs.MiddlePoint }, + {typeof(SphereGadget) , GadgetIDs.SphereGadget}, }; /// <summary> Position in tool belt. </summary> diff --git a/Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs b/Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs new file mode 100644 index 00000000..e44b735a --- /dev/null +++ b/Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using UnityEngine; + +public class SphereGadget : Gadget +{ + /// \copydoc Gadget.s_type + [JsonProperty] + protected static new string s_type = "SphereTool"; + + //Cache for collecting the line + private readonly Vector3[] LineOrigin = new Vector3[1]; + + + protected override void _Hit(RaycastHit[] hit) + { + string tempFactId = hit[0].transform.GetComponent<FactObject>().URI; + if (!Workflow.Contains(tempFactId)) + Workflow.Add(tempFactId); + + switch (Workflow.Count) + { + case 1: + LineOrigin[0] = hit[0].transform.position; + break; + + case 2: + FactAdder.AddSphereFact(Workflow[0], Workflow[1], gadget: this); + ResetGadget(); + return; + } + } +} diff --git a/Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs.meta b/Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs.meta new file mode 100644 index 00000000..a6d11e83 --- /dev/null +++ b/Assets/Scripts/InteractionEngine/Gadgets/SphereGadget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b82608d3a00b8fd49bb3cf9f24d9dc28 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- GitLab