private void FavouritePrefab(bool favourite, PrefabItem caller) { string name = caller.GetName(); PrefabStates[name].isFavourite = favourite; EasySpawnerPlugin.SaveFavourites(); RebuildPrefabDropdown(); }
public void UpdateItemPrefabPool(Vector2 slider) { PrefabScrollView.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (SearchItems.Count - 1) * 20f); Rect scrollRect = PrefabScrollView.GetComponent <RectTransform>().rect; Vector2 scrollPos = PrefabScrollView.content.anchoredPosition; // search for items that are out of visible scroll rect foreach (PrefabItem item in PrefabItems) { if (PrefabItemPool.Contains(item)) { continue; } float posY = item.rectTransform.anchoredPosition.y; if (posY > -scrollPos.y + 20 || posY < -scrollPos.y - scrollRect.height - 20) { PoolPrefabItem(item); } } int startIndex = Mathf.Max(0, Mathf.CeilToInt((scrollPos.y - 20) / 20)); int maxItems = Mathf.CeilToInt((scrollRect.height + 40) / 20); for (int i = startIndex; i < Mathf.Min(startIndex + maxItems, SearchItems.Count); i++) { if (PrefabItems.Any(x => x.posIndex == i)) { continue; } if (PrefabItemPool.Count > 0) { PrefabItem item = PrefabItemPool.Dequeue(); item.rectTransform.anchoredPosition = new Vector2(0, -i * 20 - 10f); item.posIndex = i; item.SetName(SearchItems[i]); item.toggle.SetIsOnWithoutNotify(SelectedPrefabName == item.GetName()); item.SetFavouriteOn(PrefabStates[item.GetName()].isFavourite, true); item.gameObject.SetActive(true); } } }
private void SelectPrefab(PrefabItem caller) { foreach (PrefabItem prefabItem in PrefabItems) { // Disable all other prefabItems, without calling this method recursively prefabItem.toggle.SetIsOnWithoutNotify(prefabItem == caller); } SelectedPrefabName = caller != null?caller.GetName() : null; }