블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2741)
Unity3D (30)
Programming (475)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (54)
Android (15)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
05-17 00:10

Unity에서 Xcode 출력 후 필요한 설정을 자동화하는 방법입니다. 
이번에는 잘 사용할 것 같은 것을 샘플 형식으로 정리했습니다.

■ 이용하는 기능 
Unity5에서 표준 이용할 수있게되었다 XcodeAPI을 이용 
Unity - Scripting API : PBXProject

■ 자동화 항목 
빌드 설정 편집 
프레임 워크의 추가 
컴파일 플래그의 설정 
· Info.plist 추가

■ 전 준비 
PostProcessBuildAttribute를 이용하여 빌드 후 메소드를 호출

using System.IO;
 using UnityEngine;
 using UnityEditor;
 using UnityEditor.iOS.Xcode;
 using UnityEditor.Callbacks;
 using System.Collections;

public  class XcodeSettingsPostProcesser
{
    [PostProcessBuildAttribute ( 0 )]
     public  static  void OnPostprocessBuild (BuildTarget buildTarget, string pathToBuiltProject)
    {
        // iOS 이외 플랫폼은 처리를하지 
        if (buildTarget! = BuildTarget.iOS) return ;

        // PBXProject 초기화 
        var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj" ;
        PBXProject pbxProject = new PBXProject ();
        pbxProject.ReadFromFile (projectPath);
        string targetGuid = pbxProject.TargetGuidByName ( "Unity-iPhone" );
        
        // 여기에 자동화 처리 기술

        // 설정을 반영
        File.WriteAllText (projectPath, pbxProject.WriteToString ());
    }
}

■ 빌드 설정 편집

// 빌드 설정 추가 
pbxProject.AddBuildProperty (targetGuid, "OTHER_LDFLAGS" , "-all_load" );

// 빌드 설정 추가 
pbxProject.SetBuildProperty (targetGuid, "ENABLE_BITCODE" , "NO" );

// 빌드 설정 편집, 제 3 인수는 추가 설정 제 4 인수는 삭제 설정 
pbxProject.UpdateBuildProperty (targetGuid, "OTHER_LDFLAGS" , new  string [] { "-ObjC" }, new  string [] { "- weak_framework " });

■ 프레임 워크 추가

// 필수 프레임 워크의 추가 
pbxProject.AddFrameworkToProject (targetGuid, "Security.framework" , false );

// 옵션 프레임 워크의 추가 
pbxProject.AddFrameworkToProject (targetGuid, "SafariServices.framework" , true );

■ 컴파일 플래그 설정

// Keyboard.mm에 -fno-objc-arc를 설정 
var guid = pbxProject.FindFileGuidByProjectPath ( "Classes / UI / Keyboard.mm" );
var flags = pbxProject.GetCompileFlagsForFile (targetGuid, guid);
flags.Add ( "-fno-objc-arc" );
pbxProject.SetCompileFlagsForFile (targetGuid, guid, flags);

■ Info.plist 추가

// Plist 설정을위한 초기화 

var plistPath = Path.Combine (pathToBuiltProject, "Info.plist" );

var plist = new PlistDocument ();

plist.ReadFromFile (plistPath);



// 문자열의 설정 

plist.root.SetString ( "hogehogeId" , "dummyid" );



// URL 스키마 추가 var array = plist.root.CreateArray ( "CFBundleURLTypes");

var urlDict = array.AddDict ();

urlDict.SetString ( "CFBundleURLName" , "hogehogeName" );

var urlInnerArray = urlDict.CreateArray ( "CFBundleURLSchemes" );

urlInnerArray.AddString ( "hogehogeValue" );



// 설정을 반영

plist.WriteToFile (plistPath);

■ 정리 
Unity5되어 설정이 상당히 쉬워졌습니다

■ 코드 전체

