示例#1
0
 public void insertConnection(NetworkNode node, NodeConnections connection)
 {
     if (this.nodes.ContainsKey(node) == true)
     {
         if (this.nodes[node].Count == 0)
         {
             this.nodes[node].Add(connection);
         }
         else
         {
             Dictionary <NodeConnections, int> activeConnections = new Dictionary <NodeConnections, int>();
             foreach (NodeConnections activeConnection in this.nodes[node])
             {
                 if (activeConnections.ContainsKey(activeConnection) == false)
                 {
                     activeConnections.Add(activeConnection, 1);
                 }
             }
             if (activeConnections.ContainsKey(connection) == false)
             {
                 this.nodes[node].Add(connection);
             }
         }
     }
     else
     {
         List <NodeConnections> connectionList = new List <NodeConnections>();
         connectionList.Add(connection);
         this.nodes.Add(node, connectionList);
     }
 }
示例#2
0
    public void setActive(bool active)
    {
        isActiveNode = active;
        ship.SetActive(active);

        // Tell ObjectManager if I'm the new active node
        if (active)
        {
            ObjectManager.Instance.currentActiveNode = this;
        }

        // Game over, so don't do any game logic
        if (TimeCounter.Instance.gameOver)
        {
            return;
        }

        // Enable/disable the adjacent nodes as clickable
        NodeConnections myNodeConnections = GetComponent <NodeConnections>();

        if (myNodeConnections != null)
        {
            foreach (var node in myNodeConnections.connectedNodes.Keys)
            {
                ActiveNode nodeScript = node.GetComponent <ActiveNode>();
                if (nodeScript != null)
                {
                    nodeScript.setRingActive(isActiveNode);
                }
            }
        }
    }
示例#3
0
    public NetworkGraph findFinalGraph()
    {
        NetworkGraph returnGraph = new NetworkGraph();
        Dictionary <NetworkNode, NodeConnections> endPoints = new Dictionary <NetworkNode, NodeConnections>();

        foreach (NetworkNode existingNode in this.nodes.Keys.ToList())
        {
            returnGraph.insertNode(existingNode);
            if (this.nodes[existingNode].Count > 0)
            {
                foreach (NodeConnections connection in this.nodes[existingNode])
                {
                    if (endPoints.ContainsKey(connection.getEndNode()) == true)
                    {
                        NodeConnections test = endPoints[connection.getEndNode()];
                        if (endPoints[connection.getEndNode()].getConnectionLength() >= connection.getConnectionLength())
                        {
                            endPoints[connection.getEndNode()] = connection;
                        }
                    }
                    else
                    {
                        endPoints.Add(connection.getEndNode(), connection);
                    }
                }
            }
        }
        foreach (NetworkNode endPoint in endPoints.Keys.ToList())
        {
            returnGraph.insertConnection(endPoints[endPoint].getStartNode(), endPoints[endPoint]);
        }
        return(returnGraph);
    }
    IEnumerator ReplaceNodesForLevels()
    {
        foreach (var node in Nodes)
        {
            NodeConnections NodeConfigSet = node.GetConnectionSet();
            int             code          = LevelCoder.GetCode(NodeConfigSet);
            //print("Config Code: " + code);
            if (code == 0)
            {
                continue;
            }

            List <GameObject> posibleLevel = LevelCollectionManager.getLevelPrefabs(NodeConfigSet);
            if (posibleLevel.Count > 0)
            {
                //print("Lista de Posibles niveles: " + posibleLevel.Count);
                int randomIndex = UnityEngine.Random.Range(0, posibleLevel.Count);
                //print("Index Random: " + randomIndex);

                Vector3    nodePos = node.transform.position;
                Quaternion rot     = posibleLevel[randomIndex].transform.rotation;
                Instantiate(posibleLevel[randomIndex], nodePos, rot);
            }
            else
            {
                continue;
            }

            yield return(new WaitForEndOfFrame());
        }
        CleanNodes();
        print("Los nodos han sido reemplazados correctamente.");
        StopCoroutine(ReplaceNodesForLevels());
    }
 void Awake()
 {
     isGamePaused   = false;
     nodeGroup      = gameObject.GetComponent <NodeGroup>();
     nodeConnection = gameObject.GetComponent <NodeConnections>();
     joystick.GetComponentInParent <Canvas>().enabled = false;
 }
