FC2ブログ
    05 «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.» 07

    ハルシオンシステムの気ままBlog

    株式会社ハルシオンシステムのメンバーが送る、UnityやらJavaやらの技術的話題から、自社開発のアプリの宣伝とかとかのブログです。ほんと気ままにいきたいと思います。更新日は毎週 月 木でっす!

     

    【ハルシオンブログ】UnityでAndroidのバックキー対応 

    こんにちは。
    大坂です。

    ポケットガール~受け継がれし希望~よろしくお願いします。
    URL(Android):https://play.google.com/store/apps/details?id=com.halcyon.pocketgirl3
    URL(iOS):https://itunes.apple.com/jp/app/id1539553611

    PV:


    今更ですが、UnityでAndroidのバックキー対応のやり方。

    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Escape))
    {
    // なんか処理
    }
    }

    Updateの中で「if (Input.GetKeyDown(KeyCode.Escape))」をするとバックキーが押されたかを取得できます。
    UnityEditor上で確認するときは「Escキー」でできますね。

    前の画面に戻る(ポップアップを閉じるとかも)機能やアプリを終了させるポップアップを開く処理を書くといいみたいです。

    ほんと今更な記事ですが、今週もこれにてノシ

    Category: 開発日記(Unity)

    tb 0 : cm 0   

    【ハルシオンブログ】Unityのバージョン上げたらビルド時に「Building scene 0:」から進まなくなった件。 

    まずはポケガ3の宣伝。坂内っす。

    ポケットガール~受け継がれし希望~よろしくお願いします。
    URL(Android):https://play.google.com/store/apps/details?id=com.halcyon.pocketgirl3
    URL(iOS):https://itunes.apple.com/jp/app/id1539553611

    PV:




    最近ポケガ2のバグ報告を受け、修正ビルドをしていたのですが、Unity2019>Unity2021にする際に色々と問題が発生し、ビルドができないという罠に・・・・

    とりあえずAndroidの方はなんとかしました。

    AdmobやらNCMBのSDKを新しくしたり色々とはまりましたが、とりあえずビルドをするところで以下の問題が発生。

    「Building scene 0:」

    ビルドがここから進まないのよね。

    何度やっても進まない‥‥

    色々調べるとLightの設定が問題だとか。

    Window>Rendering>LightingのBaked Grobal Illminationのチェックを外す。





    とかで直るらしいんだけど、ここのチェックはついていなかった(SSは違うプロジェクトのため付いています)

    これは違うようだ。


    次に記事があったのが、「Admobが入っていると起きる現象」というものだ。

    厳密にはExternalDependencyManager周りの問題らしい。

    Asset>External Dependency Manager>Android Resolver>Delete Resolved Librariesをすると直るらしい。




    うちの環境だとこれをするとエラーが出た。

    なにやら見たことのないエラーだった。


    Job failed with exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Insecure connection not allowed
    at (wrapper managed-to-native) UnityEngine.Networking.UnityWebRequest.BeginWebRequest(UnityEngine.Networking.UnityWebRequest)
    at UnityEngine.Networking.UnityWebRequest.SendWebRequest () [0x00001] in /Users/bokken/build/output/unity/unity/Modules/UnityWebRequest/Public/UnityWebRequest.bindings.cs:288
    at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
    at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in :0
    --- End of inner exception stack trace ---
    at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in :0
    at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0
    at Google.PortableWebRequest.StartRequest (Google.PortableWebRequest+HttpMethod method, System.String url, System.Collections.Generic.IDictionary`2[TKey,TValue] headers, UnityEngine.WWWForm form) [0x0019d] in Z:\tmp\tmp.laQ8zV8qX7\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\PortableWebRequest.cs:508
    at Google.PortableWebRequest+c__AnonStorey0.<>m__0 () [0x00000] in Z:\tmp\tmp.laQ8zV8qX7\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\PortableWebRequest.cs:458
    at Google.RunOnMainThread.ExecuteNext () [0x0003d] in Z:\tmp\tmp.laQ8zV8qX7\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:486
    UnityEngine.Debug:LogError (object)
    Google.RunOnMainThread:ExecuteNext () (at Z:/tmp/tmp.laQ8zV8qX7/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:488)
    Google.RunOnMainThread:m__1 () (at Z:/tmp/tmp.laQ8zV8qX7/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:536)
    Google.RunOnMainThread:RunAction (System.Action) (at Z:/tmp/tmp.laQ8zV8qX7/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
    Google.RunOnMainThread:ExecuteAllUnnested (bool) (at Z:/tmp/tmp.laQ8zV8qX7/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
    Google.RunOnMainThread:ExecuteAll () (at Z:/tmp/tmp.laQ8zV8qX7/third_party/unity/unity_jar_resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:512)
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions () (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorApplication.cs:362)



    え?なにこれ?ってことで、一旦External Dependency ManagerをProjectから消して、再度AdmobのPackageから入れなおしたら無事エラーはでなくなった。


    この状態でビルド!

    進んだ!

    Building scene 0: 超えたよ!!

    (この後違うエラーでまた嵌りました)


    ってことで、Building scene 0:でビルドが止まって進まない方、External Dependency Manager見直してみて!

    では あでゅ~ノシ

    Category: 開発日記(Unity)

    tb 0 : cm 0   

    【ハルシオンブログ】out修飾子のあるメソッドを作る 

    こんにちは。
    大坂です。
    今日から6月ですね。今年ももう半年終わりそうです…。

    ポケットガール~受け継がれし希望~よろしくお願いします。
    URL(Android):https://play.google.com/store/apps/details?id=com.halcyon.pocketgirl3
    URL(iOS):https://itunes.apple.com/jp/app/id1539553611

    PV:


    DictionaryのTryGetValueみたいなことを自分でしたいときのお話。

    DictionaryのTryGetValue。

    Dictionary testDic = new Dictionary() { { 1, "test_1" }, { 2, "test_2" }};
    if(testDic.TryGetValue(1, out var test))
    {
    Debug.Log(test);
    }


    keyに含まれていたらboolを返却してくれて、outで対応したvalueを受け取れるメソッド。

    こんなことを自分で作ったメソッドでもやりたいときは、メソッドにout修飾子を追加してあげればできます。

    out修飾子のメソッドを作ってみる。

    private bool TryCheckTest(int index, out string test)
    {
    test = null;
    if(index >= 1 && index < 10)
    {
    test = "テスト";
    return true;
    }
    else
    {
    return false;
    }
    }

    メソッドの中でout修飾子の変数に値を入れてあげれば呼び出し側で受け取れます。

    呼び出し側

    if(TryCheckTest(1, out string test_1))
    {
    Debug.Log("引数:1:" + test_1);
    }

    if (TryCheckTest(10, out string test_2))
    {
    Debug.Log("引数:10:" + test_2);
    }



    引数が「1」の時だけちゃんとifの中に入ってログが流れますね。

    簡単な構成ならDictionaryとか使ってできますが、複雑な条件でで判定したい場合はこの方法で使うと比較的わかりやすくかけるので便利ですね!

    ではではノシ

    Category: 開発日記(Unity)

    tb 0 : cm 0