Daikon Forge Fix

Инструменты для разработки

Daikon Forge Fix

Сообщение Golandez 01 май 2014, 14:10

Фикс актуален для любой версии, включая актуальную на сегодня 1.0.16. При более менее толстом проекте при выборе атласа в инспекторе контророла daikon forge получаем забитую оперативку полностью всем проектом(в моем случае около 3Гб). Для снижения негатива от использования фреймворка ищем класс dfPrefabSelectionDialog и меняем в нем метод getFilteredItems() на приведенный ниже. И соответственно меняем имя обьявленной коллекции allPrefabsInProject на allAtlasInProject.

Синтаксис:
Используется csharp
private List<GameObject> getFilteredItems()
        {
                if( allAtlasInProject == null )
                {
                        allAtlasInProject = new List<GameObject>();
                        var progressTime = Environment.TickCount;
                        var allAssetPaths = AssetDatabase.GetAllAssetPaths();

                        for( int i = 0; i < allAssetPaths.Length; i++ )
                        {
                                if( Environment.TickCount - progressTime > 250 )
                                {
                                        progressTime = Environment.TickCount;
                                        EditorUtility.DisplayProgressBar( this.title, "Loading prefabs", (float)i / (float)allAssetPaths.Length );
                                }

                                var path = allAssetPaths[ i ];
                                if( !path.EndsWith( ".prefab", StringComparison.OrdinalIgnoreCase ) )
                                        continue;

                                try
                                {
                                        var go = AssetDatabase.LoadMainAssetAtPath( path ) as GameObject;
                    if (IsPrefab(go))                      
                                        {
                        if (go.GetComponent(componentType) != null)
                        {
                            try
                            {
                                if (filterCallback != null && !filterCallback(go))
                                    continue;
                            }
                            catch { continue; }

                            if (go.name.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) != -1)
                            {
                                allAtlasInProject.Add(go);                              
                            }                            
                        }
                                        }    
                    go = null;
                    EditorUtility.UnloadUnusedAssets();
                                }
                                catch( Exception err )
                                {
                                        Debug.LogError( "Error loading prefab at " + path + " - " + err.Message );
                                }
                        }

                        EditorUtility.ClearProgressBar();

                        allAtlasInProject.Sort( ( GameObject lhs, GameObject rhs ) =>
                        {
                                return lhs.name.CompareTo( rhs.name );
                        } );

                }
        return allAtlasInProject;
        }
Ты нужен только тогда,когда нужен.(С)
Сказать спасибо
Аватара пользователя
Golandez
Пилигрим
 
Сообщения: 1637
Зарегистрирован: 06 авг 2009, 13:55
Откуда: Харьков
Skype: lestardigital

Re: Daikon Forge Fix

Сообщение _Ignat_ 01 май 2014, 14:57

(3A4OT)
А официально это изменить не хотят?
Изображение
| · участник клуба GCC · |
Аватара пользователя
_Ignat_
UNITрон
 
Сообщения: 311
Зарегистрирован: 11 дек 2013, 20:26
Откуда: Российская Федерация
  • Сайт

Re: Daikon Forge Fix

Сообщение Golandez 01 май 2014, 16:21

Логично было бы пофиксить, когда не в курсе- не общаюсь непосредственно с разработчиком.
Ты нужен только тогда,когда нужен.(С)
Сказать спасибо
Аватара пользователя
Golandez
Пилигрим
 
Сообщения: 1637
Зарегистрирован: 06 авг 2009, 13:55
Откуда: Харьков
Skype: lestardigital

Re: Daikon Forge Fix

Сообщение gnoblin 01 май 2014, 17:27

запости на оф форум дайкона плиз )
skypeid: madkust
Мои крайние проекты:
Убойный Хоккей
Cube Day Z (альфа)
Аватара пользователя
gnoblin
Адепт
 
Сообщения: 4633
Зарегистрирован: 08 окт 2008, 17:23
Откуда: Минск, Беларусь
Skype: madkust
  • Сайт

Re: Daikon Forge Fix

Сообщение Golandez 03 май 2014, 13:11

