Unity Native Chroma Sdk

by tgraupmann

wip

( Crawled 2 hours ago )
+

UnityNativeChromaSDK - Unity native library for the ChromaSDK

Table of Contents

Related

Frameworks supported

  • Unity 3.5.7 or later
  • Windows Editor / Windows Standalone

Dependencies

  • CChromaEditor - C++ Native MFC Library for playing and editing Chroma animations

Packaging

Import UnityNativeChromaSDK.unitypackage into your project.

Getting Started

1 Install Synapse

2 (Optional) Install the Emulator

3 Connect Razer Chroma hardware

4 Install Unity3d

5 Open Unity and start with an existing project or open a new project

6 Import UnityNativeChromaSDK.unitypackage into your project.

7 Create Chroma animations from the Assets/ChromaSDK/Create Chroma Animation menu item. This will open a file save dialog and create a chroma animation file when saved.

8 Edit Chroma animations by selecting a Chroma animation in the Object Hierarchy and select the Assets/ChromaSDK/Edit Chroma Animation menu item.

9 You can also associate the Chroma editor application with the .chroma extension and double-click .chroma assets in the Object Hierarchy.

Assets

Use the GameObject->ChromaSDK menu to create Chroma animations.

image_1

Chroma animations should be saved in the StreamingAssets folder.

Editing Chroma animations will open the Chroma editor dialog.

image_2

API

Add the ChromaSDK namespace.

using ChromaSDK;

The API is only available on the Windows Editor and Windows Standalone platforms.

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
// put your windows specific code in here
#endif

The native plugin should be initialized on Awake. -1 indicates failure, otherwise success.

private void Awake()
{
    bool isInitialized = UnityNativeChromaSDK.PluginIsInitialized();
    if (!isInitialized)
    {
        int result = UnityNativeChromaSDK.PluginInit();
    }
}

The native plugin should be uninitialized on Quit. -1 indicates failure, otherwise success.

private void OnApplicationQuit()
{
    bool isInitialized = UnityNativeChromaSDK.PluginIsInitialized();
    if (isInitialized)
    {
        int result = UnityNativeChromaSDK.PluginUninit();
    }
}

Chroma animations are initially loaded by path. Be sure to reference the StreamingAssets folder.

string GetStreamingPath(string animation)
{
   return string.Format("{0}/{1}", Application.streamingAssetsPath, animation);
}

Chroma animations only need to be opened once. Upon opening successfully, an identifier zero or greator will be returned that can be referenced to Play/Stop/Close.

int animationid = UnityNativeChromaSDK.OpenAnimation(path);

Once loaded, the Chroma animation can be played using the id. -1 will indicate a failure, otherwise the id will be returned. Play will start animation playback.

int result = UnityNativeChromaSDK.PluginPlayAnimation(animationId);

Once loaded, the Chroma animation can be stopped using the id. -1 will indicate a failure, otherwise the id will be returned. Stop will stop the animation playback.

int result = UnityNativeChromaSDK.PluginStopAnimation(animationId);

Once loaded, the Chroma animation can be closed using the id. -1 will indicate a failure, otherwise the id will be returned. Once closed, the animation can no longer be referenced by that id.

int result = UnityNativeChromaSDK.PluginCloseAnimation(animationId);

Chroma animations can be edited via path. -1 will indicate a failure, otherwise 0 will be returned. Edit will open the Chroma editor dialog.

int result = UnityNativeChromaSDK.EditAnimation(path);

Examples

Example01

UnityNativeChromaSDKExample01.cs has a GUI example to play/stop/edit Chroma animations at runtime.

image_3

Example02

UnityNativeChromaSDKExample02.cs has a GUI button to load scene 1 to show animations work with multiple scenes.

image_4

UnityNativeChromaSDKPlayOnEnable

The UnityNativeChromaSDKPlayOnEnable.cs script will automatically open and play a Chroma animation by name.

The AnimationName field references a .chroma asset filename from the StreamingAssets folder.

The .chroma extension on the AnimationName field is optional.

The UnityNativeChromaSDKPlayOnEnable.cs script will play the animation when the OnEnable event fires.

The UnityNativeChromaSDKPlayOnEnable.cs script will stop the animation when the OnDisable event fires.

image_5