Exemple #1
0
    void DecodeDirection(int directionIndex)
    {
        UnityEngine.Profiling.Profiler.BeginSample("DCC.DecodeDirection");
        int internalIndex = DirectionMapping.MapToInternal(header.directionCount, directionIndex);

        sprites[directionIndex] = new Sprite[header.framesPerDir];
        var       bitReader = new BitReader(bytes, header.dirOffset[internalIndex] * 8);
        Direction dir       = new Direction();

        ReadDirection(bitReader, dir);

        int optionalBytesSum = 0;

        dir.frames = new Frame[header.framesPerDir];

        for (int f = 0; f < header.framesPerDir; ++f)
        {
            Frame frame = new Frame();
            dir.frames[f] = frame;
            ReadFrame(bitReader, dir, frame);

            optionalBytesSum += frame.optionalBytes;

            if (frame.bottomUp != 0)
            {
                Debug.LogWarning("BottomUp frames are not implemented yet (" + filename + ")");
                continue;
            }

            if (f == 0)
            {
                dir.box = frame.box;
            }
            else
            {
                dir.box.xMin = Mathf.Min(dir.box.xMin, frame.box.xMin);
                dir.box.yMin = Mathf.Min(dir.box.yMin, frame.box.yMin);
                dir.box.xMax = Mathf.Max(dir.box.xMax, frame.box.xMax);
                dir.box.yMax = Mathf.Max(dir.box.yMax, frame.box.yMax);
            }
        }

        if (optionalBytesSum != 0)
        {
            Debug.LogWarning("optionalBytesSum != 0, not tested");
        }
        bitReader.ReadBits(optionalBytesSum * 8);

        Streams streams = new Streams();

        ReadStreamsInfo(bitReader, dir, bytes, streams);

        FrameBuffer frameBuffer = CreateFrameBuffer(dir.box);                             // dcc_prepare_buffer_cells

        FillPixelBuffer(header, frameBuffer, dir, streams);                               // dcc_fill_pixel_buffer
        MakeFrames(header, dir, frameBuffer, streams, textures, sprites[directionIndex]); // dcc_make_frames

        UnityEngine.Profiling.Profiler.EndSample();
    }
Exemple #2
0
    public DefaultValueAndColorGenerator(string data) : base(data)
    {
        string[] split = data.Split('\n');

        if (split.Length < 3)
        {
            throw new Exception($"Can't build {GetType()} from this data: {data}");
        }

        ColorPicker             = ColorPickerFactory.BuildColorPicker(split[1]);
        directionToValueMapping = new DirectionMapping(split[2]);
    }
Exemple #3
0
    private Direction ReadFrames(Stream stream, BinaryReader reader, int dirIndex)
    {
        int internalIndex = DirectionMapping.MapToInternal(directionCount, dirIndex);
        var dir           = new Direction();

        dir.frames  = new Frame[framesPerDirection];
        dir.sprites = new Sprite[framesPerDirection];
        int maxWidth  = 0;
        int maxHeight = 0;

        for (int frameIndex = 0; frameIndex < framesPerDirection; frameIndex++)
        {
            int offset = offsets[internalIndex * framesPerDirection + frameIndex];
            stream.Seek(offset, SeekOrigin.Begin);

            var frame = new Frame();
            reader.ReadInt32(); // skip
            frame.width   = reader.ReadInt32();
            frame.height  = reader.ReadInt32();
            frame.offsetX = reader.ReadInt32();
            frame.offsetY = reader.ReadInt32();
            reader.ReadInt32(); // skip
            reader.ReadInt32(); // skip
            frame.dataSize         = reader.ReadInt32();
            frame.dataOffset       = (int)stream.Position;
            dir.frames[frameIndex] = frame;

            maxWidth  = Mathf.Max(maxWidth, frame.width);
            maxHeight = Mathf.Max(maxHeight, frame.height);
        }

        TexturePacker packer;
        int           padding = framesPerDirection > 1 ? 2 : 0;

        if (textureSize == -1)
        {
            int textureWidth  = Mathf.NextPowerOfTwo((maxWidth + padding) * framesPerDirection);
            int textureHeight = Mathf.NextPowerOfTwo(maxHeight + padding);
            textureWidth = Mathf.Min(1024, textureWidth);
            packer       = new TexturePacker(textureWidth, textureHeight, padding);
        }
        else
        {
            packer = new TexturePacker(textureSize, textureSize, padding);
        }

        DrawFrames(dir, packer);

        return(dir);
    }
Exemple #4
0
    // Use this for initialization

    void Start()
    {
        mapping = new DirectionMapping();
        InitializeInputFields();
    }
Exemple #5
0
 public DefaultValueAndColorGenerator(ColorPicker colorPicker, DirectionMapping mapping) : base(colorPicker, mapping)
 {
 }
Exemple #6
0
 protected BaseValueAndColorGenerator(ColorPicker colorPicker, DirectionMapping mapping)
 {
     this.ColorPicker             = colorPicker;
     this.directionToValueMapping = mapping;
 }