public static bool SaveCurrentGame(string SaveName = "AutoSave.bin") { //GameHandler.Instance => Save GameHandler SaveInstance = GameHandler.Instance; BinaryFormatter BFormatter = new BinaryFormatter(); string Path = GetSaveGameFolder(); Directory.CreateDirectory(Path); Debug.Log("Created path." + Path); FileStream SaveFile = File.Open(Path + SaveName, FileMode.Create); if (SaveInstance == null) { UiDialog.ShowWarningDialog("GameHandler not instanced...could not save"); return(false); } //Shouldn't happen but just in case. if (SaveInstance.InMiniGame) { UiDialog.ShowWarningDialog("Game is inside a minigame...couldn't save"); return(false); } //OK! BFormatter.Serialize(SaveFile, BuildSaveGame()); SaveFile.Flush(); SaveFile.Close(); return(true); }
private void OnResolutionSelected() { Coroutine ConfirmResolution; Resolution SelectedRes; GameObject Dialog; Debug.Log("Selected resolution: " + ResolutionList.value); Debug.Log("This means that our index is: " + Screen.resolutions[ResolutionList.value]); Debug.Log("ScreenRes: " + Screen.currentResolution.width + "x" + Screen.currentResolution.height + "@" + Screen.currentResolution.refreshRate); Debug.Log("Screen Width/Height: " + Screen.width + "x" + Screen.height + "@"); Dialog = null; SelectedRes = Screen.resolutions[ResolutionList.value]; if (SelectedRes.width == Screen.width && SelectedRes.height == Screen.height) { return; } ConfirmResolution = null; Screen.SetResolution(SelectedRes.width, SelectedRes.height, Screen.fullScreen, SelectedRes.refreshRate); Dialog = UiDialog.ShowWarningDialog("The resolution will reset if ok is not pressed in 5 seconds", "Confirm resolution change:", delegate { VideoSettingsPanel.GetComponent <Image>().StopCoroutine(ConfirmResolution); SafeResolution = SelectedRes; //Save it to playerprefs. SaveResolutionToPlayerPrefs(SelectedRes); Destroy(Dialog); }); Debug.Log("Started coroutine."); ConfirmResolution = VideoSettingsPanel.GetComponent <Image>().StartCoroutine(IsResolutionValid(Dialog)); }
public void OnOverWriteSaveGame(string SaveGameName) { GameObject Dialog = null; Dialog = UiDialog.ShowQuestionDialog("Are you sure you want to overwrite " + SaveGameName + "?", "Confirm Overwrite", (delegate { SaveManager.SaveCurrentGame(SaveGameName + SaveManager.DefaultSaveFileExtension); if (Dialog != null) { Destroy(Dialog); } })); }
private void EvaluateRank() { int Score; if (GameHandler.Instance == null) { Debug.Log("EvaluateRank:Gamehandler instance is not valid."); return; } Score = GameHandler.Instance.GetPlayer().GetScore(); if (LeaderBoard.Instance.IsHighScore(Score)) { LeaderboardDialog = UiDialog.ShowInputDialog("New record", "Enter your name", this, this); } }
/* */ public void OnInputFieldValueSubmit(InputField Field) { string SaveFileName; if (Field.text.LastIndexOf(".") >= 0) { SaveFileName = Field.text; } else { SaveFileName = Field.text + SaveManager.DefaultSaveFileExtension; } if (SaveManager.SaveGameExists(SaveFileName)) { UiDialog.ShowWarningDialog("The name you have specified already exists...pick another"); Field.text = ""; return; } SaveManager.SaveCurrentGame(SaveFileName); }
public static void LaunchSavedGame(MonoBehaviour ReferenceScript, string SaveGame = "AutoSave.bin") { Nullable <SaveManager.SaveGame> SavedGame = SaveManager.LoadGame(SaveGame); if (SavedGame == null) { UiDialog.ShowWarningDialog("Couldn't load " + SaveGame + "...try to start a new game...."); return; } Debug.Log("LaunchSavedGame Loading " + SaveGame); if (GameHandler.Instance) { GameHandler.Instance.CleanUp(); //GameHandler.Instance.CleanUp(); } Debug.Log("Loading scene: " + SavedGame.Value.SceneName); //GameObject FantomGameObject = new GameObject(); //MonoBehaviour Dummy = FantomGameObject.AddComponent<MonoBehaviour>(); InputManager.Instance.StartCoroutine(SceneUtils.LoadSceneAsync(SavedGame.Value)); //Debug.Log("GameHandler resuming load: " + GameHandler.Instance.IsPaused); }
private IEnumerator GetNewBinding(string ButtonName) { Button Element = Buttons.Find(x => x.name == ButtonName); Element.GetComponentInChildren <Text>().text = "Press..."; EditMode = true; while (/*!Input.anyKey || (Input.GetMouseButton(0) && EventSystem.current.IsPointerOverGameObject()) */ true) { if (Input.anyKeyDown && !Input.GetMouseButton(0)) { break; } yield return(null); } Debug.Log("Got something..."); foreach (KeyCode kCode in Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(kCode)) { if (!InputManager.Instance.IsKeyBindInUse(kCode)) { Debug.Log("Binding: " + kCode.ToString()); Element.GetComponentInChildren <Text>().text = kCode.ToString(); BindNewKey(ButtonName, kCode); InputManager.Instance.SaveSettings(); Debug.Log("Bind"); } else { Debug.Log("Key Already in Use"); Debug.Log("Bind Failed"); UiDialog.ShowWarningDialog("Key already in use."); Element.GetComponentInChildren <Text>().text = PreviousBindTextButton; } break; } } SetOtherButtonsState(ButtonName, true); EditMode = false; }
internal bool HideModal(UiDialog dialog, object returnValue) { _logger.InfoFormat("HideModal({0})", dialog.name); //表示一种方法,该方法定义了一组条件,指定对象是否符合这组条件 var i = _modals.FindIndex(m => m.Handle.Dialog == dialog); if (i == -1) { _logger.Info("Failed to hide modal because not shown"); return(false); } var entity = _modals[i]; _modals.RemoveAt(i); // trigger UiDialog.OnHide var uiDialog = entity.Handle.Dialog.GetComponent <UiDialog>(); if (uiDialog != null) { uiDialog.OnHide(); } // remove dialog var dialogCg = dialog.GetComponent <CanvasGroup>(); dialogCg.DOFade(0f, 0.2f).SetEase(Ease.OutCubic).SetUpdate(true).OnComplete(() => { if (entity.IsTemporary) { UnityEngine.Object.Destroy(entity.Handle.Dialog.gameObject); } else { entity.Handle.Dialog.gameObject.SetActive(false); } }); // remove curtain if (entity.Curtain != null) { if ((entity.Option & ShowModalOption.BlackCurtain) != 0) { _blackCurtainCount -= 1; _fadingOutBlackCurtain = entity.Curtain; var image = entity.Curtain.GetComponentInChildren <Image>(); image.DOColor(new Color(0, 0, 0, 0), 0.1f).SetEase(Ease.InQuad).SetUpdate(true) .OnComplete(() => { if (_fadingOutBlackCurtain == entity.Curtain) { _fadingOutBlackCurtain = null; } UnityEngine.Object.Destroy(entity.Curtain.gameObject); }); } else { UnityEngine.Object.Destroy(entity.Curtain.gameObject); } } // trigger Hidden event entity.Handle.Visible = false; entity.Handle.ReturnValue = returnValue; if (entity.Handle.Hidden != null) { entity.Handle.Hidden(entity.Handle.Dialog, returnValue); } return(true); }
/// <summary> /// ********显示窗口的实现方法******* /// </summary> /// <param name="dialog">会话框</param> /// <param name="isTemporary"></param> /// <param name="param"></param> /// <param name="option"></param> /// <returns></returns> private UiDialogHandle ShowModalInternal(UiDialog dialog, bool isTemporary, object param, ShowModalOption option) { // create curtain for blocking input ///<summary> ///背景黑罩 ///</summary> RectTransform curtain = null; if ((option & ShowModalOption.BlackCurtain) != 0 && _fadingOutBlackCurtain != null) { // When there is a curtain fading out, reuse it to reduce flickering curtain = _fadingOutBlackCurtain; DOTween.Kill(curtain.GetComponentInChildren <Image>()); _fadingOutBlackCurtain = null; } else { //curtain为对话框弹出后的背景遮罩 改变背景颜色 curtain = CreateCurtain(new Color(0, 0, 0, 0), _dialogRoot); } //SetSiblingIndex->用于设置节点在hierarchy中的层级 如0,1,2,3 //在UI layer中hierarchy中的层级代表了渲染顺序 //渲染层级与父节点统一 SiblingIndex(渲染) curtain.SetSiblingIndex(dialog.GetComponent <RectTransform>().GetSiblingIndex()); //会话框要比背景后渲染 // unnecessary but it works as workaround for setting sibling index dialog.GetComponent <RectTransform>().SetSiblingIndex(curtain.GetSiblingIndex() + 1); if ((option & ShowModalOption.BlackCurtain) != 0) { _blackCurtainCount += 1; var image = curtain.GetComponentInChildren <Image>(); image.DOColor(new Color(0, 0, 0, 0.7f), 0.15f).SetUpdate(true); } // fade in dialog var dialogRt = dialog.GetComponent <RectTransform>(); dialogRt.localScale = Vector3.one * 1.1f; dialogRt.DOScale(Vector3.one, 0.2f).SetEase(Ease.OutCubic).SetUpdate(true); var dialogCg = dialog.GetComponent <CanvasGroup>(); dialogCg.alpha = 0.2f; //渐变 dialogCg.DOFade(1f, 0.2f).SetEase(Ease.OutCubic).SetUpdate(true); // create handle and register to modals var handle = new UiDialogHandle { Dialog = dialog, Visible = true }; _modals.Add(new ModalEntity { Handle = handle, IsTemporary = isTemporary, Curtain = curtain, Option = option }); dialog.OnShow(param); return(handle); }
private void Playtest() { GameObject LeaderBoard = UiDialog.ShowInputDialog("New record", "Enter your name", null, this); }