Exemplo n.º 1
0
    /// <summary>
    /// Converts stockType to an actual prefab model
    /// </summary>
    /// <param name="stockType">StockType you're looking for</param>
    /// <returns>Random prefab of said stockType</returns>
    public GameObject GetStockTypePrefab(StockTypes stockType)
    {
        for (int c = 0; c < stockPrefabs.Length; c++)
        {
            // Collect stock pack
            StockData stockPrefabPack = stockPrefabs[c];

            // Check if stockType matches what you're looking for
            if (stockPrefabPack.GetStockType() == stockType)
            {
                // Check if there's only one prefab model in the pack
                if (stockPrefabPack.GetPrefabs().Length == 1)
                {
                    // Return the one
                    return(stockPrefabPack.GetPrefabs()[0]);
                }
                else
                {
                    // Return a random prefab in the pack
                    return(EssentialFunctions.GetRandomFromArray(stockPrefabPack.GetPrefabs()));
                    //return stockPrefabPack.prefabs[Random.Range(0, stockPrefabPack.prefabs.Length)];
                }
            }
        }

        // Return nothing because it doesn't exist
        return(null);
    }
    private void OnValidate()
    {
        // Always have at least one face available for pickup
        if (!allowPickupF && !allowPickupB && !allowPickupL && !allowPickupR)
        {
            allowPickupF = true;
        }

        stockAmount = Mathf.Clamp(stockAmount, 0, shelfSize);

        UpdatePickupPositionsArray();


        _adjacentShelves.Clear();
        _adjacentShelves.AddRange(GetAdjacentShelves());

        // Update Stock
        ShelfVisual[] c = transform.GetComponentsInChildren <ShelfVisual>();

        if (c.Length > 0)
        {
            UnityEditor.EditorApplication.delayCall += () =>
            {
                for (int i = 0; i < c.Length; i++)
                {
                    DestroyImmediate(c[i].gameObject);
                }
            };
        }

        shelfVisual    = null;
        shelfStockType = StockTypes.None;

        if (stock)
        {
            // Setup stats
            shelfStockType = stock.GetStockType();
            GameObject newStockVisual = null;

            // Setup Visuals
            UnityEditor.EditorApplication.delayCall += () =>
            {
                newStockVisual = Instantiate(stock.GetStockVisual(), transform, true);

                shelfVisual = newStockVisual.GetComponent <ShelfVisual>();

                newStockVisual.transform.localPosition = Vector3.zero;
            };
        }

        UpdateVisuals();
    }