コード例 #1
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            Button button = PSDImportUtility.LoadAndInstant <Button>(PSDImporterConst.ASSET_PATH_BUTTON, layer.name, parent);

            if (layer.layers != null)
            {
                for (int imageIndex = 0; imageIndex < layer.layers.Length; imageIndex++)
                {
                    PSImage image = layer.layers[imageIndex].image;
                    if (image.imageType != ImageType.Label && image.imageType != ImageType.Texture)
                    {
                        var    p      = PSDImportCtrl.Instance.GetFilePath(image);
                        Sprite sprite = AssetDatabase.LoadAssetAtPath(p, typeof(Sprite)) as Sprite;
                        if (image.name.ToLower().Contains("normal"))
                        {
                            button.image.sprite = sprite;
                            RectTransform rectTransform = button.GetComponent <RectTransform>();
                            rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                            rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
                            adjustButtonBG(image.imageType, button);
                        }
                        else if (image.name.ToLower().Contains("pressed"))
                        {
                            button.transition = Selectable.Transition.SpriteSwap;
                            SpriteState state = button.spriteState;
                            state.pressedSprite = sprite;
                            button.spriteState  = state;
                        }
                        else if (image.name.ToLower().Contains("disabled"))
                        {
                            button.transition = Selectable.Transition.SpriteSwap;
                            SpriteState state = button.spriteState;
                            state.disabledSprite = sprite;
                            button.spriteState   = state;
                        }
                        else if (image.name.ToLower().Contains("highlighted"))
                        {
                            button.transition = Selectable.Transition.SpriteSwap;
                            SpriteState state = button.spriteState;
                            state.highlightedSprite = sprite;
                            button.spriteState      = state;
                        }
                    }
                    else
                    {
                        ctrl.DrawLayer(layer.layers[imageIndex], button.gameObject);
                    }
                }
            }
        }
コード例 #2
0
ファイル: ToggleLayerImport.cs プロジェクト: yangjiejie/Tools
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.Toggle toggle = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Toggle>(PSDImporterConst.ASSET_PATH_TOGGLE, layer.name, parent);

            if (layer.layers == null)
            {
                Debug.LogError("error! bad toggle layers.");
                return;
            }

            for (int index = 0; index < layer.layers.Length; index++)
            {
                Layer   subLayer = layer.layers[index];
                PSImage image    = subLayer.image;
                if (image != null)
                {
                    string lowerName = image.name.ToLower();
                    if (lowerName.Contains("checkmark"))
                    {
                        ctrl.DrawImage(image, toggle.gameObject, toggle.graphic.gameObject);
                    }
                    else if (lowerName.Contains("background"))
                    {
                        ctrl.DrawImage(image, toggle.gameObject, toggle.targetGraphic.gameObject);
                    }
                    else
                    {
                        ctrl.DrawImage(image, toggle.gameObject);
                    }
                }
                else
                {
                    ctrl.DrawLayer(subLayer, toggle.gameObject);
                }
            }
        }