From 1246657b24616c45fe9feb3fc53db4a6cc9eb9bd Mon Sep 17 00:00:00 2001
From: Marius Kern <mariusskern@gmail.com>
Date: Thu, 7 Mar 2024 17:32:45 +0100
Subject: [PATCH] new gadget

---
 .../GadgetDataContainerGadgetCollection.asset |  4 ++-
 .../TestGadgetDataContainerGadgetInit.asset   | 26 +++++++++++++++
 ...stGadgetDataContainerGadgetInit.asset.meta |  8 +++++
 .../InteractionEngine/Gadgets/Gadget.cs       |  3 ++
 .../InteractionEngine/Gadgets/TestGadget.cs   | 33 +++++++++++++++++++
 .../Gadgets/TestGadget.cs.meta                | 11 +++++++
 6 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset
 create mode 100644 Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset.meta
 create mode 100644 Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs
 create mode 100644 Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs.meta

diff --git a/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset b/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset
index f1d6edce..9310e7a2 100644
--- a/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset
+++ b/Assets/ScriptableObjects/Gadgets/GadgetDataContainerGadgetCollection.asset
@@ -27,7 +27,8 @@ MonoBehaviour:
   - {fileID: 21300000, guid: d456617ba2282854d9570dcebcc2b279, type: 3}
   - {fileID: 21300000, guid: e35797aede3d7bd449ca9195a409b0cc, type: 3}
   - {fileID: 21300000, guid: 9831128faf2531e4cba52f58894091be, type: 3}
-  GadgetType: ffffffff00000000010000000200000003000000040000000500000006000000070000000800000009000000
+  - {fileID: 21300000, guid: e706f1d2fb068e342b1c80c357d84b40, type: 3}
+  GadgetType: ffffffff000000000100000002000000030000000400000005000000060000000700000008000000090000000a000000
   GadgetData:
   - {fileID: 11400000, guid: 7431ff31b707d2a4082b65b61e15e5df, type: 2}
   - {fileID: 11400000, guid: c149a1e468d3b3b48a0732c2e0811856, type: 2}
@@ -40,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: 9c857513d338e4549ad22b712627eda6, type: 2}
diff --git a/Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset b/Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset
new file mode 100644
index 00000000..cef4362c
--- /dev/null
+++ b/Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.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: TestGadgetDataContainerGadgetInit
+  m_EditorClassIdentifier: Assembly-CSharp::DataContainerGadgetInit
+  Rank: 0
+  MaxRange: Infinity
+  MaxHeight: Infinity
+  UiName: Test Gadget
+  MaterialIndx: 0
+  ButtonIndx: 11
+  LayerHitMask:
+    serializedVersion: 2
+    m_Bits: 1581105
+  SecondaryLayerMask:
+    serializedVersion: 2
+    m_Bits: 0
diff --git a/Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset.meta b/Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset.meta
new file mode 100644
index 00000000..e66aab52
--- /dev/null
+++ b/Assets/ScriptableObjects/Gadgets/TestGadgetDataContainerGadgetInit.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 9c857513d338e4549ad22b712627eda6
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 11400000
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs b/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs
index d9958998..826d8d48 100644
--- a/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs
+++ b/Assets/Scripts/InteractionEngine/Gadgets/Gadget.cs
@@ -12,6 +12,7 @@
 /// </summary>
 [JsonConverter(typeof(JsonSubtypes), "s_type")]
 [JsonSubtypes.KnownSubType(typeof(Pointer), "Pointer")]
+[JsonSubtypes.KnownSubType(typeof(TestGadget), "TestGadget")]
 [JsonSubtypes.KnownSubType(typeof(Tape), "Tape")]
 [JsonSubtypes.KnownSubType(typeof(LineTool), "LineTool")]
 [JsonSubtypes.KnownSubType(typeof(LotTool), "LotTool")]
@@ -47,11 +48,13 @@ public enum GadgetIDs
         Remover = 7,
         EqualCircles = 8,
         MiddlePoint = 9,
+        TestGadget = 10,
     }
 
     public static Dictionary<Type, GadgetIDs> GadgetTypeToIDs = new(){
         {typeof(UndefinedGadget)    , GadgetIDs.Undefined },
         {typeof(Pointer)            , GadgetIDs.Pointer },
+        {typeof(TestGadget)            , GadgetIDs.TestGadget },
         {typeof(Tape)               , GadgetIDs.Tape },
         {typeof(AngleTool)          , GadgetIDs.AngleTool },
         {typeof(LineTool)           , GadgetIDs.LineTool },
diff --git a/Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs b/Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs
new file mode 100644
index 00000000..f08f3cce
--- /dev/null
+++ b/Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs
@@ -0,0 +1,33 @@
+using UnityEngine;
+
+public class TestGadget : Gadget
+{
+    /// \copydoc Gadget.s_type
+    [Newtonsoft.Json.JsonProperty]
+    protected static new string s_type = "TestGadget";
+
+
+    protected override void _Hit(RaycastHit[] hit)
+    {
+        string pid = FactAdder.AddPointFact(hit[0], gadget: this).Id;
+
+        for (int i = 0; i < hit.Length; i++)
+        {
+            if (!Mathf.Approximately(hit[0].distance, hit[i].distance))
+                break;
+
+            if (hit[i].transform.gameObject.layer == LayerMask.NameToLayer("Ray"))
+            {
+                Workflow.Add(hit[i].transform.GetComponent<FactObject>().URI);
+                FactAdder.AddOnLineFact
+                    (pid
+                    , Workflow[i]
+                    , samestep: true
+                    , gadget: this
+                    , is_certain: false);
+            }
+        }
+
+        ResetGadget();
+    }
+}
diff --git a/Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs.meta b/Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs.meta
new file mode 100644
index 00000000..dfbf87af
--- /dev/null
+++ b/Assets/Scripts/InteractionEngine/Gadgets/TestGadget.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 201a7ead1e39b2d4e832db9738fb7c19
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
-- 
GitLab