From ce73a1338de58d796b080a65f290fc27558df9d4 Mon Sep 17 00:00:00 2001 From: Arshvir Goraya <113562877+ArshvirGoraya@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:09:44 -0500 Subject: [PATCH] customize map notes model --- Assets/Scripts/Game/Automap.cs | 78 ++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Game/Automap.cs b/Assets/Scripts/Game/Automap.cs index a757a91905..d7a240dfb6 100644 --- a/Assets/Scripts/Game/Automap.cs +++ b/Assets/Scripts/Game/Automap.cs @@ -243,6 +243,7 @@ public enum AutomapFocusObject int idOfUserMarkerNoteToBeChanged; // used to identify id of last double-clicked user note marker when changing note text DaggerfallInputMessageBox messageboxUserNote; GameObject gameObjectUserNoteMarkers = null; // container object for custom user notes markers + GameObject customGameObjectUserNoteMarker = null; /// @@ -368,6 +369,18 @@ public static bool IsCreatingDungeonAutomapBaseGameObjects get { return isCreatingDungeonAutomapBaseGameObjects; } } + /// + /// Used to overwrite the gameObjectUserNoteMarker to a custom prefab. + /// Only overwrites if not null. + /// Default: null. + /// Note: The Prefab must contain at least 1 collider for it to be edited/removed. + /// + public GameObject CustomGameObjectUserNoteMarker + { + set { customGameObjectUserNoteMarker = value; } + get { return customGameObjectUserNoteMarker; } + } + #endregion #region Public Methods @@ -811,11 +824,16 @@ public bool TryToRemoveUserNoteMarkerOnDungeonSegmentAtScreenPosition(Vector2 sc if (nearestHit.HasValue) { if (nearestHit.Value.transform.name.StartsWith(NameGameobjectUserNoteMarkerSubStringStart)) // if user note marker was hit - { + { int id = System.Convert.ToInt32(nearestHit.Value.transform.name.Replace(NameGameobjectUserNoteMarkerSubStringStart, "")); if (listUserNoteMarkers.ContainsKey(id)) listUserNoteMarkers.Remove(id); // remove it from list - GameObject.Destroy(nearestHit.Value.transform.gameObject); // and destroy gameobject + + if (customGameObjectUserNoteMarker == null){ + GameObject.Destroy(nearestHit.Value.transform.gameObject); // and destroy gameobject + } else { + GameObject.Destroy(GetHighestAncestorBelowAncestor(nearestHit.Value.transform.gameObject, NameGameobjectUserMarkerNotes)); + } return true; } } @@ -1574,15 +1592,24 @@ private GameObject CreateUserMarker(int id, Vector3 spawningPosition) gameObjectUserNoteMarkers.transform.SetParent(gameobjectAutomap.transform); gameObjectUserNoteMarkers.layer = layerAutomap; } - GameObject gameObjectUserNoteMarker = CreateDiamondShapePrimitive(); + + GameObject gameObjectUserNoteMarker; + if (customGameObjectUserNoteMarker == null){ + gameObjectUserNoteMarker = CreateDiamondShapePrimitive(); + gameObjectUserNoteMarker.name = NameGameobjectUserNoteMarkerSubStringStart + id; + gameObjectUserNoteMarker.layer = layerAutomap; + Material materialUserNoteMarker = new Material(Shader.Find("Standard")); + materialUserNoteMarker.color = new Color(1.0f, 0.55f, 0.0f); + gameObjectUserNoteMarker.GetComponent().material = materialUserNoteMarker; + gameObjectUserNoteMarker.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f); + }else{ + gameObjectUserNoteMarker = Instantiate(customGameObjectUserNoteMarker); + SetLayerRecursively(gameObjectUserNoteMarker, layerAutomap); + SetNameRecursively(gameObjectUserNoteMarker, NameGameobjectUserNoteMarkerSubStringStart + id); + } + gameObjectUserNoteMarker.transform.SetParent(gameObjectUserNoteMarkers.transform); gameObjectUserNoteMarker.transform.position = spawningPosition; - gameObjectUserNoteMarker.name = NameGameobjectUserNoteMarkerSubStringStart + id; - Material materialUserNoteMarker = new Material(Shader.Find("Standard")); - materialUserNoteMarker.color = new Color(1.0f, 0.55f, 0.0f); - gameObjectUserNoteMarker.GetComponent().material = materialUserNoteMarker; - gameObjectUserNoteMarker.layer = layerAutomap; - gameObjectUserNoteMarker.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f); return gameObjectUserNoteMarker; } @@ -1716,6 +1743,39 @@ private static void SetLayerRecursively(GameObject obj, int layer) } } + /// + /// sets name of a GameObject and all of its childs recursively + /// + /// the target GameObject + /// the name to be set + private static void SetNameRecursively(GameObject obj, string name) + { + obj.name = name; + + foreach (Transform child in obj.transform) + { + SetNameRecursively(child.gameObject, name); + } + } + + /// + /// Gets the highest ancestor which is below a specified ancestor. + /// Returns null if specified ancestor cannot be found. + /// + /// the child from which the search begins + /// the name of the ancestor + private static GameObject GetHighestAncestorBelowAncestor(GameObject child, string name){ + if (child.transform.parent == null){ + return null; + } + + if (child.transform.parent.name == name){ + return child.transform.gameObject; + } + + return GetHighestAncestorBelowAncestor(child.transform.parent.gameObject, name); + } + /// /// updates the micro map texture ///