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(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); ShelfVisual myScript = (ShelfVisual)target; if (GUILayout.Button("Collect Visuals")) { int children = myScript.AddVisuals(myScript.transform); if (children == 0) { Debug.Log("There are no visual children in this transform!"); } } }
private void UpdateVisuals() { if (shelfVisual) { shelfVisual.StockAmountPercentage = (float)stockAmount / shelfSize; } else { ShelfVisual _shelfVisual = GetComponentInChildren <ShelfVisual>(); if (!_shelfVisual) { return; } shelfVisual = _shelfVisual; UpdateVisuals(); } }