From f868dea90e5094c72a9753c1ac922efa76469d4d Mon Sep 17 00:00:00 2001 From: Lysander <73167687+lilSander@users.noreply.github.com> Date: Wed, 25 Oct 2023 22:27:34 +0200 Subject: [PATCH] Fixed a few minor code issues. --- Assets/SEE/Controls/Actions/MarkAction.cs | 11 +++----- .../Game/SceneManipulation/GameNodeMarker.cs | 26 +++++++++---------- Assets/SEE/Net/Actions/MarkNetAction.cs | 2 +- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Assets/SEE/Controls/Actions/MarkAction.cs b/Assets/SEE/Controls/Actions/MarkAction.cs index 6d2ab49e51..a5aeff389d 100644 --- a/Assets/SEE/Controls/Actions/MarkAction.cs +++ b/Assets/SEE/Controls/Actions/MarkAction.cs @@ -30,12 +30,10 @@ public override bool Update() { // the hit object is the parent in which to create the new node GameObject parent = raycastHit.collider.gameObject; - Vector3 position = GameObjectExtensions.GetTop(parent); - Vector3 scale = parent.transform.lossyScale; - addedSphere = GameNodeMarker.NewSphere(parent, scale); + addedSphere = GameNodeMarker.NewSphere(parent); // addedSphere has the scale of parent and position on top of the parent. - memento = new Memento(parent, position, scale); - new MarkNetAction(memento.Parent.name, position, scale).Execute(); //ID: memento.Parent.name, memento.Position, memento.Scale + memento = new Memento(parent, addedSphere.transform.position, addedSphere.transform.position); + new MarkNetAction(memento.Parent.name, addedSphere.transform.position, addedSphere.transform.position).Execute(); result = true; CurrentState = IReversibleAction.Progress.Completed; AudioManagerImpl.EnqueueSoundEffect(IAudioManager.SoundEffect.NewNodeSound, parent); @@ -111,7 +109,7 @@ public override void Undo() public override void Redo() { base.Redo(); - addedSphere = GameNodeMarker.NewSphere(memento.Parent, memento.Scale); + addedSphere = GameNodeMarker.NewSphere(memento.Parent); if (addedSphere != null) { new MarkNetAction(memento.Parent.name, memento.Position, memento.Scale).Execute(); @@ -153,7 +151,6 @@ public override HashSet GetChangedObjects() { return new HashSet { - memento.Parent.name, memento.ParentID }; } diff --git a/Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs b/Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs index f1f6ec65e2..45bc40fd07 100644 --- a/Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs +++ b/Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs @@ -9,7 +9,9 @@ namespace SEE.Game.SceneManipulation { /// - /// Creates new game objects representing marker. + /// Creates new game objects representing a marker. + /// The position is over the marked Node. + /// The scale is proportional to the marked Node. /// public static class GameNodeMarker { @@ -22,24 +24,23 @@ public static class GameNodeMarker private static GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); //[SerializeField] private static List markedNodes; - public static GameObject NewSphere(GameObject parent, Vector3 scale) + public static GameObject NewSphere(GameObject parent) { if (parent == null) { throw new Exception("Parent must not be null."); } - else if (existing(parent) && (sphere.activeSelf != false)) + else if (Existing(parent) && !sphere.activeSelf) { sphere.SetActive(false); return null; } sphere.GetComponent().material.color = Color.red; - float realScale = Math.Min(scale.x, scale.y); - Vector3 position = GameObjectExtensions.GetTop(parent); - sphere.transform.position = position; //parent.transform.position; - sphere.transform.localScale = new Vector3(realScale, realScale, realScale); //parent.transform.lossyScale; - //bool hm = parent.transform.GetChild(parent.transform.childCount) == sphere; + float realScale = Math.Min(parent.transform.lossyScale.x, parent.transform.lossyScale.y); + Vector3 position = parent.GetTop(); + sphere.transform.position = position; + sphere.transform.localScale = new Vector3(realScale, realScale, realScale); sphere.transform.SetParent(parent.transform); sphere.SetActive(true); return sphere; @@ -50,14 +51,11 @@ public static GameObject NewSphere(GameObject parent, Vector3 scale) /// /// the parent node of the sphere /// true if the parent already has a sphere - public static bool existing(GameObject parent) + public static bool Existing(GameObject parent) { - for (int i = 0; i <= parent.transform.childCount - 1; i++) + if (parent.transform.Find("Sphere")) { - if (parent.transform.GetChild(i).transform.name == "Sphere") - { - return true; - } + return true; } return false; } diff --git a/Assets/SEE/Net/Actions/MarkNetAction.cs b/Assets/SEE/Net/Actions/MarkNetAction.cs index 6c03c0c4d4..c20ccc8522 100644 --- a/Assets/SEE/Net/Actions/MarkNetAction.cs +++ b/Assets/SEE/Net/Actions/MarkNetAction.cs @@ -4,7 +4,7 @@ namespace SEE.Net.Actions { /// - /// This class is responsible for adding a node via network from one client to all others and + /// This class is responsible for marking a node via network from one client to all others and /// to the server. /// public class MarkNetAction : AbstractNetAction