protected virtual void InitializeUI() { scrollAnim.OnUpdate = (val) => { scrollbar.value = val; }; itemPrefabs.OrderBy(go => go.name).ToList(); for (int i = 0; i < itemPrefabs.Count; i++) { GameObject itemPrefab = itemPrefabs[i]; GameObject toAdd = Instantiate(iconTemplate); PLEItem pleItem = itemPrefab.GetComponent <PLEItem>(); pleItems.Add(pleItem); PLEUIItem pleUIItem = toAdd.GetComponent <PLEUIItem>(); pleUIItems.Add(pleUIItem); pleUIItem.InitializeItem(i, this, itemPrefab); toAdd.SetActive(true); toAdd.name = itemPrefab.name; toAdd.transform.SetParent(groupContent.transform); RectTransform myRec = toAdd.GetComponent <RectTransform>(); myRec.localScale = Vector3.one; myRec.localRotation = Quaternion.identity; myRec.localPosition = Vector3.zero; } SelectUIItem(0, false); }
public virtual PLEUIItem SelectLastSelectedUIItem() { pleUIItems.ForEach(item => { item.OnGroupSelectChanged(LastSelectedIndex); }); PLEUIItem lastSelectedItem = pleUIItems[LastSelectedIndex]; placementMenu.PostSelectUIItem(lastSelectedItem); return(lastSelectedItem); }
public virtual void TrySelectFirstAvailable() { PLEUIItem firstAvailable = scrollGroup.TryGetFirstAvailableUIItem(); if (firstAvailable) { selectedPreviewImage.sprite = firstAvailable.imagePreview.sprite; scrollGroup.SelectUIItem(firstAvailable.ItemIndex, false); } }
protected override void PostPlaceItem(GameObject newItem) { int currentWaveIndex = PLESpawnManager.Instance.CurrentWaveIndex; int maxWaveIndex = PLESpawnManager.Instance.MaxWaveIndex; Transform waveParent = levelEditor.TryCreateWaveParent(currentWaveIndex); for (int i = maxWaveIndex; i >= 0; i--) { levelEditor.TryCreateWaveParent(i); } newItem.transform.SetParent(waveParent); MouseHelper.currentBlockUnit.AddSpawn(newItem); if (newItem.CompareTag(Strings.Editor.PLAYER_SPAWN_TAG)) { if (playerSpawnInstance != null) { DestroyImmediate(playerSpawnInstance); } playerSpawnInstance = newItem; playerSpawnInstance.transform.SetParent(levelEditor.TryCreateWaveParent(0).parent); } PLESpawn newSpawn = newItem.GetComponent <PLESpawn>(); if (newSpawn) { int spawnAmount = newSpawn.totalSpawnAmount; UpdateMinSpawnAmounts(newSpawn); int requiredAmount = GetRequiredKillCountInCurrentWave(newSpawn); ChangeSpawnAmountsInternally(spawnAmount, requiredAmount, false); int remainingSpawns = RemainingSpawnsInCurrentWave(newSpawn); UpdateAvailableField(remainingSpawns); SelectGameItem(newSpawn); //if (!SpawnManager.SpawnsUnderMaximum(newSpawn)) { // DeselectItem(); // DeselectUIItem();//destroys preview gameobject too //} if (newSpawn.spawnType == SpawnType.Keira) { PLEUIItem firstAvailable = scrollGroup.TryGetFirstAvailableUIItem(); if (firstAvailable) { selectedPreviewImage.sprite = firstAvailable.imagePreview.sprite; scrollGroup.SelectUIItem(firstAvailable.ItemIndex, false); } } } mainPLEMenu.SetMenuButtonInteractabilityByState(); }
public virtual void PostSelectUIItem(PLEUIItem item) { if (allowInput) { if (item.isInteractable) { DeselectItem(); selectedItemPrefab = item.registeredItem; TryDestroyPreview(); previewItem = Instantiate(selectedItemPrefab); previewItem.name = previewItem.name.TryCleanName(Strings.CLONE); previewItem.name += Strings.PREVIEW; previewItem.GetComponent <PLEItem>().TryHighlight(highlightColor); PostSelectUIItemMenuSpecific(previewItem); } else { scrollGroup.DeselectAllUIItems(); } } }
private void RaycastToScrollGroup() { currentUIItem = null; pointerData.position = Input.mousePosition; results = new List <RaycastResult>(); current.RaycastAll(pointerData, results); if (results.Count > 0) { foreach (RaycastResult r in results) { currentUIItem = r.gameObject.GetComponent <PLEUIItem>(); if (currentUIItem) { break; } } } }