Пример #1
0
        public static void registWord()
        {
            // 参数绑定解析
            importParser["name"]   = new NameBinder();
            importParser["img"]    = new ImageBinder();
            importParser["ignore"] = new IgnoreBinder();
            importParser["font"]   = new FontBinder();
            // 脚本组件
            if (PsdSetting.Instance.curGUIType == GUIType.UGUI)
            {
                importParser["button"]     = new ButtonBinder();
                importParser["toggle"]     = new ToggleBinder();
                importParser["slider"]     = new SliderBinder();
                importParser["scrollview"] = new ScrollViewBinder();
                importParser["scrollbar"]  = new ScrollbarBinder();
                importParser["inputfield"] = new InputFieldBinder();
            }
            else if (PsdSetting.Instance.curGUIType == GUIType.NGUI)
            {
                importParser["button"]     = new NButtonBinder();
                importParser["toggle"]     = new NToggleBinder();
                importParser["slider"]     = new NSliderBinder();
                importParser["scrollview"] = new NScrollViewBinder();
                importParser["scrollbar"]  = new NScrollbarBinder();
                importParser["inputfield"] = new NInputFieldBinder();
                importParser["texture"]    = new NTextureBinder();
                importParser["tmpt"]       = new NTempletBinder();
            }

#if NGUI
            NAtlasHelper.LoadAllAtlas(PsdSetting.Instance.AtlasImportFolder);
#endif
            NTempletHelper.LoadAllTemplet(PsdSetting.Instance.TempletImportFolder);
        }
Пример #2
0
        public void AddComponents(int layerIndex, GameObject imageObject, Sprite sprite, TextureImporterSettings settings)
        {
#if NGUI
            var    uiImg   = imageObject.AddComponent <UISprite>();
            string sprPath = PSDExporter.GetLayerFilename(this.layer);
            if (sprPath == null)
            {
                Debug.LogWarning("Cant find sprite path . layer name :" + this.layer.Name);
            }
            else
            {
                string spriteName = Path.GetFileNameWithoutExtension(sprPath);
                NAtlasHelper.UIAtlasData atlas = NAtlasHelper.FindSprite(spriteName);
                if (atlas != null)
                {
                    uiImg.atlas = atlas.mainAtlas;
                    UISpriteData spriteData = uiImg.atlas.GetSprite(spriteName);
                    if (spriteData.borderLeft != 0 || spriteData.borderRight != 0 ||
                        spriteData.borderBottom != 0 || spriteData.borderTop != 0)
                    {
                        uiImg.type = UIBasicSprite.Type.Sliced;
                    }
                }
                uiImg.spriteName = spriteName;
            }

            uiImg.depth = layerIndex;
            uiImg.SetDimensions((int)layer.Rect.width, (int)layer.Rect.height);
            uiImg.transform.SetAsFirstSibling();


//            Vector2 sprPivot = PsdBuilder.GetPivot(settings);
//            uiImg.pivot = NGUIMath.GetPivot(sprPivot);
#else
            var uiImg = imageObject.AddComponent <Image>();

            uiImg.sprite = sprite;
            uiImg.SetNativeSize();
            uiImg.rectTransform.SetAsFirstSibling();

            Vector2 sprPivot = PsdBuilder.GetPivot(settings);
            uiImg.rectTransform.pivot = sprPivot;
#endif
        }
Пример #3
0
        public void AddComponents(int layerIndex, GameObject imageObject, Sprite sprite, TextureImporterSettings settings)
        {
            string sprPath = PSDExporter.GetLayerFilename(this.layer);

            if (sprPath == null)
            {
                Debug.LogWarning("Cant find sprite path . layer name :" + this.layer.Name);
                return;
            }
            string spriteName = Path.GetFileNameWithoutExtension(sprPath);

#if NGUI
            var uiImg = imageObject.AddComponent <UISprite>();
            NAtlasHelper.UIAtlasData atlas = NAtlasHelper.FindSprite(spriteName);
            if (atlas != null)
            {
                uiImg.atlas = atlas.mainAtlas;
                UISpriteData spriteData = uiImg.atlas.GetSprite(spriteName);
                if (spriteData.borderLeft != 0 || spriteData.borderRight != 0 ||
                    spriteData.borderBottom != 0 || spriteData.borderTop != 0)
                {
                    uiImg.type = UIBasicSprite.Type.Sliced;
                }
            }
            uiImg.spriteName = spriteName;

            uiImg.depth = layerIndex;
            uiImg.SetDimensions((int)layer.Rect.width, (int)layer.Rect.height);
            uiImg.transform.SetAsFirstSibling();


//            Vector2 sprPivot = PsdBuilder.GetPivot(settings);
//            uiImg.pivot = NGUIMath.GetPivot(sprPivot);
#elif ART_PROJ
            var      uiImg       = imageObject.AddComponent <Image>();
            string[] all_sprites = Directory.GetFiles("Assets/Textures", "*.png", SearchOption.AllDirectories);
            foreach (var file in all_sprites)
            {
                string tmpName = Path.GetFileNameWithoutExtension(file);
                var    tmp     = AssetDatabase.LoadAssetAtPath <Sprite>(file);
                if (tmp.name == spriteName)
                {
                    sprite = tmp as Sprite;
                    break;
                }
            }
            uiImg.sprite = sprite;
            if (sprite != null && sprite.border != Vector4.zero)
            {
                uiImg.type = Image.Type.Sliced;
            }
            //uiImg.SetNativeSize();
            uiImg.rectTransform.sizeDelta = new Vector2((int)layer.Rect.width, (int)layer.Rect.height);
            uiImg.rectTransform.SetAsFirstSibling();

            //Vector2 sprPivot = PsdBuilder.GetPivot(settings);
            //uiImg.rectTransform.pivot = sprPivot;
#else
            var      uiImg       = imageObject.AddComponent <Image>();
            string[] all_sprites = Directory.GetFiles("Assets/Res/Atlas", "*.png", SearchOption.AllDirectories);
            foreach (var file in all_sprites)
            {
                string tmpName = Path.GetFileNameWithoutExtension(file);
                var    sprites = AssetDatabase.LoadAllAssetsAtPath(file);

                bool created = false;
                foreach (var tmp in sprites)
                {
                    if (tmp.name == spriteName)
                    {
                        sprite  = tmp as Sprite;
                        created = true;
                        break;
                    }
                }
                if (created)
                {
                    break;
                }
            }
            uiImg.sprite = sprite;
            if (sprite != null && sprite.border != Vector4.zero)
            {
                uiImg.type = Image.Type.Sliced;
            }
            //uiImg.SetNativeSize();
            uiImg.rectTransform.sizeDelta = new Vector2((int)layer.Rect.width, (int)layer.Rect.height);
            uiImg.rectTransform.SetAsFirstSibling();

            //Vector2 sprPivot = PsdBuilder.GetPivot(settings);
            //uiImg.rectTransform.pivot = sprPivot;
#endif
        }