Skip to content

Commit

Permalink
support multi display
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshidan committed Apr 30, 2022
1 parent 4b43497 commit 96ad383
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 46 deletions.
9 changes: 8 additions & 1 deletion src/N0vaMac/Assets/Plugins/WindowApi/WindowApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class WindowApi

[DllImport(Target)]
private static extern void initializePosition();


[DllImport(Target)]
private static extern void maximize();

public static void Background()
{
Expand All @@ -28,5 +30,10 @@ public static void InitializePosition()
{
initializePosition();
}

public static void Maximize()
{
maximize();
}

}
Binary file modified src/N0vaMac/Assets/Plugins/WindowApi/macOS/libWindowApi.dylib
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/N0vaMac/Assets/Scenes/Wallpaper.unity
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1808250840}
m_Father: {fileID: 0}
Expand Down Expand Up @@ -302,6 +303,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
Expand Down Expand Up @@ -368,6 +370,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
Expand Down Expand Up @@ -403,6 +406,7 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 298844938}
m_RootOrder: 0
Expand Down
36 changes: 27 additions & 9 deletions src/N0vaMac/Assets/Scripts/VideoController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
Expand All @@ -13,8 +14,9 @@ public class VideoController : MonoBehaviour
private float aspectRatio = 1.0f;
private VideoAspectRatio videoAspectRatio;

[SerializeField]
private VideoClip defaultClip;
// [SerializeField] private Text debugInfo;

[SerializeField] private VideoClip defaultClip;

void Awake()
{
Expand All @@ -25,13 +27,14 @@ void Awake()
player.prepareCompleted += (source) =>
{
var texture = source.texture;
aspectRatio = (float)texture.height / texture.width;
aspectRatio = (float) texture.height / texture.width;
};
videoAspectRatio = player.aspectRatio;
}

private void Start()
{

var settingFile = $"{Application.persistentDataPath}/path.txt";
if (File.Exists(settingFile))
{
Expand All @@ -56,6 +59,7 @@ private void Start()
WindowApi.Background();
WindowApi.HideTitleBar();
#endif
StartCoroutine(AdjustLoop());
}

public void ChangeUrl(string url)
Expand All @@ -65,7 +69,7 @@ public void ChangeUrl(string url)
player.url = $"file://{url}";
player.Play();
}

public void ChangeClip(VideoClip clip)
{
player.Stop();
Expand All @@ -74,16 +78,30 @@ public void ChangeClip(VideoClip clip)
player.Play();
}

private IEnumerator AdjustLoop()
{
while (true)
{
yield return Adjust();
yield return new WaitForSeconds(0.5f);
}
}

private IEnumerator Adjust()
{
var resolution = Screen.currentResolution;
Screen.SetResolution(resolution.width, resolution.height, false);
var currentMonitor = Screen.mainWindowDisplayInfo;
//always move to origin in current monitor
yield return Screen.MoveMainWindowTo(currentMonitor, currentMonitor.workArea.min);
}

