Command Pattern


1. 정의

- 요청을 캡슐화 해서 사용자가 보낸 요청에 대한 정보를 저장, 취소 등 할 수 있도록 하는 패턴


2. 설명

- 다양한 요청을 똑같은 함수의 호출로 처리 가능토록 인터페이스로 구현.

- 커맨드를 만들 때 해당 인터페이스를 상속받아 구현

- 커맨드를 저장하여 해당 커맨드의 로그를 남기거나 할 수 있다


3. 장/단점

1) 장점

- 작업 요청 로그를 남기거나 할 때 쓰면 쉽게 구현이 가능

2) 단점

- 객체의 캡슐화 하기 어려운 요청의 경우 구현이 힘들 수 있다.


4. 예제 코드

using System;
using System.Collections.Generic;

namespace CommandPattern
{
    // Command 인터페이스
    interface ICommand
    {
        // 실행
        int[,] Execute();
        // 되돌리기
        int[,] Undo();
    }

    class DrawSquareCommand : ICommand
    {
        // 왼쪽 위 좌표
        private int x1, y1;

        // 오른쪽 아래 좌표
        private int x2, y2;

        // 사각형 색깔
        private int color;

        // 이전의 캔버스를 저장
        private int[,] canvas;

        // 현재 캔버스와 사각형 좌표들을 받음
        public DrawSquareCommand(int[,] old, int x1, int y1, int x2, int y2, int color)
        {
            canvas = new int[ old.GetLength( 0 ), old.GetLength( 1 ) ];

            for(int i=0 ;i= x1 && i <= x2 && j >= y1 && j <= y2 )
                    {
                        resultCanvas[ i, j ] = color;
                    }
                    else
                        resultCanvas[ i, j ] = canvas[ i, j ];
                }
            }

