-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8497930
commit af575ff
Showing
7 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using SEE.Utils.History; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using SEE.GO; | ||
using SEE.Utils; | ||
using SEE.Game.Scenemanipulation; | ||
using SEE.Net.Actions; | ||
using SEE.Audio; | ||
using SEE.Game.SceneManipulation; | ||
|
||
namespace SEE.Controls.Actions { | ||
public class MarkAction : AbstractPlayerAction | ||
{ | ||
/// <summary> | ||
/// Returns a new instance of <see cref="MarkAction"/>. | ||
/// </summary> | ||
/// <returns>new instance</returns> | ||
public static IReversibleAction CreateReversibleAction() | ||
{ | ||
return new MarkAction(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the <see cref="ActionStateType"/> of this action. | ||
/// </summary> | ||
/// <returns><see cref="ActionStateTypes.Mark"/></returns> | ||
public override ActionStateType GetActionStateType() | ||
{ | ||
return ActionStateTypes.Mark; | ||
} | ||
|
||
/// <summary> | ||
/// If the user clicks with the mouse hitting a game object representing a graph node, | ||
/// will be marked. A sphere will appear above the marked node. | ||
/// <see cref="IReversibleAction.Update"/>. | ||
/// </summary> | ||
/// <returns>true if completed</returns> | ||
public override bool Update() | ||
{ | ||
bool result = false; | ||
|
||
// FIXME: Needs adaptation for VR where no mouse is available. | ||
if (Input.GetMouseButtonDown(0) | ||
&& Raycasting.RaycastGraphElement(out RaycastHit raycastHit, out GraphElementRef _) == HitGraphElement.Node) | ||
{ | ||
// the hit object is the parent in which to create the sphere | ||
GameObject parent = raycastHit.collider.gameObject; | ||
Vector3 position = parent.transform.position; | ||
Vector3 scale = parent.transform.lossyScale; | ||
// create or delete the sphere | ||
addedSphere = GameNodeMarker.CreateOrDeleteSphere(parent, scale); | ||
memento = new Memento(parent, position: position, scale: scale); | ||
memento.NodeID = addedSphere.name; | ||
new MarkNetAction(memento.Parent, memento.Position, memento.Scale).Execute(); | ||
result = true; | ||
CurrentState = IReversibleAction.Progress.Completed; | ||
AudioManagerImpl.EnqueueSoundEffect(IAudioManager.SoundEffect.NewNodeSound, parent); | ||
} | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// The node that was added when this action was executed. It is saved so | ||
/// that it can be removed on Undo(). | ||
/// </summary> | ||
private GameObject addedSphere; | ||
|
||
/// <summary> | ||
/// Memento capturing the data necessary to re-do this action. | ||
/// </summary> | ||
private Memento memento; | ||
|
||
/// <summary> | ||
/// The information we need to re-add a node whose addition was undone. | ||
/// </summary> | ||
private struct Memento | ||
{ | ||
/// <summary> | ||
/// The parent of the new node. | ||
/// </summary> | ||
public readonly GameObject Parent; | ||
|
||
/// <summary> | ||
/// The position of the new node in world space. | ||
/// </summary> | ||
public readonly Vector3 Position; | ||
|
||
/// <summary> | ||
/// The scale of the new node in world space. | ||
/// </summary> | ||
public readonly Vector3 Scale; | ||
|
||
/// <summary> | ||
/// The node ID for the added node. It must be kept to re-use the | ||
/// original name of the node in Redo(). | ||
/// </summary> | ||
public string NodeID; | ||
|
||
/// <summary> | ||
/// Constructor setting the information necessary to re-do this action. | ||
/// </summary> | ||
/// <param name="markedNode">The marked node</param> | ||
public Memento(GameObject parent, Vector3 position, Vector3 scale) | ||
{ | ||
Parent = parent; | ||
Position = position; | ||
Scale = scale; | ||
NodeID = null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns all IDs of gameObjects manipulated by this action. | ||
/// </summary> | ||
/// <returns>all IDs of gameObjects manipulated by this action</returns> | ||
public override HashSet<string> GetChangedObjects() | ||
{ | ||
return new HashSet<string> | ||
{ | ||
memento.Parent.name, | ||
memento.NodeID | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Returns a new instance of <see cref="MarkAction"/>. | ||
/// </summary> | ||
/// <returns>new instance</returns> | ||
public override IReversibleAction NewInstance() | ||
{ | ||
return CreateReversibleAction(); | ||
} | ||
|
||
/// <summary> | ||
/// Undoes this MarkAction. | ||
/// </summary> | ||
public override void Undo() | ||
{ | ||
base.Undo(); | ||
if (addedSphere != null) | ||
{ | ||
new DeleteNetAction(addedSphere.name).Execute(); | ||
Destroyer.Destroy(addedSphere); | ||
addedSphere = null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Redoes this MarkAction. | ||
/// </summary> | ||
public override void Redo() | ||
{ | ||
base.Redo(); | ||
addedSphere = GameNodeAdder.AddChild(memento.Parent, worldSpacePosition: memento.Position, worldSpaceScale: memento.Scale, nodeID: memento.NodeID); | ||
if (addedSphere != null) | ||
{ | ||
new MarkNetAction(memento.Parent, memento.Position, memento.Scale).Execute(); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fileFormatVersion: 2 | ||
guid: e3343ced081912e4ea17588e0f757233 | ||
MonoImporter: | ||
externalObjects: {} | ||
serializedVersion: 2 | ||
defaultReferences: [] | ||
executionOrder: 0 | ||
icon: {instanceID: 0} | ||
userData: | ||
assetBundleName: | ||
assetBundleVariant: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using SEE.Game.City; | ||
using SEE.GO; | ||
using SEE.Utils; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace SEE.Game.Scenemanipulation | ||
{ | ||
/// <summary> | ||
/// Creates or deletes sphere to mark certain nodes. | ||
/// </summary> | ||
public static class GameNodeMarker | ||
{ | ||
/// <summary> | ||
/// Creates a sphere above the selected node or deletes if a sphere exist. | ||
/// </summary> | ||
/// <param name="parent">selected node</param> | ||
/// <param name="scale">scale of the node</param> | ||
/// <returns></returns> | ||
public static GameObject CreateOrDeleteSphere(GameObject parent, Vector3 scale) | ||
{ | ||
GameObject sphere = null; | ||
//Search for sphere | ||
foreach(Transform child in parent.transform) | ||
{ | ||
if(child.name == "Sphere") | ||
{ | ||
sphere = child.gameObject; | ||
break; | ||
} | ||
} | ||
//Delete sphere if one existed | ||
if(sphere != null) | ||
{ | ||
Destroyer.Destroy(sphere); | ||
return null; | ||
} | ||
//Create and scale sphere | ||
else | ||
{ | ||
sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); | ||
sphere.transform.position = GameObjectExtensions.GetTop(parent); | ||
sphere.transform.localScale = scale; | ||
sphere.transform.SetParent(parent.transform); | ||
sphere.SetColor(parent.GetColor().Darker()); | ||
|
||
return sphere; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fileFormatVersion: 2 | ||
guid: cf226ed20a94fa348ba99cc4ec89cd26 | ||
MonoImporter: | ||
externalObjects: {} | ||
serializedVersion: 2 | ||
defaultReferences: [] | ||
executionOrder: 0 | ||
icon: {instanceID: 0} | ||
userData: | ||
assetBundleName: | ||
assetBundleVariant: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using SEE.Game.Scenemanipulation; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
|
||
namespace SEE.Net.Actions | ||
{ | ||
/// <summary> | ||
/// This class is responsible for marking a node via network from one client to all others and | ||
/// to the server. | ||
/// </summary> | ||
public class MarkNetAction : AbstractNetAction | ||
{ | ||
// Note: All attributes are made public so that they will be serialized | ||
// for the network transfer. | ||
|
||
/// <summary> | ||
/// The Parent gameObject. | ||
/// </summary> | ||
public GameObject Parent; | ||
|
||
/// <summary> | ||
/// The position of the node. | ||
/// </summary> | ||
public Vector3 Position; | ||
|
||
/// <summary> | ||
/// The scale of the node. | ||
/// </summary> | ||
public Vector3 Scale; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="parent">parent in which to mark the new node</param> | ||
/// <param name="position">the position for the parent node</param> | ||
/// <param name="scale">the scale of the parent node in world space</param> | ||
public MarkNetAction | ||
(GameObject parent, | ||
Vector3 position, | ||
Vector3 scale) | ||
: base() | ||
{ | ||
this.Parent = parent; | ||
this.Position = position; | ||
this.Scale = scale; | ||
} | ||
|
||
/// <summary> | ||
/// Marks a new GameObject on each client. | ||
/// </summary> | ||
protected override void ExecuteOnClient() | ||
{ | ||
if (!IsRequester()) | ||
{ | ||
GameObject markSphere = GameNodeMarker.CreateOrDeleteSphere(Parent, Scale); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Things to execute on the server (none for this class). Necessary because it is abstract | ||
/// in the superclass. | ||
/// </summary> | ||
protected override void ExecuteOnServer() | ||
{ | ||
// Intentionally left blank. | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fileFormatVersion: 2 | ||
guid: 80bd75152c10e0342b05382bcda6b095 | ||
MonoImporter: | ||
externalObjects: {} | ||
serializedVersion: 2 | ||
defaultReferences: [] | ||
executionOrder: 0 | ||
icon: {instanceID: 0} | ||
userData: | ||
assetBundleName: | ||
assetBundleVariant: |