//도큐먼트 폴더 주소

    NSString *documentsDir = [NSString stringWithString:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]];

    

    //라이브러리 폴더 주소

    NSString *LibraryDir = [NSString stringWithString:[NSHomeDirectory() stringByAppendingPathComponent:@"Library"]];

    

    //라이브러리->캐쉬폴더 폴더주소

    NSString *Library_CachesDir = [NSString stringWithString:[LibraryDir stringByAppendingPathComponent:@"Caches"]];

    

NSFileManager *fm = [NSFileManager defaultManager];

    //도큐먼트 폴더안에 있는 파일 리스트 가져온다.

    NSArray *list = [[NSFileManager defaultManagercontentsOfDirectoryAtPath:documentsDir error:nil];

    //파일 리스트 갯수를 가져와서..

    int fileCount = [list count];

    //갯수가 0이 아니면 아래 실행..(갯수가 0이면 빈 폴더임)

    if (fileCount!=0)

    {

        //도큐먼트안에 파일들을 라이브러리->캐쉬 폴더로 이동시킨다.

        for (NSString *path in [fm contentsOfDirectoryAtPath:documentsDir error:nil])

        {

            [fm moveItemAtPath:[documentsDir stringByAppendingPathComponent:path] toPath:[Library_CachesDir stringByAppendingPathComponent:path] error:nil];

        }

        

        //도큐멘트 안에 파일을 지운다.

        for (NSString *path in [fm contentsOfDirectoryAtPath:documentsDir error:nil])

        {

            [fm removeItemAtPath:[documentsDir stringByAppendingPathComponent:path] error:nil];

        }

    }


참고 주소 : http://jaesung2124.tistory.com/31


1.  NGUIMath.cs 의 맨 하단에 아래의 코드를 추가 한다.

static public Bounds CalculateRelativeWidgetBounds2 ( Transform root, Transform firstTemplate, Transform lastTemplate )

{

if( firstTemplate == null || lastTemplate == null )

return new Bounds(Vector3.zero, Vector3.zero);

UIWidget[] widgets1 = firstTemplate.GetComponentsInChildren<UIWidget>(true) as UIWidget[];

UIWidget[] widgets2 = lastTemplate.GetComponentsInChildren<UIWidget>(true) as UIWidget[];

if (widgets1.Length == 0 || widgets2.Length == 0 ) return new Bounds(Vector3.zero, Vector3.zero);

 

Vector3 vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

Vector3 vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);

 

Matrix4x4 toLocal = root.worldToLocalMatrix;

 

for (int i = 0, imax = widgets1.Length; i < imax; ++i)

{

UIWidget w = widgets1[i];

Vector2 size = w.relativeSize;

Vector2 offset = w.pivotOffset;

Transform toWorld = w.cachedTransform;

 

float x = (offset.x + 0.5f) * size.x;

float y = (offset.y - 0.5f) * size.y;

size *= 0.5f;

// Start with the corner of the widget

Vector3 v = new Vector3(x - size.x, y - size.y, 0f);

// Transform the coordinate from relative-to-widget to world space

v = toWorld.TransformPoint(v);

// Now transform from world space to relative-to-parent space

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

// Repeat for the other 3 corners

v = new Vector3(x - size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y - size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

}

for (int i = 0, imax = widgets2.Length; i < imax; ++i)

{

UIWidget w = widgets2[i];

Vector2 size = w.relativeSize;

Vector2 offset = w.pivotOffset;

Transform toWorld = w.cachedTransform;

 

float x = (offset.x + 0.5f) * size.x;

float y = (offset.y - 0.5f) * size.y;

size *= 0.5f;

// Start with the corner of the widget

Vector3 v = new Vector3(x - size.x, y - size.y, 0f);

// Transform the coordinate from relative-to-widget to world space

v = toWorld.TransformPoint(v);

// Now transform from world space to relative-to-parent space

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

// Repeat for the other 3 corners

v = new Vector3(x - size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y - size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

}

 

Bounds b = new Bounds(vMin, Vector3.zero);

b.Encapsulate(vMax);

return b;

}


2. SpringPanel.cs 에 아래의 코드를 추가 한다.

static public SpringPanel Begin (GameObject go, Vector3 pos, float strength, OnFinished finish )

{

 SpringPanel sp = go.GetComponent<SpringPanel>();

 if (sp == null) sp = go.AddComponent<SpringPanel>();

 sp.target = pos;

 sp.strength = strength;

 sp.onFinished = finish;

 if (!sp.enabled)

 {

  sp.mThreshold = 0f;

  sp.enabled = true;

 }

 

 return sp;

}


3. 첨부한 3개의 파일을 프로젝트에 포함 시킨다.

cUIScrollListBase.cs


UIDraggablePanel2.cs


UIListItem.cs



4. UIDraggablePanel.cs 에서 에러가 날 것이다.. 

virtual 을 해서 없애도 되고~ 

UIDraggablePanel.cs


위 파일로 교체를 해도 된다.~~


5. 사용 방법은 

transform.GetComponent<UIDraggablePanel2>().Init( count, delegate(UIListItem item, int index) {

CMsgUserItem scr = item.Target.GetComponent<CMsgUserItem>();

scr.transform.name = "clip_"+index;

scr.transform.localScale = Vector3.one;

} );


6. 마지막 가장 중요한 감사의 마음을 표시 한다.~ 

나 말고~ http://idmanner.blog.me/70176641036  

위에 링크 블러그 주인한테 감사의 마음을 표시 한다.~~~


감사 합니다.~!~!~!

^^ 즐코딩 하세요~!


// string -> base64Encoding 으로 바꾼 상태를 문자열로 표기 할때

private string StringConvertBase64(string _str) {

byte[] byteArr = utf8Enc.GetBytes(_str);

return Convert.ToBase64String(byteArr);

}


// base64Encoding 로 바뀐 문자열을 일반 문자열로 표기 할때

private string Base64ConvertString(string _str) {

byte[] byteArr = Convert.FromBase64String(_str);

return utf8Enc.GetString(byteArr);

}



System.Random r = new System.Random();

int keyValue = r.Next(0,7);


0~7사이 랜덤 숫자를 생성 합니다.


C#에서 암호화 할시 php에서와 암호화 할시 다르게 나오는 경우가 있어

구글 검색 후 
참고 링크 입니다.

아래 코드 같은 경우에는 흔히 구글에서 볼수 있지만 이 C# 코드와 동일하게 암호화 하기 위해서는 위의 링크에 들어 가서 
php암호화 코드를 사용 하여야만 한다..
사용 결과 잘 됩니다.~

private string Decrypt256(String Input, String key)

{

 RijndaelManaged aes = new RijndaelManaged();

            aes.KeySize = 256;

            aes.BlockSize = 128;

            aes.Mode = CipherMode.CBC;

            aes.Padding = PaddingMode.PKCS7;

            aes.Key = Encoding.UTF8.GetBytes(key);

            aes.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };


            var decrypt = aes.CreateDecryptor();

            byte[] xBuff = null;

            using (var ms = new MemoryStream())

            {

                using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write))

                {

                    byte[] xXml = Convert.FromBase64String(Input);

                    cs.Write(xXml, 0, xXml.Length);

                }


                xBuff = ms.ToArray();

            }


            String Output = Encoding.UTF8.GetString(xBuff);

            return Output;

}

 

  private String AESEncrypt256(String Input, String key)

