Пример #1
0
        public static EffectArray2dInput CreateColors2D(ChromaDevice2DEnum device)
        {
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            EffectArray2dInput effectArray2dInput = new EffectArray2dInput();

            for (int i = 0; i < maxRow; i++)
            {
                List <int> list = new List <int>();
                for (int j = 0; j < maxColumn; j++)
                {
                    list.Add(0);
                }
                effectArray2dInput.Add(list);
            }
            return(effectArray2dInput);
        }
Пример #2
0
        public static EffectArray2dInput CreateRandomColors2D(ChromaDevice2DEnum device)
        {
            int maxRow    = GetMaxRow(device);
            int maxColumn = GetMaxColumn(device);
            var rows      = new EffectArray2dInput();

            for (int i = 0; i < maxRow; ++i)
            {
                var row = new List <int>();
                for (int j = 0; j < maxColumn; ++j)
                {
                    row.Add(_sRandom.Next(16777215));
                }
                rows.Add(row);
            }
            return(rows);
        }
    private void OnClickImportButton()
    {
        ChromaSDKAnimation2D 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_2D)
                        {
                            Debug.LogError("Unexpected device type!");
                            return;
                        }

                        //device
                        switch ((ChromaDevice2DEnum)br.ReadByte())
                        {
                        case ChromaDevice2DEnum.Keyboard:
                            animation.Device = ChromaDevice2DEnum.Keyboard;
                            break;

                        case ChromaDevice2DEnum.Keypad:
                            animation.Device = ChromaDevice2DEnum.Keypad;
                            break;

                        case ChromaDevice2DEnum.Mouse:
                            animation.Device = ChromaDevice2DEnum.Mouse;
                            break;

                        default:
                            Debug.LogError("Unexpected device!");
                            return;
                        }

                        List <EffectArray2dInput> frames = new List <EffectArray2dInput>();

                        // 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)
                        {
                            EffectArray2dInput frame = new EffectArray2dInput();

                            //duration
                            float duration = br.ReadSingle();
                            time += duration;
                            animation.Curve.AddKey(time, 0f);
                            // colors
                            int maxRow    = ChromaUtils.GetMaxRow(animation.Device);
                            int maxColumn = ChromaUtils.GetMaxColumn(animation.Device);
                            for (int i = 0; i < maxRow; ++i)
                            {
                                List <int> row = new List <int>();
                                for (int j = 0; j < maxColumn; ++j)
                                {
                                    int color = br.ReadInt32();
                                    row.Add(color);
                                }
                                frame.Add(row);
                            }
                            frames.Add(frame);
                        }

                        animation.Frames = frames;
                    }
                }
            }
        }
    }