https://github.com/beatthat/defines
Make the define symbols in Unity projects discoverable and easy to enable/disable with an editor window.
https://github.com/beatthat/defines
csharp npm package plugin unity unity3d unpm
Last synced: 2 months ago
JSON representation
Make the define symbols in Unity projects discoverable and easy to enable/disable with an editor window.
- Host: GitHub
- URL: https://github.com/beatthat/defines
- Owner: beatthat
- License: mit
- Created: 2018-07-05T16:56:47.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-07T16:37:29.000Z (almost 8 years ago)
- Last Synced: 2025-05-15T08:43:07.362Z (about 1 year ago)
- Topics: csharp, npm, package, plugin, unity, unity3d, unpm
- Language: C#
- Homepage:
- Size: 854 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Make the define symbols in Unity projects discoverable and easy to enable/disable with an editor window.
## Usage
#### Define/Undefine Symbols
Follow these steps to define or undefine symbols already annotated in your project's code:
1. ```Window => Define Scripting Symbols```
2. Check/uncheck symbols in the list
3. Tap ```Save```

#### Use ```[EditDefine]``` to Make a Define Option Show in the ```Define Scripting Symbols``` Window
For any define that you want visible in the Define Scripting Symbols window, add ```[EditDefine]``` to at least one class. The attribute must be applied to a class, not a method or other.
```csharp
[EditDefine(
"MY_CUSTOM_DEFINE",
"When defined, MyClass does something different on Start"
)
]
public class MyClass
{
void Start()
{
#if MY_CUSTOM_DEFINE
// some custom behavior
#endif
}
}
```
#### Create an options-style define by passing an array of symbols to ```[EditDefine]```
Defines can be useful switching among a set of configuration options. A common example is configuring which env 'stage' your server-connected app is pointing at, e.g. dev or production.
```csharp
[EditDefine(
new string[] {
"ENV_PRODUCTION",
"ENV_DEV",
"ENV_DEVLOCAL"
},
"Toggle the server environment"
)
]
public class ServerConfig
{
public const string HOST =
#if ENV_DEVLOCAL
"http://localhost:3001";
#elif ENV_DEV
"http://dev.mydomain.com";
#else
"http://mydomain.com";
#endif
}
```

## Install
From your unity project folder:
npm init
npm install beatthat/defines --save
## Development
You can edit the code and samples in the test environment and then use ```npm run overwrite:test2src``` to sync changes back to the package src.
```
npm run install:test
cd test
# edit code under Assets/Plugins/packages/beatthat/defines
# edit samples under Assets/Samples/packages/beatthat/defines
# sync changes back to src
npm run overwrite:test2src
```
**REMEMBER:** changes made under the test folder are not saved to the package
unless they are copied back into the source folder