{

            RijndaelManaged aes = new RijndaelManaged();

            aes.KeySize = 256;

            aes.BlockSize = 128;

            aes.Mode = CipherMode.CBC;

            aes.Padding = PaddingMode.PKCS7;

            aes.Key = Encoding.UTF8.GetBytes(key);        

            aes.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };


            var encrypt = aes.CreateEncryptor(aes.Key, aes.IV);

            byte[] xBuff = null;

            using (var ms = new MemoryStream())

            {

                using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))

                {

                    byte[] xXml = Encoding.UTF8.GetBytes(Input);

                    cs.Write(xXml, 0, xXml.Length);

                }


                xBuff = ms.ToArray();

            }


            String Output = Convert.ToBase64String(xBuff);

            return Output;

}



카카오의 친구 정보를 받아서 Unity3D로 값을 넘겨 줄때 Json 으로 변환 하여 NSString 을 넘겨 주는 방식으로 하다 보니 


malloc error이 발생 하였다... 


해결 방법은


char *MakeStringCopy(const char* string) {

    if (string == NULL)

        return NULL;

    char* res = (char*) malloc (strlen(string) + 1 );

    strcpy (res, string);

    return res;

}


extern "C" {

    const char *_GetFriendInfoList() {

        

        

        NSString *JSONString = @"";

        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[[DataManager manager] friendList]

                                                           options:0

                                                             error:nil];

        if (!jsonData) {

            NSLog(@"Error");

        } else {

            

            JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];

            NSLog(@"JSONString = %@",JSONString);

            return MakeStringCopy([JSONString UTF8String]);

        }

        

        return MakeStringCopy([JSONString UTF8String]);

        

    }

    float getTest() {

    return 0.5f;

    }

}



ngui 사용시 위와 같은 이미지 자른 후에 1~2픽셀의 공간이 생기는 현상이 있습니다. 

흔히 모든 해상도에 대응을 하게 되면 생기는 현상 같기도 하구요..


이 문제점을 해결 하는 방법은 ngui 의 Atlas 텍스쳐의 Filter Mode를 Point로 변경 하면 해결 됩니다. ㅜㅜ


너무 힘들었네요 이 부분 찾느라 ~ 


