OnGUI() 상에서 마우스 더블 클릭 구현
'Unity3D > Script' 카테고리의 다른 글
| 외부 이미지 다운로드 후 png 파일 저장 하는 방법 (0) | 2014.12.02 |
|---|---|
| Load Textrue with WWW (0) | 2014.12.02 |
| LightMap 동적 로딩. (0) | 2014.10.01 |
| 좀 더 복잡한 데이터 저장하기 (6) | 2014.09.25 |
| Unity Serializer (0) | 2014.09.25 |
| 외부 이미지 다운로드 후 png 파일 저장 하는 방법 (0) | 2014.12.02 |
|---|---|
| Load Textrue with WWW (0) | 2014.12.02 |
| LightMap 동적 로딩. (0) | 2014.10.01 |
| 좀 더 복잡한 데이터 저장하기 (6) | 2014.09.25 |
| Unity Serializer (0) | 2014.09.25 |
유니티 문서 웹사이트에서 검색 - Unity3d Web Document (Ctrl+F2)
접두어와 함께 구글에서 검색 - Google Search (Shift+F1)
접두어와 함께 네이버에서 검색 - Naver Search (Shift+F2)
| [펌] Sniper - 검열우회 | 광고차단 | 보안 앱 (0) | 2019.08.07 |
|---|---|
| [링크][화면보호기] 플립형 시계 화면보호기(스크린 세이버, screen saver) 모음 (0) | 2019.08.06 |
| 3D Model Viewer (0) | 2013.01.18 |
| Unity3D Tools (0) | 2013.01.18 |
| 웹브라우저 유니티 툴바 (0) | 2013.01.15 |
실행할 때, 문제는 없는 데 유니티(에디터)를 종료할 때 아래와 같은 에러메시지를 확인..
CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
| Error building Player:NullReferenceException : object reference not set to an instance of an object (0) | 2015.08.25 |
|---|---|
| The asset bundle can't be loaded (0) | 2015.03.18 |
| Unity3D iOS BinaryFormatter 사용 중 ExecutionEngineException: Attempting to JIT compile method (0) | 2014.09.22 |
| Mesh has more materials (2) than subsets (1) (0) | 2014.09.03 |
| SQLite syntax error (0) | 2014.03.21 |
| [펌] 유니티 최적화 테크닉 총정리 (0) | 2014.12.09 |
|---|---|
| 텍스처, 리소스 메모리 최적화 (0) | 2014.12.02 |
| 유저 기기 고유 ID(UUID) [SystemInfo.deviceUniqueIdentifier] (2) | 2014.10.07 |
| 안드로이드 네이티브 크래쉬 덤프 (ARM cpu) (0) | 2014.09.18 |
| 모바일 게임 최적화의 정석 (0) | 2014.09.18 |
출처 : http://www.lionheart.pe.kr/board_uFoa63/913
현재 UDID라 불리는 Unique Device ID는 기기마다 가지고 있는 고유의 아이디입니다.
주로 폰에서 아이디를 만들떄 자동으로 만들어 줄려고 사용하는 거지만 안드로이드는 아무 문제가 없습니다
문제는 애플인데 저걸 사용하면 리젝사유가 된다고 하네요
iPhoneSettings.uniqueIdentifier 이 함수를 사용해 UDID라는 것을 생성을 할수가 있는데 이제는 쓰면 안되겠죠
(특히 일본쪽은 UDID나 Mac어드레스등 유저 해킹에 대한 정보를 가져다 쓰는 어플은 무조건 안된다고 합니다)
그래서 나온게 UUID라 불리는 Universally Unique ID 입니다
유니티 최신버젼을 쓰시면 SystemInfo.deviceUniqueIdentifier 값이 자동으로 생성된다고 합니다
앱을 깔고나서 지우면 값이 바뀌기는 하지만 여전히 고유값이라고 하네요
But,
UUID 분석을 통해 앱을 다시 지웠다가 설치 해도 바뀌지 않는 방법이 있습니다.
IOS 기기 국가정보 및 기기 UIDI 대체 UUID 키체인에 저장하여 사용하기(앱 다시 깔아도 그대로 기기값유지)
// 기기 국가정보가져오기
NSLocale *locale =[NSLocale currentLocale];
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
//유니티 메세지 보내기
UnitySendMessage("GetDeviceID", "SetContry", [countryCode UTF8String]);
// 기기 아이디 생성해서 키체인에 저장
NSString *result_uuid = [[LUKeychainAccess standardKeychainAccess] stringForKey:@"uuid"];
if(result_uuid == nil)
{
NSString *uuid;
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"6.0" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending) {
uuid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
else
{
uuid = [[NSUUID UUID] UUIDString];
}
[[LUKeychainAccess standardKeychainAccess] setString:uuid forKey:@"uuid"];
result_uuid = [[LUKeychainAccess standardKeychainAccess] stringForKey:@"uuid"];
}
//기기아이디 유니티로 전송
UnitySendMessage("GetDeviceID", "SetDeviceID", [result_uuid UTF8String]);
* 기기 아이디 생성해서 키체인에 저장해서 쓰는 것은 첨부파일이 필요하다.
| 텍스처, 리소스 메모리 최적화 (0) | 2014.12.02 |
|---|---|
| 유니티 게임 최적화 성능을 위한 정리 (그래픽과 성능) (0) | 2014.10.17 |
| 안드로이드 네이티브 크래쉬 덤프 (ARM cpu) (0) | 2014.09.18 |
| 모바일 게임 최적화의 정석 (0) | 2014.09.18 |
| Doxygen For Unity (0) | 2014.09.11 |
| 유니티 인거죠? UnityEngine 에 LightmapData 라고 있고, LightmapSettings 라고 있습니다. 라이트맵을 구으면 텍스쳐가 나올거고 씬 생성시에 ·미리보기 | 소스복사·
일단 제가 말한 키워드들로 검색해보세요. 저도 이게 테스트때 해본거라...-_-;; 장담을 못드리겠네요 ㅋ |
출처 : http://www.gamecodi.com/board/zboard-id-GAMECODI_Talkdev-no-2903-z-1.htm
| Load Textrue with WWW (0) | 2014.12.02 |
|---|---|
| OnGUI() 상에서 마우스 더블 클릭 구현 (0) | 2014.11.20 |
| 좀 더 복잡한 데이터 저장하기 (6) | 2014.09.25 |
| Unity Serializer (0) | 2014.09.25 |
| Simple C# Unity Serializer (0) | 2014.09.25 |
// 원하는 Type을 Object로 넘겨서 시리얼라이즈 한 후, string으로 받아옴.
// 이 값을 PlayerPrefs에 저장.
private string ObjectToString(System.Object _cObject)
{
if (_cObject == null)
return null;
var binaryFormatter = new BinaryFormatter();
var memoryStream = new MemoryStream();
binaryFormatter.Serialize(memoryStream, _cObject);
return Convert.ToBase64String(memoryStream.GetBuffer());
}
// PlayerPrefs에 저장된 값을 string에 받아와서 Object로 변환 후, 맞는 Type으로 형변환. Collection도 가능.
// 예) List<MyClass> listValues = StringToObject(strValue) as List<MyClass>;
private System.Object StringToObject(string _strValue)
{
if (true == string.IsNullOrEmpty(_strValue))
return null;
var binaryFormatter = new BinaryFormatter();
var memoryStream = new MemoryStream(Convert.FromBase64String(_strValue));
System.Object obj = binaryFormatter.Deserialize(memoryStream);
return obj;
}
출처 : http://kookiandkiki.blogspot.kr/2014/01/unity3d_432.html
이전 포스팅에서 간단한 데이터를 저장하는 법을 봤는데요,
만약에 저장할 데이터가 간단하지 않고 좀 복잡하다...라고 한다면 아래처럼 테이블을 만들어서 저장합니다.
==============================================================================
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // 리스트를 쓰기 위해 추가합니다.
public class csTest : MonoBehaviour
{
// 이렇게 클래스를 만들고
[Serializable] // 저장하기 위해서 있어야 합니다.
public class ScoreEntry
{
public string name;
public int score;
}
string currentPlayerName;
int score;
// 만든 클래스를 리스트에 담아서 관리하면 마치 테이블처럼 사용할 수 있습니다.
public List<ScoreEntry> highScore = new List<ScoreEntry>();
void AddData()
{
// 이렇게 새로운 데이터를 추가해주고
highScore.Add(new ScoreEntry { name = currentPlayerName, score = score });
}
void OnGUI()
{
// 이렇게 화면에 랭킹 정보를 보여주면 됩니다.
foreach (ScoreEntry nowScore in highScore)
{
GUILayout.Label(string.Format("{0} : {1:#, 0}", nowScore.name, nowScore.score));
}
}
}
==============================================================================
이렇게 정보를 테이블처럼 만든 후에는 BinaryFormatter를 사용해서 저장할 수 있습니다.
BinaryFormatter는 '파라미터를 갖지 않는 생성자'를 갖는 클래스라면 어떤 클래스도 바이트 배열로 변환하고, 그것을 다시 문자열 값으로 변환할 수 있습니다.
문자열 값으로 변환이 가능하다면 이전 포스팅에서 설명한 PlayerPrefs에 저장할 수 있게 되겠죠.
==============================================================================
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // 리스트를 쓰기 위해 추가합니다.
// BinaryFormatter를 사용하기 위해서는 반드시 아래의 네임스페이스를 추가해줘야 해요.
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class csTest : MonoBehaviour
{
// 이렇게 클래스를 만들고
[Serializable] // 저장하기 위해서 있어야 합니다.
public class ScoreEntry
{
public string name;
public int score;
}
// 만든 클래스를 리스트에 담아서 관리하면 마치 테이블처럼 사용할 수 있습니다.
public List<ScoreEntry> highScore = new List<ScoreEntry>();
void SaveScores()
{
var binaryFormatter = new BinaryFormatter();
var memoryStream = new MemoryStream();
// score를 바이트 배열로 변환해서 저장합니다.
binaryFormatter.Serialize(memoryStream, highScore);
// 그것을 다시 한번 문자열 값으로 변환해서
// 'HighScore'라는 스트링 키값으로 PlayerPrefs에 저장합니다.
PlayerPrefs.SetString("HighScore", Convert.ToBase64String(memoryStream.GetBuffer()));
}
void Start()
{
// 'HighScore' 스트링 키값으로 데이터를 가져옵니다.
var data = PlayerPrefs.GetString("HighScore");
if (!string.IsNullOrEmpty(data))
{
var binaryFormatter = new BinaryFormatter();
var memoryStream = new MemoryStream(Convert.FromBase64String(data)));
// 가져온 데이터를 바이트 배열로 변환하고
// 사용하기 위해 다시 리스트로 캐스팅해줍니다.
highScore = (List<ScoreEntry>)binaryFormatter.Deserialize(memoryStream);
}
}
}
==============================================================================| OnGUI() 상에서 마우스 더블 클릭 구현 (0) | 2014.11.20 |
|---|---|
| LightMap 동적 로딩. (0) | 2014.10.01 |
| Unity Serializer (0) | 2014.09.25 |
| Simple C# Unity Serializer (0) | 2014.09.25 |
| ClipboardHelper (0) | 2014.05.15 |
| LightMap 동적 로딩. (0) | 2014.10.01 |
|---|---|
| 좀 더 복잡한 데이터 저장하기 (6) | 2014.09.25 |
| Simple C# Unity Serializer (0) | 2014.09.25 |
| ClipboardHelper (0) | 2014.05.15 |
| 유니티 코루틴 깊이 알고 재미있게 쓰기. (0) | 2014.05.09 |
I wrote this class to serializes common unity types into and out of a byte array. Its nothing fancy, but its handy for networking player state.
//--- Serialize ---
UnitySerializer srlzr = new UnitySerializer();
srlzr.Serialize(new Vector3(4, 8, 6));
byte[] byteArray = srlzr.ByteArray;
// send byte array somewhere..
//--- Deserialize ---
UnitySerializer dsrlzr = new UnitySerializer(byteArray);
Vector3 point3 = dsrlzr.DeserializeVector3();
It supports Vector3, Vector2 and Quaternions, as well as the common primitives and its easy enough to extend to extra types. Just be sure to deserialize the data in the same order it was serialized. Check out the Example() function at the bottom to see how it works.
// Author: Richard Pieterse, April 2013
using UnityEngine;
using System.Collections.Generic;
using System;
public class UnitySerializer {
private List<byte> byteStream = new List<byte>();
private byte[] byteArray;
private int index = 0;
/// <summary>
/// Returns the stream as a Byte Array
/// </summary>
public byte[] ByteArray
{
get
{
if ( byteArray == null || byteStream.Count != byteArray.Length)
byteArray = byteStream.ToArray();
return byteArray;
}
}
/// <summary>
/// Create a new empty stream
/// </summary>
public UnitySerializer()
{
}
/// <summary>
/// Initialiaze a stream from a byte array.
/// Used for deserilaizing a byte array
/// </summary>
/// <param name="ByteArray"></param>
public UnitySerializer(byte[] ByteArray)
{
byteArray = ByteArray;
byteStream = new List<byte>(ByteArray);
}
// --- double ---
public void Serialize(double d)
{
byteStream.AddRange( BitConverter.GetBytes(d));
}
public double DeserializeDouble()
{
double d = BitConverter.ToDouble(ByteArray, index); index += 8;
return d;
}
//
// --- bool ---
public void Serialize(bool b)
{
byteStream.AddRange(BitConverter.GetBytes(b));
}
public bool DeserializeBool()
{
bool b = BitConverter.ToBoolean(ByteArray, index); index += 1;
return b;
}
//
// --- Vector2 ---
public void Serialize(Vector2 v)
{
byteStream.AddRange(GetBytes(v));
}
public Vector2 DeserializeVector2()
{
Vector2 vector2 = new Vector2();
vector2.x = BitConverter.ToSingle(ByteArray, index); index += 4;
vector2.y = BitConverter.ToSingle(ByteArray, index); index += 4;
return vector2;
}
//
// --- Vector3 ---
public void Serialize(Vector3 v)
{
byteStream.AddRange(GetBytes(v));
}
public Vector3 DeserializeVector3()
{
Vector3 vector3 = new Vector3();
vector3.x = BitConverter.ToSingle(ByteArray, index); index += 4;
vector3.y = BitConverter.ToSingle(ByteArray, index); index += 4;
vector3.z = BitConverter.ToSingle(ByteArray, index); index += 4;
return vector3;
}
//
// --- Type ---
public void Serialize(System.Type t)
{
// serialize type as string
string typeStr = t.ToString();
Serialize(typeStr);
}
public Type DeserializeType()
{
// type stored as string
string typeStr = DeserializeString();
return Type.GetType(typeStr); ;
}
//
// --- String ---
public void Serialize(string s)
{
// add the length as a header
byteStream.AddRange(BitConverter.GetBytes(s.Length));
foreach (char c in s)
byteStream.Add((byte)c);
}
public string DeserializeString()
{
int length = BitConverter.ToInt32(ByteArray, index); index += 4;
string s = "";
for (int i = 0; i < length; i++)
{
s += (char)ByteArray[index];
index++;
}
return s;
}
//
// --- byte[] ---
public void Serialize(byte[] b)
{
// add the length as a header
byteStream.AddRange(BitConverter.GetBytes(b.Length));
byteStream.AddRange(b);
}
public byte[] DeserializeByteArray()
{
int length = BitConverter.ToInt32(ByteArray, index); index += 4;
byte[] bytes = new byte[length];
for (int i = 0; i < length; i++)
{
bytes[i] = ByteArray[index];
index++;
}
return bytes;
}
//
// --- Quaternion ---
public void Serialize(Quaternion q)
{
byteStream.AddRange(GetBytes(q));
}
public Quaternion DeserializeQuaternion()
{
Quaternion quat = new Quaternion();
quat.x = BitConverter.ToSingle(ByteArray, index); index += 4;
quat.y = BitConverter.ToSingle(ByteArray, index); index += 4;
quat.z = BitConverter.ToSingle(ByteArray, index); index += 4;
quat.w = BitConverter.ToSingle(ByteArray, index); index += 4;
return quat;
}
//
// --- float ---
public void Serialize(float f)
{
byteStream.AddRange(BitConverter.GetBytes(f));
}
public float DeserializeFloat()
{
float f = BitConverter.ToSingle(ByteArray, index); index += 4;
return f;
}
//
// --- int ---
public void Serialize(int i)
{
byteStream.AddRange(BitConverter.GetBytes(i));
}
public int DeserializeInt()
{
int i = BitConverter.ToInt32(ByteArray, index); index += 4;
return i;
}
//
// --- internal ----
Vector3 DeserializeVector3(byte[] bytes, ref int index)
{
Vector3 vector3 = new Vector3();
vector3.x = BitConverter.ToSingle(bytes, index); index += 4;
vector3.y = BitConverter.ToSingle(bytes, index); index += 4;
vector3.z = BitConverter.ToSingle(bytes, index); index += 4;
return vector3;
}
Quaternion DeserializeQuaternion(byte[] bytes, ref int index)
{
Quaternion quat = new Quaternion();
quat.x = BitConverter.ToSingle(bytes, index); index += 4;
quat.y = BitConverter.ToSingle(bytes, index); index += 4;
quat.z = BitConverter.ToSingle(bytes, index); index += 4;
quat.w = BitConverter.ToSingle(bytes, index); index += 4;
return quat;
}
byte[] GetBytes(Vector2 v)
{
List<byte> bytes = new List<byte>(8);
bytes.AddRange(BitConverter.GetBytes(v.x));
bytes.AddRange(BitConverter.GetBytes(v.y));
return bytes.ToArray();
}
byte[] GetBytes(Vector3 v)
{
List<byte> bytes = new List<byte>(12);
bytes.AddRange(BitConverter.GetBytes(v.x));
bytes.AddRange(BitConverter.GetBytes(v.y));
bytes.AddRange(BitConverter.GetBytes(v.z));
return bytes.ToArray();
}
byte[] GetBytes(Quaternion q)
{
List<byte> bytes = new List<byte>(16);
bytes.AddRange(BitConverter.GetBytes(q.x));
bytes.AddRange(BitConverter.GetBytes(q.y));
bytes.AddRange(BitConverter.GetBytes(q.z));
bytes.AddRange(BitConverter.GetBytes(q.w));
return bytes.ToArray();
}
public static void Example()
{
//
Debug.Log("--- UnitySerializer Example ---");
Vector2 point = UnityEngine.Random.insideUnitCircle;
Vector3 position = UnityEngine.Random.onUnitSphere;
Quaternion quaternion = UnityEngine.Random.rotation;
float f = UnityEngine.Random.value;
int i = UnityEngine.Random.Range(0, 10000);
double d = (double)UnityEngine.Random.Range(0, 10000);
string s = "Brundle Fly";
bool b = UnityEngine.Random.value < 0.5f ? true : false;
System.Type type = typeof(UnitySerializer);
//
Debug.Log("--- Before ---");
Debug.Log(point + " " + position + " " + quaternion + " " + f + " " + d + " " + s + " " + b + " " + type);
//
Debug.Log("--- Serialize ---");
UnitySerializer us = new UnitySerializer();
us.Serialize(point);
us.Serialize(position);
us.Serialize(quaternion);
us.Serialize(f);
us.Serialize(i);
us.Serialize(d);
us.Serialize(s);
us.Serialize(b);
us.Serialize(type);
byte[] byteArray = us.ByteArray;
// the array must be deserialized in the same order as it was serialized
Debug.Log("--- Deserialize ---");
UnitySerializer uds = new UnitySerializer(byteArray);
Vector2 point2 = uds.DeserializeVector2();
Vector3 position2 = uds.DeserializeVector3();
Quaternion quaternion2 = uds.DeserializeQuaternion();
float f2 = uds.DeserializeFloat();
int i2 = uds.DeserializeInt();
double d2 = uds.DeserializeDouble();
string s2 = uds.DeserializeString();
bool b2 = uds.DeserializeBool();
System.Type type2 = uds.DeserializeType();
//
Debug.Log("--- After ---");
Debug.Log(point2 + " " + position2 + " " + quaternion2 + " " + f2 + " " + d2 + " " + s2 + " " + b2 + " " + type2);
}
}
출처 : http://deciduousgames.blogspot.kr/2013/04/unity-serializer.html
| 좀 더 복잡한 데이터 저장하기 (6) | 2014.09.25 |
|---|---|
| Unity Serializer (0) | 2014.09.25 |
| ClipboardHelper (0) | 2014.05.15 |
| 유니티 코루틴 깊이 알고 재미있게 쓰기. (0) | 2014.05.09 |
| ScreenWipe CrossFade with C# (0) | 2014.04.22 |
| The asset bundle can't be loaded (0) | 2015.03.18 |
|---|---|
| CompareBaseObjectsInternal can only be called from the main thread. (0) | 2014.11.06 |
| Mesh has more materials (2) than subsets (1) (0) | 2014.09.03 |
| SQLite syntax error (0) | 2014.03.21 |
| Actor::updateMassFromShape Error (0) | 2013.12.12 |