Inheritance: UnityEngine.ScriptableObject
Exemple #1
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    static void CreateDB()
    {
        dbPath = EditorPrefs.GetString(dbKey, dbPath);

        // first create db directory if not exists
        string dbDir = Path.GetDirectoryName(dbPath);

        if (new DirectoryInfo(dbDir).Exists == false)
        {
            Directory.CreateDirectory(dbDir);
        }

        // get atlas db, if not found, create one
        db = (exAtlasDB)AssetDatabase.LoadAssetAtPath(dbPath, typeof(exAtlasDB));
        if (db == null)
        {
            db = ScriptableObject.CreateInstance <exAtlasDB>();
            AssetDatabase.CreateAsset(db, dbPath);
            needSync = true;
        }
        else
        {
            db = (exAtlasDB)AssetDatabase.LoadAssetAtPath(dbPath, typeof(exAtlasDB));
        }

        //
        if (version != db.curVersion)
        {
            db.curVersion = version;
            needSync      = true;
            EditorUtility.SetDirty(db);
        }
    }
Exemple #2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    public override void OnInspectorGUI()
    {
        if ( target != curEditTarget ) {
            curEditTarget = target as exAtlasDB;
        }
        EditorGUIUtility.LookLikeInspector ();
        EditorGUILayout.Space();

        // sync button
        EditorGUI.indentLevel = 1;
        if ( GUILayout.Button ("Sync", GUILayout.Width(100)) ) {
            exAtlasDB.ForceSync();
        }

        // rebuild all
        if ( GUILayout.Button ("Build All", GUILayout.Width(100)) ) {
            exAtlasDB.BuildAll();
        }

        // show version
        GUI.enabled = false;
        EditorGUILayout.LabelField( "version", curEditTarget.curVersion.ToString() );
        GUI.enabled = true;

        // show atlasInfoGUIDs
        EditorGUI.indentLevel = 0;
        curEditTarget.showData = EditorGUILayout.Foldout(curEditTarget.showData, "Atlas Asset List");
        EditorGUI.indentLevel = 2;
        if ( curEditTarget.showData ) {
            GUI.enabled = false;
            for ( int i = 0; i < curEditTarget.atlasInfoGUIDs.Count; ++i ) {
                string guid = curEditTarget.atlasInfoGUIDs[i];
                string path = AssetDatabase.GUIDToAssetPath(guid);
                string atlasInfoName = Path.GetFileNameWithoutExtension (path);
                EditorGUILayout.LabelField( "[" + i + "]",  atlasInfoName );
            }
            GUI.enabled = true;
        }

        // show texture to AtlasElement table
        EditorGUI.indentLevel = 0;
        curEditTarget.showTable = EditorGUILayout.Foldout(curEditTarget.showTable, "Texture To Atlas.Element Table");
        EditorGUI.indentLevel = 2;
        if ( curEditTarget.showTable ) {
            GUI.enabled = false;
            foreach ( KeyValuePair<string,exAtlasDB.ElementInfo> pair in exAtlasDB.GetTexGUIDToElementInfo() ) {
                string textureName = Path.GetFileNameWithoutExtension ( AssetDatabase.GUIDToAssetPath(pair.Key) );
                string atlasName = Path.GetFileNameWithoutExtension ( AssetDatabase.GUIDToAssetPath(pair.Value.guidAtlas) );
                EditorGUILayout.LabelField ( atlasName + "[" + pair.Value.indexInAtlas + "]", textureName );
            }
            GUI.enabled = true;
        }
        EditorGUI.indentLevel = 0;

        //
        if ( GUI.changed ) {
            EditorUtility.SetDirty(curEditTarget);
        }
    }
Exemple #3
0
 ///////////////////////////////////////////////////////////////////////////////
 // functions
 ///////////////////////////////////////////////////////////////////////////////
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 public static void UpdateAtlas( exSprite _sprite, 
                                  exAtlasDB.ElementInfo _elInfo )
 {
     // get atlas and index from textureGUID
     if ( _elInfo != null ) {
         if ( _elInfo.guidAtlas != exEditorHelper.AssetToGUID(_sprite.atlas) ||
              _elInfo.indexInAtlas != _sprite.index )
         {
             _sprite.SetSprite( exEditorHelper.LoadAssetFromGUID<exAtlas>(_elInfo.guidAtlas),
                                _elInfo.indexInAtlas );
         }
     }
     else {
         _sprite.Clear();
     }
 }
