/// <summary> /// 插入按钮 /// </summary> protected void InsertButton(UnitButton button, int insertIndex) { if (button != null && insertIndex >= 0 && insertIndex <= _buttons.Count) { _buttons.Insert(insertIndex, button); OnButtonAdded(button); button.TextChanged += OnButtonTextChanged; button.ExplicitDisposing += OnButtonDisposing; SelectedIndex = insertIndex; if (_buttons.Count == 1) { using (Graphics graphics = CreateGraphics()) { UpdatePositions(graphics, true); } } else { _updatePositionsOnDraw = true; } UpdateSize(); Invalidate(); } }
/// <summary> /// Init all button with AgentSelected Helps and update them /// </summary> private void InitMenu() { //catch Agent selected in AngentSelector and set button AgentSelector agentSelector = AgentSelector.Instance; if (agentSelector != null) { for (int i = 0; i < agentSelector.selectedAgents.Count; i++) { Unit m_unit = AgentSelector.Instance.selectedAgents[i].GetComponent <Unit>(); UnitButton unitButton = unitButtonList[i]; unitButton.unitIcon.sprite = m_unit.icon; unitButton.UnitCostText.text = m_unit.cost.ToString(); unitButton.cdFillText.enabled = false; unitButton.agentSelectorIndex = i; unitButton.unit = m_unit; m_unit.isInCD = false; } if (agentSelector.selectedAgents.Count < unitButtonList.Count) { RemoveEmptyFromList(); } UpdateButtons(); } }
/// <summary> /// Occurs when tab button is removed /// </summary> /// <param name="button">button removed</param> protected override void OnButtonRemoved(UnitButton button) { Form page = (Form)button.Page; page.FormClosing -= OnPageClosing; page.FormClosed -= OnPageClosed; page.ParentChanged -= OnPageParentChanged; PagesPanel.Remove(page); DockableFormInfo info = null; for (int index = _cachedInfos.Count - 1; index >= 0; index--) { if (_cachedInfos[index].Button == button) { info = _cachedInfos[index]; _cachedInfos.RemoveAt(index); info.ExplicitDisposing -= OnInfoDisposing; info.SelectedChanged -= OnInfoSelectedChanged; break; } } EventHandler <FormEventArgs> handler = FormRemoved; if (handler != null) { FormEventArgs args = new FormEventArgs(page, info.Id); handler(this, args); } }
/// <summary> /// Begin button drag /// </summary> /// <param name="selected">selected button</param> /// <param name="mousePosition">mouse position</param> /// <param name="cursor">cursor</param> /// <returns>true if button drag is started</returns> protected override bool BeginButtonDrag(UnitButton selected, Point mousePosition, ref Cursor cursor) { if (CanMoveByMouse == false) { return(true); } EventHandler <FormEventArgs> handler = UndockForm; if (handler != null) { _movedButton = selected; _movedForm = (Form)_movedButton.Page; _movedIndex = SelectedIndex; Point mouseScreenPosition = Control.MousePosition; FormEventArgs args = new FormEventArgs(_movedForm, GetPageInfo(_movedForm).Id); handler(this, args); RemoveButton(_movedButton); _movedDecorator = HierarchyUtility.GetFormsDecorator(_movedForm); IsFocused = false; _movedDecorator.IsFocused = true; _movedDecorator.BeginMovementByMouse(mouseScreenPosition); cursor = Cursors.SizeAll; } return(true); }
/// <summary> /// Occurs when mouse button was pressed while the cursor was over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected override void OnMouseDownInTabButton(UnitButton buttonUnderMouse) { EventHandler <ControlEventArgs> handler = SelectButton; if (handler != null) { ControlEventArgs args = new ControlEventArgs(buttonUnderMouse.Page); handler(this, args); } }
/// <summary> /// Occurs when tab button is added /// </summary> /// <param name="button">button added</param> protected override void OnButtonAdded(UnitButton button) { EventHandler <FormEventArgs> handler = FormAdded; if (handler != null) { DockableFormInfo info = GetPageInfo((Form)button.Page); FormEventArgs args = new FormEventArgs(info.DockableForm, info.Id); handler(this, args); } }
void OnButtonClick(int index) { if (Tutorial.instance.IsTutorial && Tutorial.instance.phase4.activeSelf) { return; } buttonSelection = unitButtons[index]; buildManager.SelectUnitToPlace(unitButtons[index].unit); unitPanelUI.ShowUnitPanel(); }
/// <summary> /// Occurs when mouse button was moved over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected override void OnMouseMoveOverTabButton(UnitButton buttonUnderMouse) { EventHandler <PreviewEventArgs> handler = ShowPreview; if (handler != null) { PreviewEventArgs args = new PreviewEventArgs(new Point(buttonUnderMouse.Left, buttonUnderMouse.Top), (Form)buttonUnderMouse.Page); handler(this, args); } }
/// <summary> /// Get the page at given index /// </summary> /// <param name="pageIndex">zero based page index</param> /// <returns>page at given index</returns> public Form GetPageAt(int pageIndex) { UnitButton buton = GetButtonAt(pageIndex); if (buton == null) { return(null); } return((Form)buton.Page); }
private void BuildAnPlaceMyUnitButton() { if (myUnit != null) { GameObject myUnitButton = Instantiate(myUnit, transform.position, Quaternion.identity); myUnitButton.transform.SetParent(gameObject.transform); myUnitButton.transform.position = gameObject.transform.position; UnitButton myButtonScript = myUnitButton.GetComponent <UnitButton>(); myButtonScript.myUnitCard = PlayerInfoStatic.PlayerDeck[buttonNumber]; myButtonScript.myButtonNumber = buttonNumber; } }
/// <summary> /// Used to enable the Agent's purchasing after his cooldown is gone /// </summary> private void Reset(UnitInCd unitInCd) { UnitButton unitButton = unitInCd.unitButton; unitButton.unit.isInCD = false; unitButton.cdFillText.enabled = false; unitButton.cdFillImage.enabled = false; unitsInCD.Remove(unitInCd); UpdateButtons(); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { PlaceUnit(); } if (Input.GetMouseButtonDown(1)) { this.clickedButton = null; } }
bool CreatUnitButton(GameObject _UIunit, UnitStruct _us) { //从资源池里实例化一个 UnitButtonDefault 并挂在 content 下: GameObject this_unit_button = Instantiate(Resources.Load <GameObject>("UI/UnitButton/UnitButtonDefault"), content); //获取这个 UnitButtonDefault 上的 UnitButton 脚本: UnitButton ub = this_unit_button.GetComponent <UnitButton>(); //初始化这个脚本: ub.Init(_UIunit); ub.self_unit_struct = _us; return(true); }
void LoadUnits(GameData data) { Dictionary <string, UnitButton> unitButtons = unitSelectionUI.buttons; for (int i = 0; i < data.unlockedUnits.Count; i++) { // Gets the unit that needs to be loaded in and sets appropriate level and active status string unitName = data.unlockedUnits[i]; Unit unitToLoad = null; if (!UnitManager.instance.unlockedUnits.ContainsKey(unitName)) { // If the standard unit name from the button doesn't match, it is an awoken unit if (unitButtons[unitName].unit.unitName != unitName) { // Searches available awoken units to find correct name // Sets the awoken unit to the unit to be loaded foreach (AwokenUnit awokenUnit in unitButtons[unitName].awokenUnitOptions) { if (unitName == awokenUnit.unitName) { unitToLoad = Instantiate(awokenUnit); break; } } } else { unitToLoad = Instantiate(unitButtons[unitName].unit); } unitToLoad.SetLevel(data.unitLevels[i]); unitToLoad.gameObject.SetActive(data.unitActiveStatuses[i]); unitToLoad.unitAI = data.unitActiveAI[i]; unitToLoad.transform.parent = UnitManager.instance.transform; UnitManager.instance.UnlockUnit(unitToLoad); // Updates the button within unit selection panel with original unit status UnitButton buttonToUpdate = unitButtons[unitName]; buttonToUpdate.UnlockButton(); buttonToUpdate.UpdateButton(unitToLoad); if (data.nodeUnitNames.Contains(unitName)) { int nodeIndex = data.nodeUnitNames.IndexOf(unitName); Node nodeWithUnit = UnitManager.instance.nodes[nodeIndex]; nodeWithUnit.PlaceUnit(unitToLoad); } } } }
/// <summary> /// Get the button associated with given form /// </summary> /// <param name="form">form</param> /// <returns>button</returns> private UnitButton GetButton(Form form) { for (int index = ButtonsCount - 1; index >= 0; index--) { UnitButton button = GetButtonAt(index); if (button.Page == form) { return(button); } } return(null); }
/// <summary> /// Call when button as been pressed, and set a cooldown on the button /// </summary> public void Cooldown(UnitButton unitButton) { // fill the image to start animation cd unitButton.cdFillImage.fillAmount = 1; unitButton.unit.isInCD = true; UnitInCd unitInCd = new UnitInCd(); unitInCd.unitButton = unitButton; unitInCd.unitCd = unitButton.unit.cDBetweenSpawns; unitsInCD.Add(unitInCd); }
private void AddButtons() { // Debug.Log("these are army list length: " + unitList.Count); //Debug.Log("Unit list len: " + unitList.Count); for (int i = 0; i < unitList.Count; i++) { Unit unit = unitList[i]; GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); UnitButton sampleButton = newButton.GetComponent <UnitButton>(); sampleButton.Setup(unit, i, this); } }
internal DockableFormInfo(Form form, DockAllowed allowedDock, Guid identifier) { if (identifier == Guid.Empty) { throw new ArgumentException("Err"); } _identifier = identifier; _dockableForm = form; _allowedDock = allowedDock; _button = new UnitButton(form); _button.ExplicitDisposing += OnButtonDisposing; form.GotFocus += OnFormGotFocus; }
/// <summary> /// Checks if this panel contains give panel /// </summary> /// <param name="panel">panel to check</param> /// <returns>true if this panel contains given pane</returns> public bool ContainsPanel(AutoHidePanel panel) { for (int index = ButtonsCount - 1; index >= 0; index--) { UnitButton button = GetButtonAt(index); FormsTabbedView view = HierarchyUtility.GetTabbedView((Form)button.Page); if (view.Parent == panel) { return(true); } } return(false); }
// Use this for initialization void Awake() { OriginalClip = Resources.Load("Click2") as AudioClip; ErrorClip = Resources.Load("Error") as AudioClip; src = gameObject.AddComponent <AudioSource>(); src.playOnAwake = false; src.clip = OriginalClip; ubScript1 = GameObject.Find("AddUnitPopup/Unit" + (1).ToString()).GetComponent <UnitButton>(); ubScript2 = GameObject.Find("AddUnitPopup/Unit" + (2).ToString()).GetComponent <UnitButton>(); ubScript3 = GameObject.Find("AddUnitPopup/Unit" + (3).ToString()).GetComponent <UnitButton>(); ubScript4 = GameObject.Find("AddUnitPopup/Unit" + (4).ToString()).GetComponent <UnitButton>(); ubScript5 = GameObject.Find("AddUnitPopup/Unit" + (5).ToString()).GetComponent <UnitButton>(); ubScript6 = GameObject.Find("AddUnitPopup/Unit" + (6).ToString()).GetComponent <UnitButton>(); }
/// <summary> /// Occurs when the page is closed /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">event argument</param> private void OnPageClosed(object sender, FormClosedEventArgs e) { DockableFormInfo info = GetPageInfo((Form)sender); Guid id = info.Id; Form form = info.DockableForm; UnitButton button = GetButton(form); button.Dispose(); EventHandler <FormEventArgs> handler = FormClosed; if (handler != null) { FormEventArgs args = new FormEventArgs(form, id); handler(this, args); } }
/// <summary> /// Ask for buy the Unit, then call to spawn /// <param name="unitButton">has all infomation needed by htis methode</param> /// </summary> protected void Spawn(UnitButton unitButton) { int cost = unitButton.unit.cost; bool succesPurchase = PlayerStats.Instance.TryPurchase(cost); if (succesPurchase) { if (NetworkManager.InstanceExists) { foreach (NetworkPlayer player in NetworkManager.Instance.connectedPlayers) { if (player.hasAuthority) { int indexUniteToSpawn = unitButton.agentSelectorIndex; Vector3 positionToSpawn; if (player.spawnPoint != null) { positionToSpawn = player.spawnPoint.position; } else { Debug.LogWarning("player.spawnPoint is not set"); positionToSpawn = defaultSpawnPoint.transform.position; } player.CmdSpawnFromPool(indexUniteToSpawn, positionToSpawn); } } } else { int indexUniteToSpawn = unitButton.agentSelectorIndex; Vector3 spawnPosition = defaultSpawnPoint.GetRandomPointInNodeArea(); GameObject ally = PoolManager.Instance.poolDictionnary [AgentSelector.Instance.selectedAgentsString[indexUniteToSpawn]].GetFromPool(spawnPosition); Unit unitAlly = ally.GetComponent <Unit>(); unitAlly.transform.position = spawnPosition; unitAlly.Initialize(); unitAlly.SetNode(defaultSpawnPoint); unitAlly.transform.rotation = defaultSpawnPoint.transform.rotation; } } }
/// <summary> /// 结束鼠标操作 /// </summary> private void EndMouseAction(bool cancel) { _isMouseDownInTabButton = false; if (_isMovingTabButton) { if (_isDraggingTabButton) { EndButtonDrag(cancel); } _isMovingTabButton = false; _buttonDisplaced = null; } IsMouseDownInScrollBackButton = false; IsMouseDownInScrollNextButton = false; }
/// <summary> /// Remove empty button from unitButtonList /// </summary> private void RemoveEmptyFromList() { AgentSelector agentSelector = AgentSelector.Instance; List <int> empty = new List <int>(); for (int i = agentSelector.selectedAgents.Count; i < unitButtonList.Count; i++) { empty.Add(i); } for (int i = empty.Count - 1; i >= 0; i--) { UnitButton unitButton = unitButtonList[empty[i]]; unitButtonList.RemoveAt(empty[i]); Destroy(unitButton.gameObject); } }
private void SetUpButtons(Dictionary <UnitType, int> unitCredits) { footmanButton = GameObject.FindGameObjectWithTag("FootmanButton").GetComponent <UnitButton>(); healerButton = GameObject.FindGameObjectWithTag("HealerButton").GetComponent <UnitButton>(); archerButton = GameObject.FindGameObjectWithTag("ArcherButton").GetComponent <UnitButton>(); startBattleButton = GameObject.FindGameObjectWithTag("StartBattleButton").GetComponent <StartBattleButton>(); pausePanel = GameObject.FindGameObjectWithTag("PausePanel").transform.GetChild(0).gameObject; footmanButton.SetUnitPrefab(footmanPrefab); if (unitCredits[UnitType.FOOTMAN] > 0) { footmanButton.buttonListeners += OnButtonClick; footmanButton.SetUnitCount(unitCredits[UnitType.FOOTMAN]); } else { footmanButton.Deactivate(); } healerButton.SetUnitPrefab(healerPrefab); if (unitCredits[UnitType.HEALER] > 0) { healerButton.buttonListeners += OnButtonClick; healerButton.SetUnitCount(unitCredits[UnitType.HEALER]); } else { healerButton.Deactivate(); } archerButton.SetUnitPrefab(archerPrefab); if (unitCredits[UnitType.ARCHER] > 0) { archerButton.buttonListeners += OnButtonClick; archerButton.SetUnitCount(unitCredits[UnitType.ARCHER]); } else { archerButton.Deactivate(); } startBattleButton.buttonListeners += OnStartBattleButtonClick; }
/// <summary> /// 删除按钮 /// </summary> protected bool RemoveButton(UnitButton button) { if (_buttons.Contains(button) == false) { return(false); } // If the selected index is the last button index, must decrement the selected index // to prevent index out of range exception after the count of buttons is updated. if (SelectedIndex > 0 && SelectedIndex == ButtonsCount - 1) { SelectedIndex--; } _buttons.Remove(button); OnButtonRemoved(button); button.TextChanged -= OnButtonTextChanged; button.ExplicitDisposing -= OnButtonDisposing; if (_buttons.Count == 0) { if (Disposing == false && IsDisposed == false) { using (Graphics graphics = CreateGraphics()) { UpdatePositions(graphics, false); } } } else { _updatePositionsOnDraw = true; } if (Disposing == false && IsDisposed == false) { UpdateSize(); Invalidate(); } return(true); }
/// <summary> /// Display a countdown regarding the if the unit spwaning is on CD /// </summary> private void Update() { if (unitsInCD.Count == 0) { return; } for (int i = 0; i < unitsInCD.Count; i++) { UnitButton unitButton = unitsInCD[i].unitButton; Unit unit = unitButton.unit; if (!unit.isInCD) { continue; } unitButton.cdFillText.enabled = true; unitButton.cdFillImage.enabled = true; float cooldownNormalize = Time.deltaTime / unit.cDBetweenSpawns; float cooldown = (unitsInCD[i].unitCd -= Time.deltaTime); if (cooldown > 60) { string minutes = ((int)cooldown / 60).ToString("00"); string seconds = ((int)cooldown % 60).ToString("00"); if (seconds == "60") { seconds = "00"; } unitButton.cdFillText.text = minutes + ":" + seconds; } else { unitButton.cdFillText.text = cooldown.ToString("0"); } unitButton.cdFillImage.fillAmount -= cooldownNormalize; if (cooldown <= 0) { Reset(unitsInCD[i]); } } }
/// <summary> /// 在鼠标向下时发生 /// </summary> protected override void OnMouseDown(MouseEventArgs e) { _isMouseDownInTabButton = false; _isMovingTabButton = false; if (IsMouseOverScrollBackButton) { IsMouseDownInScrollBackButton = true; ScrollBack(); } else if (IsMouseOverScrollNextButton) { IsMouseDownInScrollNextButton = true; ScrollNext(); } else if (_captionButtonsBounds.Contains(e.Location)) { int captionIndex = ButtonsRenderer.GetCaptionButtonIndex(_captionButtonsBounds, e.Location); OnMouseDownInCaptionButton(captionIndex, e); } else { int index = 0; UnitButton button = GetButtonFromPoint(e.Location, out index); if (button != null) { SelectedIndex = index; Invalidate(); _isMouseDownInTabButton = e.Button == MouseButtons.Left; OnMouseDownInTabButton(button); } } base.OnMouseDown(e); }
public void Setup(List <UnitAsset> Assets) { if (unitButtons != null) { this.transform.localScale -= new Vector3(0, unitButtons.Count, 0); foreach (UnitButton button in unitButtons) { Destroy(button.gameObject); } } unitButtons = new List <UnitButton>(); for (int i = 0; i < Assets.Count; i++) { UnitButton newButton = Instantiate(this.unitButtonPrefab, this.transform); newButton.Unit = Assets[i]; newButton.GameManager = this.GameManager; newButton.GetComponentInChildren <Text>().text = Assets[i].Name; this.unitButtons.Add(newButton); } this.transform.localScale += new Vector3(0, Assets.Count, 0); }
/// <summary> /// Removes the panel if is contained here /// </summary> /// <param name="panel">panel to remove</param> /// <returns>true if is removed the panel</returns> public bool Remove(AutoHidePanel panel) { bool removed = false; for (int index = ButtonsCount - 1; index >= 0; index--) { UnitButton button = GetButtonAt(index); FormsTabbedView view = HierarchyUtility.GetTabbedView((Form)button.Page); if (view.Parent == panel) { RemoveButton(button); removed = true; } } panel.View.FormAdded -= OnFormAddedToPanel; panel.View.FormRemoved -= OnFormRemovedFromPanel; panel.View.FormSelected -= OnFormSelectedIntoView; return(removed); }