All posts by Ted Hong

[Unity] Application.systemLanguage -> ISO 639-1 변환

Application.systemLanguage -> ISO 639-1 변환하는 함수입니다.

 

 public static string GetLocalCode()
{
			switch(Application.systemLanguage)
{
                case SystemLanguage.Afrikaans:  return "af";
                case SystemLanguage.Arabic:     return "ar";
                case SystemLanguage.Basque:     return "eu";
                case SystemLanguage.Belarusian: return "be";
                case SystemLanguage.Bulgarian:  return "bg";
                case SystemLanguage.Catalan:    return "ca";
                case SystemLanguage.Chinese:    return "zh";
                case SystemLanguage.Czech:      return "cs";
                case SystemLanguage.Danish:     return "da";
                case SystemLanguage.Dutch:      return "nl";
                case SystemLanguage.English:    return "en";
                case SystemLanguage.Estonian:   return "et";
                case SystemLanguage.Faroese:    return "fo";
                case SystemLanguage.Finnish:    return "fi";
                case SystemLanguage.French:     return "fr";
                case SystemLanguage.German:     return "de";
                case SystemLanguage.Greek:      return "el";
                case SystemLanguage.Hebrew:     return "he";
                case SystemLanguage.Hungarian:  return "hu";
                case SystemLanguage.Icelandic:  return "is";
                case SystemLanguage.Indonesian: return "id";
                case SystemLanguage.Italian:    return "it";
                case SystemLanguage.Japanese:   return "ja";
                case SystemLanguage.Korean:     return "ko";
                case SystemLanguage.Latvian:    return "lv";
                case SystemLanguage.Lithuanian: return "lt";
                case SystemLanguage.Norwegian:  return "no";
                case SystemLanguage.Polish:     return "pl";
                case SystemLanguage.Portuguese: return "pt";
                case SystemLanguage.Romanian:   return "ro";
                case SystemLanguage.Russian:    return "ru";
                case SystemLanguage.SerboCroatian: return "sr";
                case SystemLanguage.Slovak:     return "sk";
                case SystemLanguage.Slovenian:  return "sl";
                case SystemLanguage.Spanish:    return "es";
                case SystemLanguage.Swedish:    return "sv";
                case SystemLanguage.Thai:       return "th";
                case SystemLanguage.Turkish:    return "tr";
                case SystemLanguage.Ukrainian:  return "uk";
                case SystemLanguage.Vietnamese: return "vi";
                default: return "en";
            } 
		}

[Unity3D] UGUI 아틀라스에서 Sprite 파일 분리하기

이미 합쳐져 있는 UGUI용 Atlas File 에서 Sprite 를 분리하는 방법

Atlas 의  Texture로 부터
Sprite 영역만큼 Pixel 값을 가져와
새로운 Texture에 입히고 
파일로 저장하면 됩니다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class AtlasLoader
{
    public Dictionary<string, Sprite> spriteDic = new Dictionary<string, Sprite>();

    public AtlasLoader()
    {

    }

    public AtlasLoader(string spriteBaseName)
    {
        loadSprite(spriteBaseName);
    }

    //Loads the provided sprites
    public void loadSprite(string spriteBaseName)
    {
        Sprite[] allSprites =  Resources.LoadAll<Sprite>(spriteBaseName);
        if (allSprites == null || allSprites.Length <= 0)
        {
            Debug.LogError("The Provided Base-Atlas Sprite `" + spriteBaseName + "` does not exist!");
            return;
        }

        for (int i = 0; i < allSprites.Length; i++)
        {
            spriteDic.Add(allSprites[i].name, allSprites[i]);
            MakeFile(allSprites[i]);
        }
    }

    void MakeFile(Sprite sprite)
    {
        try
        {
            Debug.Log(string.Format("{0} : {1}", sprite.name, sprite.rect.ToString()));
            Rect rect = sprite.rect; //분리할 스프라이트의 시작 좌표와 사이즈
            Texture2D mainTex = sprite.texture; //스프라이트의 메인 텍스쳐를 가져옴
            //새로 만들어질 텍스쳐, sprite.texture.format 이건 메인 텍스쳐의 포맷을 그대로 사용
            Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, sprite.texture.format, false); 
            //메인 텍스쳐에서 스프라이트의 영역 만큼 픽셀 값을 가져옴
            Color[] c = mainTex.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
            tex.SetPixels(c);// 새 텍스쳐에 픽셀값을 입힘
            tex.Apply(); // 적용
            var bytes = tex.EncodeToPNG(); // PNG byte로 형태로 만듬. JPG는 EncodeToJPG 사용 
            string savePath = string.Format("{0}/{1}.png", Application.persistentDataPath, sprite.name); //저장할 파일 위치
            Object.DestroyImmediate(tex, true); //새텍스쳐는 쓸일이 없으므로 삭제
            System.IO.File.WriteAllBytes(savePath, bytes); //파일로 쓰기
            Debug.Log("MakeFile : " + sprite.name);
        }
        catch (System.Exception ex)
        {

        }

    }
}

#Split_sprite_file_from_UGUI_atlas_file. 

[Android] Glide

안드로이드용 이미지 로딩 라이브러리.

 

https://futurestud.io/blog/glide-getting-startedhttps://github.com/bumptech/glide
http://dktfrmaster.blogspot.kr/2016/09/glide.html
http://itpangpang.xyz/243

 

[Android] Retrofit

HTTP REST API 구현을 위한 라이브러리.

GET, POST, PUT, DELETED 전달  ->  xml, json, text, rss  등으로 응답을 받을 수 있음

 

 

http://thdev.tech/androiddev/2016/11/13/Android-Retrofit-Intro.html

[Android] Gallery Refresh after Kitkat (ver. 4.4)

안드로이드 킷캣 (4.4) 이후 갤러리 갱신 하는 방법이 변경되었다고 합니다.

이전에는 Media Mount 를 이용해서 전체적으로 갱신을 했었는데 배터리 소모가 심한 이슈가 있었다네요

이후에는 아래 코드를 사용하시면 됩니다.

원문 : http://stackoverflow.com/questions/4646913/android-how-to-use-mediascannerconnection-scanfile

import java.io.File;
import android.content.Context;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;

public class SingleMediaScanner implements MediaScannerConnectionClient {

private MediaScannerConnection mMs;
private File mFile;

public SingleMediaScanner(Context context, File f) {
    mFile = f;
    mMs = new MediaScannerConnection(context, this);
    mMs.connect();
}

@Override
public void onMediaScannerConnected() {
    mMs.scanFile(mFile.getAbsolutePath(), null);
}

@Override
public void onScanCompleted(String path, Uri uri) {
    mMs.disconnect();
}

}

간단하게는 이 함수만 써도 될 것 같네요~

private void scanFile(String path) {

        MediaScannerConnection.scanFile(MainActivity.this,
                new String[] { path }, null,
                new MediaScannerConnection.OnScanCompletedListener() {

                    public void onScanCompleted(String path, Uri uri) {
                        Log.i("TAG", "Finished scanning " + path);
                    }
                });
    }