unity and native osx bundles and frameworks build from the same project now

This commit is contained in:
Joseph Henry
2016-06-16 11:47:08 -07:00
parent 621970619d
commit 699edf8f30
111 changed files with 11112 additions and 14 deletions

View File

@@ -0,0 +1,55 @@

using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
namespace UnityExtension
{
public static class Texture2DExt
{
//------------------------------------------------------------------------------------------------------------
public static byte[] EncodeToTGA(this Texture2D lTexture)
{
MemoryStream lDataStream = new MemoryStream(18 + (lTexture.width * lTexture.height * 3));
BinaryWriter lDataWriter = new BinaryWriter(lDataStream);
if (lDataWriter != null)
{
lDataWriter.Write((short)0);
lDataWriter.Write((byte)2);
lDataWriter.Write((int)0);
lDataWriter.Write((int)0);
lDataWriter.Write((byte)0);
lDataWriter.Write((short)lTexture.width);
lDataWriter.Write((short)lTexture.height);
lDataWriter.Write((byte)24);
lDataWriter.Write((byte)0);
Color32[] lPixelData = lTexture.GetPixels32();
for (int lCount = 0; lCount < lPixelData.Length; ++lCount)
{
lDataWriter.Write(lPixelData[lCount].b);
lDataWriter.Write(lPixelData[lCount].g);
lDataWriter.Write(lPixelData[lCount].r);
}
}
return lDataStream.GetBuffer();
}
//------------------------------------------------------------------------------------------------------------
public static void ConvertLightmapToMobile(this Texture2D lTexture)
{
Color[] lColorData = lTexture.GetPixels();
for (int lCount = 0; lCount < lColorData.Length; ++lCount)
{
lColorData[lCount] = (lColorData[lCount] * (8f * lColorData[lCount].a)) * 0.5f;
}
lTexture.SetPixels(lColorData);
lTexture.Apply();
lColorData = null;
}
}
}