Пример #1
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            RectTransform obj           = PSDImportUtility.LoadAndInstant <RectTransform>(PSDImporterConst.ASSET_PATH_LAYOUTELEMENT, layer.name, parent);
            RectTransform rectTransform = parent.GetComponent <RectTransform>();

            obj.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            obj.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            var le = obj.GetComponent <LayoutElement>();

            le.preferredWidth  = layer.size.width;
            le.preferredHeight = layer.size.height;

            if (layer.image != null)
            {
                //for (int imageIndex = 0; imageIndex < layer.layers.Length; imageIndex++)
                //{
                PSImage image = layer.image;
                ctrl.DrawImage(image, obj.gameObject);
                //}
            }

            ctrl.DrawLayers(layer.layers, obj.gameObject);
            //obj.transform.SetParent(parent.transform, false); //parent.transform;
        }
Пример #2
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            ScrollRect    scrollRect    = PSDImportUtility.LoadAndInstant <ScrollRect>(PSDImporterConst.ASSET_PATH_SCROLLVIEW, layer.name, parent);
            RectTransform rectTransform = scrollRect.GetComponent <RectTransform>();

            rectTransform.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            rectTransform.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            if (layer.layers != null)
            {
                string type = layer.arguments[0].ToUpper();
                switch (type)
                {
                case "V":
                    BuildVerticalScrollView(scrollRect, layer);
                    break;

                case "H":
                    BuildHorizonScrollView(scrollRect, layer);
                    break;

                default:
                    break;
                }

                ctrl.DrawLayers(layer.layers, scrollRect.content.gameObject);
            }
        }
Пример #3
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            //UnityEngine.UI.Image temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.PREFAB_PATH_IMAGE, typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
            UnityEngine.UI.Image panel = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, layer.name, parent);//GameObject.Instantiate(temp) as UnityEngine.UI.Image;

            panel.name = layer.name;

            ctrl.DrawLayers(layer.layers, panel.gameObject);//子节点

            //for (int i = 0; i < layer.images.Length; i++)
            //{
            PSImage image = layer.image;

            if (image.name.ToLower().Contains("background"))
            {
                string assetPath = PSDImportCtrl.Instance.GetFilePath(image);    // PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
                panel.sprite = sprite;

                RectTransform rectTransform = panel.GetComponent <RectTransform>();
                rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);

                //panel.transform.SetParent(parent.transform, false); //parent = parent.transform;
            }
            else
            {
                ctrl.DrawImage(image, panel.gameObject);
            }
            //}
        }
Пример #4
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.GridLayoutGroup gridLayoutGroup = PSDImportUtility.LoadAndInstant <UnityEngine.UI.GridLayoutGroup>(PSDImporterConst.ASSET_PATH_GRID, layer.name, parent);

            RectTransform rectTransform = gridLayoutGroup.GetComponent <RectTransform>();

            rectTransform.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            rectTransform.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            gridLayoutGroup.padding = new RectOffset();

            float width, height;

            if (float.TryParse(layer.arguments[2], out width) && float.TryParse(layer.arguments[3], out height))
            {
                gridLayoutGroup.cellSize = new Vector2(width, height);
            }
            gridLayoutGroup.spacing = new Vector2(System.Convert.ToInt32(layer.arguments[4]), System.Convert.ToInt32(layer.arguments[5]));

            ctrl.DrawLayers(layer.layers, gridLayoutGroup.gameObject);
        }
Пример #5
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            RectTransform obj = PSDImportUtility.LoadAndInstant <RectTransform>(PSDImporterConst.ASSET_PATH_EMPTY, layer.name, parent);

            obj.offsetMin = Vector2.zero;
            obj.offsetMax = Vector2.zero;
            obj.anchorMin = Vector2.zero;
            obj.anchorMax = Vector2.one;

            RectTransform rectTransform = parent.GetComponent <RectTransform>();

            obj.sizeDelta        = rectTransform.sizeDelta;
            obj.anchoredPosition = rectTransform.anchoredPosition;

            if (layer.image != null)
            {
                PSImage image = layer.image;
                //ctrl.DrawImage(image, obj.gameObject);
                ctrl.DrawImage(image, parent, obj.gameObject);
            }

            ctrl.DrawLayers(layer.layers, obj.gameObject);
        }
Пример #6
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            GameObject temp;
            string     type = layer.arguments[0].ToUpper();

            switch (type.ToUpper())
            {
            case "V":
                temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.ASSET_PATH_GROUP_V, typeof(GameObject)) as GameObject;
                break;

            case "H":
                temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.ASSET_PATH_GROUP_H, typeof(GameObject)) as GameObject;
                break;

            default:
                return;
            }

            UnityEngine.UI.HorizontalOrVerticalLayoutGroup group = GameObject.Instantiate(temp).GetComponent <UnityEngine.UI.HorizontalOrVerticalLayoutGroup>(); //as UnityEngine.UI.HorizontalOrVerticalLayoutGroup;
            group.transform.SetParent(parent.transform, false);                                                                                                  //parent = parent.transform;

            RectTransform rectTransform = group.GetComponent <RectTransform>();

            rectTransform.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            rectTransform.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            float span;

            if (float.TryParse(layer.arguments[1], out span))
            {
                group.spacing = span;
            }

            pSDImportCtrl.DrawLayers(layer.layers, group.gameObject);
        }