Ejemplo n.º 1
0
    void DestroyBlock(Vector3 coords)
    {
        int x = (int)coords.x;
        int y = (int)coords.y;
        int z = (int)coords.z;

        Block         b  = BlockUtilities.GetBlockAt(blockMap, x, y, z);
        OrientedBlock ob = null;

        if (b != null)
        {
            ob = b as OrientedBlock;
        }

        if (ob != null)
        {
            StreamingMapNode n = GetNodeAt(x, y, z);

            if (n != null)
            {
                n.variantIndex = ob.GetCurrentVariant();
            }

            GameObject cio = ob.GetCurrentInstantiatedObject();

            if (cio != null)
            {
                TidyMapBoundObject mbo = cio.GetComponentInChildren <TidyMapBoundObject>();

                if (mbo != null)
                {
                    if (!mbo.DestroyWhenStreaming())
                    {
                        return;
                    }
                }
            }
        }

        BlockUtilities.AddBlockToMap(blockMap, null, false, 0, true, x, y, z, false, false);
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a save string for an individual Block
        /// </summary>
        /// <param name="b">
        /// The Block in question
        /// </param>
        /// <param name="library">
        /// The type library constructed in the body of the save Map function
        /// </param>
        /// <returns>
        /// The save string for this block.
        /// </returns>
        public static string BlockToString(Block b, List <string> library)
        {
            OrientedBlock ob = b as OrientedBlock;

            string blockString = "";

            blockString += GetIndexForBlock(ob.name, library) + "" + BLOCK_FIELD_DELIM;

            blockString += ob.GetCurrentVariant() + "" + BLOCK_FIELD_DELIM;

            blockString += ob.x + "," + ob.y + "," + ob.depth + "" + BLOCK_FIELD_DELIM;

            TidyMapBoundObject[] boundObjects = ob.GetComponentsInChildren <TidyMapBoundObject>();

            for (int i = 0; i < boundObjects.Length; i++)
            {
                blockString += boundObjects[i].ToString() + "" + BLOCK_FIELD_DELIM;
            }

            return(blockString);
        }
Ejemplo n.º 3
0
    //Instantiate our block! Wrap the AssetPool functions nicely
    void InstantiateBlock(Vector3 coords)
    {
        int x = (int)coords.x;
        int y = (int)coords.y;
        int z = (int)coords.z;

        StreamingMapNode n = GetNodeAt(x, y, z);

        Block b  = null;
        int   bv = 0;

        if (n != null)
        {
            b  = n.blockPrefab;
            bv = n.variantIndex;
        }

        Block toAdd = null;

        if (b != null)
        {
            GameObject o = AssetPool.Instantiate(b.gameObject) as GameObject;

#if UNITY_4_0
            o.SetActive(true);
#else
//			o.SetActiveRecursively (true);
#endif

            toAdd = o.GetComponent <Block>();

            OrientedBlock ob = toAdd as OrientedBlock;

            if (ob != null)
            {
                ob.PreRandomiseBlockOrientations();
            }
        }

        if (n != null && n.HasVariant())
        {
            BlockUtilities.AddBlockToMap(blockMap, toAdd, false, bv, true, x, y, z, false, false);
        }
        else
        {
            BlockUtilities.AddBlockToMap(blockMap, toAdd, true, bv, true, x, y, z, false, false);
        }

        if (n != null)
        {
            if (!n.HasVariant())
            {
                Vector3 focus = new Vector3(focus_x, focus_y, focus_z);

                if (!IsOnOuterRim(focus, coords))
                {
                    //Let's save the variant so that we always get a consistent map
                    //It saves the programmer having to randomise this themselves
                    OrientedBlock ob = BlockUtilities.GetBlockAt(blockMap, x, y, z) as OrientedBlock;

                    if (ob != null)
                    {
                        n.variantIndex = ob.GetCurrentVariant();
                    }
                }
            }
        }
    }