2014년 10월 31일 금요일

Unity for IOS_Screen Capture한 이미지 카메라롤 에 등록하기.


Explan.

IOS에서 Application.CaptureScreenShot(path) 메소드를 사용할경우
캡처는 진행되나 해당 app 의 document폴더로 들어가서 카메라 롤에서 확인할수가 없다.
이를 등록해주는 방법 포스팅.


CaptureHelper.h
#import <Foundation/Foundation.h>

@interface CaptureHelper : NSObject

+(CaptureHelper *)sharedInstancs;

@end
CaptureHelper.mm
#import "CaptureHelper.h"

static CaptureHelper * captureHelper = [CaptureHelper sharedInstancs];

@implementation CaptureHelper : NSObject

+ (void)initialize{
    if(captureHelper == nil)
        captureHelper = [[CaptureHelper alloc] init];
}

+ (CaptureHelper *)sharedInstancs{
    return captureHelper;
}

- (id)init{
    if(captureHelper != nil){
        return  captureHelper;
    }
    
    self = [super init];
    if(self){
        captureHelper = self;
    }
    
    return self;
}


- (NSString *)getDocumentDirectory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    return [paths objectAtIndex:0];
}

@end

extern "C"{
    void CaptureToCameraRoll(const char *fileName)
    {
        NSString *file = [NSString stringWithUTF8String:(fileName)];
        NSString *filePath = [[captureHelper getDocumentDirectory] stringByAppendingString:file];
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
        
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    }
}

위 2개의 파일을 생성후 Plugin/IOS 폴더에 위치 그후

how to used.
[DllImport("__Internal")]
public static extern void CaptureToCameraRoll(String fileName);

// 그이후 스크린 캡처 진행시.

Application.CaptureScreenShot(path);
CaptureToCameraRoll(string.Format("/{0}",path));


이후 카메라롤에서 캡쳐된 이미지를 확인하실수 있다.

2014년 10월 1일 수요일

CSharp_Visual Studio Custom Snippet 적용 시키기. in Visual Studio & Unity

Explain.
Visual Studio를 사용할경우 snippet파일을 직접 만들어서 적용.
Snippet을 적용하여 작업하는 이유는 모든 스크립트의 전체적으로 통일된 디자인을 적용하고 반복되어지는 작업을 최소화 시켜줌.

How to use.
아래처럼 xml형식으로 snippet 파일을 생성후 저장(*.snippet)으로 저장 하여야 한다.
(아래 형식은 제가 사용하는(unity)에서 형식이고 내용은 필요한대로 편집하여 사용하시면됩니다.)
저장경로 : Users\User\Documents\Visual Studio XXXX\Code Snippets\Visual C#\My Code Snippets

그 이후
프로젝트에서 우클릭-> Insert Code Snippet -> My Code Snippet -> 해당 Snippet 선택
해주시면 snippet이 짠 하고 나타나는것을 보실수 있습니다.
ctrl + K + X가 Hotkey이니 애용하시면 될듯합니다. -End.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>#Classregion</Title>
      <Shortcut>#Classregion</Shortcut>
      <Description>Code snippet for #Classregion</Description>
      <Author>Author Name</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>name</ID>
          <ToolTip>Region name</ToolTip>
          <Default>MyRegion</Default>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[
        #region -------Public Field-------
        $selected$ $end$
        #endregion
    
        #region -------Private Field-------
        $selected$ $end$
        #endregion
    
        #region -------Default Method-------
        $selected$ $end$
        #endregion

        #region -------Public Method-------
        $selected$ $end$
        #endregion
    
        #region -------Private Method-------
        $selected$ $end$
        #endregion
    
        #region -------Property-------
        $selected$ $end$
        #endregion
    ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>