그럼 즐 코딩 하세요~


IEnumerator fImageDownCheck() {


WWW www = new WWW(_url);

yield return www;


if(www.size == 0) {

mImage = true;

StopCoroutine("fImageDownCheck");

else {

noticeManager.fNoticeTextureMake(www.texture);

Debug.Log("Image Save");

// Texture2D savedTexture = _materialToSave.mainTexture as Texture2D;

       Texture2D newTexture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.ARGB32, false);

 

             newTexture.SetPixels(0,0, www.texture.width, www.texture.height, www.texture.GetPixels());

       newTexture.Apply();

             byte[] bytes = newTexture.EncodeToPNG();

Debug.Log(bytes);

            File.WriteAllBytes(Application.temporaryCachePath+"/"+"test.png", bytes);

}

}


Application.temporaryCachePath 폴더 : /var/folders/dy/********************/T/DefaultCompany/ProjectName

에 저장 됩니다. 




역시 extable 키 값을 각각 지정 해주시면 됩니다. ^^아래의 값은 임시 적입니다.~


const unsigned char extable[4] = {0x1D, 0x1D, 0x1B, 0xF1};


void IntToByte(int num, unsigned char* value)

{

    value[0] = ((unsigned char)(num >> 24)) ^ extable[0];

    value[1] = ((unsigned char)(num >> 16)) ^ extable[1];

    value[2] = ((unsigned char)(num >> 8)) ^ extable[2];

    value[3] = ((unsigned char)(num)) ^ extable[3];

}


void IntToByteNon(int num, unsigned char* value)

{

    value[0] = ((unsigned char)(num >> 24));

    value[1] = ((unsigned char)(num >> 16));

    value[2] = ((unsigned char)(num >> 8));

    value[3] = ((unsigned char)(num));

}


int ByteToInt(unsigned char* value)

{

    int retV = 0;

    

    retV = (((value[0] & 0xFF) ^ extable[0]) << 24) |

    (((value[1] & 0xFF) ^ extable[1]) << 16) |

    (((value[2] & 0xFF) ^ extable[2]) << 8) |

    ((value[3] & 0xFF) ^ extable[3]);

    

    return retV;

}


int ByteToIntNon(unsigned char* value)

{

    int retV = 0;

    

    retV = (((value[0] & 0xFF)) << 24) |

    (((value[1] & 0xFF)) << 16) |

    (((value[2] & 0xFF)) << 8) |

    ((value[3] & 0xFF));

    

    return retV;

}


- (int) setInt_XOR:(int)value {

    IntToByte(value,_changeBuf);

    return ByteToIntNon(_changeBuf);

}


- (int) getInt_XOR:(int)value {

    memset(_changeBuf, 0x00, 4);

    IntToByteNon(value,_changeBuf);

    return ByteToInt(_changeBuf);

}

아래의 extable 은 각 고유 키를 넣어 주면 됩니다. ^^



byte[] extable = {0x1D, 0x1D, 0x1B, 0x3F} ;

byte[] _changeBuf = {0,0,0,0} ;


void Start() {

Debug.Log(intToXOR(1000));

int kTemp = intToXOR(1000);

Debug.Log(xorToINT(kTemp));

Debug.Log(intToXOR(10000));

kTemp = intToXOR(10000);

Debug.Log(xorToINT(kTemp));

}

private void IntToByte(int num, byte[] value)

{

    value[0] = (byte)((num >> 24) ^ extable[0]);

    value[1] = (byte)((num >> 16) ^ extable[1]);

    value[2] = (byte)((num >> 8) ^ extable[2]);

    value[3] = (byte)(num ^ extable[3]);

}

private int ByteToIntNon(byte[] value)

{

    int retV = 0;

    

    retV = (((value[0] & 0xFF)) << 24) |

    (((value[1] & 0xFF)) << 16) |

    (((value[2] & 0xFF)) << 8) |

    ((value[3] & 0xFF));

    

    return retV;

}

private void IntToByteNon(int num, byte[] value)

{

   value[0] = ((byte)(num >> 24));

    value[1] = ((byte)(num >> 16));

    value[2] = ((byte)(num >> 8));

    value[3] = ((byte)(num));

}

private int ByteToInt(byte[] value)

{

    int retV = 0;

    

    retV = (((value[0] & 0xFF) ^ extable[0]) << 24) |

    (((value[1] & 0xFF) ^ extable[1]) << 16) |

    (((value[2] & 0xFF) ^ extable[2]) << 8) |

    ((value[3] & 0xFF) ^ extable[3]);

    

    return retV;

}

public int intToXOR(int _value) {

IntToByte(_value,_changeBuf);

return ByteToIntNon(_changeBuf);

}

public int xorToINT(int _value) {

    IntToByteNon(_value,_changeBuf);

return ByteToInt(_changeBuf);

}

+ Recent posts