|
2013/01/21 11:48
|
작업하던 도중 모바일에선 경로가 파일경로가 바뀌고 읽어오지못하는 문제가 발생하였다.
pc에선 잘되지만 모바일에서만 이상이있었음
찾다 찾다 유니티 포럼에서 좋은거 긁어왔습니다. ㅋㅋ 아이폰도 됩니다~
public void writeStringToFile( string str, string filename )
{
#if !WEB_BUILD
string path = pathForDocumentsFile( filename );
FileStream file = new FileStream (path, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter( file );
sw.WriteLine( str );
sw.Close();
file.Close();
#endif
}
public string readStringFromFile( string filename)//, int lineIndex )
{
#if !WEB_BUILD
string path = pathForDocumentsFile( filename );
if (File.Exists(path))
{
FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader( file );
string str = null;
str = sr.ReadLine ();
sr.Close();
file.Close();
return str;
}
else
{
return null;
}
#else
return null;
#endif
}
// 파일쓰고 읽는넘보다 이놈이 핵심이죠
public string pathForDocumentsFile( string filename )
{
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
string path = Application.dataPath.Substring( 0, Application.dataPath.Length - 5 );
path = path.Substring( 0, path.LastIndexOf( '/' ) );
return Path.Combine( Path.Combine( path, "Documents" ), filename );
}
else if(Application.platform == RuntimePlatform.Android)
{
string path = Application.persistentDataPath;
path = path.Substring(0, path.LastIndexOf( '/' ) );
return Path.Combine (path, filename);
}
else
{
string path = Application.dataPath;
path = path.Substring(0, path.LastIndexOf( '/' ) );
return Path.Combine (path, filename);
}
}
[출처] [ Unity3D ] 모바일(안드로이드) 파일생성 및 읽고 쓰기|작성자 호랑낚시
'유니티 > Note' 카테고리의 다른 글
| 유니티 안드로이드 관련 (0) | 2014.08.13 |
|---|---|
| 유니티 관련 노트. (0) | 2014.08.11 |
| [펌][ Unity3D ] 모바일(안드로이드) 파일생성 및 읽고 쓰기 Unity3D (0) | 2014.07.07 |
| 에셋번들 관련 글 및 링크 모음 (0) | 2014.07.07 |
| 안드로이드 스튜디오를 사용시 기존 이클립스 폴더 불러오기. (0) | 2014.06.26 |
| 기본적인 프로그래머.. (0) | 2014.06.22 |
에셋번들 예제
http://u3d.as/1qS
에셋번들 관련 글
파일에 쓰는법
var cache = new System.IO.FileStream( 저장할 경로 , System.IO.FileMode.Create);
cache.Write(download.bytes, 0, download.bytes.Length);
cache.Close();
조금은 하드코딩이 되겠지만요 ^^;
제가 사용한 방법을 예를 들자면 에셋에서 그림파일을 불러온후
그것을 PNG로 변환 설정한후에 byte[]형으로 변환해서
FileStream을 사용해 Write해주는 방식으로 처리 했어요.
다른 한가지 방법으로는 zip를 이용해서 다운로드 한후 압축을 풀어 사용하는 방법도 있습니다.
전 요즘엔 이 방법을 더 많이 쓰는것 같군요 ^^;
zip 파일로 다운로드를 만든 경우에는 Object로 불러 오신후 그것을
(GameObject)Instantiate(불러온 오브젝트, 좌표, Quaternion회전) 등으로 사용할 수 있을듯 합니다.
테스트는 안해 봤어요 ^^;;
{
string[] assetName =
{
"assets/resources/object/mobobject/n2010_wolf/face/n2010f01.png",
"assets/resources/object/mobobject/n2010_wolf/n2010.png",
return assetName;
}
public static void BuildAssetWindows()
{
string[] assetName = AssetBundleModule.GetAssetNameList();
for (int i = 0; i < assetName.Length; ++i)
{
asset[i] = AssetDatabase.LoadMainAssetAtPath(assetName[i]);
assetName[i] = Regex.Replace(assetName[i], @"(?i)Assets/Resources/", "");
assetName[i] = assetName[i].Remove(assetName[i].LastIndexOf("."));
Debug.Log(assetName[i]);
}
}
{
string assetPath = GetAssetBundleWebURL();
Debug.Log(assetPath);
m_WWW = WWW.LoadFromCacheOrDownload(assetPath, m_nAssetBundleVersion);
}
else
{
string assetPath = GetAssetBundlePath();
Debug.Log(assetPath);
m_WWW = new WWW(assetPath);
}
m_WWW.Dispose();
m_WWW = null;
if (findObject == null)
{
Debug.Log("FindAssetName not exists object : " + name + " / type : " + type.ToString());
}
return findObject;
http://botta.tistory.com/38 이 사이트를 참고하셔서 만들어보세요~ 그리고
public IEnumerator OnLoadAssetBundle()
{
m_WWW = new WWW("file://" + Application.dataPath + "/../" + "애셋번들");
yield return m_WWW;
m_AssetBundle = m_WWW.assetBundle;
m_WWW.Dispose();
m_WWW = null;
Texture m_Tex1 = (Texture)m_AssetBundle.Load("CFa0.png", typeof(Texture));
}
C#을 기준으로 설명 드릴께요.
먼저 변수선언으로
int _gender = 0;
int _job = 0;
Texture2D _texture = null;
AssetBundle _assetBundle = null;
를 주시고,
함수 한개를 만들어서
IEnumerator gameHeroImageLoad (int argGender, int argJob) {
WWW _www = new WWW("file://" + "디렉토리와 파일명");
yield return _www;
_assetBundle = _www.assetBundle;
string _tmpHeroImageName = argGender + "-" + argJob + "-Texture";
if (_assetBundle.Gontains(_tmpHeroImageName)) {
_texture = (Texture2D)_assetBundle.Load(_tmpHeroImageName);
}
}
Update () 에서 특정 조건일때 위에 함수를 불러 오게되면 _texture에
이미지가 들어 가겠죠.
그후 OnGUI ()에서 _texture가 null일때와 아닐때의 표시 부분을 바꿔 주시면 될듯 합니다.
단 한가지 주의할 점은 그래픽을 다른 그래픽으로 바꾸시고 싶으시다면,
void deleteGameObject () {
_texture = null;
_assetBundle.Unload(true);
_assetBundle = null;
}
이 함수를 부르신 후에 다시 gameHeroImageLoad를 불러와 주시면 됩니다.
번들을 만들때는 이름에 주의 하셔서 성별-직업-Texture와 같이 png파일을 저장해 주시면 될 것 같습니다.
그냥 머리속의 프로그램을 적는 거니 버그가 있을 수 있습니다.
에셋번들 관련 링크
api
http://docs.unity3d.com/ScriptReference/AssetBundle.html
menual
http://docs.unity3d.com/Manual/AssetBundlesIntro.html
'유니티 > Note' 카테고리의 다른 글
| 유니티 관련 노트. (0) | 2014.08.11 |
|---|---|
| [펌][ Unity3D ] 모바일(안드로이드) 파일생성 및 읽고 쓰기 Unity3D (0) | 2014.07.07 |
| 에셋번들 관련 글 및 링크 모음 (0) | 2014.07.07 |
| 안드로이드 스튜디오를 사용시 기존 이클립스 폴더 불러오기. (0) | 2014.06.26 |
| 기본적인 프로그래머.. (0) | 2014.06.22 |
| 유니티 재귀함수의 예(헥사, 캔디팡) -Recursive Methods (0) | 2014.06.05 |
2014 년에 3.5버전을 사용하려고 하니 없는 자료들이 많다.
안된다.. 뭔짓을 해도 안된다.
그냥 따라하자
무조건
32비트로 무조건 다운받자 프로그램들은..
1. jdk 1.6 버전 설치
일단 JDK 를 다운받자
1.6 버전으로 다운받아야 된다.
http://ghaffarian.net/downloads/Java/JDK/
2. Andorid SDK 설치
일단 SDK 를 다운받자. 32비트로
http://developer.android.com/sdk/index.html
sdk Manager을 열어보면 tools 에서 17버전을 다운받을수있는데 다운받고 난후
build-tools 폴더에 17.0.0 파일들을 platform-tools폴더에 복사
3. Android sdk r20 버전 설치후 tools 폴더 교체
22이후부터 apkbuilder.bat 파일이 없다고 합니다.
| 구글링 하니 rev.22 버젼에서 없어졌다고 하네요. rev.20 수동으로 받아서 넣으니 있네요. 유니티 컴파일중에 이파일 없다고 빌드 안되서 당황 했네요. rev.20 버젼 필요하신분은 http://dl-ssl.google.com/android/repository/tools_r20-windows.zip 에서 받으셔서 기존 tools 백업 해놓으시고 교체 하시면 됩니다. |
'유니티 > 스크립트' 카테고리의 다른 글
| baas.io 유니티 유저 정보 입력 및 받아오기. (0) | 2014.08.08 |
|---|---|
| 카메라 부드럽게 움직이는 스크립트 (0) | 2014.07.22 |
| 유니티 3.5.7 버전 설치하기. (0) | 2014.07.02 |
| 유니티 2D 스파라이트 이미지 변경하기 (0) | 2014.06.12 |
| 라인 렌더러 사용하기(게임 내 레이저 효과) (0) | 2014.06.10 |
| 드래곤 플라이트 움직임(마우스 드래그) Unity3D (1) | 2014.06.09 |