            return resultCanvas;
        }

        // 사각형 그리기 되돌리기
        public int[,] Undo()
        {
            return canvas;
        }
    }

    class DrawCircleCommand : ICommand
    {
        // 중심 좌표
        private int x1, y1;

        // 원 반지름
        private int squareRadius;

        // 원 색깔
        private int color;

        // 이전의 캔버스를 저장
        private int[,] canvas;

        // 현재 캔버스와 사각형 좌표들을 받음
        public DrawCircleCommand(int[,] old, int x1, int y1, int radius, int color)
        {
            canvas = new int[ old.GetLength( 0 ), old.GetLength( 1 ) ];

            for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
            {
                for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                {
                    canvas[ i, j ] = old[ i, j ];
                }

            }

            this.x1 = x1;
            this.y1 = y1;

            squareRadius = radius * radius;

            this.color = color;
        }

        // 사각형 그리기 실행
        public int[,] Execute()
        {
            // 결과 값 저장할 변수
            int[,] resultCanvas = new int[ canvas.GetLength( 0 ), canvas.GetLength( 1 ) ];

            // 원 그림
            for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
            {
                for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                {
                    if ( ( i - x1 ) * ( i - x1 ) + ( j - y1 ) * ( j - y1 ) <= squareRadius ) 
                    {
                        resultCanvas[ i, j ] = color;
                    }
                    else
                        resultCanvas[ i, j ] = canvas[ i, j ];
                }
            }

            return resultCanvas;
        }

        // 원 그리기 되돌리기
        public int[,] Undo()
        {
            return canvas;
        }
    }

    class DrawLineCommand : ICommand
    {
        // 왼쪽 위 좌표
        private int x1, y1;

        // 오른쪽 아래 좌표
        private int x2, y2;

        // 사각형 색깔
        private int color;

        // 이전의 캔버스를 저장
        private int[,] canvas;

        // 현재 캔버스와 사각형 좌표들을 받음
        public DrawLineCommand(int[,] old, int x1, int y1, int x2, int y2, int color)
        {
            canvas = new int[ old.GetLength( 0 ), old.GetLength( 1 ) ];

            for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
            {
                for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                {
                    canvas[ i, j ] = old[ i, j ];
                }
            }

            this.x1 = x1;
            this.y1 = y1;
            this.x2 = x2;
            this.y2 = y2;

            this.color = color;
        }

        // 사각형 그리기 실행
        public int[,] Execute()
        {
            // 결과 값 저장할 변수
            int[,] resultCanvas = new int[ canvas.GetLength( 0 ), canvas.GetLength( 1 ) ];

            // 기울기를 구할 수 없을 때
            if (x2 == x1)
            {
                // 선 그림
                for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
                {
                    for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                    {
                        if ( i == x1 && j >= y1 && j <= y2 )
                        {
                            resultCanvas[ i, j ] = color;
                        }
                        else
                            resultCanvas[ i, j ] = canvas[ i, j ];
                    }
                }
            }
            else
            {
                // 기울기
                float slope = ( float ) ( y2 - y1 ) / ( x2 - x1 );

                // y 절편
                float yIntercept = y1 - ( x1 * slope );
                
                // 선 그림
                for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
                {
                    for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                    {
                        if ( i >= x1 && i <= x2 && j >= y1 && j <= y2 )
                        {
                            if ( j == ( int ) ( slope * i + yIntercept ) )
                            {
                                resultCanvas[ i, j ] = color;
                            }
                            else
                                resultCanvas[ i, j ] = canvas[ i, j ];
                        }
                        else
                            resultCanvas[ i, j ] = canvas[ i, j ];
                    }
                }
            }

            return resultCanvas;
        }

        // 선 그리기 되돌리기
        public int[,] Undo()
        {
            return canvas;
        }
    }

    class CommandManager
    {
        // 실행취소 기록
        private Stack undoHistory;
        // 다시실행 기록
        private Stack redoHistory;

        public CommandManager()
        {
            undoHistory = new Stack();
            redoHistory = new Stack();
        }

        // 명령 실행
        public int[,] ExecuteCommand(ICommand com)
        {
            // 일반 명령 실행 시 다시 실행 기록은 삭제.
            redoHistory.Clear();

            // 실행할 명령을 실행취소 기록에 넣어줌.
            undoHistory.Push( com );
            
            return com.Execute();
        }

        // 실행 취소
        public int[,] UndoCommand()
        {
            ICommand undoCom = undoHistory.Pop();
            redoHistory.Push( undoCom );

            return undoCom.Undo();
        }

        // 다시 실행
        public int[,] RedoCommand()
        {
            ICommand redoCom = redoHistory.Pop();
            undoHistory.Push( redoCom );

            return redoCom.Execute();
        }
    }

    class Program
    {
        public static void PrintCanvas(int[,] canvas)
        {
            for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
            {
                for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                {
                    Console.Write( canvas[ i, j ] );
                    Console.Write( " " );
                }
                Console.Write( "\n" );
            }
            Console.Write( "\n" );
        }

        public static void UpdateCanvas(int[,] canvas, int[,] newCanvas)
        {
            for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
            {
                for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                {
                    canvas[ i, j ] = newCanvas[ i, j ];
                }
            }
        }

        static void Main(string[] args)
        {
            // canvas 생성
            int[,] canvas = new int[ 10, 10 ];

            // canvas 초기화
            for ( int i = 0 ; i < canvas.GetLength( 0 ) ; i++ )
            {
                for ( int j = 0 ; j < canvas.GetLength( 1 ) ; j++ )
                {
                    canvas[ i, j ] = 0;
                }
            }

            Console.WriteLine( "==================== 초기 캔버스 ====================" );
            PrintCanvas( canvas );

            // 명령 매니저 생성
            CommandManager cManager = new CommandManager();

            // 원 그리기 명령 생성 후 실행
            DrawCircleCommand dCircle = new DrawCircleCommand( canvas, 5, 5, 3, 5 );
            UpdateCanvas(canvas, cManager.ExecuteCommand( dCircle ));
            Console.WriteLine( "==================== 1.원 그리기 ====================" );
            PrintCanvas( canvas );

            // 사각형 그리기 명령 생성 후 실행
            DrawSquareCommand dSquare = new DrawSquareCommand( canvas, 4, 4, 6, 6, 3 );
            UpdateCanvas( canvas, cManager.ExecuteCommand( dSquare ) );
            Console.WriteLine( "================== 2.사각형 그리기 ==================" );
            PrintCanvas( canvas );

            // 선 그리기 명령 생성 후 실행
            DrawLineCommand dLine = new DrawLineCommand( canvas, 4, 4, 6, 6, 1 );
            UpdateCanvas( canvas, cManager.ExecuteCommand( dLine ) );
            Console.WriteLine( "==================== 3.선 그리기 ====================" );
            PrintCanvas( canvas );

            // 되돌리기 명령 실행
            UpdateCanvas( canvas, cManager.UndoCommand() );
            Console.WriteLine( "================== 2번으로 되돌리기 =================" );
            PrintCanvas( canvas );

            // 되돌리기 명령 실행
            UpdateCanvas( canvas, cManager.UndoCommand() );
            Console.WriteLine( "================== 1번으로 되돌리기 =================" );
            PrintCanvas( canvas );

            // 다시 실행 명령 실행
            UpdateCanvas( canvas, cManager.RedoCommand() );
            Console.WriteLine( "================== 2번으로 다시실행 =================" );
            PrintCanvas( canvas );
        }
    }
}