В продолжении темы. Если имеем толстый проект, с большим количеством элементов в project(в моем случае около 7000), получаем при выборе атласа длительный парсинг проекта. Дабы избежать этого нужно каким то образом индексировать атласы. Данное решение работает только в контексте индексации самих атласов и ничего более.
Ищем класс dfTextureAtlasInspector, в любом месте добавляем
Синтаксис:
Используется csharp
private static string tempPath;
    [MenuItem("Tools/Daikon Forge/Texture Atlas/Rebuild Atlas Index")]
    public static void RebuildIndex()
    {
        var collection = new List<GameObject>();
        var progressTime = Environment.TickCount;
        var allAssetPaths = AssetDatabase.GetAllAssetPaths();
        for (int i = 0; i < allAssetPaths.Length; i++)
        {
            if (Environment.TickCount - progressTime > 250)
            {
                progressTime = Environment.TickCount;
                EditorUtility.DisplayProgressBar("Build Index", "Loading prefabs", (float)i / (float)allAssetPaths.Length);
            }

            var path = allAssetPaths[i];
            if (!path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase))
                continue;

            try
            {
                var go = AssetDatabase.LoadMainAssetAtPath(path) as GameObject;
                if (IsPrefab(go))
                {
                    if (go.GetComponent<dfAtlas>() != null)
                    {                    
                            collection.Add(go);                        
                    }
                }
                go = null;
                EditorUtility.UnloadUnusedAssets();
            }
            catch (Exception err)
            {
                Debug.LogError("Error loading prefab at " + path + " - " + err.Message);
            }
        }
        EditorUtility.ClearProgressBar();
        dfIndexLogic logic = new dfIndexLogic();
        logic.SaveIndex(collection);
    }
    private static bool IsPrefab(GameObject item)
    {

        try
        {
            return
                item != null &&
                PrefabUtility.GetPrefabParent(item) == null &&
                PrefabUtility.GetPrefabObject(item) != null;
        }
        catch
        {
            return false;
        }

    }
 

Ищем в нем в CreateAtlasFromSelection(). После
Синтаксис:
Используется csharp
finally
                {
                        EditorUtility.ClearProgressBar();
                }
 

Добавляем
Синтаксис:
Используется csharp
         dfIndexLogic logic = new dfIndexLogic();
         var addableAtlas = AssetDatabase.LoadMainAssetAtPath(tempPath) as GameObject;
         logic.AddAtlas((GameObject)addableAtlas);
         addableAtlas = null;
 

Ищем класс dfPrefabSelectionDialog. Ищем метод getFilteredItems(). Заменяем его на
Синтаксис:
Используется csharp
private List<GameObject> getFilteredItems()
        {
        if (allAtlasInProject == null)
        {
            allAtlasInProject = new List<GameObject>();
            dfIndexLogic indexLogic = new dfIndexLogic();
            var _atlasIndex = indexLogic.GetIndex();

            if (_atlasIndex != null)
            {
                if (_atlasIndex.Atlases.Count > 0)
                {
                    foreach (var atlas in _atlasIndex.Atlases)
                    {
                        if (atlas != null)
                        {
                            allAtlasInProject.Add(atlas);
                        }
                        else
                        {
                            allAtlasInProject.Clear();
                            IniAtlasInProject(indexLogic);
                            break;
                        }
                    }
                }
                else
                {
                    IniAtlasInProject(indexLogic);
                }
            }
            else
            {              
                IniAtlasInProject(indexLogic);
            }        
            indexLogic = null;
        }      
        return allAtlasInProject;
}
 

