Skip to content

tgraupmann/UnityNativeChromaSDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnityNativeChromaSDK - Unity native library for the ChromaSDK

Table of Contents

Related

Apps:

Plugins:

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.

Import Unity Package

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();

MultiplyIntensityAllFramesName

The MultiplyIntensityAllFramesName method multiplies a color intensity for all frames of an animation. This is useful to control the intensity of a layer. 0.0 results in a completely black layer. 0.5 would half the color values for all frames.

string baseLayer = "EnvironmentSnow_Keyboard.chroma";

// reload the animation
UnityNativeChromaSDK.CloseAnimationName(baseLayer);

// set the intensity of the layer
UnityNativeChromaSDK.MultiplyIntensityAllFramesName(baseLayer, _mBaseIntensity);

OffsetNonZeroColorsAllFramesName

The OffsetNonZeroColorsAllFrames method offsets the RGB values for all frames in the animation that aren't black. This method allows a gray animation layer to be tinted to any color while keeping the black colors black. Red, green, blue use expected values 0 to 255.

string layer2 = "RingGray_Keyboard.chroma";

// reload the animation
UnityNativeChromaSDK.CloseAnimationName(layer2);

//animation starts with 127,127,127 so adding -127,127,-127 results in 0,255,0 or green
UnityNativeChromaSDK.OffsetNonZeroColorsAllFramesName(layer2, -127, 127, -127);

CopyNonZeroAllKeysAllFramesName

The CopyNonZeroAllKeysAllFramesName method copies all non-black colors for all frames from a source animation to a target animation. This is useful for combining multiple layers into a base layer.

UnityNativeChromaSDK.CopyNonZeroAllKeysAllFramesName(sourceAnimation, targetAnimation);

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.

Example10

Chroma animations support independent layering.