Exemplo n.º 1
0
        public bool _isLeftover            = false;//PSD로 부터 있는 이미지라면 false, PSD에 없는 이미지라면 True

        public apPSDLayerBakeParam(apPSDLayerData targetLayer,
                                   int atlasIndex,
                                   int posOffset_X,
                                   int posOffset_Y,
                                   bool isLeftover
                                   )
        {
            _targetLayer = targetLayer;
            _atlasIndex  = atlasIndex;
            _posOffset_X = posOffset_X;
            _posOffset_Y = posOffset_Y;
            _isLeftover  = isLeftover;
        }
Exemplo n.º 2
0
        public void AddChildLayer(apPSDLayerData childLayer)
        {
            if (_childLayers == null)
            {
                _childLayers = new List <apPSDLayerData>();
            }
            _childLayers.Add(childLayer);
            childLayer._parentLayer = this;

            //World 값을 Parent 값을 이용해서 계싼
            //childLayer._posOffsetLocal = childLayer._posOffset - _posOffsetLocal;
            childLayer._posOffsetLocal = childLayer._posOffset - _posOffset;
        }
Exemplo n.º 3
0
        public bool AddImage(apPSDLayerData layerData, int pixelX, int pixelY, float resizeRatio, int resizedWidth, int resizedHeight, int padding)
        {
            int iLastX     = -1;
            int iLastY     = -1;
            int iLastIndex = 0;

            try
            {
                Color curColor = Color.black;
                for (int iX = 0; iX < resizedWidth; iX++)
                {
                    iLastX = iX;
                    for (int iY = 0; iY < resizedHeight; iY++)
                    {
                        iLastY   = iY;
                        curColor = layerData._image.GetPixelBilinear((float)iX / (float)resizedWidth, (float)iY / (float)resizedHeight);

                        iLastIndex             = ((iY + pixelY + padding) * _width) + (iX + pixelX + padding);
                        _colorData[iLastIndex] = curColor;
                    }
                }

                _bakedLayerData.Add(layerData);
                return(true);
            }
            catch (Exception ex)
            {
                Debug.LogError("Error");
                Debug.LogError("X, Y Index : " + iLastX + ", " + iLastY + " (" + resizedWidth + ", " + resizedHeight + ")");
                Debug.LogError("Width / Height : " + _width + " / " + _height);
                Debug.LogError("Data Length : " + _colorData.Length);
                Debug.LogError("Last Pixel X : " + (iLastX + pixelX));
                Debug.LogError("Last Pixel Y : " + (iLastY + pixelY));
                Debug.LogError("Last Data Pixel Index : " + (((iLastY + pixelY) * _width) + (iLastX + pixelX)));
                Debug.LogError("Last Index : " + iLastIndex);
                Debug.LogError("AddImage Exception : " + ex);
                return(false);
            }
        }
