Ejemplo n.º 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);
    }
Ejemplo n.º 2
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;
    }
Ejemplo n.º 3
0
        public void DrawWindow()
        {
            EditorGUILayout.BeginVertical();

            GUILayout.Label("Objects in pool:");

            if (AssetPool.IsPoolingEnabled())
            {
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

                foreach (string s in AssetPool.pool.Keys)
                {
                    EditorGUILayout.BeginHorizontal();

                    GUILayout.Label(s + ":");

                    GUILayout.Label(AssetPool.pool[s].Count + " objects in pool.");

                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("Asset pooling is disabled.");
            }

            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 4
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;
    }