using System.IO ;
using UnityEngine ;
using UnityEditor ;
using UnityEditor.iOS.Xcode ;
using UnityEditor.Callbacks ;
using System.Collections ;
public class XcodeSettingsPostProcesser
{
[PostProcessBuildAttribute ( 0 )
public static void OnPostprocessBuild ( BuildTarget buildTarget , string pathToBuiltProject )
{
// Stop processing if targe is NOT iOS
if (buildTarget! = BuildTarget.iOS)
return ;
// Initialize PbxProject
var projectPath = pathToBuiltProject + " /Unity-iPhone.xcodeproj/project.pbxproj " ;
PBXProject pbxProject = new PBXProject ();
pbxProject.ReadFromFile (projectPath);
string targetGuid = pbxProject.TargetGuidByName ( " Unity-iPhone " );
// Sample of adding build property
pbxProject.AddBuildProperty (targetGuid, " OTHER_LDFLAGS " , " -all_load " );
// Sample of setting build property
pbxProject.SetBuildProperty (targetGuid, " ENABLE_BITCODE " , " NO " );
// Sample of update build property
pbxProject.UpdateBuildProperty (targetGuid, " OTHER_LDFLAGS " , new string [] { " -ObjC " }, new string [] { " -weak_framework " });
// Sample of adding REQUIRED framwrok
pbxProject.AddFrameworkToProject (targetGuid, " Security.framework " , false );
// Sample of adding OPTIONAL framework
pbxProject.AddFrameworkToProject (targetGuid, " SafariServices.framework " , true );
// Sample of setting compile flags
var guid = pbxProject.FindFileGuidByProjectPath ( " Classes / UI / Keyboard.mm " );
var flags = pbxProject.GetCompileFlagsForFile (targetGuid, guid);
flags.Add ( " -fno-objc-arc " );
pbxProject.SetCompileFlagsForFile (targetGuid, guid, flags);
// Apply settings
File.WriteAllText (projectPath, pbxProject.WriteToString ());
// Samlpe of editing Info.plist
var plistPath = Path.Combine (pathToBuiltProject, " Info.plist " );
var plist = new PlistDocument ();
plist.ReadFromFile (plistPath);
// Add string setting
plist.root.SetString ( " hogehogeId " , " dummyid " );
// Add URL Scheme
var array = plist.root.CreateArray ( " CFBundleURLTypes " );
var urlDict = array.AddDict ();
urlDict.SetString ( " CFBundleURLName " , " hogehogeName " );
var urlInnerArray = urlDict.CreateArray ( " CFBundleURLSchemes " );
urlInnerArray.AddString ( " hogehogeValue " );

// Localizations [added blueasa / 2018-03-28] // need Language Code(ref:https://ko.wikipedia.org/wiki/ISO_639) var arrayLocalizations = plist.root.CreateArray("CFBundleLocalizations"); arrayLocalizations.AddString("en"); // 영어 arrayLocalizations.AddString("ko"); // 한국어

//arrayLocalizations.AddString("zh"); // 중국어

arrayLocalizations.AddString("zh_CN"); // 중국어(간체) : 중국 arrayLocalizations.AddString("zh_TW"); // 중국어(번체) : 대만 arrayLocalizations.AddString("ja"); // 일본어 arrayLocalizations.AddString("de"); // 독일어

// Apply editing settings to Info.plist
plist.WriteToFile (plistPath);
}
}

gist.github.com



[출처] http://smartgames.hatenablog.com/entry/2016/06/19/164052

반응형
Posted by blueasa
, |

■iOSの広告識別子「IDFA=Advertising Identifier」

■Androidの広告ID「ADID=AdvertisingID」

■実機操作による確認方法
 ・Android
  「設定」->「Google」->「広告」で広告IDを確認

