Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
whs committed Jun 15, 2014
0 parents commit 32f2906
Show file tree
Hide file tree
Showing 1,334 changed files with 27,554 additions and 0 deletions.
Empty file.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Ll]ibrary/
[Tt]emp/
[Oo]bj/

# Autogenerated VS/MD solution and project files
/*.csproj
/*.unityproj
/*.sln
/*.suo
/*.user
/*.userprefs
/*.pidb
/*.booproj
*.apk
Binary file added Assets/.DS_Store
Binary file not shown.
Binary file added Assets/Anonymice Powerline.ttf
Binary file not shown.
14 changes: 14 additions & 0 deletions Assets/Anonymice Powerline.ttf.meta

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

Binary file added Assets/Boss.unity
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/Boss.unity.meta

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

5 changes: 5 additions & 0 deletions Assets/CNJoystick.meta

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

5 changes: 5 additions & 0 deletions Assets/CNJoystick/Editor.meta

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

94 changes: 94 additions & 0 deletions Assets/CNJoystick/Editor/CreateAtlas.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;

public class CreateAtlas : ScriptableWizard
{
public string AtlasName = "Atlas";
public Texture2D[] textures;
public int padding = 4;

[MenuItem("GameObject/Create Other/Create Atlas")]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard<CreateAtlas>("Create Atlas");
}

void OnWizardCreate()
{
GenerateAtlas();
}

void ConfigureForAtlas(string texturePath)
{
TextureImporter texImporter = AssetImporter.GetAtPath(texturePath) as TextureImporter;
TextureImporterSettings texImporterSettings = new TextureImporterSettings();

texImporter.textureType = TextureImporterType.Sprite;
texImporter.ReadTextureSettings(texImporterSettings);
texImporterSettings.readable = true;

texImporter.SetTextureSettings(texImporterSettings);
AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
AssetDatabase.Refresh();
}

void GenerateAtlas()
{
foreach (Texture2D t in textures)
ConfigureForAtlas(AssetDatabase.GetAssetPath(t));

Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
Rect[] uvs = texture.PackTextures(textures, padding, 4096);

string assetPath = AssetDatabase.GenerateUniqueAssetPath("Assets/" + AtlasName + ".png");

byte[] bytes = texture.EncodeToPNG();
System.IO.File.WriteAllBytes(assetPath, bytes);
bytes = null;

UnityEngine.Object.DestroyImmediate(texture);

AssetDatabase.ImportAsset(assetPath);
texture = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;

ConfigureSpriteAtlas(texture, uvs);
}

void ConfigureSpriteAtlas(Texture2D texture, Rect[] uvs)
{
string path = AssetDatabase.GetAssetPath(texture);
TextureImporter texImporter = AssetImporter.GetAtPath(path) as TextureImporter;
TextureImporterSettings texImporterSettings = new TextureImporterSettings();

texImporter.textureType = TextureImporterType.Sprite;
texImporter.spriteImportMode = SpriteImportMode.Multiple;
// texImporterSettings.readable = true;

SpriteMetaData[] spritesheetMeta = new SpriteMetaData[uvs.Length];
for(int i = 0; i < uvs.Length; i++)
{
SpriteMetaData currentMeta = new SpriteMetaData();
Rect currentRect = uvs[i];
currentRect.x *= texture.width;
currentRect.width *= texture.width;
currentRect.y *= texture.height;
currentRect.height *= texture.height;
currentMeta.rect = currentRect;
currentMeta.name = textures[i].name;
currentMeta.alignment = (int)SpriteAlignment.Center;
currentMeta.pivot = new Vector2(currentRect.width / 2, currentRect.height / 2);
spritesheetMeta[i] = currentMeta;
}
texImporter.spritesheet = spritesheetMeta;
texImporter.spritePixelsToUnits = 1000f;
texImporter.ReadTextureSettings(texImporterSettings);

texImporter.SetTextureSettings(texImporterSettings);

AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
AssetDatabase.Refresh();
}

}
8 changes: 8 additions & 0 deletions Assets/CNJoystick/Editor/CreateAtlas.cs.meta

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

5 changes: 5 additions & 0 deletions Assets/CNJoystick/Materials.meta

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

Binary file added Assets/CNJoystick/Materials/159.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions Assets/CNJoystick/Materials/159.JPG.meta

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

Binary file added Assets/CNJoystick/Materials/159.mat
Binary file not shown.
4 changes: 4 additions & 0 deletions Assets/CNJoystick/Materials/159.mat.meta

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

5 changes: 5 additions & 0 deletions Assets/CNJoystick/OnScreenControls.meta

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

Binary file added Assets/CNJoystick/OnScreenControls/Flat Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 106 additions & 0 deletions Assets/CNJoystick/OnScreenControls/Flat Dark.png.meta

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

Binary file added Assets/CNJoystick/OnScreenControls/Flat Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 32f2906

Please sign in to comment.