private void ConvertUnitTo(int type) { SubmitStdCommand(() => new ChangeParamsCmd(CmdCode.Convert) { IntParams = new int[] { type } }, (playerIndex, unitId) => { int controllableUnitsCount = m_gameState.GetStats(playerIndex).ControllableUnitsCount; long[] selection = m_unitSelection.GetSelection(playerIndex, playerIndex); IVoxelDataController dataController = m_gameState.GetVoxelDataController(playerIndex, unitId); if (dataController.CanConvertImmediate(type) != CmdResultCode.Success || selection.Length == controllableUnitsCount) { Debug.LogWarning("Can't convert unit " + unitId + " to " + type); return(false); } return(true); }); }
private void UpdateState() { int playerIndex = m_gameState.LocalToPlayerIndex(LocalPlayerIndex); long[] selection = m_selection.GetSelection(playerIndex, playerIndex); if (selection.Length == 0) { IsOpen = false; return; } m_cancelBtn.gameObject.SetActive(selection.Length > 0); m_attackBtn.gameObject.SetActive(selection.Length > 0); m_moveBtn.gameObject.SetActive(selection.Length > 0); m_autoBtn.gameObject.SetActive(selection.Length > 0); m_bombBtn.gameObject.SetActive(false); m_wallBtn.gameObject.SetActive(false); m_spawnButton.gameObject.SetActive(false); m_growButton.gameObject.SetActive(false); m_diminishButton.gameObject.SetActive(false); m_splitButton.gameObject.SetActive(false); m_split4Button.gameObject.SetActive(false); HUDControlBehavior hcbBomb = m_bombBtn.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbWall = m_wallBtn.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbSpawn = m_spawnButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbGrow = m_growButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbDiminish = m_diminishButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbSplit = m_splitButton.GetComponent <HUDControlBehavior>(); HUDControlBehavior hcbSplit4 = m_split4Button.GetComponent <HUDControlBehavior>(); hcbBomb.IsDisabled = true; hcbWall.IsDisabled = true; hcbSpawn.IsDisabled = true; hcbGrow.IsDisabled = true; hcbDiminish.IsDisabled = true; hcbSplit.IsDisabled = true; hcbSplit4.IsDisabled = true; for (int i = 0; i < selection.Length; ++i) { IVoxelDataController dc = m_gameState.GetVoxelDataController(playerIndex, selection[i]); if (dc != null) { CmdResultCode canBomb = dc.CanConvertImmediate((int)KnownVoxelTypes.Bomb); if (canBomb != CmdResultCode.Fail_NotSupported) { m_bombBtn.gameObject.SetActive(true); if (canBomb == CmdResultCode.Success) { hcbBomb.IsDisabled = false; } } CmdResultCode canGround = dc.CanConvertImmediate((int)KnownVoxelTypes.Ground); if (canGround != CmdResultCode.Fail_NotSupported) { m_wallBtn.gameObject.SetActive(true); if (canGround == CmdResultCode.Success) { hcbWall.IsDisabled = false; } } CmdResultCode canSpawner = dc.CanConvertImmediate((int)KnownVoxelTypes.Spawner); if (canSpawner != CmdResultCode.Fail_NotSupported) { m_spawnButton.gameObject.SetActive(true); if (canSpawner == CmdResultCode.Success) { hcbSpawn.IsDisabled = false; } } CmdResultCode canGrow = dc.CanGrowImmediate(); if (canGrow != CmdResultCode.Fail_NotSupported) { m_growButton.gameObject.SetActive(true); if (canGrow == CmdResultCode.Success) { hcbGrow.IsDisabled = false; } } CmdResultCode canDiminish = dc.CanDiminishImmediate(); if (canDiminish != CmdResultCode.Fail_NotSupported) { m_diminishButton.gameObject.SetActive(true); if (canDiminish == CmdResultCode.Success) { hcbDiminish.IsDisabled = false; } } CmdResultCode canSplit = dc.CanSplitImmediate(); if (canSplit != CmdResultCode.Fail_NotSupported) { m_splitButton.gameObject.SetActive(true); if (canSplit == CmdResultCode.Success) { hcbSplit.IsDisabled = false; } } CmdResultCode canSplit4 = dc.CanSplit4Immediate(); if (canSplit4 != CmdResultCode.Fail_NotSupported) { m_split4Button.gameObject.SetActive(true); if (canSplit4 == CmdResultCode.Success) { hcbSplit4.IsDisabled = false; } } } } if (m_eventSystem.currentSelectedGameObject != null && m_eventSystem.currentSelectedGameObject.GetComponent <HUDControlBehavior>().IsDisabled) { m_eventSystem.SetSelectedGameObjectOnLateUpdate(m_autoBtn.gameObject); } }