 ・iPhone
  わかんない

●Unity公式のサンプルスクリプト
https://docs.unity3d.com/jp/540/ScriptReference/Application.RequestAdvertisingIdentifierAsync.html

advertisingId には広告ID
enabledにはユーザーが広告IDを使用させるか?の有無が返ってくる

■自分用にソース

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GetIdfaAndAdid : MonoBehaviour {

    [SerializeField]
    public Text DisplayID;

    // ボタンが押されると呼ばれる
    public void GetID()
    {
        Debug.Log("■■■■■GetID()■■■■■");
        // IDFA
        Application.RequestAdvertisingIdentifierAsync(
                (string advertisingId, bool trackingEnabled, string error) =>
                {
                    Debug.Log("advertisingId=" + advertisingId + " enabled=" + trackingEnabled + " error=" + error);
                    DisplayID.text = "advertisingId=" + advertisingId + " enabled=" + trackingEnabled + " error=" + error;

                }
        );
    }
}

■参考URL
https://reviewlog.info/adid-android/
https://reviewlog.info/ios-idfa-reset/
https://stackoverflow.com/questions/34193282/apple-idfa-in-unity-via-plugin

Appleの規約
https://support.apple.com/ja-jp/HT205223



[출처] https://qiita.com/satotin/items/f4afb0a08adbec26a062

[참조] https://docs.unity3d.com/ScriptReference/Application.RequestAdvertisingIdentifierAsync.html

반응형
Posted by blueasa
, |

以下はUnity2017.1.1f1Xcode9.0GMで確認しています。

前置き

iPhoneXの対応がめんどくさそう
https://developer.apple.com/ios/human-interface-guidelines/overview/whats-new/

やりたいこと

Unity側でいちいち対応するのは面倒なので、Unityの描画領域を変更して、
iPhoneXの場合は上下に余白を持たせれば良いのでは?という案。

iPhone 8iPhoneX beforeiPhoneX after
iphonex8p.pngiphonex1.pngiphonex2.png

iPhoneX beforeの画像は、iPhone 8の画像と同じコードをそのまま実行したものです。
どう表示されるかはもちろんUnityでの実装によりますが、このサンプルの場合は
画面上部に合わせてテキストを表示しているので、iPhoneXの凹部に隠れてしまっています。

iPhoneX afterの画像は、Unityの描画領域を上50pt、下40pt短くし、余白部分に画像を設定しています。
ついでにステータスバーも表示しています。

ソース

GitHubに上げました。
https://github.com/tkyaji/UnityIPhoneXSupport

UnityIPhoneXSupport.unitypackage をインポートすると、
PostProcessBuildでビルド時にUnityのソースを書き換えて、余白を設定するようになります。

余白のサイズと色、または画像を定数で指定できます。

やってること

1. iPhoneXの場合、ステータスバーを表示する

iPhoneXではステータスバーの非表示は非推奨とのことなので、表示するようにします。

UnityのPlayerSettingsで、Status Ber Hiddenが設定されている場合のみ以下の処理を行います。

  • Info.plistの設定を、ステータスバー表示とする
  • UnityViewControllerBaseiOS.mmを書き換え、iPhoneXの場合は表示、それ以外は非表示とする

2. UnityのViewサイズを変更する

UnityAppController.mmUnityView.mmを書き換え、UIWindowUIViewのサイズをそれぞれ変更します。
高さを90pt短くし、Windowの位置を50pt下げています。
これで上50pt、下40ptの余白ができます。
上下余白部分にUIViewをそれぞれ設定し、色を設定します。
さらに画像がある場合はUIImageViewaddSubViewします。

備考

  • シミュレータで少し確認しただけなので、もしかしたら色々問題があるかもしれません。使用する場合は自己責任でお願いします。
  • iPhoneXのSafe Areaは左右にも余白があるため、ちゃんとやるなら左右にも気を使う必要がありそうです
  • 余白部分がただの黒帯とかだと、そのせいでリジェクトになる可能性があるかもしれません
  • iPhoneXかどうかは画面アスペクト比でざっくり判定しています



[출처] https://qiita.com/tkyaji/items/8cdc0a4324d4e89633e8

반응형
Posted by blueasa
, |

[Link] unity-webview

Unity3D/Plugins / 2017. 10. 23. 19:11


[Link] https://github.com/gree/unity-webview

반응형
Posted by blueasa
, |

우선, 유니티에서 Window -> Services 합니다.



그러고 나면 Inspector 옆에 Services라는 텝이 생기는데 

Select Organization 하고 Create 해줍니다.



그러면 유니티에서 제공하는 Service들이 보일 것입니다.

그 중에, OFF상태인 In-App Purchasing 텝을 클릭합니다.



우측상단에 있는 토글을 눌러 OFF되어있던 상태를 ON으로 만들어줍니다.

그리고 13세 이하 어린이에게 지도감독이 필요한 지 여부를 선택하고 Save Changes 합니다.



이제, 프로젝트에 In-App Purchasing이 활성화 된 모습을 보실 수 있을 것입니다.

여기서 잊지말고 Import 버튼을 꼬옥 눌러줍니다!



프로젝트 뷰에 Unity IAP 플러그인이 제대로 임포트 된 모습입니다.



이제 기본 세팅이 다 되었습니다. 그렇다면 코딩을 해볼까요?

아래와 같이 Script를 작성합니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using UnityEngine;
using UnityEngine.Purchasing;
 
public class InAppPurchaser : MonoBehaviour, IStoreListener
{
    private static IStoreController storeController;
    private static IExtensionProvider extensionProvider;
 