5. 출력 결과물


==================== 초기 캔버스 ====================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

==================== 1.원 그리기 ====================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 0 0 0 0 0 0 0

================== 2.사각형 그리기 ==================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 3 3 3 5 0 0
0 0 5 5 3 3 3 5 5 0
0 0 0 5 3 3 3 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 0 0 0 0 0 0 0

==================== 3.선 그리기 ====================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 1 3 3 5 0 0
0 0 5 5 3 1 3 5 5 0
0 0 0 5 3 3 1 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 0 0 0 0 0 0 0

================== 2번으로 되돌리기 =================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 3 3 3 5 0 0
0 0 5 5 3 3 3 5 5 0
0 0 0 5 3 3 3 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 0 0 0 0 0 0 0

================== 1번으로 되돌리기 =================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 5 5 5 5 5 5 5 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 0 0 0 0 0 0 0

================== 2번으로 다시실행 =================
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 5 3 3 3 5 0 0
0 0 5 5 3 3 3 5 5 0
0 0 0 5 3 3 3 5 0 0
0 0 0 5 5 5 5 5 0 0
0 0 0 0 0 5 0 0 0 0
0 0 0 0 0 0 0 0 0 0


'C# > Design Pattern' 카테고리의 다른 글

[Design Pattern C#]Singleton Pattern  (0) 2016.11.26

Singleton Pattern


1. 정의

- 오직 단 하나의 인스턴스만 생성되는 클래스로 전역 범위에서 접근 가능함


2. 설명

- 생성자를 private로 선언해서 하나의 인스턴스 외에는 생성 자체가 불가능 하도록 함.

- 해당 클래스의 인스턴스를 저장하는 Instance란 멤버변수를 선언하고 이 멤버변수에 접근하는 방식으로만 인스턴스 접근

- Instance에 접근 할 때 만약 인스턴스가 생성되어 있지 않을 경우에만 생성자를 호출해 인스턴스를 생성.

- Instance 멤버변수를 static으로 선언하기 때문에 전역 범위에서 접근 가능.


3. 장/단점

1) 장점

- 인스턴스가 하나만 생성 되므로 메모리 관리가 효율적이다

- 인스턴스가 여러개 생성되면 안되는 경우에 사용하는 것이 좋다

2) 단점

- 전역변수나 마찬가지라 다양한 접근이 있을 경우 데이터 관리에 문제가 생길 수 있다

- 멀티 쓰레드 프로그램 일 경우 locking에 신경 써주지 않으면 문제가 발생한다.


4. 예제 코드

