Insert() public method

public Insert ( int idx, MapTile, t ) : void
idx int
t MapTile,
return void
Exemplo n.º 1
0
    public void AddIsoTileAt(int x, int y, int z)
    {
        if (stacks == null)
        {
            ResetStacks(Vector2.zero);
        }
        MapColumn stackC = TileColumnAt(x, y);
        MapTile   stack  = null;
        bool      added  = false;

        if (stackC == null || stackC.Count == 0)
        {
            stack = new MapTile(x, y, z);
            stack.serializeHackUsable = true;
            SetTileStackAt(stack, x, y);
            added = true;
        }
        else
        {
            MapTile newStack = new MapTile(x, y, z);
            newStack.serializeHackUsable = true;
            bool present = false;
            for (int i = 0; i < stackC.Count; i++)
            {
                stack = stackC.At(i);
                if (stack.IsAboveZ(z))
                {
                    stackC.Insert(i, newStack);
                    present = true;
                    added   = true;
                    break;
                }
                else if (stack.ContainsZ(z))
                {
                    present = true;
                    break;
                }
            }
            if (!present)
            {
                if (stack.maxZ == z && stack.maxHeight != 1)
                {
                    //don't propagate heights, just clobber the old ones
                    int max = stack.maxHeight;
                    //stack.next.heights = stack.heights;
                    //stack.heights = new int[]{1,1,1,1};
                    stack.heights = new int[] { max, max, max, max };
                }
                stackC.Add(newStack);
                added = true;
            }
        }
        if (added)
        {
            RemakeMesh();
        }
    }
Exemplo n.º 2
0
    void SetNextTile(MapTile prev, MapTile next)
    {
        int idx = prev.y * (int)_size.x + prev.x;

        if (idx >= stacks.Length)
        {
            return;
        }
        MapColumn stack = stacks[idx];

        if (stack == null)
        {
            return;
        }
        int tidx = stack.IndexOf(prev);

        if (tidx == -1)
        {
            return;
        }
        stack.Insert(tidx, next);
    }