레이블이 SNS인 게시물을 표시합니다. 모든 게시물 표시
레이블이 SNS인 게시물을 표시합니다. 모든 게시물 표시

2019년 7월 18일 목요일

Unity SNS Sharing

유니티에서 게임을 SNS에 공유(share)하는 방법 중 한 개를 정리해 본다.

에셋 다운 : [URL]
샘플 : [URL]


1. 에셋을 다운로드한다. 

  • 유니티 에셋 스토어에서 "Native Share for Android & iOS" 에셋을 검색해 현재 프로젝트에 Import 한다.

2. 환경을 설정한다.

  • Assets/Plugins/Android 경로에 AndroidManifest.xml 파일이 있는지 확인한다.
  • [설치된 유니티 경로]\Editor\Data\PlaybackEngines\AndroidPlayer\Apk 폴더에서 AndroidManifest.xml 파일을 복사한다.



  • adroid:authorities 설정은 내 프로젝트의 이름으로 설정한다.
<provider
  android:name="com.yasirkula.unity.UnitySSContentProvider"
  android:authorities="MY_UNIQUE_AUTHORITY"
  android:exported="false"
  android:grantUriPermissions="true" />

3.코드로 기능을 호출 한다. 


  • GitHub의 샘플 코드를 확인해 내게 필요한 항목을 설정한다.
  • SetText 에 마켓 URL를 넣으면 간단하게 공유 기능을 구현할 수 있다.


using System.IO;

void Update()
{
 if( Input.GetMouseButtonDown( 0 ) )
  StartCoroutine( TakeSSAndShare() );
}
 
private IEnumerator TakeSSAndShare()
{
 yield return new WaitForEndOfFrame();

 Texture2D ss = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false );
 ss.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 );
 ss.Apply();

 string filePath = Path.Combine( Application.temporaryCachePath, "shared img.png" );
 File.WriteAllBytes( filePath, ss.EncodeToPNG() );
 
 // To avoid memory leaks
 Destroy( ss );

 new NativeShare().AddFile( filePath ).SetSubject( "Subject goes here" ).SetText( "Hello world!" ).Share();

 // Share on WhatsApp only, if installed (Android only)
 //if( NativeShare.TargetExists( "com.whatsapp" ) )
 // new NativeShare().AddFile( filePath ).SetText( "Hello world!" ).SetTarget( "com.whatsapp" ).Share();
}

Unity - Firebase 연동 (Analytics, AdMob)

버전 : firebase_unity_sdk_6.5.0.zip 게임에서 통계 측정 및 광고 추적을 위해 Firebase 을 연동한다. 앞서 [Unity - GPGS 와 Admob 연동 및 배포 준비 작업]  연동 이후에 작업을 진행 한다. 유니...