    #region 상품ID
    // 상품ID는 구글 개발자 콘솔에 등록한 상품ID와 동일하게 해주세요.
    public const string productId1 = "gem1";
    public const string productId2 = "gem2";
    public const string productId3 = "gem3";
    public const string productId4 = "gem4";
    public const string productId5 = "gem5";
    #endregion
 
    void Start()
    {
        InitializePurchasing();
    }
 
    private bool IsInitialized()
    {
        return (storeController != null && extensionProvider != null);
    }
 
    public void InitializePurchasing()
    {
        if (IsInitialized())
            return;
 
        var module = StandardPurchasingModule.Instance();
 
        ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);
 
        builder.AddProduct(productId1, ProductType.Consumable, new IDs
        {
            { productId1, AppleAppStore.Name },
            { productId1, GooglePlay.Name },
        });
 
        builder.AddProduct(productId2, ProductType.Consumable, new IDs
        {
            { productId2, AppleAppStore.Name },
            { productId2, GooglePlay.Name }, }
        );
 
        builder.AddProduct(productId3, ProductType.Consumable, new IDs
        {
            { productId3, AppleAppStore.Name },
            { productId3, GooglePlay.Name },
        });
 
        builder.AddProduct(productId4, ProductType.Consumable, new IDs
        {
            { productId4, AppleAppStore.Name },
            { productId4, GooglePlay.Name },
        });
 
        builder.AddProduct(productId5, ProductType.Consumable, new IDs
        {
            { productId5, AppleAppStore.Name },
            { productId5, GooglePlay.Name },
        });
 
        UnityPurchasing.Initialize(this, builder);
    }
 
    public void BuyProductID(string productId)
    {
        try
        {
            if (IsInitialized())
            {
                Product p = storeController.products.WithID(productId);
 
                if (p != null && p.availableToPurchase)
                {
                    Debug.Log(string.Format("Purchasing product asychronously: '{0}'", p.definition.id));
                    storeController.InitiatePurchase(p);
                }
                else
                {
                    Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
                }
            }
            else
            {
                Debug.Log("BuyProductID FAIL. Not initialized.");
            }
        }
        catch (Exception e)
        {
            Debug.Log("BuyProductID: FAIL. Exception during purchase. " + e);
        }
    }
 
    public void RestorePurchase()
    {
        if (!IsInitialized())
        {
            Debug.Log("RestorePurchases FAIL. Not initialized.");
            return;
        }
 
        if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXPlayer)
        {
            Debug.Log("RestorePurchases started ...");
 
            var apple = extensionProvider.GetExtension<IAppleExtensions>();
 
            apple.RestoreTransactions
                (
                    (result) => { Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore."); }
                );
        }
        else
        {
            Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
        }
    }
 
    public void OnInitialized(IStoreController sc, IExtensionProvider ep)
    {
        Debug.Log("OnInitialized : PASS");
 
        storeController = sc;
        extensionProvider = ep;
    }
 
    public void OnInitializeFailed(InitializationFailureReason reason)
    {
        Debug.Log("OnInitializeFailed InitializationFailureReason:" + reason);
    }
 
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
 
        switch (args.purchasedProduct.definition.id)
        {
            case productId1:
 
                // ex) gem 10개 지급
 
                break;
 
            case productId2:
 
                // ex) gem 50개 지급
 
                break;
 
            case productId3:
 
                // ex) gem 100개 지급
 
                break;
 
            case productId4:
 
                // ex) gem 300개 지급
 
                break;
 
            case productId5:
 
                // ex) gem 500개 지급
 
                break;
        }
 
        return PurchaseProcessingResult.Complete;
    }
 
    public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    {
        Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    }
}
 
cs



결제를 진행해야하는 부분에서 


위의 BuyProductID 함수의 파라미터로 상품ID를 넣고 콜(구매요청)하면


product가 initialize된 후 ProcessPurchase로 결과가 넘어오는데


args.purchasedProduct.definition.id로 구매요청된 상품ID를 판별하여


상품에 맞는 보상을 지급해주면 됩니다. 참 쉽죠?


유니티 5.3버전 이전에는(유니티가 자체 IAP를 지원하기 전) Android와 iOS 각각 따로 결제시스템을 만들어야했는데


지금은 Android와 iOS를 동시에 지원해주기 때문에 정말 편하답니다~


    


