Skip to content

Commit 41f7970

Browse files
committed
Created Platform Define Switcher
1 parent 2f38b4e commit 41f7970

9 files changed

+278
-2
lines changed

BuildPlatform.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace AbyssMoth
2+
{
3+
public enum BuildPlatform
4+
{
5+
None = 0,
6+
RU_STORE = 1,
7+
YANDEX_GAMES = 2,
8+
GOOGLE_PLAY = 3,
9+
NASH_STORE = 4,
10+
}
11+
}

BuildPlatform.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PlatformBuildSettings.cs

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#if UNITY_EDITOR
2+
using System.Linq;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace AbyssMoth
7+
{
8+
public sealed class PlatformBuildSettings : EditorWindow
9+
{
10+
private BuildPlatform selectedPlatform = BuildPlatform.None;
11+
private GUIStyle greenTextStyle;
12+
13+
[MenuItem("Platform Build Settings/Platform Build Settings")]
14+
public static void ShowWindow() =>
15+
GetWindow<PlatformBuildSettings>("Platform Build Settings");
16+
17+
private void OnEnable() =>
18+
selectedPlatform = GetCurrentPlatform();
19+
20+
private void OnGUI()
21+
{
22+
if (greenTextStyle == null)
23+
greenTextStyle = new GUIStyle(EditorStyles.label) { normal = { textColor = Color.green } };
24+
25+
GUILayout.Label("Select the build platform:", EditorStyles.boldLabel);
26+
27+
GUILayout.Label("Current platform: " + selectedPlatform, greenTextStyle);
28+
29+
selectedPlatform = (BuildPlatform)EditorGUILayout.EnumPopup("Platform", selectedPlatform);
30+
31+
if (GUILayout.Button("Apply"))
32+
ApplyPlatformSettings(selectedPlatform);
33+
}
34+
35+
private static void ApplyPlatformSettings(BuildPlatform platform)
36+
{
37+
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
38+
39+
defines = RemoveDefine(defines, "RU_STORE");
40+
defines = RemoveDefine(defines, "YANDEX_GAMES");
41+
defines = RemoveDefine(defines, "GOOGLE_PLAY");
42+
defines = RemoveDefine(defines, "NASH_STORE");
43+
44+
switch (platform)
45+
{
46+
case BuildPlatform.RU_STORE:
47+
defines = AddDefine(defines, "RU_STORE");
48+
break;
49+
case BuildPlatform.YANDEX_GAMES:
50+
defines = AddDefine(defines, "YANDEX_GAMES");
51+
break;
52+
case BuildPlatform.GOOGLE_PLAY:
53+
defines = AddDefine(defines, "GOOGLE_PLAY");
54+
break;
55+
case BuildPlatform.NASH_STORE:
56+
defines = AddDefine(defines, "NASH_STORE");
57+
break;
58+
case BuildPlatform.None:
59+
break;
60+
default:
61+
defines = AddDefine(defines, "GOOGLE_PLAY");
62+
break;
63+
}
64+
65+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines);
66+
67+
Debug.Log($"Platform define set: {platform}");
68+
}
69+
70+
private static BuildPlatform GetCurrentPlatform()
71+
{
72+
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
73+
74+
if (defines.Contains("RU_STORE"))
75+
return BuildPlatform.RU_STORE;
76+
77+
if (defines.Contains("YANDEX_GAMES"))
78+
return BuildPlatform.YANDEX_GAMES;
79+
80+
if (defines.Contains("GOOGLE_PLAY"))
81+
return BuildPlatform.GOOGLE_PLAY;
82+
83+
if (defines.Contains("NASH_STORE"))
84+
return BuildPlatform.NASH_STORE;
85+
86+
return BuildPlatform.None;
87+
}
88+
89+
private static string AddDefine(string defines, string defineToAdd)
90+
{
91+
if (!defines.Contains(defineToAdd))
92+
{
93+
if (defines.Length > 0)
94+
defines += ";";
95+
96+
defines += defineToAdd;
97+
}
98+
99+
return defines;
100+
}
101+
102+
private static string RemoveDefine(string defines, string defineToRemove)
103+
{
104+
var allDefines = defines.Split(';').ToList();
105+
106+
allDefines.Remove(defineToRemove);
107+
108+
return string.Join(";", allDefines.ToArray());
109+
}
110+
}
111+
}
112+
#endif

