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); } }
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; }
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); } //} }
public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null) { if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Private) { Image pic; if (ownObj != null) { pic = PSDImportUtility.AddMissingComponent <Image>(ownObj); } else { pic = PSDImportUtility.LoadAndInstant <Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, parent); } RectTransform rectTransform = pic.GetComponent <RectTransform>(); rectTransform.offsetMin = new Vector2(0.5f, 0.5f); rectTransform.offsetMax = new Vector2(0.5f, 0.5f); rectTransform.anchorMin = new Vector2(0.5f, 0.5f); rectTransform.anchorMax = new Vector2(0.5f, 0.5f); var p = PSDImportCtrl.Instance.GetFilePath(image); Sprite sprite = AssetDatabase.LoadAssetAtPath(p, typeof(Sprite)) as Sprite; if (sprite == null) { Debug.Log("loading asset at path: " + p); } pic.sprite = sprite; rectTransform.sizeDelta = new Vector2(image.size.width, image.size.height); rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y); } }
public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null) { RectTransform halfRectTrans = parent.GetComponent <RectTransform>(); PSDImportUtility.SetAnchorMiddleCenter(halfRectTrans); halfRectTrans.sizeDelta = new Vector2(image.size.width, image.size.height); halfRectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y); UnityEngine.UI.Image leftOrUpSprite; if (ownObj != null) { leftOrUpSprite = PSDImportUtility.AddMissingComponent <Image>(ownObj); } else { leftOrUpSprite = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, halfRectTrans.gameObject); } //string assetPath = ""; //if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom) //{ // assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX; //} //else //{ // assetPath = PSDImporterConst.Globle_BASE_FOLDER + image.name.Replace(".", "/") + PSDImporterConst.PNG_SUFFIX; //} //Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite; Sprite sprite = PSDImportUtility.LoadAssetAtPath <Sprite>(image) as Sprite; // if (sprite == null) // { // Debug.Log("loading asset at path: " + assetPath); // } leftOrUpSprite.sprite = sprite; RectTransform lOrURectTrans = leftOrUpSprite.GetComponent <RectTransform>(); lOrURectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y); //添加镜像组件 var mirror = lOrURectTrans.gameObject.AddComponent <Mirror>(); if (image.imageType == ImageType.BottomHalfImage) { mirror.mirrorType = Mirror.MirrorType.Vertical; } else if (image.imageType == ImageType.LeftHalfImage) { mirror.mirrorType = Mirror.MirrorType.Horizontal; } else if (image.imageType == ImageType.QuarterImage) { mirror.mirrorType = Mirror.MirrorType.Quarter; } mirror.SetNativeSize(); }
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); } } } }
public void BeginDrawUILayers() { RectTransform obj = PSDImportUtility.LoadAndInstant <RectTransform>(PSDImporterConst.ASSET_PATH_EMPTY, PSDImportUtility.baseFilename, PSDImportUtility.canvas.gameObject); obj.offsetMin = Vector2.zero; obj.offsetMax = Vector2.zero; obj.anchorMin = Vector2.zero; obj.anchorMax = Vector2.one; for (int layerIndex = 0; layerIndex < psdUI.layers.Length; layerIndex++) { DrawLayer(psdUI.layers[layerIndex], obj.gameObject); } AssetDatabase.Refresh(); }
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); }
public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null) { RawImage pic; if (ownObj != null) { pic = PSDImportUtility.AddMissingComponent <RawImage>(ownObj); } else { pic = PSDImportUtility.LoadAndInstant <RawImage>(PSDImporterConst.ASSET_PATH_RAWIMAGE, image.name, parent); } Texture2D texture = PSDImportUtility.LoadAssetAtPath <Texture2D>(image) as Texture2D; pic.texture = texture as Texture; RectTransform rectTransform = pic.GetComponent <RectTransform>(); PSDImportUtility.SetAnchorMiddleCenter(rectTransform); rectTransform.sizeDelta = new Vector2(image.size.width, image.size.height); rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y); }
private void InitDataAndPath(string xmlFilePath) { psdUI = (PSDUI)PSDImportUtility.DeserializeXml(xmlFilePath, typeof(PSDUI)); Debug.Log(psdUI.psdSize.width + "=====psdSize======" + psdUI.psdSize.height); if (psdUI == null) { Debug.Log("The file " + xmlFilePath + " wasn't able to generate a PSDUI."); return; } #if UNITY_5_2 if (EditorApplication.SaveCurrentSceneIfUserWantsTo() == false) { return; } #elif UNITY_5_3 if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() == false) { return; } #endif PSDImportUtility.baseFilename = Path.GetFileNameWithoutExtension(xmlFilePath); // PSDImportUtility.baseDirectory = "Assets/" + Path.GetDirectoryName(xmlFilePath.Remove(0, Application.dataPath.Length + 1)) + "/"; }
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); }
public void DrawImage(PSImage image, GameObject parent, GameObject ownObj) { Image pic; if (ownObj != null) { pic = PSDImportUtility.AddMissingComponent <Image>(ownObj); } else { pic = PSDImportUtility.LoadAndInstant <Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, parent); } RectTransform rectTransform = pic.GetComponent <RectTransform>(); PSDImportUtility.SetAnchorMiddleCenter(rectTransform); //var p = PSDImportCtrl.Instance.GetFilePath(image); //var imp = AssetImporter.GetAtPath(p) as TextureImporter; //if (!PSDImportCtrl.Instance.IsSetBorder(imp)) //{ // PSDImportCtrl.Instance.SetSpriteBorder(imp, image.arguments); // AssetDatabase.WriteImportSettingsIfDirty(p); // AssetDatabase.ImportAsset(p); //} //else //{ // Debug.Log("已设置九宫格:"+p); //} Sprite sprite = PSDImportUtility.LoadAssetAtPath <Sprite>(image) as Sprite; pic.sprite = sprite; pic.type = Image.Type.Sliced; //RectTransform rectTransform = pic.GetComponent<RectTransform>(); rectTransform.sizeDelta = new Vector2(image.size.width, image.size.height); rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y); }
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); } } }
public void DrawLayer(Layer layer, GameObject parent) { Slider slider = PSDImportUtility.LoadAndInstant <Slider>(PSDImporterConst.ASSET_PATH_SLIDER, layer.name, parent); RectTransform rectTransform = slider.GetComponent <RectTransform>(); rectTransform.sizeDelta = new Vector2(layer.size.width, layer.size.height); rectTransform.anchoredPosition = new Vector2(layer.position.x, layer.position.y); PosLoader posloader = slider.gameObject.AddComponent <PosLoader>(); posloader.worldPos = rectTransform.position; string type = layer.arguments[0].ToUpper(); switch (type) { case "R": slider.direction = Slider.Direction.RightToLeft; break; case "L": slider.direction = Slider.Direction.LeftToRight; break; case "T": slider.direction = Slider.Direction.TopToBottom; break; case "B": slider.direction = Slider.Direction.BottomToTop; break; default: break; } for (int i = 0; i < layer.layers.Length; i++) { PSImage image = layer.layers[i].image; var p = PSDImportCtrl.Instance.GetFilePath(image); Sprite sprite = AssetDatabase.LoadAssetAtPath(p, typeof(Sprite)) as Sprite; if (image.name.ToLower().Contains("bg")) { var bgRect = slider.transform.Find("Background").GetComponent <RectTransform>(); var bgImage = bgRect.GetComponent <Image>(); if (image.imageType != ImageType.SliceImage) { bgImage.type = Image.Type.Simple; } bgImage.sprite = sprite; bgRect.sizeDelta = new Vector2(image.size.width, image.size.height); } else if (image.name.ToLower().Contains("fill")) { var fillImage = slider.fillRect.GetComponent <Image>(); if (image.imageType != ImageType.SliceImage) { fillImage.type = Image.Type.Simple; } fillImage.sprite = sprite; var fillArea = slider.transform.Find("Fill Area").GetComponent <RectTransform>(); fillArea.sizeDelta = new Vector2(image.size.width, image.size.height); } else if (image.name.ToLower().Contains("handle")) //默认没有handle { var handleRectTrans = slider.transform.Find("Handle Slide Area/Handle").GetComponent <RectTransform>(); var handleSprite = handleRectTrans.GetComponent <Image>(); slider.handleRect = handleRectTrans; handleSprite.sprite = sprite; handleRectTrans.gameObject.SetActive(true); } } }
public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null) { Text myText; if (ownObj != null) { myText = PSDImportUtility.AddMissingComponent <Text>(ownObj); } else { myText = PSDImportUtility.LoadAndInstant <Text>(PSDImporterConst.ASSET_PATH_TEXT, image.name, parent); } RectTransform rectTransform = myText.GetComponent <RectTransform>(); PSDImportUtility.SetAnchorMiddleCenter(rectTransform); Debug.Log("Label Color : " + image.arguments[0]); Debug.Log("fontSize : " + image.arguments[2]); Color color; if (ColorUtility.TryParseHtmlString(("#" + image.arguments[0]), out color)) { myText.color = color; } else { Debug.Log(image.arguments[0]); } float size; if (float.TryParse(image.arguments[2], out size)) { myText.fontSize = (int)size; } myText.text = image.arguments[3]; //设置字体,注意unity中的字体名需要和导出的xml中的一致 string fontFolder; if (image.arguments[1].ToLower().Contains("static")) { fontFolder = PSDImporterConst.FONT_STATIC_FOLDER; } else { fontFolder = PSDImporterConst.FONT_FOLDER; } string fontFullName = fontFolder + image.arguments[1] + PSDImporterConst.FONT_SUFIX; Debug.Log("font name ; " + fontFullName); var font = AssetDatabase.LoadAssetAtPath(fontFullName, typeof(Font)) as Font; if (font == null) { Debug.LogWarning("Load font failed : " + fontFullName); } else { myText.font = font; } //ps的size在unity里面太小,文本会显示不出来,暂时选择溢出 myText.verticalOverflow = VerticalWrapMode.Overflow; myText.horizontalOverflow = HorizontalWrapMode.Overflow; //设置对齐 if (image.arguments.Length >= 5) { myText.alignment = ParseAlignmentPS2UGUI(image.arguments[4]); } rectTransform.sizeDelta = new Vector2(image.size.width, image.size.height); rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y); myText.gameObject.name = "Text"; }