Ejemplo n.º 1
0
 private static void UpdateScaleImgSprite()
 {
     foreach (KeyValuePair <string, List <Image> > kvp in _scaleImgDic)
     {
         string path = kvp.Key.Replace(PsdUtils.GetFullProjectPath(), string.Empty);
         AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
         Sprite sprite = (Sprite)AssetDatabase.LoadAssetAtPath(path, typeof(Sprite));
         if (null == sprite)
         {
             Debug.LogWarning(string.Format("缺少引用资源 {0} ", path));
         }
         else
         {
             foreach (var img in kvp.Value)
             {
                 img.sprite = sprite;
             }
         }
     }
 }
Ejemplo n.º 2
0
 private static string GetRelativePath(string fullPath)
 {
     return(fullPath.Replace(PsdUtils.GetFullProjectPath(), string.Empty));
 }
Ejemplo n.º 3
0
        private static void Import(string asset)
        {
            _scaleImgDic = new Dictionary <string, List <Image> >();

            _imageDic = new Dictionary <string, Sprite>();

            _btnNameList = new List <string>();

            _nullImageIndex = 0;

            _positionDic = new Dictionary <GameObject, Vector3>();

            _currentDepth = MaximumDepth;

            string fullPath = Path.Combine(PsdUtils.GetFullProjectPath(), asset.Replace('\\', '/'));

            PsdFile psd = new PsdFile(fullPath);

            _canvasSize = ScreenResolution;

            _depthStep = psd.Layers.Count != 0 ? MaximumDepth / psd.Layers.Count : 0.1f;

            int lastSlash = asset.LastIndexOf('/');

            string assetPathWithoutFilename = asset.Remove(lastSlash + 1, asset.Length - (lastSlash + 1));

            _psdName = asset.Replace(assetPathWithoutFilename, string.Empty).Replace(".psd", string.Empty);

            _currentPath = PsdUtils.GetFullProjectPath() + "Assets/" + CURR_IMG_PATH_ROOT;
            _texturePath = Path.Combine(_currentPath, "Textures");
            _currentPath = Path.Combine(_currentPath, _psdName);

            CreateDic(_texturePath);
            CreateDic(_currentPath);

            if (_layoutInScene || _createPrefab)
            {
                if (UseUnityUI)
                {
                    CreateUIEventSystem();
                    CreateUICanvas();
                }

                //create ui Root
                _rootPsdGameObject = CreateObj(_psdName);
                _rootPsdGameObject.transform.SetParent(_canvasObj.transform, false);
                _rootNode    = new UINode();
                _rootNode.Go = _rootPsdGameObject;
                Debug.Log("Name:" + _rootPsdGameObject.name);

                RectTransform rectRoot = _rootPsdGameObject.GetComponent <RectTransform>();

                rectRoot.anchorMin = new Vector2(0, 0);
                rectRoot.anchorMax = new Vector2(1, 1);
                rectRoot.offsetMin = Vector2.zero;
                rectRoot.offsetMax = Vector2.zero;

                _rootNode.rect = new Rect(0, 0, ScreenResolution.x, ScreenResolution.y);

                Vector3 rootPos = Vector3.zero;
                _rootPsdGameObject.transform.position = Vector3.zero;
                _currentGroupGameObject = _rootPsdGameObject;
            }

            List <Layer> tree = BuildLayerTree(psd.Layers);

            ExportTree(tree, _rootNode);
            PsdUtils.CreateUIHierarchy(_rootNode);
            PsdUtils.UpdateAllUINodeRectTransform(_rootNode);

            if (_createPrefab)
            {
                UnityEngine.Object prefab = PrefabUtility.CreateEmptyPrefab(asset.Replace(".psd", ".prefab"));
                PrefabUtility.ReplacePrefab(_rootPsdGameObject, prefab);
            }

            UpdateScaleImgSprite();
            AssetDatabase.Refresh();
        }