Skip to content

Commit

Permalink
#479 GameNodeMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
ZerlindaYu authored and koschke committed Dec 28, 2022
1 parent 0b5715b commit 525fa8e
Showing 1 changed file with 21 additions and 64 deletions.
85 changes: 21 additions & 64 deletions Assets/SEE/Game/GameNodeMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,89 +19,46 @@ public static class GameNodeMarker
/// </summary>
/// <param name="nodeID">the unique ID of the new node; if null or empty, an empty ID will be used</param>
/// <returns>new graph node</returns>
private static Mark NewGraphMark(string nodeID,int spehre)
private static Node NewGraphNode(string nodeID)
{
string ID = string.IsNullOrEmpty(nodeID) ? Guid.NewGuid().ToString() : nodeID;
return new Node()
{
ID = ID,
Spehre = spehre,
SourceName = string.Empty,
Type = Graph.UnknownType
};
}



/// <summary>
/// Adds a <paramref name="node"/> as a child of <paramref name="parent"/> to the
/// graph containing <paramref name="parent"/> with a random unique ID.
///
/// If node has no ID yet (null or empty), a random unique ID will be used. If it has
/// an ID, that ID will be kept. In case this ID is not unique, an exception will
/// be thrown.
/// Creates and returns a new node mark.
///
/// Precondition: <paramref name="parent"/> must not be null, neither may
/// <paramref name="parent"/> and <paramref name="node"/> be equal; otherwise an exception
/// will be thrown.
/// </summary>
/// <param name="parent">The node that should be the parent of <paramref name="node"/></param>
/// <param name="node">The node to add to the graph</param>
private static void AddMarkToGraph(Node node, Node mark)
/// <param name="diameter">the diameter of the sphere of the mark</param>
/// <param name="nodeid">the unique ID of the new node; if null or empty, a random ID will be used</param>
/// <returns>new node mark or null if none could be created</returns>
/// <exception cref="Exception">thrown if <paramref name="mark"/> is not contained in a code city</exception>
public static GameObject AddMark(GameObject mark,int diameter,string nodeid)
{
if (node == null)
{
throw new Exception("Node must not be null.");
}
else if (parent== mark)
{
throw new Exception("Node must not be its own mark.");
}
else
SEECity city = mark.ContainingCity() as SEECity;
if (city != null)
{
Graph graph = node.ItsGraph;
if (graph == null)
if (mark != null)
{
throw new Exception("Node must be in a graph.");
Destroyer.DestroyGameObject(mark);
}
if (string.IsNullOrEmpty(mark.ID))
else
{
// Loop until the node.ID is unique within the graph.
mark.ID = Guid.NewGuid().ToString();
while (graph.GetNode(mark.ID) != null)
{
mark.ID = Guid.NewGuid().ToString();
}
Node node = NewGraphNode(nodeID);
mark = GameObject.CreatePrimitive(PrimitiveType.Sphere);
mark.transform.position = node.transform.position;
mark.transform.localScale = node.transform.localScale;
mark.GetComponent<SphereCollider>().radius = diameter;
mark.GetComponent<Renderer>().material.color = Color.Blue;
}
graph.AddNode(node);
node.AddMark(mark, node.position.x, node.ID);
}
}

/// <summary>
/// Creates and returns a new game node as a child of <paramref name="parent"/> at the
/// given <paramref name="position"/> with the given <paramref name="worldSpaceScale"/>.
///
/// Precondition: <paramref name="parent"/> must have a valid node reference.
/// </summary>
/// <param name="parent">parent of the new node</param>
/// <param name="position">the position in world space for the center point of the new game node</param>
/// <param name="worldSpaceScale">the scale in world space of the new game node</param>
/// <param name="nodeID">the unique ID of the new node; if null or empty, a random ID will be used</param>
/// <returns>new child game node or null if none could be created</returns>
/// <exception cref="Exception">thrown if <paramref name="parent"/> is not contained in a code city</exception>
public static GameObject AddMark(GameObject mark,int diameter,string nodeid)
{
SEECity city = mark.ContainingCity() as SEECity;
if (city != null)
{
Node node = NewGraphNode(nodeID);
AddMarkToGraph(mark.GetNode(), mark);



GameObject result = city.Renderer.DrawNode(mark);
result.transform.position = node.transform.position;

return result;
return mark;
}
else
{
Expand Down

0 comments on commit 525fa8e

Please sign in to comment.