Exemple #4
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    static void CreateDB()
    {
        dbPath = EditorPrefs.GetString( dbKey, dbPath );

        // first create db directory if not exists
        string dbDir = Path.GetDirectoryName(dbPath);
        if ( new DirectoryInfo(dbDir).Exists == false ) {
            Directory.CreateDirectory (dbDir);
        }

        // get atlas db, if not found, create one
        db = (exAtlasDB)AssetDatabase.LoadAssetAtPath( dbPath, typeof(exAtlasDB) );
        if ( db == null ) {
            db = ScriptableObject.CreateInstance<exAtlasDB>();
            AssetDatabase.CreateAsset( db, dbPath );
            needSync = true;
        }
        else {
            db = (exAtlasDB)AssetDatabase.LoadAssetAtPath( dbPath, typeof(exAtlasDB) );
        }

        //
        if ( version != db.curVersion ) {
            db.curVersion = version;
            needSync = true;
            EditorUtility.SetDirty(db);
        }
    }
 ///////////////////////////////////////////////////////////////////////////////
 // functions
 ///////////////////////////////////////////////////////////////////////////////
 // ------------------------------------------------------------------
 // Desc:
 // ------------------------------------------------------------------
 public static void UpdateAtlas( exSpriteBorder _spriteBorder, 
                                  exAtlasDB.ElementInfo _elInfo )
 {
     // get atlas and index from textureGUID
     if ( _elInfo != null ) {
         if ( _elInfo.guidAtlas != exEditorHelper.AssetToGUID(_spriteBorder.atlas) ||
              _elInfo.indexInAtlas != _spriteBorder.index )
         {
             _spriteBorder.SetBorder( _spriteBorder.guiBorder,
                                exEditorHelper.LoadAssetFromGUID<exAtlas>(_elInfo.guidAtlas),
                                _elInfo.indexInAtlas );
         }
     }
     else {
         exGUIBorder guiBorder = _spriteBorder.guiBorder;
         _spriteBorder.Clear();
         _spriteBorder.SetBorder( guiBorder, null, -1 );
     }
 }
Exemple #6
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override void OnInspectorGUI()
    {
        if (target != curEditTarget)
        {
            curEditTarget = target as exAtlasDB;
        }
        EditorGUIUtility.LookLikeInspector();
        EditorGUILayout.Space();

        // sync button
        EditorGUI.indentLevel = 1;
        if (GUILayout.Button("Sync", GUILayout.Width(100)))
        {
            exAtlasDB.ForceSync();
        }

        // rebuild all
        if (GUILayout.Button("Build All", GUILayout.Width(100)))
        {
            exAtlasDB.BuildAll();
        }

        // show version
        GUI.enabled = false;
        EditorGUILayout.LabelField("version", curEditTarget.curVersion.ToString());
        GUI.enabled = true;

        // show atlasInfoGUIDs
        EditorGUI.indentLevel  = 0;
        curEditTarget.showData = EditorGUILayout.Foldout(curEditTarget.showData, "Atlas Asset List");
        EditorGUI.indentLevel  = 2;
        if (curEditTarget.showData)
        {
            GUI.enabled = false;
            for (int i = 0; i < curEditTarget.atlasInfoGUIDs.Count; ++i)
            {
                string guid          = curEditTarget.atlasInfoGUIDs[i];
                string path          = AssetDatabase.GUIDToAssetPath(guid);
                string atlasInfoName = Path.GetFileNameWithoutExtension(path);
                EditorGUILayout.LabelField("[" + i + "]", atlasInfoName);
            }
            GUI.enabled = true;
        }

        // show texture to AtlasElement table
        EditorGUI.indentLevel   = 0;
        curEditTarget.showTable = EditorGUILayout.Foldout(curEditTarget.showTable, "Texture To Atlas.Element Table");
        EditorGUI.indentLevel   = 2;
        if (curEditTarget.showTable)
        {
            GUI.enabled = false;
            foreach (KeyValuePair <string, exAtlasDB.ElementInfo> pair in exAtlasDB.GetTexGUIDToElementInfo())
            {
                string textureName = Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(pair.Key));
                string atlasName   = Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(pair.Value.guidAtlas));
                EditorGUILayout.LabelField(atlasName + "[" + pair.Value.indexInAtlas + "]", textureName);
            }
            GUI.enabled = true;
        }
        EditorGUI.indentLevel = 0;

        //
        if (GUI.changed)
        {
            EditorUtility.SetDirty(curEditTarget);
        }
    }