-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ryanslikesocool/2.1.0
2.1.0
- Loading branch information
Showing
36 changed files
with
180 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ sysinfo.txt | |
# Crashlytics generated file | ||
crashlytics-build.properties | ||
|
||
# Other | ||
*.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#if UNITY_EDITOR_OSX | ||
using UnityEditor; | ||
|
||
namespace NativeColorScheme { | ||
public static class EditorThemeSwitcher { | ||
private static System.Reflection.MethodInfo switchSkinMethod; | ||
|
||
public static ColorScheme? DesiredAppearance { | ||
get => (byte)EditorPrefs.GetInt(SETTING_NAME, 0) switch { | ||
1 => ColorScheme.Light, | ||
2 => ColorScheme.Dark, | ||
_ => null | ||
}; | ||
set { | ||
int newValue = value switch { | ||
ColorScheme.Light => 1, | ||
ColorScheme.Dark => 2, | ||
_ => 0 | ||
}; | ||
EditorPrefs.SetInt(SETTING_NAME, newValue); | ||
} | ||
} | ||
|
||
[InitializeOnLoadMethod] | ||
static void Load() { | ||
switchSkinMethod = System.Reflection.Assembly.GetAssembly(typeof(UnityEditorInternal.AssetStore)).GetType("UnityEditorInternal.InternalEditorUtility", true).GetMethod("SwitchSkinAndRepaintAllViews"); | ||
|
||
EditorApplication.update += UpdateColorScheme; | ||
//EditorApplication.focusChanged += FocusChanged; | ||
SetColorScheme(DesiredAppearance); | ||
} | ||
|
||
private static void FocusChanged(bool state) | ||
=> UpdateColorScheme(); | ||
|
||
private static void SetDesiredColorScheme(ColorScheme? colorScheme) { | ||
DesiredAppearance = colorScheme; | ||
SetColorScheme(DesiredAppearance, true); | ||
} | ||
|
||
private static void UpdateColorScheme() | ||
=> SetColorScheme(DesiredAppearance); | ||
|
||
private static void SetColorScheme(ColorScheme? colorScheme, bool force = false) { | ||
ColorScheme finalColorScheme = colorScheme ?? ColorSchemeUtil.Current ?? ColorScheme.Light; | ||
|
||
if (finalColorScheme != DesiredAppearance || force) { | ||
Menu.SetChecked(SYSTEM_PATH, colorScheme == null); | ||
Menu.SetChecked(LIGHT_PATH, colorScheme == ColorScheme.Light); | ||
Menu.SetChecked(DARK_PATH, colorScheme == ColorScheme.Dark); | ||
|
||
if (finalColorScheme == ColorScheme.Dark ^ EditorGUIUtility.isProSkin) { | ||
switchSkinMethod.Invoke(null, null); | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Menu | ||
|
||
[MenuItem(SYSTEM_PATH, priority = 0)] | ||
private static void SetSystem() | ||
=> SetDesiredColorScheme(null); | ||
|
||
[MenuItem(LIGHT_PATH, priority = 11)] | ||
private static void SetLight() | ||
=> SetDesiredColorScheme(ColorScheme.Light); | ||
|
||
[MenuItem(DARK_PATH, priority = 12)] | ||
private static void SetDark() | ||
=> SetDesiredColorScheme(ColorScheme.Dark); | ||
|
||
// MARK: - Constants | ||
|
||
private const string SETTING_NAME = "NativeColorScheme.ColorScheme"; | ||
|
||
private const string SYSTEM_PATH = "Window/Color Scheme/System"; | ||
private const string LIGHT_PATH = "Window/Color Scheme/Light"; | ||
private const string DARK_PATH = "Window/Color Scheme/Dark"; | ||
} | ||
} | ||
#endif |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "NativeColorScheme.Editor", | ||
"rootNamespace": "NativeColorScheme.Editor", | ||
"references": [ | ||
"GUID:c8c56aad610fe4ee3936149e38efa88a" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": false, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
# NativeColorScheme | ||
System color scheme detection in Unity for macOS and iOS (runtime) and macOS (editor). | ||
System color scheme detection in Unity for macOS and iOS. | ||
|
||
## Requirements | ||
Color Scheme requires macOS 11 or later, or iOS 14 or later | ||
### Runtime | ||
- macOS 11+ | ||
- iOS 14+ | ||
- tvOS 14+ | ||
|
||
**Recommended Installation** (Unity Package Manager) | ||
- "Add package from git URL..." | ||
- `https://github.com/ryanslikesocool/NativeColorScheme.git` | ||
--- | ||
|
||
**Alternate Installation** | ||
- Get the latest [release](https://github.com/ryanslikesocool/ColorScheme/releases) | ||
- Open with the desired Unity project | ||
- Import into the Plugins folder | ||
### Editor | ||
- macOS 11+, Unity 2020.3+ | ||
|
||
## Installation (Unity Package Manager) | ||
- Select "Add package from git URL..." from the plus menu in the package manager window. | ||
- Paste the package's git url. | ||
``` | ||
https://github.com/ryanslikesocool/NativeColorScheme.git | ||
``` | ||
|
||
## Usage | ||
Get the value from `ColorScheme.ColorSchemeUtil.CurrentColorScheme` from anywhere in your code and use accordingly.\ | ||
Unsupported platforms/OS versions will return `ColorScheme.Unknown`. | ||
### C# | ||
```cs | ||
using NativeColorScheme; | ||
|
||
static class Somewhere { | ||
static Color GetColorForColorScheme() => ColorSchemeUtil.Current switch { | ||
ColorScheme.Light => Color.white, | ||
ColorScheme.Dark => Color.black, | ||
_ => Color.magenta | ||
}; | ||
} | ||
``` | ||
Unsupported platforms or OS versions will return `null`. | ||
|
||
--- | ||
|
||
### Editor | ||
Using the Unity editor on macOS, the plugin will automatically detect the system's color scheme and change the editor accordingly.\ | ||
The preference can be set to `System`, `Light`, or `Dark` from the `Window/Color Scheme` menu. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace NativeColorScheme { | ||
public enum ColorScheme : byte { | ||
Light = 1, | ||
Dark = 2 | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS | ||
using System.Runtime.InteropServices; | ||
#endif | ||
|
||
namespace NativeColorScheme { | ||
public static class ColorSchemeUtil { | ||
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX | ||
[DllImport("ColorScheme_macOS")] | ||
private static extern int getCurrentColorScheme_macOS(); | ||
|
||
public static ColorScheme? Current => getCurrentColorScheme_macOS() switch { | ||
1 => ColorScheme.Light, | ||
2 => ColorScheme.Dark, | ||
_ => null | ||
}; | ||
#elif UNITY_IOS || UNITY_TVOS | ||
[DllImport("__Internal")] | ||
private static extern int getCurrentColorScheme_iOS(); | ||
|
||
public static ColorScheme? Current => getCurrentColorScheme_iOS() switch { | ||
1 => ColorScheme.Light, | ||
2 => ColorScheme.Dark, | ||
_ => null | ||
}; | ||
#else | ||
public static ColorScheme? Current => null; | ||
#endif | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters