Example #1
0
    /// <summary>
    ///Show the selected block from the blockset
    /// </summary>
    public void Show()
    {
        Hide();

        if (blockSet == null || blockSet.Length <= 0)
        {
            return;
        }

        if (currentBlockIndex >= blockSet.Length)
        {
            currentBlockIndex = 0;
        }

        if (AssetPool.IsPoolingEnabled())
        {
            currentObject = AssetPool.Instantiate(blockSet[currentBlockIndex]);
        }
        else
        {
            currentObject = GameObject.Instantiate(blockSet[currentBlockIndex]) as GameObject;
        }

        currentObject.name = blockSet[currentBlockIndex].name;

        currentObject.transform.parent        = rootObject.transform;
        currentObject.transform.localPosition = offset;
        currentObject.transform.localRotation = Quaternion.Euler(rotation);

        //PREFAB
        //blockSet[currentBlockIndex].SetActiveRecursively(true);
    }
Example #2
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();
                    }
                }
            }
        }
    }