/// <summary> /// Manufactures a random diagram /// </summary> /// <param name="diagramName"></param> /// <returns></returns> Serializablediagram IdiagramSerializer.Loaddiagram(string diagramName) { var diagram = _saveddiagrams.SingleOrDefault(s => s.diagramName == diagramName); return(diagram); // create a random diagram var numberOfNodes = UnityEngine.Random.Range(10, 40); var numberOfConnectors = UnityEngine.Random.Range(numberOfNodes * 2, numberOfNodes * 5); var nodeList = new List <SerializableNode>(); for (int i = 0; i < numberOfNodes; i++) { var newNode = new SerializableNode(Guid.NewGuid(), i.ToString(), "", Color.blue); nodeList.Add(newNode); } var connectorList = new List <SerializableConnector>(); for (int i = 0; i < numberOfConnectors; i++) { var nodeInd = UnityEngine.Random.Range(0, numberOfNodes); var originNode = nodeList[nodeInd]; nodeInd = UnityEngine.Random.Range(0, numberOfNodes); var endNode = nodeList[nodeInd]; var newConnector = new SerializableConnector(originNode.uniqueID, endNode.uniqueID); connectorList.Add(newConnector); } var sdiagram = new Serializablediagram("Random diagram - " + Guid.NewGuid().ToString(), nodeList, connectorList); return(sdiagram); }
/// <summary> /// Creates a node from a serialized node /// </summary> /// <param name="diagram"></param> /// <returns></returns> public static Node CreateNode(Diagram diagram, SerializableNode serializedNode) { GameObject newNodeObj = Instantiate(Instance._nodeTypes.Single(n => n.NodeTypeName == serializedNode.type).NodeObject); newNodeObj.transform.parent = diagram.transform; Node newNode = newNodeObj.AddComponent <Node>(); newNode.name = serializedNode.name; newNode.UniqueID = serializedNode.uniqueID; newNode.NodeType = serializedNode.type; return(newNode); }