示例#6
0
 public NodeConnections getBestPath(NodeConnections otherConnection)
 {
     if (this.connectionLength >= otherConnection.getConnectionLength())
     {
         return(this);
     }
     else
     {
         return(otherConnection);
     }
 }
示例#7
0
    public Defs.ConnectionTypes GetConnectionType(NodeConnections node)
    {
        for (int i = 0; i < nodesToConnect.Count; i++)
        {
            if (nodesToConnect[i] == node)
            {
                return(nodeConnectionTypes[i]);
            }
        }

        return(Defs.ConnectionTypes.CONNECTIONTYPE_NOCONNECTION);
    }
示例#8
0
        /// <summary>
        /// Uses a 4-way fill algorithm to change items from one type to another.
        /// </summary>
        /// <typeparam name="TNode">The item type that is changed.</typeparam>
        /// <param name="node">The item to change.</param>
        /// <param name="shouldNodeChange">Determines if the node should change.</param>
        /// <param name="changeNode">After it is determined if the node should change, this changes the node.</param>
        /// <param name="getNodeConnections">Gets any other nodes connected to this node.</param>
        public static void FloodFill <TNode>(TNode node, Func <TNode, bool> shouldNodeChange, Action <TNode> changeNode, Func <TNode, NodeConnections <TNode> > getNodeConnections)
            where TNode : class
        {
            var queue = new Queue <TNode>();

            TNode workingNode = node;

            if (!shouldNodeChange(workingNode))
            {
                return;
            }

            queue.Enqueue(workingNode);

            while (true)
            {
                workingNode = queue.Dequeue();

                if (shouldNodeChange(workingNode))
                {
                    changeNode(workingNode);

                    NodeConnections <TNode> connections = getNodeConnections(workingNode);

                    if (connections.West != null)
                    {
                        queue.Enqueue(connections.West);
                    }

                    if (connections.East != null)
                    {
                        queue.Enqueue(connections.East);
                    }

                    if (connections.North != null)
                    {
                        queue.Enqueue(connections.North);
                    }

                    if (connections.South != null)
                    {
                        queue.Enqueue(connections.South);
                    }
                }

                if (queue.Count == 0)
                {
                    break;
                }
            }
        }