Также добавляем методы
Синтаксис:
Используется csharp
    void IniAtlasInProject(dfIndexLogic _logic)
    {
        allAtlasInProject = GetAtlasCollection();
        _logic.SaveIndex(allAtlasInProject);
    }
    private List<GameObject> GetAtlasCollection()
    {
            var collection= new List<GameObject>();
            var progressTime = Environment.TickCount;
                        var allAssetPaths = AssetDatabase.GetAllAssetPaths();

                        for( int i = 0; i < allAssetPaths.Length; i++ )
                        {
                                if( Environment.TickCount - progressTime > 250 )
                                {
                                        progressTime = Environment.TickCount;
                                        EditorUtility.DisplayProgressBar( this.title, "Loading prefabs", (float)i / (float)allAssetPaths.Length );
                                }

                                var path = allAssetPaths[ i ];
                                if( !path.EndsWith( ".prefab", StringComparison.OrdinalIgnoreCase ) )
                                        continue;

                                try
                                {
                                        var go = AssetDatabase.LoadMainAssetAtPath( path ) as GameObject;
                    if (IsPrefab(go))                      
                                        {
                        if (go.GetComponent(componentType) != null)
                        {
                            try
                            {
                                if (filterCallback != null && !filterCallback(go))
                                    continue;
                            }
                            catch { continue; }

                            if (go.name.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) != -1)
                            {
                                collection.Add(go);                              
                            }                            
                        }
                                        }    
                    go = null;
                    EditorUtility.UnloadUnusedAssets();
                                }
                                catch( Exception err )
                                {
                                        Debug.LogError( "Error loading prefab at " + path + " - " + err.Message );
                                }
                        }
                        EditorUtility.ClearProgressBar();
            return collection;
    }
 

Создаем класс
Синтаксис:
Используется csharp
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

public class dfIndexLogic
{
   public const string indexPath = "Assets/_dfIndex.asset";

    public dfAtlasIndex GetIndex()
    {
        return Resources.LoadAssetAtPath(indexPath, typeof(dfAtlasIndex)) as dfAtlasIndex;
    }
    public void SaveIndex(List<GameObject> _collection)
    {
        if (_collection.Count > 0)
        {
            dfAtlasIndex newIndex = ScriptableObject.CreateInstance<dfAtlasIndex>();
            Sort(_collection);
            foreach (var atlas in _collection)
            {
                newIndex.Atlases.Add(atlas);
            }
            AssetDatabase.CreateAsset(newIndex, dfIndexLogic.indexPath);
            AssetDatabase.SaveAssets();
        }
        else BuildIndex();
    }
    void BuildIndex()
    {
        dfAtlasIndex newIndex = ScriptableObject.CreateInstance<dfAtlasIndex>();
        AssetDatabase.CreateAsset(newIndex, dfIndexLogic.indexPath);
        AssetDatabase.SaveAssets();
    }
   void Sort(List<GameObject> _collection)
    {
        _collection.Sort((GameObject lhs, GameObject rhs) =>
        {
            return lhs.name.CompareTo(rhs.name);
        });
    }
    public void AddAtlas(GameObject _atlas)
    {
        var index = GetIndex();
        if (index == null)
        {
            BuildIndex();
            index = GetIndex();
        }      
            var collection = index.Atlases;
            collection.Add(_atlas);
            SaveIndex(collection);              
    }
}

Создаем класс индекса
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class dfAtlasIndex : ScriptableObject
{
    public List<GameObject> Atlases = new List<GameObject>();  
}
 

Перед началом использования в уже рабочем проекте, если есть созданные атласы, создать индекс- Tools/ Daikon Forge/ Texture Atlas/ Rebuild Atlas Index. Все ваши атласы хранятся в _dfIndex.asset. Если вы удалите атлас из проекта, при последующем обращении к атласам индекс будет обновлен. Если ручками начнете править индекс, инициализировать корректный индекс можно через его ребилд.
Ты нужен только тогда,когда нужен.(С)
Сказать спасибо
Аватара пользователя
Golandez
Пилигрим
 
Сообщения: 1637
Зарегистрирован: 06 авг 2009, 13:55
Откуда: Харьков
Skype: lestardigital

Re: Daikon Forge Fix

Сообщение DbIMok 01 сен 2014, 17:57

не стал заводить отдельную тему https://github.com/TakuanDaikon/DFGUI
правильный вопрос - половина ответа. учитесь формулировать вопросы понятно.
Новости > _Telegram чат @unity3d_ru (11.6k/4.8k online) > _Telegram канал @unity_news (4.7k подписчиков) > Телеграм тема > "Спасибо"
Аватара пользователя
DbIMok
Адепт
 
Сообщения: 6372
Зарегистрирован: 31 июл 2009, 14:05


Вернуться в Инструментарий

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2