SDK

Unity Native Chroma SDK

UnityNativeChromaSDK - Unity native library for the ChromaSDK

Table of Contents

Frameworks supported

  • Unity 3.5.7 or later
  • Windows Editor / Windows Standalone

Prerequisites

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 Backup your project in source control!

7 Import UnityNativeChromaSDK.unitypackage into your project.

8 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.

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

image_1

10 Also edit Chroma animations by selecting a .chroma file in the Object Hierarchy, right-click, and select the ChromaSDK/Edit Chroma Animation context item.

image_6

Tutorials

Razer Chroma Playlist

Capture Window

Composite Capture

Composite Playback

Capture With Images

Keyboard Layout Toggle

Loop and Reverse

Keyboard Masks

Layouts and Playback Looping

Assets

Chroma animations are loaded from the StreamingAssets folder.

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

Init

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

private void Awake()
{
    UnityNativeChromaSDK.Init();
}

Uninit

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

private void OnApplicationQuit()
{
    UnityNativeChromaSDK.Uninit();
}

PluginIsInitialized

Returns true if the plugin has been initialized. Returns false if the plugin is uninitialized.

bool isInitialized = UnityNativeChromaSDK.PluginIsInitialized();

PlayAnimationName

The animation will play with looping ON or OFF.

string animation = "Random_Keyboard.chroma";
bool loop = true;
UnityNativeChromaSDK.PlayAnimationName(animation, loop);

StopAnimationName

The animation will stop playing.

string animation = "Random_Keyboard.chroma";
UnityNativeChromaSDK.StopAnimationName(animation);

StopAnimationType

Stop playing animations by type.

UnityNativeChromaSDK.StopAnimationType(UnityNativeChromaSDK.Device.ChromaLink);
UnityNativeChromaSDK.StopAnimationType(UnityNativeChromaSDK.Device.Headset);
UnityNativeChromaSDK.StopAnimationType(UnityNativeChromaSDK.Device.Keyboard);
UnityNativeChromaSDK.StopAnimationType(UnityNativeChromaSDK.Device.Keypad);
UnityNativeChromaSDK.StopAnimationType(UnityNativeChromaSDK.Device.Mouse);
UnityNativeChromaSDK.StopAnimationType(UnityNativeChromaSDK.Device.Mousepad);

CloseAnimationName

The animation will be closed so that it can be reloaded from disk.

string animation = "Random_Keyboard.chroma";
UnityNativeChromaSDK.CloseAnimationName(animation);

EditAnimation

The animation will open in the editor dialog. Only one animation can be edited at a time.

string animation = "Random_Keyboard.chroma";
UnityNativeChromaSDK.EditAnimation(animation);

GetFrameCountName

Get the frame count of the animation.

string animation = "Random_Keyboard.chroma";
int frameCount = UnityNativeChromaSDK.GetFrameCountName(animation);

CopyKeysColorAllFramesName

Copy a set of key colors from the source animation to the target animation for all frames.

string sourceAnimation = "Fire_Keyboard.chroma";
string targetAnimation = "Random_Keyboard.chroma";
UnityNativeChromaSDK.CopyKeysColorAllFramesName(sourceAnimation, targetAnimation,
    new int[] {
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_W,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_A,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_S,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_D,
        (int)UnityNativeChromaSDK.Keyboard.RZLED.RZLED_LOGO});

SetKeysColorAllFramesName

Assign a set of key colors to a static color for all animation frames.

string animation = "Random_Keyboard.chroma";
Color color = Color.red;
UnityNativeChromaSDK.SetKeysColorAllFramesName(animation,
    new int[] {
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_I,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_J,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_K,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_L,
        (int)UnityNativeChromaSDK.Keyboard.RZKEY.RZKEY_ENTER},
    color);

GetCurrentFrameName

Get the current frame of the animation.

string animation = "Random_Keyboard.chroma";
int currentFrame = UnityNativeChromaSDK.GetCurrentFrameName(animation)

SetCurrentFrameName

Set the current frame of the animation.

string animation = "Random_Keyboard.chroma";
int frameId = 0;
UnityNativeChromaSDK.SetCurrentFrameName(animation, frameId);

IsAnimationPausedName

Check if the animation is paused.

string animation = "Random_Keyboard.chroma";
bool isPaused = UnityNativeChromaSDK.IsAnimationPausedName(animation);

HasAnimationLoopName

Check if the animation has loop ON or OFF.

string animation = "Random_Keyboard.chroma";
bool loop = UnityNativeChromaSDK.HasAnimationLoopName(animation);

PauseAnimationName

Pause the animation.

string animation = "Random_Keyboard.chroma";
UnityNativeChromaSDK.PauseAnimationName(animation);

ResumeAnimationName

Resume playing the animation with loop ON or OFF.

string animation = "Random_Keyboard.chroma";
bool loop = true;
UnityNativeChromaSDK.ResumeAnimationName(animation, loop);

PlayComposite

Play a set of animations with loop ON or OFF. A set includes ChromaLink, Headset, Keyboard, Keypad, Mouse, and Mousepad.

string composite = "Random";
bool loop = true;
UnityNativeChromaSDK.PlayComposite(composite, loop);

StopComposite

Stop playing a set of animations.

string composite = "Random";
UnityNativeChromaSDK.StopComposite(composite);

IsPlaying

Check if an animation is playing.

string animation = "Random_Keyboard.chroma";
bool isPlaying = UnityNativeChromaSDK.IsPlaying(animation);

PluginIsPlatformSupported

Check if the current platform supports playing Chroma.

bool isPlatformSupported = UnityNativeChromaSDK.PluginIsPlatformSupported();

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

Example03

Particle capture example

Example04

Show PlayOnEnable script

Example05

Image plane capture example

Example06

Show PlayAndDeactivate script

Example07

Show PlayOnDestroy script

Example08

SetKeys and CopyKeys can be used to highlight keys on top of an animated base layer.

Example09

Chroma animations can be paused and resumed with looping ON or OFF.