//#endif public static bool Save() { #if UNITY_EDITOR return(false); #endif WindowModel wm = new WindowModel(); if (windowPtr == IntPtr.Zero) { windowPtr = FindWindow(null, WindowName); } Rect windowrect = new Rect(); if (!GetWindowRect(windowPtr, out windowrect)) { Debug.LogFormat("Save window is fail: {0}", ""); return(false); } wm.WindowRect = windowrect.ToURect(); long styles = GetWindowLong(windowPtr, WindowLong.GWL_STYLE); if (styles == 0) { Debug.LogFormat("Save window is fail: {0}", ""); return(false); } wm.WindowStyles = styles; string jsonStr = JsonUtility.ToJson(wm); Debug.LogFormat("Saving values: {0}", jsonStr); PlayerPrefs.SetString(playerPrefsKey, jsonStr); return(true); }
public static bool Restore() { #if UNITY_EDITOR return(false); #endif if (!PlayerPrefs.HasKey(playerPrefsKey)) { Debug.LogFormat("Restore window is fail: {0}", ""); return(false); } string jsonStr = PlayerPrefs.GetString(playerPrefsKey); Debug.LogFormat("Restoring values: {0}", jsonStr); WindowModel wm = JsonUtility.FromJson <WindowModel>(jsonStr); if (wm == null) { Debug.LogFormat("Restore window is fail: {0}", "Saved data is corupted"); return(false); } windowPtr = FindWindow(null, WindowName); if (SetWindowLong(windowPtr, WindowLong.GWL_STYLE, wm.WindowStyles) == 0) { Debug.LogFormat("Restore window is fail: {0}", "Can`t set window styles"); return(false); } if (SetWindowPos(windowPtr, 0, (int)wm.WindowRect.x, (int)wm.WindowRect.y, (int)wm.WindowRect.width, (int)wm.WindowRect.height, 0x0040).ToInt32() == 0) { Debug.LogFormat("Restore window is fail: {0}", "Can`t set window position"); return(false); } return(true); }