public static EffectArray1dInput CreateRandomColors1D(ChromaDevice1DEnum device) { int maxLeds = GetMaxLeds(device); var elements = new EffectArray1dInput(); for (int i = 0; i < maxLeds; ++i) { elements.Add(_sRandom.Next(16777215)); } return(elements); }
public static EffectArray1dInput CreateColors1D(ChromaDevice1DEnum device) { int maxLeds = ChromaUtils.GetMaxLeds(device); EffectArray1dInput effectArray1dInput = new EffectArray1dInput(); for (int i = 0; i < maxLeds; i++) { effectArray1dInput.Add(new int?(0)); } return(effectArray1dInput); }
private void OnClickImportButton() { ChromaSDKAnimation1D animation = GetAnimation(); if (animation) { //string initialPath = string.Format("{0}/{1}.chroma", GetChromaFolder(), animation.name); string path = EditorUtility.OpenFilePanel("Open Chroma", GetChromaFolder(), GetChromaExtensions()); if (!string.IsNullOrEmpty(path)) { EditorPrefs.SetString(KEY_FOLDER_CHROMA, Path.GetDirectoryName(path)); using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader br = new BinaryReader(fs)) { //version int version = br.ReadInt32(); if (version != ANIMATION_VERSION) { Debug.LogError("Unexpected file version!"); return; } //device type if (br.ReadByte() != (byte)ChromaDeviceTypeEnum.Type_1D) { Debug.LogError("Unexpected device type!"); return; } //device switch ((ChromaDevice1DEnum)br.ReadByte()) { case ChromaDevice1DEnum.ChromaLink: animation.Device = ChromaDevice1DEnum.ChromaLink; break; case ChromaDevice1DEnum.Headset: animation.Device = ChromaDevice1DEnum.Headset; break; case ChromaDevice1DEnum.Mousepad: animation.Device = ChromaDevice1DEnum.Mousepad; break; default: Debug.LogError("Unexpected device!"); return; } List <EffectArray1dInput> frames = new List <EffectArray1dInput>(); // reset curve while (animation.Curve.keys.Length > 0) { animation.Curve.RemoveKey(0); } //frame count int frameCount = br.ReadInt32(); float time = 0f; //frames for (int index = 0; index < frameCount; ++index) { EffectArray1dInput frame = new EffectArray1dInput(); //duration float duration = br.ReadSingle(); time += duration; animation.Curve.AddKey(time, 0f); // colors int maxLeds = ChromaUtils.GetMaxLeds(animation.Device); for (int i = 0; i < maxLeds; ++i) { int color = br.ReadInt32(); frame.Add(color); } frames.Add(frame); } animation.Frames = frames; } } } } }