예제 #1
0
        private void DrawSprites(List <ACSprite> sprites)
        {
            for (int i = 0; i < sprites.Count; i++)
            {
                var sprite = sprites[i];

                GUILayout.BeginHorizontal();
                {
                    sprite.DrawIcon();

                    bool lastToggle = _toggleStates[i];
                    _toggleStates[i] = GUILayout.Toggle(_toggleStates[i], sprite.AssetFile, ACWindow.ACStyles.SpriteButton,
                                                        GUILayout.Height(ACStyles.IconSize), GUILayout.Height(ACStyles.IconSize));

                    if (!lastToggle && _toggleStates[i])
                    {
                        _curSelectSprite = sprite;
                        EditorWindowHelper.ResetToggleStates(_toggleStates, i);

                        Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(sprite.AssetFile);
                        EditorGUIUtility.PingObject(Selection.activeObject);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
예제 #2
0
 private void TryInitDrawAcSpritesParams()
 {
     if (_spriteToggleStates.Count == 0)
     {
         int spriteCount = _acSprites.Count;
         if (spriteCount > 0)
         {
             _curSelectSprite    = _acSprites[0];
             _spriteToggleStates = EditorWindowHelper.InitToggleStates(spriteCount);
         }
     }
 }
예제 #3
0
 private void TryInitDrawUnReferenceFolderRefSpritesParams()
 {
     if (_toggleStates.Count == 0)
     {
         int spriteCount = _unReferenceFolderRefSprites.Count;
         if (spriteCount > 0)
         {
             _curSelectSprite = _unReferenceFolderRefSprites[0];
             _toggleStates    = EditorWindowHelper.InitToggleStates(spriteCount);
         }
     }
 }
예제 #4
0
        private string TryCreateTargetFolder(float minBackgroundWidth, float minBackgroundHeight, string spriteOutFolder,
                                             ACSprite acSprite)
        {
            // 计算目标新目录
            string targetFolder = spriteOutFolder + "/";

            if (acSprite.Width >= minBackgroundWidth && acSprite.Height >= minBackgroundHeight)
            {
                targetFolder += SceneBackgounrdFolderName;

                // 目录不存在就新建
                if (!AssetDatabase.IsValidFolder(targetFolder))
                {
                    AssetDatabase.CreateFolder(spriteOutFolder, SceneBackgounrdFolderName);
                }
            }
            else
            {
                string newSceneFolderName;
                string newModuleFolderName;
                acSprite.GetNewFolderName(SceneCommonFolderName, ModuleCommonFolderName, out newSceneFolderName, out newModuleFolderName);

                // 先创建场景目录,如果不存在
                targetFolder += newSceneFolderName;
                if (!AssetDatabase.IsValidFolder(targetFolder))
                {
                    AssetDatabase.CreateFolder(spriteOutFolder, newSceneFolderName);
                }

                if (_atlasCollectRule == AtlasCollectRule.WithSceneAndModel)
                {
                    if (!string.IsNullOrEmpty(newModuleFolderName))
                    {
                        string sceneFolderPath = targetFolder;
                        targetFolder += "/" + newModuleFolderName;

                        // 目录不存在就新建
                        if (!AssetDatabase.IsValidFolder(targetFolder))
                        {
                            AssetDatabase.CreateFolder(sceneFolderPath, newModuleFolderName);
                        }
                    }
                }
            }

            return(targetFolder);
        }
예제 #5
0
        /// <summary>
        /// 收集该预制所引用的所有图片
        /// </summary>
        /// <param name="acPrefab"></param>
        private void CollectPrefabAllSpritesByDependencies(ACPrefab acPrefab)
        {
            Object uiPrefab = AssetDatabase.LoadAssetAtPath <Object>(acPrefab.AssetFile);

            Object[] allResObjects = EditorUtility.CollectDependencies(new Object[] { uiPrefab });

            for (int i = 0; i < allResObjects.Length; i++)
            {
                Sprite sprite = allResObjects[i] as Sprite;
                if (sprite == null)
                {
                    continue;
                }

                string spriteFilePath = AssetDatabase.GetAssetPath(sprite.GetInstanceID());
                if (!IsSpriteCanCollect(spriteFilePath))
                {
                    // 更新非关联目录被引用的Sprite个数
                    ACSprite tempSprite;
                    if (!_allUnReferenceFolderSpritesDic.TryGetValue(sprite, out tempSprite))
                    {
                        tempSprite = new ACSprite(sprite, spriteFilePath);
                        _allUnReferenceFolderSpritesDic[sprite] = tempSprite;
                    }

                    tempSprite.UpdateReference(acPrefab);
                    continue;
                }

                // 更新关联目录里被引用到的Sprite个数
                ACSprite acSprite;
                if (!_allReferenceFolderSpritesDic.TryGetValue(sprite, out acSprite))
                {
                    acSprite = new ACSprite(sprite, spriteFilePath);
                    _allReferenceFolderSpritesDic[sprite] = acSprite;
                }

                acPrefab.AddACSprite(acSprite);
                acSprite.UpdateReference(acPrefab);
            }
        }
예제 #6
0
        public void DrawAcSprites()
        {
            GUILayout.BeginVertical(GUILayout.Width(ACStyles.SpriteViewWidth));
            GUILayout.Label("SPRITES " + _acSprites.Count);
            _spriteScrollPos = GUILayout.BeginScrollView(_spriteScrollPos);

            TryInitDrawAcSpritesParams();

            for (int i = 0; i < _acSprites.Count; i++)
            {
                var sprite = _acSprites[i];

                GUILayout.BeginHorizontal();
                {
                    sprite.DrawIcon();

                    bool lastToggle = _spriteToggleStates[i];
                    _spriteToggleStates[i] = GUILayout.Toggle(_spriteToggleStates[i], sprite.AssetFile, ACWindow.ACStyles.SpriteButton,
                                                              GUILayout.Height(ACStyles.IconSize), GUILayout.Height(ACStyles.IconSize));

                    if (!lastToggle && _spriteToggleStates[i])
                    {
                        _curSelectSprite = sprite;
                        EditorWindowHelper.ResetToggleStates(_spriteToggleStates, i);

                        Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(sprite.AssetFile);
                        EditorGUIUtility.PingObject(Selection.activeObject);
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            if (_curSelectSprite != null)
            {
                _curSelectSprite.DrawReferences();
            }
        }
예제 #7
0
        private void MoveAllUseSpritesToFolder(float minBackgroundWidth, float minBackgroundHeight, string spriteOutFolder)
        {
            var allAcSprites = new List <ACSprite>(_allReferenceFolderSpritesDic.Values);

            int allAcSpritesCount = allAcSprites.Count;

            for (int i = 0; i < allAcSpritesCount; i++)
            {
                ACSprite acSprite = allAcSprites[i];

                var newFolderPath = TryCreateTargetFolder(minBackgroundWidth, minBackgroundHeight, spriteOutFolder, acSprite);

                string newSpritePath = newFolderPath + "/" + acSprite.Name;
                if (string.Compare(acSprite.AssetFile, newSpritePath, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                // 计算进度
                int    curIndex = i + 1;
                string log      = string.Format("REF_{0}/{1}_正在移动_{2}_到_{3}", curIndex, allAcSpritesCount, acSprite.Name, newFolderPath);
                Debug.Log(string.Format("AtlasCollect_{0}", log));
                {
                    float progress = (float)curIndex / allAcSpritesCount;
                    EditorUtility.DisplayProgressBar("进度", log, progress);
                }

                string result = AssetDatabase.MoveAsset(acSprite.AssetFile, newSpritePath);
                if (result != string.Empty)
                {
                    Debug.LogError(string.Format("REF_{0}/{1}_{2}", curIndex, allAcSpritesCount, result));
                }
            }

            EditorUtility.ClearProgressBar();
        }
예제 #8
0
 public void AddACSprite(ACSprite acSprite)
 {
     _acSprites.Add(acSprite);
 }