示例#9
0
 public bool areSameConnections(NodeConnections otherConnection)
 {
     if (this.startNode == otherConnection.getStartNode() && this.endNode == otherConnection.getEndNode())
     {
         return(true);
     }
     else if (this.endNode == otherConnection.getStartNode() && this.startNode == otherConnection.getEndNode())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#10
0
    public void LoadGraph()
    {
        NodeInfos nodeInfos = JsonUtility.FromJson <NodeInfos>(nodeInfosText.text);

        foreach (NodeInfo nodeInfo in nodeInfos.nodes)
        {
            GameObject spawnedNode = Instantiate(nodePrefab);
            spawnedNode.SetActive(false);
            NodeBehaviour node = spawnedNode.GetComponent <NodeBehaviour>();
            node.info  = nodeInfo;
            node.graph = this;
            nodeMap.Add(nodeInfo.id, spawnedNode);
        }

        HashSet <int>   allNodes         = new HashSet <int>();
        HashSet <int>   destinationNodes = new HashSet <int>();
        NodeConnections connectionsInfo  = JsonUtility.FromJson <NodeConnections>(nodeConnectionsText.text);

        foreach (NodeConnection connectionInfo in connectionsInfo.connections)
        {
            if (!nodeConnections.ContainsKey(connectionInfo.source))
            {
                nodeConnections.Add(connectionInfo.source, new List <int>());
            }
            nodeConnections[connectionInfo.source].Add(connectionInfo.destination);

            allNodes.Add(connectionInfo.source);
            allNodes.Add(connectionInfo.destination);

            destinationNodes.Add(connectionInfo.destination);
        }

        allNodes.ExceptWith(destinationNodes);
        if (allNodes.Count != 1)
        {
            string error = "";
            foreach (int nd in allNodes)
            {
                error += nd + ", ";
            }
            throw new MissingComponentException("Incorrect graph configuration, incorrect source node count : " + allNodes.Count + " - " + error);
        }

        int        sourceId   = new List <int>(allNodes)[0];
        GameObject sourceNode = nodeMap[sourceId];

        UpdateState(sourceNode);
    }
示例#11
0
 public bool haveSameLocations(NodeConnections otherConnection)
 {
     if (this.startNode.getNodeLocation() == otherConnection.getStartNode().getNodeLocation() &&
         this.endNode.getNodeLocation() == otherConnection.getEndNode().getNodeLocation())
     {
         return(true);
     }
     else if (this.endNode.getNodeLocation() == otherConnection.getStartNode().getNodeLocation() &&
              this.startNode.getNodeLocation() == otherConnection.getEndNode().getNodeLocation())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#12
0
    public void HighlightAvailableNodes()
    {
        NodeConnections     connections = map.ConnectionsForNode(pieces.currentPiece.currentNode);
        List <NodeMovement> moves       = pieces.pieceMoves = new List <NodeMovement> ();
        List <int>          move_ids    = new List <int> ();

        AddMoves(connections.type1, 0, moves, move_ids);
        AddMoves(connections.type2, 1, moves, move_ids);
        AddMoves(connections.type3, 2, moves, move_ids);
        AddMoves(connections.type4, 3, moves, move_ids);

        for (int i = 0; i < map.nodeCount; i++)
        {
            MapNode node = map.NodeForId(i);
            node.ShowParticles(move_ids.IndexOf(node.ID) >= 0);
        }
    }
示例#13
0
    // Update is called once per frame
    void UpdateNodePosition()
    {
        if (startArrange)
        {
            ArrangeNodes();
        }
        if (doArrange)
        {
            arrangeFrameCount++;
            foreach (NodeConnections nodeConnectionScript in nodesToArrange)
            {
                // Make the first node static so we have a reference point
                if (nodeConnectionScript == nodesToArrange[0])
                {
                    continue;
                }
                // Final vector we want our current node to travel
                Vector3 compositeVector = new Vector3();
                // Check each connection this node has
                for (int i = 0; i < nodeConnectionScript.nodesToConnect.Count; i++)
                {
                    NodeConnections otherNodeConnectionScript = nodeConnectionScript.nodesToConnect[i];
                    Transform       otherNodeTransform        = otherNodeConnectionScript.transform;

                    // Work out the position vector of the desired end position
                    Vector3 vectorToDesiredPosition = (nodeConnectionScript.transform.position - otherNodeTransform.position).normalized * (nodeConnectionScript.timeToTravel[i] / 10);
                    Vector3 desiredPosition         = vectorToDesiredPosition + otherNodeTransform.position;

                    // Pull our node in the direction of the other node, trying to make sure the distance between them is the jump cost
                    compositeVector = compositeVector + (desiredPosition - nodeConnectionScript.transform.position).normalized * 0.1f;
                }
                nodeConnectionScript.transform.Translate(compositeVector);
            }
            if (stopArrange)
            {
                Debug.Log("Stopping...");
                stopArrange = false;
                doArrange   = false;
            }
        }
    }
示例#14
0
 public void addNode(NetworkNode newNode)
 {
     if (this.nodes.Count == 0)
     {
         List <NodeConnections> toAdd = new List <NodeConnections>();
         this.nodes.Add(newNode, toAdd);
     }
     else
     {
         foreach (NetworkNode existingNode in this.nodes.Keys.ToList())
         {
             if (existingNode.testCompatibility(newNode) == true)
             {
                 if (existingNode.getNodeName() == "router" || existingNode.getNodeName() == "switch" || existingNode.getNodeName() == "accesspoint")
                 {
                     NodeConnections oldConnectionToNew = new NodeConnections(existingNode, newNode);
                     this.nodes[existingNode].Add(oldConnectionToNew);
                     if (this.nodes.ContainsKey(newNode) == false)
                     {
                         this.nodes.Add(newNode, new List <NodeConnections>());
                     }
                 }
                 else if (newNode.getNodeName() == "router" || newNode.getNodeName() == "switch" || newNode.getNodeName() == "accesspoint")
                 {
                     NodeConnections newConnectionToOld = new NodeConnections(newNode, existingNode);
                     if (this.nodes.ContainsKey(newNode) == true)
                     {
                         this.nodes[newNode].Add(newConnectionToOld);
                     }
                     else
                     {
                         List <NodeConnections> toAdd = new List <NodeConnections>();
                         toAdd.Add(newConnectionToOld);
                         this.nodes.Add(newNode, toAdd);
                     }
                 }
             }
         }
     }
 }
示例#15
0
    public List <string[]> DebugResults = new List <string[]>();// Nombre del objeto [0],Codigo Generado[1],Si hay repetidos[2],Objetos que comparten codigo[3](x defecto None).

    public static int GetCode(NodeConnections ConfigSet)
    {
        int code = ConfigSet.ConnectionsNumber;

        if (ConfigSet.TopConnection)
        {
            code += TopConnectionWeight * ConfigSet.ConnectionsNumber;
        }
        if (ConfigSet.BottomConnection)
        {
            code += BottomConnectionWeight * ConfigSet.ConnectionsNumber;
        }
        if (ConfigSet.RightConnection)
        {
            code += RightConnectionWeight * ConfigSet.ConnectionsNumber;
        }
        if (ConfigSet.LeftConnections)
        {
            code += LeftConnectionWeight * ConfigSet.ConnectionsNumber;
        }
        return(code);
    }
    //----------------------------------------------------------------
    public static List <GameObject> getLevelPrefabs(NodeConnections ParameterNode)
    {
        //Relleno la lista de prefabs
        if (LevelPrefabs.Count > 0)
        {
            //obtengo el codigo del nodo recibido.
            int recievedCode = LevelCoder.GetCode(ParameterNode);
            //devuelvo los prefabs existentes.
            NodeConnections A = ParameterNode;

            int code = LevelCoder.GetCode(A);

            if (prefabs.ContainsKey(code))
            {
                return(prefabs[recievedCode]);
            }
            else
            {
                MonoBehaviour.print(string.Format("No hay objetos con codigo {0} en la coleccion!.", code));
                return(new List <GameObject>());
            }
        }
        return(null);
    }
    string[] valdidateConnections(Node editado, NodeConnections conecciones)
    {
        string[] ValidatedConnections = new string[4] {
            "InValid", "InValid", "InValid", "InValid"
        };

        List <Node> TrueConnections = new List <Node>();

        foreach (var item in editado.Connections)
        {
            if (item)
            {
                TrueConnections.Add(item);
            }
        }


        foreach (var coneccion in TrueConnections)
        {
            Vector3 dir       = (coneccion.transform.position - editado.transform.position).normalized;
            Node    AChequear = coneccion;

            if (dir == Vector3.forward)
            {
                //Chequeo la valides de la coneccion.
                foreach (var connec in AChequear.Connections)
                {
                    if (connec == editado)
                    {
                        ValidatedConnections[0] = "Valid";
                        break;
                    }
                }
            }
            else
            if (dir == Vector3.back)
            {
                //Chequeo la valides de la coneccion.
                foreach (var connec in AChequear.Connections)
                {
                    if (connec == editado)
                    {
                        ValidatedConnections[1] = "Valid";
                        break;
                    }
                }
            }
            else
            if (dir == Vector3.right)
            {
                //Chequeo la valides de la coneccion.
                foreach (var connec in AChequear.Connections)
                {
                    if (connec == editado)
                    {
                        ValidatedConnections[2] = "Valid";
                        break;
                    }
                }
            }
            else
            if (dir == Vector3.left)
            {
                //Chequeo la valides de la coneccion.
                foreach (var connec in AChequear.Connections)
                {
                    if (connec == editado)
                    {
                        ValidatedConnections[3] = "Valid";
                        break;
                    }
                }
            }
        }
        return(ValidatedConnections);
    }
示例#18
0
        /// <summary>
        /// Build Circuit structure from a rung
        /// </summary>
        /// <param name="rung"></param>
        /// <returns></returns>
        public Circuit(Rung rung)
        {
            this.Components = new List <ComponentBase>();
            this.Mode       = CircuitMode.Serial;
            this.Parent     = null;

            List <NodeConnections> nodes = new List <NodeConnections>().RunAnalysis(rung);

            Stack <int> CircuitModeStack = new Stack <int>();

            CircuitModeStack.Push(-1);
            Stack <Circuit> Circuits = new Stack <Circuit>();

            this.LeftLide  = rung.Components.First().LeftLide;
            this.RightLide = rung.Components.Last().RightLide;
            Circuits.Push(this);

            foreach (ComponentBase component in rung.Components)
            {
                NodeConnections NodeA = nodes.GetNodeConnections(component.LeftLide);
                NodeConnections NodeB = nodes.GetNodeConnections(component.RightLide);

                //Decide when add a parallel sub-circuit
                if (NodeA.OutComponents.Count > 1)
                {
                    if (CircuitModeStack.Peek() == -1)
                    {
                        CircuitModeStack.Push(NodeA.OutComponents.Count - 1);
                        Circuit parent = Circuits.Peek();
                        Circuit son    = new Circuit(CircuitMode.Parallel, parent);
                        son.LeftLide = component.LeftLide;
                        parent.Components.Add(son);
                        Circuits.Push(son);
                    }
                    else
                    {
                        CircuitModeStack.Push(CircuitModeStack.Pop() - 1);
                    }
                }

                // Decide when add a serial sub-circuit
                if (NodeB.InComponents.Count == 1 && CircuitModeStack.Peek() != -1)
                {
                    CircuitModeStack.Push(-1);
                    Circuit parent = Circuits.Peek();
                    Circuit son    = new Circuit(CircuitMode.Serial, parent);
                    son.LeftLide = component.LeftLide;
                    parent.Components.Add(son);
                    Circuits.Push(son);
                }

                Circuits.Peek().Components.Add(component);

                //Close sub-circuit
                if ((NodeB.InComponents.Count > 1 || NodeA.InComponents.Count > 1) && CircuitModeStack.Count > 1 && CircuitModeStack.Peek() <= 0)
                {
                    CircuitModeStack.Pop();
                    Circuits.Pop().RightLide = component.RightLide;
                }
            }
        }
示例#19
0
 public static void exposeLine(Dictionary <NodeConnections, GameObject> connectionLineVals, NodeConnections connectionVal)
 {
     foreach (NodeConnections connection in connectionLineVals.Keys.ToList())
     {
         if (connection.haveSameLocations(connectionVal) == true)
         {
             connectionLineVals[connection].SetActive(true);
             if (activeLines.ContainsKey(connection) == false)
             {
                 activeLines.Add(connection, connectionLineVals[connection]);
             }
             break;
         }
     }
 }
示例#20
0
 public void CreatePawn(PlaceType.Terrain terrainType, Vector3 position, Quaternion rotation, NodeConnections connections)
 {
     for (int i = 0; i < pawnPrefabs.Count; ++i)
     {
         if (pawnPrefabs[i].name == terrainType.ToString() + " PION")
         {
             var pawn = Instantiate(pawnPrefabs[i], position, rotation) as GameObject;
             return;
         }
     }
     print("Failed to find pawn terrain type");
 }
示例#21
0
    private void OnGUI()
    {
        EditorGUILayout.LabelField("INPUT FILE MUST BE ORDERED");
        fileName = startFilePath;
        fileName = EditorGUILayout.TextField("File Name:", fileName);
        if (GUILayout.Button("Load"))
        {
            graphDict           = new Dictionary <string, Dictionary <string, int> >();
            nodeConnectionsDict = new Dictionary <string, NodeConnections>();
            mapParent           = GameObject.FindGameObjectWithTag("MapParent");

            string[] lines = System.IO.File.ReadAllLines(fileName);
            for (int i = 0; i < lines.Length; i++)
            {
                string[] lineSplit   = lines[i].Split(' ');
                string   currentNode = lineSplit[0];
                string   otherNode   = lineSplit[1];
                int      weight      = 0;
                if (lineSplit.Length > 2)
                {
                    weight = Int32.Parse(lineSplit[2]);
                }

                if (!graphDict.ContainsKey(currentNode))
                {
                    graphDict.Add(currentNode, new Dictionary <string, int>());
                    GameObject nodeGameObject = Instantiate(nodePrefab, mapParent.transform);
                    nodeGameObject.name = currentNode;
                    NodeConnections nodeConnectionsScript = nodeGameObject.GetComponent <NodeConnections>();
                    nodeConnectionsDict.Add(currentNode, nodeConnectionsScript);
                    // Don't move the first node
                    if (i > 0)
                    {
                        nodeGameObject.transform.localPosition = new Vector3(UnityEngine.Random.Range(-100, 100), UnityEngine.Random.Range(-100, 100), 0f);
                    }
                }

                graphDict[currentNode].Add(otherNode, weight);
            }

            List <string> keyList = new List <string>(graphDict.Keys);
            foreach (string nodeValue in keyList)
            {
                Dictionary <string, int> graphConnections = graphDict[nodeValue];
                foreach (string nodeValueToConnect in graphConnections.Keys)
                {
                    // Check if there are any missing nodes from the list due to one way connections
                    if (!nodeConnectionsDict.ContainsKey(nodeValueToConnect))
                    {
                        graphDict.Add(nodeValueToConnect, new Dictionary <string, int>());
                        GameObject nodeGameObject = Instantiate(nodePrefab, mapParent.transform);
                        nodeGameObject.name = nodeValueToConnect;
                        NodeConnections nodeConnectionsScript = nodeGameObject.GetComponent <NodeConnections>();
                        nodeConnectionsDict.Add(nodeValueToConnect, nodeConnectionsScript);
                        nodeGameObject.transform.localPosition = new Vector3(UnityEngine.Random.Range(-100, 100), UnityEngine.Random.Range(-100, 100), 0f);
                    }
                }
            }

            foreach (string nodeValue in graphDict.Keys)
            {
                Dictionary <string, int> graphConnections      = graphDict[nodeValue];
                NodeConnections          nodeConnectionsScript = nodeConnectionsDict[nodeValue];
                foreach (string nodeValueToConnect in graphConnections.Keys)
                {
                    NodeConnections otherConnectionScript = nodeConnectionsDict[nodeValueToConnect];
                    nodeConnectionsScript.nodesToConnect.Add(otherConnectionScript);
                    nodeConnectionsScript.timeToTravel.Add(graphConnections[nodeValueToConnect]);
                    nodeConnectionsScript.nodeConnectionTypes.Add(Defs.ConnectionTypes.CONNECTIONTYPE_DEFAULT);
                    nodeConnectionsScript.costToTravel.Add(0);

                    // NCOL sucks so have to add reference back
                    otherConnectionScript.nodesToConnect.Add(nodeConnectionsScript);
                    otherConnectionScript.timeToTravel.Add(graphConnections[nodeValueToConnect]);
                    otherConnectionScript.nodeConnectionTypes.Add(Defs.ConnectionTypes.CONNECTIONTYPE_DEFAULT);
                    otherConnectionScript.costToTravel.Add(0);
                }
            }
        }
    }
示例#22
0
        /// <summary>
        /// Write all Rungs
        /// </summary>
        /// <param name="diagram">LD diagram</param>
        /// <param name="writer">File generator</param>
        internal static void WriteRungs(IEnumerable <Rung> rungs, XmlWriter writer)
        {
            writer.WriteStartElement("Rungs");
            writer.WriteStartAttribute("Count");
            writer.WriteValue(rungs.Count());
            writer.WriteEndAttribute();

            #region Rung Loop
            foreach (Rung rung in rungs)
            {
                Trace.WriteLine("Rung Started", "DiagramWriter");
                Trace.Indent();

                #region Node Analysis
                Trace.WriteLine("Starting node analysis", "Rung");

                ///List of the nodes in circuit
                List <NodeConnections> nodes = new List <NodeConnections>().RunAnalysis(rung);

                Trace.WriteLine("Analysis finished with " + nodes.Count + " nodes", "Rung");
                #endregion Node Analysis

                writer.WriteStartElement("Rung");
                writer.WriteStartAttribute("Count");
                writer.WriteValue(rung.Components.Count);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute("Comment");
                writer.WriteValue(rung.Comment);
                writer.WriteEndAttribute();

                #region Component Write
                Stack <int> Mode = new Stack <int>();
                Mode.Push(-1);

                Trace.WriteLine("Starting component write", "Rung");
                Trace.Indent();
                foreach (ComponentBase component in rung.Components)
                {
                    NodeConnections NodeA = nodes.GetNodeConnections(component.LeftLide);
                    NodeConnections NodeB = nodes.GetNodeConnections(component.RightLide);

                    //Decide when add a parallel sub-circuit
                    if (NodeA.OutComponents.Count > 1)
                    {
                        if (Mode.Peek() == -1)
                        {
                            Mode.Push(NodeA.OutComponents.Count - 1);
                            writer.WriteStartElement("Parallel");
                            Trace.WriteLine("Opened Parallel Sub-Circuit", "Rung");
                            Trace.Indent();
                        }
                        else
                        {
                            Mode.Push(Mode.Pop() - 1);
                        }
                    }

                    // Decide when add a serial sub-circuit
                    if (NodeB.InComponents.Count == 1 && Mode.Peek() != -1)
                    {
                        Mode.Push(-1);
                        writer.WriteStartElement("Serial");
                        Trace.WriteLine("Opened Serial Sub-Circuit", "Rung");
                        Trace.Indent();
                    }

                    WriteComponent(component, writer);
                    Trace.WriteLine(component.ToString() + " Added", "Rung");

                    //Close sub-circuit
                    if ((NodeB.InComponents.Count > 1 || NodeA.InComponents.Count > 1) && Mode.Count > 1 && Mode.Peek() <= 0)
                    {
                        Mode.Pop();
                        writer.WriteEndElement();
                        Trace.Unindent();
                        Trace.WriteLine("Closed Sub-Circuit", "Rung");
                    }
                }
                Trace.Unindent();
                #endregion Component Write

                writer.WriteEndElement();
                Trace.Unindent();
                Trace.WriteLine("Rung Ended", "DiagramWriter");
            }
            #endregion Rung Loop

            writer.WriteEndElement();
        }
示例#23
0
 private void Awake()
 {
     connections = FindObjectOfType <NodeConnections>();
 }
    public override void OnInspectorGUI()
    {
        //Debugg.
        //base.OnInspectorGUI();

        EditorGUILayout.PrefixLabel("Generador de Código.");
        EditedNode.GeneradorCodigo = (LevelCoder)EditorGUILayout.ObjectField(EditedNode.GeneradorCodigo, typeof(LevelCoder), true);

        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("Calculate Connections"))
        {
            CalculatedConnections = EditedNode.GetConnectionSet();
            EditedNode.code       = LevelCoder.GetCode(CalculatedConnections);
            Calculated            = true;
        }

        EditorGUILayout.LabelField("Codigo generado: " + EditedNode.code + ".");

        //--------------------------------------Validador-----------------------------------------------------
        //-------------------------------------------------------------------------------------
        string[] validados = new string[4] {
            "InValid", "InValid", "InValid", "InValid"
        };

        if (Calculated)
        {
            validados = valdidateConnections(EditedNode, CalculatedConnections);
        }

        EditorGUILayout.BeginHorizontal();
        if (Calculated && CalculatedConnections.TopConnection)
        {
            GUI.backgroundColor = Color.green;
        }
        else
        {
            GUI.backgroundColor = Color.grey;
        }

        GUILayout.Button("", new GUILayoutOption[] { GUILayout.MaxWidth(30) });
        EditorGUILayout.LabelField("Top Connection", new GUILayoutOption[] { GUILayout.MaxWidth(150) });

        GUI.backgroundColor = Color.white;
        EditorGUILayout.LabelField(validados[0]);

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        //-------------------------------------------------------------------------------------
        EditorGUILayout.BeginHorizontal();
        if (Calculated && CalculatedConnections.BottomConnection)
        {
            GUI.backgroundColor = Color.green;
        }
        else
        {
            GUI.backgroundColor = Color.grey;
        }

        GUILayout.Button("", new GUILayoutOption[] { GUILayout.MaxWidth(30) });
        EditorGUILayout.LabelField("Bottom Connection", new GUILayoutOption[] { GUILayout.MaxWidth(150) });

        GUI.backgroundColor = Color.white;
        EditorGUILayout.LabelField(validados[1]);

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        //-------------------------------------------------------------------------------------
        EditorGUILayout.BeginHorizontal();
        if (Calculated && CalculatedConnections.RightConnection)
        {
            GUI.backgroundColor = Color.green;
        }
        else
        {
            GUI.backgroundColor = Color.grey;
        }

        GUILayout.Button("", new GUILayoutOption[] { GUILayout.MaxWidth(30) });
        EditorGUILayout.LabelField("Right Connection", new GUILayoutOption[] { GUILayout.MaxWidth(150) });

        GUI.backgroundColor = Color.white;
        EditorGUILayout.LabelField(validados[2]);

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        //-------------------------------------------------------------------------------------
        EditorGUILayout.BeginHorizontal();
        if (Calculated && CalculatedConnections.LeftConnections)
        {
            GUI.backgroundColor = Color.green;
        }
        else
        {
            GUI.backgroundColor = Color.grey;
        }

        GUILayout.Button("", new GUILayoutOption[] { GUILayout.MaxWidth(30) });
        EditorGUILayout.LabelField("Left Connection", new GUILayoutOption[] { GUILayout.MaxWidth(150) });

        GUI.backgroundColor = Color.white;
        EditorGUILayout.LabelField(validados[3]);

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        //-------------------------------------------------------------------------------------
    }