コード例 #1
0
    public override object Evaluate()
    {
        if (Refresh())
        {
            int roomSizeX = 0;
            int roomSizeY = 0;

            if (inputs[0].lineReference == null || inputs[1].lineReference == null)
            {
                ErrorLogger.ThrowErrorMessage("A room node has missing size parameters.");
                return(null);
            }
            else
            {
                roomSizeX = (int)inputs[0].lineReference.start.attachedNode.Evaluate();
                roomSizeY = (int)inputs[1].lineReference.start.attachedNode.Evaluate();
            }
            if (roomSizeX < 3 || roomSizeX > 20 || roomSizeY < 3 || roomSizeY > 20)
            {
                ErrorLogger.ThrowErrorMessage("Room size must be between 3 and 20.");
                return(null);
            }

            string returnString = GetSaveData() + ",";
            returnString += inputs[0].lineReference.start.attachedNode.Evaluate().ToString() + ",";
            returnString += inputs[1].lineReference.start.attachedNode.Evaluate().ToString() + ",";

            for (int i = 0; i < roomObjectInputs.Length; i++)
            {
                if (roomObjectInputs[i].lineReference != null)
                {
                    Node_Enemy enemy = (Node_Enemy)roomObjectInputs[i].lineReference.start.attachedNode.Evaluate();
                    if (enemy != null)
                    {
                        switch (enemy.enemyType)
                        {
                        case Node_Enemy.ENEMYTYPE.SKELETON:
                            returnString += "skl," + enemy.health + ",";
                            break;

                        case Node_Enemy.ENEMYTYPE.ZOMBIE:
                            returnString += "zmb," + enemy.health + ",";
                            break;
                        }
                    }
                }
            }

            returnString += "ext";
            return(returnString);
        }
        else
        {
            return(null);
        }
    }
コード例 #2
0
ファイル: GraphIO.cs プロジェクト: devjonathanday/DunJon
    public void LoadGraph()
    {
        string[] paths = StandaloneFileBrowser.OpenFilePanel("Open Node Graph", "", "dun", false);
        if (paths.Length == 0)
        {
            ErrorLogger.ThrowErrorMessage("File not selected.");
            return;
        }

        StreamReader reader = new StreamReader(paths[0]);

        //Delete all existing nodes before spawning new ones
        Node_Generic[] tempNodes = FindObjectsOfType <Node_Generic>();
        for (int i = 0; i < tempNodes.Length; i++)
        {
            tempNodes[i].DeleteNode();
        }

        List <Node_Generic> nodes = new List <Node_Generic>();

        try
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Length == 0)
                {
                    continue;
                }

                if (line[0] == 'N')
                {
                    string[] frags = line.Split(',');
                    switch (frags[2])
                    {
                    case "int":
                    {
                        Value_Integer newNode = Instantiate(node_integer, new Vector3(float.Parse(frags[4]), float.Parse(frags[5]), 0), Quaternion.identity).GetComponent <Value_Integer>();
                        newNode.inputField.text = frags[3];
                        newNode.transform.SetParent(worldCanvas);
                        nodes.Add(newNode);
                    }
                    break;

                    case "rom":
                    {
                        Node_Generic newNode = Instantiate(node_room, new Vector3(float.Parse(frags[3]), float.Parse(frags[4]), 0), Quaternion.identity).GetComponent <Node_Generic>();
                        newNode.transform.SetParent(worldCanvas);
                        nodes.Add(newNode);
                    }
                    break;

                    case "str":
                    {
                        Node_Generic newNode = Instantiate(node_start, new Vector3(float.Parse(frags[3]), float.Parse(frags[4]), 0), Quaternion.identity).GetComponent <Node_Generic>();
                        newNode.transform.SetParent(worldCanvas);
                        nodes.Add(newNode);
                    }
                    break;

                    case "end":
                    {
                        Node_Generic newNode = Instantiate(node_end, new Vector3(float.Parse(frags[3]), float.Parse(frags[4]), 0), Quaternion.identity).GetComponent <Node_Generic>();
                        newNode.transform.SetParent(worldCanvas);
                        nodes.Add(newNode);
                    }
                    break;

                    case "rng":
                    {
                        Randomizer newNode = Instantiate(node_randomizer, new Vector3(float.Parse(frags[4]), float.Parse(frags[5]), 0), Quaternion.identity).GetComponent <Randomizer>();
                        newNode.transform.SetParent(worldCanvas);
                        newNode.Resize(int.Parse(frags[3]));

                        nodes.Add(newNode);
                    }
                    break;

                    case "skl":
                    {
                        Node_Enemy newNode = Instantiate(node_skeleton, new Vector3(float.Parse(frags[4]), float.Parse(frags[5]), 0), Quaternion.identity).GetComponent <Node_Enemy>();
                        newNode.health    = int.Parse(frags[3]);
                        newNode.enemyType = Node_Enemy.ENEMYTYPE.SKELETON;
                        newNode.transform.SetParent(worldCanvas);
                        nodes.Add(newNode);
                    }
                    break;

                    case "zmb":
                    {
                        Node_Enemy newNode = Instantiate(node_zombie, new Vector3(float.Parse(frags[4]), float.Parse(frags[5]), 0), Quaternion.identity).GetComponent <Node_Enemy>();
                        newNode.health    = int.Parse(frags[3]);
                        newNode.enemyType = Node_Enemy.ENEMYTYPE.ZOMBIE;
                        newNode.transform.SetParent(worldCanvas);
                        nodes.Add(newNode);
                    }
                    break;

                    default:
                    {
                        ErrorLogger.ThrowErrorMessage("Graph could not be loaded correctly.");
                        return;
                    }
                    }
                }
                else if (line[0] == 'L')
                {
                    string[] frags = line.Split(',');

                    //startNodeID = int.Parse(frags[1]);
                    //outputIndex = int.Parse(frags[2]);
                    //endNodeID   = int.Parse(frags[3]);
                    //inputIndex  = int.Parse(frags[4]);

                    LineConnector newLine = Instantiate(lineConnectorPrefab, Vector3.zero, Quaternion.identity).GetComponent <LineConnector>();
                    newLine.StartLine(nodes[int.Parse(frags[1])].outputs[int.Parse(frags[2])]);
                    newLine.FinishLine(nodes[int.Parse(frags[3])].inputs[int.Parse(frags[4])]);
                }
            }

            NodeEditor.Refresh();
        }
        catch (System.Exception e)
        {
            ErrorLogger.ThrowErrorMessage(e.Message);
        }
    }