PlatformBuildSettings.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+106-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# Unity-PlatformDefineSwitcher
2-
1+
# Unity Platform Define Switcher
2+
3+
*A tool for managing and switching platform-specific scripting defines in Unity.*
4+
5+
## Introduction
6+
7+
Unity Platform Define Switcher is an editor extension for Unity that allows developers to easily manage and switch between different platform-specific scripting define symbols. This tool simplifies the process of setting up build configurations for multiple platforms by providing a user-friendly interface within the Unity Editor.
8+
9+
## Features
10+
11+
- **Easy Platform Switching**: Switch between predefined platforms with a single click.
12+
- **Customizable Defines**: Add or remove scripting define symbols for each platform.
13+
- **Editor Integration**: Seamlessly integrated into the Unity Editor through a custom window.
14+
- **Supports Multiple Platforms**: Pre-configured for platforms like RU_STORE, YANDEX_GAMES, GOOGLE_PLAY, NASH_STORE, and easily extendable.
15+
16+
## Installation
17+
18+
### Using Unity Package Manager (UPM)
19+
20+
1. Open your Unity project.
21+
2. Navigate to **Window > Package Manager**.
22+
3. Click on the **** button and select **"Add package from git URL..."**.
23+
4. Enter the Git URL of the repository:
24+
25+
```
26+
https://github.com/RimuruDev/Unity-PlatformDefineSwitcher.git
27+
```
28+
29+
5. Click **Add** to install the package.
30+
31+
### Manual Installation
32+
33+
1. Clone or download the repository from [GitHub](https://github.com/RimuruDev/Unity-PlatformDefineSwitcher).
34+
2. Copy the `Packages/com.rimurudev.platform-define-switcher` folder into your project's `Packages` directory.
35+
36+
## Usage
37+
38+
1. After installation, go to **Platform Build Settings > Platform Build Settings** in the Unity Editor menu.
39+
2. The **Platform Build Settings** window will appear.
40+
3. In the window, you can:
41+
42+
- View the **Current platform** define.
43+
- Select a platform from the dropdown menu.
44+
45+
4. Click **Apply** to set the scripting define symbols for the selected platform.
46+
5. The tool will automatically add or remove defines based on your selection.
47+
48+
### Supported Platforms
49+
50+
- **RU_STORE**
51+
- **YANDEX_GAMES**
52+
- **GOOGLE_PLAY**
53+
- **NASH_STORE**
54+
55+
To add more platforms:
56+
57+
1. Open the `BuildPlatform.cs` script located in `Runtime/`.
58+
59+
```csharp
60+
namespace AbyssMoth
61+
{
62+
public enum BuildPlatform
63+
{
64+
None = 0,
65+
RU_STORE = 1,
66+
YANDEX_GAMES = 2,
67+
GOOGLE_PLAY = 3,
68+
NASH_STORE = 4,
69+
// Add your new platforms here :D
70+
// MY_NEW_PLATFORM = 5,
71+
}
72+
}
73+
```
74+
75+
2. Add your new platform to the `BuildPlatform` enum.
76+
3. Update the switch cases in `PlatformBuildSettings.cs` to handle the new platform.
77+
78+
## License
79+
80+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
81+
82+
## Contact
83+
84+
- **Author**: RimuruDev
85+
- **Email**: [[email protected]](mailto:[email protected])
86+
- **GitHub**: [https://github.com/RimuruDev](https://github.com/RimuruDev)
87+
- **LinkedIn**: [https://www.linkedin.com/in/rimuru/](https://www.linkedin.com/in/rimuru/)
88+
89+
## Contributing
90+
91+
Contributions are welcome! Please follow these steps:
92+
93+
1. Fork the repository.
94+
2. Create your feature branch (`git checkout -b feature/NewFeature`).
95+
3. Commit your changes (`git commit -m 'Add some feature'`).
96+
4. Push to the branch (`git push origin feature/NewFeature`).
97+
5. Open a pull request.
98+
99+
## Support
100+
101+
If you encounter any issues or have questions, please open an [issue](https://github.com/RimuruDev/Unity-PlatformDefineSwitcher/issues) on GitHub.
102+
103+
## Acknowledgments
104+
105+
- Inspired by the need to simplify platform-specific build configurations in Unity projects.
106+
- Thanks to the Unity community for their continuous support and contributions.

README.md.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "com.rimurudev.platform-define-switcher",
3+
"displayName": "Unity Platform Define Switcher",
4+
"version": "1.0.0",
5+
"unity": "2020.3",
6+
"description": "A tool for managing and switching platform-specific scripting defines in Unity.",
7+
"keywords": [
8+
"platform",
9+
"define",
10+
"switcher",
11+
"unity",
12+
"rimurudev",
13+
"build",
14+
"editor",
15+
"scripting-define",
16+
"platform-switch",
17+
"build-settings"
18+
],
19+
"author": {
20+
"name": "RimuruDev",
21+
"email": "[email protected]",
22+
"url": "https://github.com/RimuruDev"
23+
},
24+
"license": "MIT",
25+
"dependencies": {}
26+
}

package.json.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)