-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
497 onboarding timdinh #653
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
/// <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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why passing |
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work because your sphere is neither a node nor an edge and hence will not be added to |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. You must use |
||
if (addedSphere != null) | ||
{ | ||
new MarkNetAction(memento.Parent, memento.Position, memento.Scale).Execute(); | ||
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this blank line? |
||
} | ||
|
||
|
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: |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
/// <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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return is undocumented. |
||
public static GameObject CreateOrDeleteSphere(GameObject parent, Vector3 scale) | ||
{ | ||
GameObject sphere = null; | ||
//Search for sphere | ||
foreach(Transform child in parent.transform) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could replace the loop by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank after |
||
{ | ||
if(child.name == "Sphere") | ||
{ | ||
sphere = child.gameObject; | ||
break; | ||
} | ||
} | ||
//Delete sphere if one existed | ||
if(sphere != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank after |
||
{ | ||
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; | ||
} | ||
} | ||
} | ||
} | ||
|
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: |
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. | ||
} | ||
} | ||
} | ||
|
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is missing.