Пример #1
0
    public void LoadFromFile()
    {
        Debug.Log("LoadFromFile");
        // Generate random anims
        for (int i = 0; i < _animSet.animations.Length; ++i)
        {
            var data = new Animations.RGBAnimation();
            data.duration = (short)Mathf.RoundToInt(1000 * Random.Range(1, 11));
            data.tracks   = new Animations.RGBAnimationTrack[Random.Range(1, 11)];
            for (int j = 0; j < data.tracks.Length; ++j)
            {
                Animations.RGBAnimationTrack track = new Animations.RGBAnimationTrack();
                track.startTime = (short)Random.Range(0, data.duration - 100);
                track.duration  = (short)Random.Range(100, data.duration - track.startTime);
                track.ledIndex  = (byte)Random.Range(0, 21);
                track.keyframes = new Animations.RGBKeyframe[Random.Range(1, 6)];
                for (int k = 0; k < track.keyframes.Length; ++k)
                {
                    track.keyframes[k].time  = (byte)Random.Range(0, 256);
                    track.keyframes[k].red   = (byte)Random.Range(0, 256);
                    track.keyframes[k].blue  = (byte)Random.Range(0, 256);
                    track.keyframes[k].green = (byte)Random.Range(0, 256);
                }
                data.tracks[j] = track;
            }
            _animSet.animations[i] = data;
        }

        // ----> Update _animSet with data from dice

        ShowFace(0);
        _animSetTogglesRoot.GetComponentsInChildren <Toggle>().First().isOn = true;
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        Animations.AnimationSet set = new Animations.AnimationSet();
        set.animations = new Animations.RGBAnimation[5];
        for (int a = 0; a < set.animations.Length; ++a)
        {
            Animations.RGBAnimation anim = new Animations.RGBAnimation();
            anim.tracks   = new Animations.RGBAnimationTrack[a + 1];
            anim.duration = 2500;
            for (int i = 0; i < anim.tracks.Length; ++i)
            {
                var keyframes = new Animations.RGBKeyframe[Animations.Constants.MAX_KEYFRAMES];
                for (int j = 0; j < 3; ++j)
                {
                    keyframes[j].time  = (byte)j;
                    keyframes[j].red   = (byte)j;
                    keyframes[j].green = (byte)j;
                    keyframes[j].blue  = (byte)j;
                }

                var track = new Animations.RGBAnimationTrack();
                track.keyframes = keyframes;
                track.count     = 3;
                track.duration  = (short)(2000 - 10 * i);
                track.startTime = (short)(123 + i);
                track.ledIndex  = (byte)(i);
                anim.tracks[i]  = track;
            }

            set.animations[a] = anim;

            var bytes = Animations.RGBAnimation.ToByteArray(anim);
            Debug.Log(bytes.ToString());
        }
    }
Пример #3
0
        public static RGBAnimation FromByteArray(byte[] data)
        {
            System.IntPtr ptr = Marshal.AllocHGlobal(data.Length);
            Marshal.Copy(data, 0, ptr, data.Length);
            RGBAnimation ret = ReadBytes(ptr);

            Marshal.FreeHGlobal(ptr);
            return(ret);
        }
Пример #4
0
        public static byte[] ToByteArray(RGBAnimation anim)
        {
            int size = ByteSize(anim);

            System.IntPtr ptr = Marshal.AllocHGlobal(size);
            WriteBytes(anim, ptr);
            byte[] ret = new byte[size];
            Marshal.Copy(ptr, ret, 0, size);
            Marshal.FreeHGlobal(ptr);
            return(ret);
        }
Пример #5
0
    void Serialize()
    {
        var anims = GetComponentsInChildren <ColorAnimator>();

        Debug.LogFormat("Serializing {0} color animations", anims.Length);

        var anim = new Animations.RGBAnimation()
        {
            duration = (short)Mathf.RoundToInt(1000 * Duration),
            tracks   = anims.Select(a => a.Serialize(Unit)).ToArray()
        };

        _animSet.animations[CurrentFace] = anim;
    }
Пример #6
0
        public static void WriteBytes(RGBAnimation anim, System.IntPtr ptr)
        {
            int   trackSize = Marshal.SizeOf(typeof(RGBAnimationTrack));
            short count     = (short)anim.tracks.Length;

            Marshal.WriteInt16(ptr, 0, anim.duration);
            Marshal.WriteInt16(ptr, 2, count);

            for (int i = 0; i < count; ++i)
            {
                var trackPtr = new System.IntPtr(ptr.ToInt64() + 4 + i * trackSize);
                Marshal.StructureToPtr(anim.tracks[i], trackPtr, false);
            }
        }
Пример #7
0
        public static RGBAnimation ReadBytes(System.IntPtr ptr)
        {
            RGBAnimation ret = new RGBAnimation();

            ret.duration = Marshal.ReadInt16(ptr, 0);
            short count = Marshal.ReadInt16(ptr, 2);

            ret.tracks = new RGBAnimationTrack[count];

            int trackSize = Marshal.SizeOf(typeof(RGBAnimationTrack));

            for (int i = 0; i < count; ++i)
            {
                var trackPtr = new System.IntPtr(ptr.ToInt64() + 4 + i * trackSize);
                ret.tracks[i] = (RGBAnimationTrack)Marshal.PtrToStructure(trackPtr, typeof(RGBAnimationTrack));
            }

            return(ret);
        }
Пример #8
0
        public static int ByteSize(RGBAnimation anim)
        {
            int trackSize = Marshal.SizeOf(typeof(RGBAnimationTrack));

            return(trackSize * anim.tracks.Length + 4);
        }
Пример #9
0
 public int GetTotalByteSize()
 {
     return(animations.Sum(anim => RGBAnimation.ByteSize(anim)));
 }