Exemplo n.º 1
0
    public void SetBlockNodeAt(StreamingMapNode node, int x, int y, int z)
    {
        int index = GetIndexFor(x, y, z);

        if (index < 0 || index >= nodeMap.Length)
        {
            return;
        }

        nodeMap[index] = node;
    }
Exemplo n.º 2
0
    public void SetBackgroundAt(Material m, int x, int y, int z)
    {
        int index = GetIndexFor(x, y, z);

        if (index < 0 || index >= nodeMap.Length)
        {
            return;
        }

        if (nodeMap[index] == null)
        {
            nodeMap[index] = new StreamingMapNode(m);
        }
        else
        {
            nodeMap[index].backgroundEntry = m;
        }
    }
Exemplo n.º 3
0
    //Set the prefab at this coordinate to... the desired prefab
    public void SetBlockPrefabAt(Block blockPrefab, int x, int y, int z)
    {
        int index = GetIndexFor(x, y, z);

        if (index < 0 || index >= nodeMap.Length)
        {
            return;
        }

        if (nodeMap[index] == null)
        {
            nodeMap[index] = new StreamingMapNode(blockPrefab);
        }
        else
        {
            nodeMap[index].blockPrefab = blockPrefab;
        }
    }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
    void AddBackgroundFor(List <Vector3> coords)
    {
        if (nodeMap == null || nodeMap.Length == 0)
        {
            return;
        }

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

        for (int i = 0; i < coords.Count; i++)
        {
            int x = (int)coords[i].x;
            int y = (int)coords[i].y;
            int z = (int)coords[i].z;

            StreamingMapNode n = nodeMap[GetIndexFor(x, y, z)];

            if (n == null)
            {
                coords.RemoveAt(i);
                i--;
                continue;
            }

            Material m = n.backgroundEntry;

            if (m == null)
            {
                coords.RemoveAt(i);
                i--;
                continue;
            }

            nodes.Add(n);
        }

        while (nodes.Count > 0)
        {
            StreamingMapNode n = nodes[0];

            List <Vector3> mNodes = new List <Vector3>();

            for (int j = 0; j < nodes.Count; j++)
            {
                if (n.backgroundEntry == nodes[j].backgroundEntry)
                {
                    mNodes.Add(coords[j]);
                    nodes.RemoveAt(j);
                    coords.RemoveAt(j);
                    j--;
                }
            }

            if (!blockMap.HasBackgroundEntryFor(n.backgroundEntry.name))
            {
                blockMap.AddBackground(n.backgroundEntry);
            }

            blockMap.AddEntryToBackground(mNodes.ToArray(), n.backgroundEntry.name);
        }

        backgroundChanged = true;
    }
Exemplo n.º 6
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();
                    }
                }
            }
        }
    }