Exemplo n.º 4
0
        public bool _isRemapPosOffset_Initialized = false;        //<<Transform과 연결후, 또는 PSD Set Layer의 값으로 부터 초기화가 되었는가

        // Init
        //---------------------------------------------------
        public apPSDLayerData(int layerIndex, IPsdLayer psdLayer, int imageTotalWidth, int imageTotalHeight)
        {
            _layerIndex = layerIndex;

            _name       = psdLayer.Name;
            _isClipping = psdLayer.IsClipping;
            _isBakable  = true;
            //_srcPsdLayer = psdLayer;
            _isClippingValid = true;            //일단 가능하다고 체크

            if (psdLayer.HasImage)
            {
                //1. 이미지 타입의 레이어
                _isImageLayer = true;

                _width          = psdLayer.Width;
                _height         = psdLayer.Height;
                _posOffset_Left = psdLayer.Left;
                _posOffset_Top  = imageTotalHeight - psdLayer.Top;               //좌표계 특성상 반전하자

                _posOffset_Right  = psdLayer.Right;
                _posOffset_Bottom = imageTotalHeight - psdLayer.Bottom;

                _posOffset = new Vector2(
                    (float)(_posOffset_Left + _posOffset_Right) * 0.5f,
                    (float)(_posOffset_Top + _posOffset_Bottom) * 0.5f
                    );

                _opacity            = psdLayer.Opacity;
                _transparentColor2X = new Color(0.5f, 0.5f, 0.5f, _opacity);


                _colorData = new byte[_width * _height * 4];                //W x H x RGBA(4)
                //_colors = new Color[_width * _height];

                int subDataLength   = _width * _height;
                int totalDataLength = imageTotalWidth * imageTotalHeight;

                byte[] colorData_R    = new byte[subDataLength];
                byte[] colorData_G    = new byte[subDataLength];
                byte[] colorData_B    = new byte[subDataLength];
                byte[] colorData_A    = new byte[subDataLength];
                byte[] colorData_Mask = new byte[subDataLength];

                bool isMask = false;

                for (int i = 0; i < subDataLength; i++)
                {
                    colorData_R[i]    = 0;
                    colorData_G[i]    = 0;
                    colorData_B[i]    = 0;
                    colorData_A[i]    = 255;
                    colorData_Mask[i] = 255;
                }


                for (int iChannel = 0; iChannel < psdLayer.Channels.Length; iChannel++)
                {
                    IChannel curChannel   = psdLayer.Channels[iChannel];
                    byte[]   curColorData = null;

                    if (curChannel.Type == ChannelType.Mask)
                    {
                        continue;
                    }

                    switch (curChannel.Type)
                    {
                    case ChannelType.Red:
                        curColorData = colorData_R;
                        break;

                    case ChannelType.Green:
                        curColorData = colorData_G;
                        break;

                    case ChannelType.Blue:
                        curColorData = colorData_B;
                        break;

                    case ChannelType.Alpha:
                        curColorData = colorData_A;
                        break;

                    case ChannelType.Mask:
                        //마스크는 무시한다.
                        curColorData = colorData_Mask;
                        isMask       = true;
                        break;
                    }

                    int dataLength = curChannel.Data.Length;
                    if (subDataLength != dataLength)
                    {
                        //저장되었어야할 데이터와 실제 데이터가 다르다.
                        bool isError = true;
                        if (curChannel.Type == ChannelType.Mask)
                        {
                            isMask = false;

                            //만약 -> Mask의 경우
                            //이미지 전체가 들어올 수는 있다.
                            //확장된 데이터 사이즈와 비교를 하자
                            if (dataLength == totalDataLength)
                            {
                                isError = false;
                                isMask  = true;

                                //데이터가 Height가 거꾸로 되어있다.
                                //X, Y의 오프셋을 적용해야한다.
                                //Debug.Log("Mask Image : Total : " + dataLength + "( " + imageTotalWidth + " x " + imageTotalHeight + " )");
                                //Debug.Log("X : " + _posOffset_Left + " ~ " + _posOffset_Right);
                                //Debug.Log("Y : " + +_posOffset_Top + " ~ " + _posOffset_Bottom);
                            }
                        }

                        if (isError)
                        {
                            Debug.LogError("Data Length is not correct : " + _name + " [ Channel : " + curChannel.Type + " ]");
                            //Debug.LogError("Data Size : " + curChannel.Data.Length + " (Expected : " + totalDataLength + " / Sub : " + subDataLength + ")");
                            //Debug.Log("Mask Image : Total : " + dataLength + "( " + imageTotalWidth + " x " + imageTotalHeight + " )");
                            //Debug.Log("X : " + _posOffset_Left + " ~ " + _posOffset_Right);
                            //Debug.Log("Y : " + +_posOffset_Top + " ~ " + _posOffset_Bottom);
                            continue;
                        }
                    }
                    else
                    {
                        //칼라값을 복사하자
                        Array.Copy(curChannel.Data, curColorData, dataLength);
                    }
                }

                //이제 마지막으로 byte 배열을 만들고 Texture로 구성하자
                int iMainColor = 0;
                int iX         = 0;
                int iY         = 0;
                if (!isMask)
                {
                    //Debug.Log("Image : " + layerIndex + " [ No Mask ]");
                    //마스크가 없는 경우
                    for (int iColor = 0; iColor < subDataLength; iColor++)
                    {
                        //iColor = y * Width + x
                        //RevYColor = ((Height - Y) * Width) + X
                        //iMainColor = iColor * 4;
                        iY         = iColor / _width;
                        iX         = iColor % _width;
                        iMainColor = ((((_height - 1) - iY) * _width) + iX) * 4;
                        _colorData[iMainColor + 0] = colorData_R[iColor];
                        _colorData[iMainColor + 1] = colorData_G[iColor];
                        _colorData[iMainColor + 2] = colorData_B[iColor];
                        _colorData[iMainColor + 3] = colorData_A[iColor];

                        //_colors[iColor] = ByteToColor(
                        //	_colorData[iMainColor + 0],
                        //	_colorData[iMainColor + 1],
                        //	_colorData[iMainColor + 2],
                        //	_colorData[iMainColor + 3]
                        //	);
                    }
                }
                else
                {
                    //Debug.Log("Image : " + layerIndex + " [ Mask ]");
                    //마스크가 있는 경우
                    for (int iColor = 0; iColor < subDataLength; iColor++)
                    {
                        //iMainColor = iColor * 4;
                        //iColor = y * Width + x
                        //RevYColor = ((Height - Y) * Width) + X
                        //iMainColor = iColor * 4;
                        iY         = iColor / _width;
                        iX         = iColor % _width;
                        iMainColor = ((((_height - 1) - iY) * _width) + iX) * 4;

                        _colorData[iMainColor + 0] = GetMaskedColor(colorData_R[iColor], colorData_Mask[iColor]);
                        _colorData[iMainColor + 1] = GetMaskedColor(colorData_G[iColor], colorData_Mask[iColor]);
                        _colorData[iMainColor + 2] = GetMaskedColor(colorData_B[iColor], colorData_Mask[iColor]);
                        _colorData[iMainColor + 3] = GetMaskedColor(colorData_A[iColor], colorData_Mask[iColor]);

                        //_colors[iColor] = ByteToColor(
                        //	_colorData[iMainColor + 0],
                        //	_colorData[iMainColor + 1],
                        //	_colorData[iMainColor + 2],
                        //	_colorData[iMainColor + 3]
                        //	);
                    }
                }

                _image = new Texture2D(_width, _height, TextureFormat.RGBA32, false);
                //_image.SetPixels(_colors);
                _image.LoadRawTextureData(_colorData);
                _image.wrapMode = TextureWrapMode.Clamp;
                _image.Apply();
            }
            else
            {
                _isImageLayer = false;

                _image     = null;
                _width     = 0;
                _height    = 0;
                _colorData = null;

                _width          = psdLayer.Width;
                _height         = psdLayer.Height;
                _posOffset_Left = psdLayer.Left;
                _posOffset_Top  = imageTotalHeight - psdLayer.Top;               //좌표계 특성상 반전하자

                _posOffset_Right  = psdLayer.Right;
                _posOffset_Bottom = imageTotalHeight - psdLayer.Bottom;

                _posOffset = new Vector2(
                    (float)(_posOffset_Left + _posOffset_Right) * 0.5f,
                    (float)(_posOffset_Top + _posOffset_Bottom) * 0.5f
                    );

                _opacity            = 1.0f;
                _transparentColor2X = Color.black;
            }

            _posOffsetLocal = _posOffset;

            _parentLayer = null;
            _childLayers = null;

            _isRemapSelected   = false;
            _remap_TransformID = -1;

            _remap_MeshTransform      = null;
            _remap_MeshGroupTransform = null;

            _remapPosOffsetDelta_X        = 0;
            _remapPosOffsetDelta_Y        = 0;
            _isRemapPosOffset_Initialized = false;

            //추가 : GUI를 위해서 랜덤한 색상을 정하자
            MakeRandomGUIColor();
        }