コード例 #1
0
    void Start()
    {
        TheBuilderSettings      = FindObjectOfType <BuilderSettings>();
        TheRoot                 = FindObjectOfType <BuilderRoot>();
        TheBoxCollider          = GetComponent <BoxCollider>();
        TheBuilderAdjacentCheck = GetComponent <BuilderAdjacentCheck>();

        UpdateStartingColor();
    }
コード例 #2
0
    //Save ship to binary file
    public void Save()
    {
        BinaryFormatter formater = new BinaryFormatter();
        //Create file
        FileStream stream = new FileStream(Application.dataPath + "/../" + "/ShipSaves" + "/" + TheBuilderSettings.ShipName, FileMode.Create);

        //Get all blocks
        BuilderRoot theBuilderRoot = ShipRoot.GetComponent <BuilderRoot>();

        theBuilderRoot.AdjacentCheck();
        theBuilderRoot.ClearAllRedBlocks();
        List <ShipBlockData> blocks = new List <ShipBlockData>();

        for (int i = 0; i < theBuilderRoot.AllChilds.Count; i++)
        {
            blocks.Add(new ShipBlockData(theBuilderRoot.AllChilds[i]));
        }
        //Get all block connections
        //Each child
        for (int i = 0; i < theBuilderRoot.AllChilds.Count; i++)
        {
            BuilderAdjacentCheck theBuilderAdjacentCheck = theBuilderRoot.AllChilds[i].GetComponent <BuilderAdjacentCheck>();
            //Each child's adjacent block
            for (int j = 0; j < theBuilderAdjacentCheck.AdjacentBlocks.Count; j++)
            {
                //Loop through each ship child
                for (int k = 0; k < theBuilderRoot.AllChilds.Count; k++)
                {
                    //If there was a match for one of the adjacent blocks
                    if (theBuilderAdjacentCheck.AdjacentBlocks[j] == theBuilderRoot.AllChilds[k])
                    {
                        blocks[i].Connections[j] = blocks[k];
                    }
                }
            }
        }

        //The whole ship's information
        ShipData theShipData = new ShipData(blocks.ToArray(), TheBuilderSettings.ShipName);

        //Write to file
        formater.Serialize(stream, theShipData);
        stream.Close();
    }