using System.IO;
using System.Text;

namespace CsharpTest
{
    class SingletonLog
    {
        // 로그 파일 이름
        private readonly string fileName = "log.txt";
        // 파일 입출력 위한 StreamWriter 변수
        private StreamWriter sw;
        // 로그 포멧 정리 위한 StreamBuilder 변수
        private StringBuilder sb;

        // 로그 종류
        private readonly int[] code = { 1000, 2000, 3000 };
        // 로그 중요도
        private readonly string[] grade = { "WARNING", " ERROR ", " INFOR " };
        
        // 하나 뿐인 인스턴스
        private static SingletonLog _instance;

        // 표면상 보이는 인스턴스
        public static SingletonLog Instance
        {
            get
            {
                // 인스턴스가 생성되지 않았을 경우 생성
                if ( _instance == null )
                    _instance = new SingletonLog();

                return _instance;
            }
        }

        // 생성자
        private SingletonLog()
        {
            // 파일 열기
            sw = new StreamWriter( fileName, true );
            // StringBuilder 생성
            sb = new StringBuilder();
        }

        // 로그 출력하는 함수
        public void WriteLog(int codeIndex, int gradeIndex, string log)
        {
            // 로그 포멧 지정
            sb.AppendFormat( "[{0}]{1}({2}) : {3}", System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"), code[codeIndex], grade[gradeIndex], log );

            // 로그 출력
            sw.WriteLine( sb.ToString() );
            sw.Flush();

            // StringBuilder 초기화
            sb.Clear();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // 특별한 생성자 없이 그냥 전역변수처럼 호출
            SingletonLog.Instance.WriteLog( 0, 0, "test0" );
            SingletonLog.Instance.WriteLog( 1, 1, "test1" );
            SingletonLog.Instance.WriteLog( 2, 2, "test2" );
        }
    }
}


5. 출력 결과물

<log.txt>

[2016-11-25 11:11:25]1000(WARNING) : test0

[2016-11-25 11:11:26]2000( ERROR ) : test1

[2016-11-25 11:11:26]3000( INFOR ) : test2



'C# > Design Pattern' 카테고리의 다른 글

[Design Pattern C#]Command Pattern  (0) 2016.11.28

원래 프로그래밍을 했던 사람이 1인 개발자로 시작하는데 가장 큰 걸림돌은 역시... 리소스다!!!

물론 게임 기획이나 밸런싱 등 처음 해보는 것들이라 쉽진 않지만

미적 감각이 없는 대부분의 공대생들은... 리소스가 문제다 ㅠㅠㅠㅠ


이런 고민을 떠안고 있던 중 고마운 은인이 등장해 좋은 리소스 제작툴을 가르쳐 주었다.


바로 매지카복셀(MagicaVoxel)

복셀(Voxel)이란 것은 3D 도트라 생각해주면 된다. 잘 상상이 안가시면 마인 크래프트 같은 디자인(?)이라 보시면 될거 같다.


- 매지카복셀 공식 사이트.

https://voxel.codeplex.com/



- 매지카 복셀 공부 동영상

https://www.youtube.com/watch?v=D4WIUNCbds8&list=PL-0nb9b-1MFhncBNUOzvp0wil7xm_QHqg

'마지막잎새'님의 매지카복셀 에디터 강좌


https://www.youtube.com/watch?v=zY0fW1Kvi2s&list=PL-0nb9b-1MFjDQNrBS43q3PO4Ob2TEB2U

'마지막잎새'님의 매지카복셀 애니메이션 강좌



- 블랜더(Blender) 공식사이트

https://www.blender.org/

OS에 비유하자면 리눅스 급의 3D 그래픽 프로그램.

복셀에 본을 넣을 수 있다.(마지막 잎새님 강좌 참조)


- Adobe Mixamo

https://www.mixamo.com/

블렌더로 삽입한 본을 이용해 애니메이션을 구현하고자 할 때

무료로 애니메이션을 구할 수 있고 상업적으로 사용 가능.(2016.09.10 확인)




위 툴들을 이용해 게임을 개발할 생각이다.

이 카테고리에는 개발하다가 올리고 싶을 때마다 갱신예정.


- 전체적인 PHP 정리된 사이트

http://modernpug.github.io/php-the-right-way/#books


- 위 사이트에서 찾은 무료 PHP7 책 (이 책 내용을 이 카테고리에 정리)

https://daylerees.com/php-pandas/


- PHP framework 사용량 비교 2016

http://webrevisions.com/tutorials/php-framework-the-best-php-framework-for-2013/


- PHP framework 장단점 비교

http://www.hongkiat.com/blog/best-php-frameworks/


- PHP, HHVM, Node.Js 성능 비교

http://www.hostingadvice.com/blog/comparing-node-js-vs-php-performance/


- javascript framework 2016

https://colorlib.com/wp/javascript-frameworks/


- html/css framework 2016

https://colorlib.com/wp/free-css3-frameworks/

이번에는 유니티에 Vungle Plugin을 설치해보도록 하겠습니다.


https://v.vungle.com/sdk

위 URL로 접속해서 유니티용 플러그인을 다운로드 합니다.


위 처럼 유니티에서

[Assets] - [Import Package] - [Custom Package]

선택


Import를 클릭해 내용을 Import 시켜줍니다.


※ Google Play Game Service가 미리 설치되어 있는 경우 [Plugin] - [google-play-services_lib] 폴더를

체크 해제 해줘야 한다. Google Play Game Service와 충돌하여 로그인이 안된다.



밑의 코드가 광고 보여주는 코드

void awake()
{
        Vungle.init( Constant.Vungle.androidApplicationId, "test" );

        if ( Vungle.isAdvertAvailable() )
        {
            Vungle.playAd();
        }
}


이번엔 Unity Ads를 붙여봅시다!


http://unity3d.com/kr/services/ads

위 사이트로 들어가서 유니티 ID로 로그인 해줍시다!


저희는 어플에 광고를 붙여서 수익을 올릴려고 하는 것이므로

위에 EARN MONEY WITH YOUR GAMES를 눌러줍니다.


이미 등록된 프로젝트가 있으면 프로젝트가 나옵니다.

프로젝트를 추가하기 위해서 +Add New project를 눌러줍시다.


등록할 Project 이름을 넣어주고

밑에 체크하는 부분에서

위의 선택지는 만 13세 이상 규제 되는 컨텐츠란 뜻이고

밑의 선택지는 만 13세 이상 규제되지 않는 컨텐츠란 뜻입니다.


위에 설명한 부분을 알맞게 입력한 뒤

Continue를 눌러주면 다음으로 넘어갑니다.


현재 등록된 URL을 넣으라고 나오는데

밑에 체크박스를 클릭하여 아직 출시되지 않았다고 명시해 주면

URL을 넣지 않아도 됩니다.


그 다음

Enable and continue

를 눌러주면 됩니다.


Unity Ads에서 정해준 Id가 보이고

Ok, Get it!

을 눌러주면 프로젝트 등록 완료


위 처럼 프로젝트가 등록된 모습을 보실 수 있습니다.


이번엔 Test Device를 설정해 봅시다.

위에서 Test device를 누르면

Test Device를 등록할 수 있는 창이 뜹니다.


맨 처음 입력칸에는 어떤 디바이스 인지 명칭을 적어두는 겁니다.

자기가 알아 볼 수 있게 적으면 됩니다.

두 번째 입력 칸에는 현재 구글의 ADID를 적어야 하는데

안드로이드 폰에서 

설정 - Google - 서비스 - 광고

에 들어가면 있는 내 광고 ID를 넣어주면 됩니다.


웹 상의 설정은 이정도로 하고

유니티에서 Unity Ads를 추가해 보겠습니다.


유니티 Asset Store 에서

Unity Ads를 검색해서 찾아서 다운로드 해줍니다.


임포트 시켜줍니다.


그리고 밑에 코드가 광고를 띄우는 코드


using UnityEngine.Advertisements;

void awake()
{
        string zoneId = null;

        if ( Advertisement.isSupported ) Advertisement.Initialize( "Game ID", true );

        if(Advertisement.IsReady( zoneId ))
        {
            Advertisement.Show( zoneId );
        }
}


Game ID는 아까 유니티에서 정해준 ID이고

true라고 설정한 부분은 test모드인지를 설정한 부분(true 일때 테스트모드)

오늘은 Google Admob Plugin 설치하는 법에 대해 알아봅시다.


https://github.com/googleads/googleads-mobile-unity/releases/tag/v3.0.4

Downloads 에서 

GoogleMobileAds.unitypackage

를 다운 받습니다.


그 다음은 Google Play Game Service와 비슷한데요

유니티에서 

[Assets] - [Import Package] - [Custom Package...]

를 선택해서 아까 받은

GoogleMobileAds.unitypackage

를 임포트 시켜 줍니다.


Import!!!


그럼 위에 처럼 GoogleMobileAds란 폴더가 추가된 것을 보실 수 있습니다.


애드몹을 추가하려면 구글 애드몹에서 

광고 단위 ID를 알아와야 합니다.



using GoogleMobileAds.Api;

void Awake()
{
    // 전면 광고 id 등록
    InterstitialAd interstitial = new InterstitialAd( "광고 단위 아이디" );

    // 애드몹 리퀘스트 초기화
    AdRequest request = new AdRequest.Builder()
        .AddTestDevice( AdRequest.TestDeviceSimulator )       // Simulator.
        .AddTestDevice( "내 디바이스 아이디" )  // My test device.
        .Build();

    // 애드몹 전면 광고 로드
    interstitial.LoadAd( request );

    // 여기서부터 밑에 부분은 앱 실행 부분에 두면 광고가 안나온다. 실행 후 얼마 뒤로 미루자. 
    // 로드 되어 있다면 광고 보여줌
    if ( interstitial.IsLoaded() )
    {
        interstitial.Show();
    }
}

위 코드를 유니티에 넣으면 광고가 나온다.

'Game > Unity' 카테고리의 다른 글

[Unity] Vungle Plugin 설치  (0) 2016.06.15
[Unity] Unity Ads 연동  (0) 2016.06.14
[Unity] Google Play Game Service 연동시키기  (0) 2016.06.04
[Unity] 유니티 성능 관련 이슈 정리  (0) 2016.05.26
[Unity] Unity3D 설치하기  (0) 2016.05.23

열심히 만든 유니티 프로젝트에 Google Play Game Service를 연동시켜 봅시다!!

요즘 네트웍이 대세니까요... 없으면 살아남기 힘든거 같아요...



https://github.com/playgameservices/play-games-plugin-for-unity

위 사이트로 접속!


접속 하시고 옆에 [Clone or download]를 눌러주시고

[Download ZIP]을 눌러주시면 unity plugin을 다운받으실 수 있습니다.


다운 받은 압축 파일을 압축 해제 하시고

유니티에 임포트 해주시면 되는데요.


위처럼 [Custom Package...]를 누르셔서 압축해제 하신 파일 중에


play-games-plugin-for-unity-master\current-build\GooglePlayGamesPlugin-0.9.34.unitypackage

를 클릭 하셔서 임포트 해주시면 됩니다.


Import!!!!!!



임포트 하면 밑에처럼 GooglePlayGames, PlayServicesResolver, plugins가 추가되는 것을 보실 수 있습니다.

이제 [Window] - [Google Play Games] - [Setup] - [Android setup...]

을 선택!


Directory to save constan... 저 부분은 저장될 폴더

Constants class name 해당 내용 작성할 클래스

Resources Definition의 부분은 Google Play Games Service 에서 긁어 오면 됩니다.



리소스 받기 누르시면 위처럼 XML 코드가 나오게 되고

Resources Definition에 넣어주시면 됩니다.


그리고 Setup!!!



그럼 플러그인 설정 끝입니다.


다음엔 설정법을 공부해야 겠네요.....

'Game > Unity' 카테고리의 다른 글

[Unity] Vungle Plugin 설치  (0) 2016.06.15
[Unity] Unity Ads 연동  (0) 2016.06.14
[Unity] Google AdMob Plugin 설치하기  (0) 2016.06.09
[Unity] 유니티 성능 관련 이슈 정리  (0) 2016.05.26
[Unity] Unity3D 설치하기  (0) 2016.05.23

Visual Studio에서 프로그래밍 하다가 소스 버전 관리를 해야겠다는 생각이 드신 여러분!!

바로 시작 합시다 안하면 나중에 후회해요........ㅠㅠ


VIusal Studio 2015에서 Git으로 버전 관리하기

솔루션에서 [오른쪽 클릭] - [소스 제어에 솔루션 추가]


밑에 출력을 보면 새로운 커밋이 생겨났습니다

이러면 git이 적용 된겁니다.


솔루션 탐색기가 있던 곳에서  팀 탐색기로 넘어가면 저렇게 변경내용을 커밋할 수 있습니다.



'Note' 카테고리의 다른 글

Visual Studio Community 설치하기  (0) 2016.05.18

막상 유니티로 뭔가를 만들려고 하니 찾아볼게 너무 많은 것 같다... 역시 게임 만드는 건 쉬운게 아닌 듯...


우선 구글링으로 성능 관련 이슈들을 정리해둔 글들을 여기에 링크 걸어두고

조금씩 공부하며 하나의 글로 만들어봐야 겠다.

유니티5로 바뀌면서 바뀐 부분들은 어떻게 알아봐야할 지가 제일 고민이다....


http://www.slideshare.net/agebreak/141206-42456391

전체적으로 잘 정리되어있는 프리젠테이션


http://smilemugi.net/wordpress/archives/227

대부분 3d 일때 성능 이슈 정리


http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=36003

http://www.bsidesoft.com/?p=215

유니티 리소스 캐싱 소스


http://unityindepth.tistory.com/15

이건 성능이라기 보단 팁?


http://unityindepth.tistory.com/30

여긴 세개의 글이 있는데 팁과 성능 이슈가 있다 번역한 걸로 보임



현재 2D게임에서 중요한 이슈


1. instiate의 호출을 줄일 수 있는 object pool 생성하기

2. Update를 이용하지 않고 coroutine 이해하고 coroutine 이용하기

3. foreach 사용금지 - for로 대체

4. 문자열 병합 금지 - StringBuilder.Append() 이용

 ※ http://www.simpleisbest.net/post/2013/04/24/Review-StringBuilder.aspx - StringBuilder 이슈 정리

5. 잠시 쓰이는 데이터 타입은 클래스가 아닌 구조체 사용 - 클래스는 나중에 GC의 먹이가 됨.

6. 이동 관련 함수는 매프레임마다 한번씩만 호출. 두번이상 이동시키면 안됨.

7. 비어있는 콜백함수는 다 지워버리자 - START라던가 UPDATE

8. 사운드는 모노로 92kb, 2d 사운드,      비 압축 사운드(wav) : 효과음,   압축 사운드(mp3, ogg) : 배경음

9. packed font - 폰트를 각 채널 (RGBA)에 따로 저장 효율적 메모리 사용

10. TimeManager FixedUpdate default는 0.02 이지만 0.2로 낮춰주면 좋음.


나중에 다시 정리할 것!

'Game > Unity' 카테고리의 다른 글

[Unity] Vungle Plugin 설치  (0) 2016.06.15
[Unity] Unity Ads 연동  (0) 2016.06.14
[Unity] Google AdMob Plugin 설치하기  (0) 2016.06.09
[Unity] Google Play Game Service 연동시키기  (0) 2016.06.04
[Unity] Unity3D 설치하기  (0) 2016.05.23

+ Recent posts