Skip to content

Commit

Permalink
・最小化、最大化時はその直前のウィンドウ状態を記憶して復帰に使うようにした
Browse files Browse the repository at this point in the history
・サンプルではStart()をAwake()に変更
・コメント修正
  • Loading branch information
kirurobo committed Mar 3, 2015
1 parent d549c05 commit aaa1a56
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
18 changes: 17 additions & 1 deletion Example/SampleBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class SampleBehaviour : MonoBehaviour {
private string Title = "";

// Use this for initialization
void Start () {
void Awake () {
// ウィンドウ制御用のインスタンス作成
Window = new WindowController();

Expand Down Expand Up @@ -87,6 +87,11 @@ void Update () {
ToggleMaximize();
}

// Insert を押すと最小化切替
if (Input.GetKeyDown(KeyCode.Insert)) {
ToggleMinimize();
}

// ジョイスティックまたはカーソルキーでウィンドウ移動
// 画面Y座標は下が大なので上下反転
Vector2 axes = new Vector2(Input.GetAxis("Horizontal"), -Input.GetAxis("Vertical"));
Expand Down Expand Up @@ -151,4 +156,15 @@ public void ToggleMaximize() {
Window.Maximize();
}
}

/// <summary>
/// 最小化を切替
/// </summary>
public void ToggleMinimize() {
if (Window.IsMinimized) {
Window.Restore();
} else {
Window.Minimize();
}
}
}
15 changes: 12 additions & 3 deletions Example/SimpleSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!1 &503448511
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -160,7 +161,8 @@ GUIText:
m_GameObject: {fileID: 503448511}
m_Enabled: 1
serializedVersion: 3
m_Text: "[Home] Maximize\r\n[End] ON/OFF Transparent\r\n[Cursor-keys] Move Window"
m_Text: "[Home] Maximize\r\n[Insert] Minimize\n[End] ON/OFF Transparent\r\n[Cursor-keys]
Move Window"
m_Anchor: 7
m_Alignment: 0
m_PixelOffset: {x: 0, y: 0}
Expand All @@ -186,6 +188,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
--- !u!1 &702689693
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -225,6 +228,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
--- !u!1 &1724359456
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -275,6 +279,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
--- !u!1 &2084589444
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -342,8 +347,11 @@ Camera:
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: .0219999999
--- !u!4 &2084589449
Transform:
m_ObjectHideFlags: 0
Expand All @@ -355,6 +363,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
--- !u!1 &2124152612
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -391,9 +400,8 @@ Renderer:
m_UseLightProbes: 0
m_LightProbeAnchor: {fileID: 0}
m_ScaleInLightmap: 1
m_SortingLayer: 0
m_SortingOrder: 0
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!65 &2124152614
BoxCollider:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -424,3 +432,4 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
14 changes: 8 additions & 6 deletions Scripts/WindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ public bool FindHandleByClass(string title)
public void Update() {
if (!IsActive) return;
long style = WinApi.GetWindowLong(hWnd, WinApi.GWL_STYLE);
if (style != this.CurrentWindowStyle) {
WinApi.SetWindowLong (hWnd, WinApi.GWL_STYLE, this.CurrentWindowStyle);
WinApi.ShowWindow(hWnd, WinApi.SW_SHOW);
if (!WinApi.IsIconic(hWnd) && !WinApi.IsZoomed(hWnd)) {
if (style != this.CurrentWindowStyle) {
WinApi.SetWindowLong (hWnd, WinApi.GWL_STYLE, this.CurrentWindowStyle);
WinApi.ShowWindow(hWnd, WinApi.SW_SHOW);
}
}
}

Expand Down Expand Up @@ -332,17 +334,17 @@ public void EnableBorderless(bool enable) {
/// </summary>
public void Maximize() {
if (!IsActive) return;
WinApi.ShowWindow(hWnd, WinApi.SW_MAXIMIZE);
this.CurrentWindowStyle = WinApi.GetWindowLong(hWnd, WinApi.GWL_STYLE);
WinApi.ShowWindow(hWnd, WinApi.SW_MAXIMIZE);
}

/// <summary>
/// ウィンドウ最大化
/// ウィンドウ最小化
/// </summary>
public void Minimize() {
if (!IsActive) return;
WinApi.ShowWindow(hWnd, WinApi.SW_MINIMIZE);
this.CurrentWindowStyle = WinApi.GetWindowLong(hWnd, WinApi.GWL_STYLE);
WinApi.ShowWindow(hWnd, WinApi.SW_MINIMIZE);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Scripts/Wrapper/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class WinApi {
public static long WS_CAPTION = 0x00C00000L;
public static long WS_SYSMENU = 0x00080000L;
public static long WS_THICKFRAME = 0x00040000L;
public static long WS_ICONIC = 0x20000000L;
public static long WS_MINIMIZE = 0x20000000L;
public static long WS_MAXIMIZE = 0x01000000L;
public static long WS_MINIMIZEBOX = 0x00020000L;
public static long WS_MAXIMIZEBOX = 0x00010000L;
public static long WS_POPUP = 0x80000000L;
Expand Down
5 changes: 3 additions & 2 deletions readme_jp.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
WindowController

Copyright (c) 2014 Kirurobo
Copyright (c) 2014-2015 Kirurobo
Released under Unlicense <http://unlicense.org/>


Expand All @@ -9,7 +9,7 @@ Released under Unlicense <http://unlicense.org/>


■ 必要環境
・Unity 4.3 以降(おそらく)
・Unity 4.6 以降(おそらく)
・Windows Vista 以降(おそらく)


Expand Down Expand Up @@ -63,6 +63,7 @@ Released under Unlicense <http://unlicense.org/>


■ 更新履歴
2015/03/03 最小化、最大化時はその直前の状態を保存するようにした
2014/04/26 公開用初版


Expand Down

0 comments on commit aaa1a56

Please sign in to comment.