void Update()
{
if (player.isPrepared)
{
image.texture = player.texture;
#if !UNITY_EDITOR
var resolution = Screen.currentResolution;
Screen.SetResolution(resolution.width, resolution.height, false);
WindowApi.InitializePosition();
#endif

switch(videoAspectRatio)
{
case VideoAspectRatio.FitHorizontally:
Expand Down
28 changes: 23 additions & 5 deletions src/N0vaMac/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--- !u!129 &1
PlayerSettings:
m_ObjectHideFlags: 0
serializedVersion: 22
serializedVersion: 23
productGUID: f6c7a3693196b4c079983b7acd72cf92
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
Expand Down Expand Up @@ -68,6 +68,12 @@ PlayerSettings:
androidRenderOutsideSafeArea: 1
androidUseSwappy: 1
androidBlitType: 0
androidResizableWindow: 0
androidDefaultWindowWidth: 1920
androidDefaultWindowHeight: 1080
androidMinimumWindowWidth: 400
androidMinimumWindowHeight: 300
androidFullscreenMode: 1
defaultIsNativeResolution: 1
macRetinaSupport: 1
runInBackground: 1
Expand Down Expand Up @@ -121,13 +127,14 @@ PlayerSettings:
vulkanEnableSetSRGBWrite: 0
vulkanEnablePreTransform: 0
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
m_SupportedAspectRatios:
4:3: 1
5:4: 1
16:10: 1
16:9: 1
Others: 1
bundleVersion: 0.1
bundleVersion: 0.1.1
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand All @@ -153,7 +160,7 @@ PlayerSettings:
tvOS: 0
overrideDefaultApplicationIdentifier: 0
AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 19
AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1
aotOptions:
Expand Down Expand Up @@ -209,6 +216,7 @@ PlayerSettings:
iOSLaunchScreeniPadCustomStoryboardPath:
iOSDeviceRequirements: []
iOSURLSchemes: []
macOSURLSchemes: []
iOSBackgroundModes: 0
iOSMetalForceHardShadows: 0
metalEditorSupport: 1
Expand Down Expand Up @@ -236,6 +244,7 @@ PlayerSettings:
useCustomGradlePropertiesTemplate: 0
useCustomProguardFile: 0
AndroidTargetArchitectures: 1
AndroidTargetDevices: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
AndroidKeystoreName:
Expand All @@ -252,6 +261,7 @@ PlayerSettings:
height: 180
banner: {fileID: 0}
androidGamepadSupportLevel: 0
chromeosInputEmulation: 1
AndroidMinifyWithR8: 0
AndroidMinifyRelease: 0
AndroidMinifyDebug: 0
Expand Down Expand Up @@ -317,7 +327,7 @@ PlayerSettings:
m_BuildTargetGraphicsAPIs:
- m_BuildTarget: AndroidPlayer
m_APIs: 150000000b000000
m_Automatic: 0
m_Automatic: 1
- m_BuildTarget: iOSSupport
m_APIs: 10000000
m_Automatic: 1
Expand Down Expand Up @@ -346,6 +356,7 @@ PlayerSettings:
m_EncodingQuality: 0
m_BuildTargetGroupLightmapSettings: []
m_BuildTargetNormalMapEncoding: []
m_BuildTargetDefaultTextureCompressionFormat: []
playModeTestRunnerEnabled: 0
runPlayModeTestAsEditModeTest: 0
actionOnDotNetUnhandledException: 1
Expand All @@ -355,6 +366,7 @@ PlayerSettings:
cameraUsageDescription:
locationUsageDescription:
microphoneUsageDescription:
bluetoothUsageDescription:
switchNMETAOverride:
switchNetLibKey:
switchSocketMemoryPoolSize: 6144
Expand All @@ -363,6 +375,7 @@ PlayerSettings:
switchScreenResolutionBehavior: 2
switchUseCPUProfiler: 0
switchUseGOLDLinker: 0
switchLTOSetting: 0
switchApplicationID: 0x01004b9000490000
switchNSODependencies:
switchTitleNames_0:
Expand Down Expand Up @@ -492,6 +505,10 @@ PlayerSettings:
switchNetworkInterfaceManagerInitializeEnabled: 1
switchPlayerConnectionEnabled: 1
switchUseNewStyleFilepaths: 0
switchUseMicroSleepForYield: 1
switchEnableRamDiskSupport: 0
switchMicroSleepForYieldTime: 25
switchRamDiskSpaceSize: 12
ps4NPAgeRating: 12
ps4NPTitleSecret:
ps4NPTrophyPackPath:
Expand Down Expand Up @@ -597,7 +614,6 @@ PlayerSettings:
suppressCommonWarnings: 1
allowUnsafeCode: 0
useDeterministicCompilation: 1
useReferenceAssemblies: 1
enableRoslynAnalyzers: 1
additionalIl2CppArgs:
scriptingRuntimeVersion: 1
Expand Down Expand Up @@ -684,4 +700,6 @@ PlayerSettings:
organizationId:
cloudEnabled: 0
legacyClampBlendShapeWeights: 0
playerDataPath:
forceSRGBBlit: 1
virtualTexturingSupportEnabled: 0
16 changes: 16 additions & 0 deletions src/N0vaMac/ProjectSettings/TimelineSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 61
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3}
m_Name:
m_EditorClassIdentifier:
assetDefaultFramerate: 60
m_DefaultFrameRate: 60
1 change: 1 addition & 0 deletions src/N0vaMac/ProjectSettings/UnityConnectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ UnityConnectSettings:
m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
m_ConfigUrl: https://config.uca.cloud.unity3d.com
m_DashboardUrl: https://dashboard.unity3d.com
m_TestInitMode: 0
CrashReportingSettings:
m_EventUrl: https://perf-events.cloud.unity3d.com
Expand Down
2 changes: 2 additions & 0 deletions src/WindowApi/WindowApi/WindowApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void hideTitleBar(void);

void initializePosition(void);

void maximize(void);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/WindowApi/WindowApi/WindowApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ void initializePosition() {
NSWindow *window = [NSApp orderedWindows][0];
[window setFrameOrigin:NSMakePoint(0,0)];
}

void maximize() {
NSWindow *window = [NSApp orderedWindows][0];
[window zoom:(NULL)];
}

0 comments on commit 96ad383

Please sign in to comment.