Skip to content

Commit

Permalink
Atlas Generator Package
Browse files Browse the repository at this point in the history
  • Loading branch information
Happyrobot33 committed Jun 3, 2024
1 parent 4fc8c66 commit e7ef0ae
Show file tree
Hide file tree
Showing 13 changed files with 566 additions and 204 deletions.
8 changes: 8 additions & 0 deletions Assets/atlas.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/com.happyrobot33.atlasgenerator/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "com.happyrobot33.editorgames.atlasgenerator",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Packages/com.happyrobot33.atlasgenerator/Editor/AtlasGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace HappysTools.AtlasGenerator
{
class AtlasGenerator : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
{
//gather up all changed textures
List<Texture2D> changedTextures = new List<Texture2D>();
foreach (string assetPath in importedAssets)
{
//load the asset
Object asset = AssetDatabase.LoadAssetAtPath<Object>(assetPath);

//check if the asset is a texture
if (asset is Texture2D)
{
//add the texture to the list
changedTextures.Add((Texture2D)asset);
}
}

//if none, return
if (changedTextures.Count == 0)
{
return;
}

List<AtlasInformation> atlasInformationList = AtlasInformation.GetAllAssociatedAtlas(changedTextures.ToArray());
//rebuild them
foreach (AtlasInformation atlasInformation in atlasInformationList)
{
atlasInformation.Rebuild();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7ef0ae

Please sign in to comment.