결제된 정보는 구글 Payments 판매자 센터에서 확인하실 수 있습니다. (https://wallet.google.com/merchant)



출처: http://minhyeokism.tistory.com/47 [programmer-dominic.kim]



반응형
Posted by blueasa
, |

[펌] Unity BigInteger

Unity3D/Script / 2017. 4. 26. 19:51

[File]

BigInteger.zip




BigInteger


現時点、unityでサポートされている.Netのバージョンは3.5相当となっている(2015/01/15現在)
この事から.Net4.0からサポートされたクラスは利用できない状態となっている


C#コードを利用した幾何解析などの演算では、扱う数字の桁数に制限がない BigInteger クラスが必要になる場合がある
そこで、検索を利用して探してみるとMITライセンスの BigInteger クラスが公開されていたので、これを利用する事にした
unityが将来.Net4.0をサポートした時の事を考え、このMIT版BigInteger に少し改編を施す。利用側のコード改編が必要ない形にしておく


資料:


<雛形とするBigIntegerクラス>


<unity用に名前空間を書き換えたBigIntegerクラス>
Scott Garland氏が作成されたBigIntegerクラスです。ライセンスはMITライセンスとして指定されています。これを使えばunityでBigIntegerの機能が利用できます
コード内の名前空間に「ScottGarland」が使われているのでこの部分を「System.Numerics」に書き換えunityの将来のバージョンアップに備えます
(少し行儀の悪い方法ですが一時的な利用になると予想しています)



ダウンロードした「BigInteger.cs」ファイルをunityのAssetsフォルダ内にコピーし「System.Numerics」名前空間を経由して他のコードから利用する事にします
当サイト内でBigIntegerをサンプルコード内で利用する場合、unityが.Net4.0に対応するまでは、このクラスを利用します



[출처] http://unitylab.wiki.fc2.com/wiki/BigInteger

반응형
Posted by blueasa
, |


[링크http://lhh3520.tistory.com/315



[추가]

Unity Analytics도 Offline 일 때,

Cache에 저장해둔 후, Online이 되면 전송함


[참조

Our SDK caches events that are sent if the request fails for any reason(e.g. no internet connection) after it reaches the retry threshold.
Once there's an internet connection, we resend the cached events.


[참조 출처]

https://forum.unity3d.com/threads/is-unity-analytics-a-best-effort-delivery-service-offline-unreliable-connections.311369/

반응형
Posted by blueasa
, |

[펌] TexturePacker

Unity3D/Plugins / 2016. 5. 10. 12:32

[링크] https://www.codeandweb.com/texturepacker



[링크] Quickstart Guide with TexturePacker and Unity





Tutorials for Unity:
Sprite Sheets &
Normal Mapped Sprites

We currently have 2 detailed tutorials for Unity,
scroll down for our Quickstart Guide.











Quickstart Guide with TexturePacker and Unity

This overview shows you how to create your first sprite sheet and import it into your unity project.

These 6 steps will cost you only 5 minutes - but make your development much easier. Promised!

1.
Open TexturePacker, select
Unity - Texture2D sprite sheet
as framework.

TexturePacker: Select Unity Texture2D as framework

2.
Add sprites ...

Drag & drop sprites
onto TexturePacker.


... or folders

TexturePacker adds
all sprites inside the folder
and updates the texture
when the content changes.

Add Sprites to TexturePacker


3.
Set output files
Make sure to set the output path of both files inside the Assets folder of your Unity project.



Set the output path for your files


4.
Optional: Set Trim mode and Pivot Point.

Crop removes transparency from sprites, allowing a better packing ratio.




5.

Click Publish sprite sheet to write the sprite sheet to your Unity project




6.

Download and install our free
TexturePacker Importer
TexturePacker Importer
Free download from Unity Asset Store 

The sprite sheet is updated after each publish.




TexturePacker allows you to set a Pivot Point and Trim your sprite





TexturePacker: Click Publish sprite sheet







Your files will be imported automatically when using TexturePacker Importer





반응형
Posted by blueasa
, |


Link : https://aws.amazon.com/ko/documentation/sdk-for-unity/

반응형
Posted by blueasa
, |

문서들을 여기 저기 따로 공유하려느 번거로워서 유니티 최적화 관련 문서들을 모아두었습니다. 정리는 두서 없이 했고,다만 출처가 유니티 크루인지 아닌지로만 분류하였습니다. 추가적으로 발견하는 대로 지속적으로 갱신 할 예정입니다.


From Unity


from Developers


출처 : http://ozlael.tistory.com/32

반응형
Posted by blueasa
, |