Beispiel #1
0
    /// <summary>
    ///Hide this blockset
    /// </summary>
    public void Hide()
    {
        if (currentObject == null)
        {
            return;
        }

        if (rootObject == null)
        {
            return;
        }

        if (AssetPool.IsPoolingEnabled())
        {
            AssetPool.Destroy(currentObject.gameObject);
            currentObject = null;
        }
        else
        {
            if (AssetPool.DestroyImmediate())
            {
                GameObject.DestroyImmediate(currentObject.gameObject);
            }
            else
            {
                GameObject.Destroy(currentObject.gameObject);
            }
            currentObject = null;
        }

        //PREFAB
        //rootObject.SetActiveRecursively(false);
        //rootObject.active = true;
    }
    public void DestroyEntity()
    {
        this.controller.UnSubscribeEntity(this);

        OnDestroyEntity();

        AssetPool.Destroy(gameObject);
    }
Beispiel #3
0
    /// <summary>
    /// Sets the block at the target chunk coordinate
    /// </summary>
    /// <param name="x">
    ///The target chunk x coordinate
    /// </param>
    /// <param name="y">
    ///The target chunk y coordinate
    /// </param>
    /// <param name="b">
    ///The block to add to the target chunk coordinate
    /// </param>
    public void SetBlockAt(int x, int y, Block b, bool destroyImmediate)
    {
        if (chunkPieces == null)
        {
            Debug.LogWarning("Block array in chunk: " + this.x + "," + this.y + " has not been initialized.");
            return;
        }

        if (x < 0 || x >= parentMap.chunkWidth)
        {
            Debug.LogWarning("Fundamental mathematics problem attempting to set block " + x + "," + y + " in chunk: " + this.x + "," + this.y);
            return;
        }

        if (y < 0 || y >= parentMap.chunkHeight)
        {
            Debug.LogWarning("Fundamental mathematics problem attempting to set block " + x + "," + y + " in chunk: " + this.x + "," + this.y);
            return;
        }

        int index = y * parentMap.chunkWidth + x;

        if (index >= chunkPieces.Length)
        {
            Debug.LogWarning("Index exceeded array length in chunk: " + x + "," + y + ". Index: " + index + " Length: " + chunkPieces.Length);
            return;
        }

        InitializeBlockPlacement(x, y, b);

        if (chunkPieces[index] != null)
        {
            //Block cb = chunkPieces[index];

            if (AssetPool.IsPoolingEnabled())
            {
                AssetPool.Destroy(chunkPieces[index].gameObject);
                chunkPieces[index] = null;
                //cb = null;
            }
            else
            {
                if (destroyImmediate)
                {
                    GameObject.DestroyImmediate(chunkPieces[index].gameObject);
                    chunkPieces[index] = null;
                }
                else
                {
                    GameObject.Destroy(chunkPieces[index].gameObject);
                    chunkPieces[index] = null;
                }
            }
        }

        chunkPieces[index] = b;
    }