質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

1172閲覧

【Unity】iBeaconException: Server initialization failed.

nakamu

総合スコア82

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2018/02/07 06:43

有料のiBeaconのアセットを使っています。
エディター側でUUIDとRegionを入れていて、一方のiPhoneをBeaconの受け取りとして動かしているのですが、
もう一方のiphoneを発信側にするとタイトルのようなエラーになってしまいます。
使っているのはそもそもExampleとして用意してあるシーンです。

using UnityEngine; using System.Runtime.InteropServices; using System; using System.Text; [RequireComponent(typeof(BluetoothState))] public class iBeaconServer : MonoBehaviour { #if iBeaconDummy public string m_uuid; public string m_identifier; public int m_major; public int m_minor; #endif #if UNITY_ANDROID private static AndroidJavaObject plugin; #endif #if UNITY_IOS [DllImport("__Internal")] private static extern bool InitBeaconServer(string region, bool shouldLog); [DllImport("__Internal")] private static extern void Transmit(bool transmit); #endif [SerializeField] private iBeaconRegion _region; [SerializeField] private int _txPower; public static iBeaconRegion region { get { return m_instance._region; } set { m_instance._region = value; initialized = false; } } public static int txPower { get { return m_instance._txPower; } set { m_instance._txPower = value; initialized = false; } } private static iBeaconServer m_instance; private static bool initialized = false; private static bool transmitting = false; private void Awake() { #if iBeaconDummy Debug.LogError("iBeaconDummy is still on! Please remove it from the Scripting Define Symbols."); #endif if (m_instance != null && m_instance != this) { #if UNITY_EDITOR DestroyImmediate(this); #else Destroy(this); #endif return; } #if UNITY_EDITOR if (!gameObject.name.Equals(BluetoothState.NAME)) { var obj = GameObject.Find(BluetoothState.NAME); if (obj == null) { gameObject.name = BluetoothState.NAME; } else { #if !iBeaconDummy var component = obj.AddComponent<iBeaconServer>(); component._region = _region; component._txPower = _txPower; DestroyImmediate(this); return; #endif } } #endif m_instance = this; initialized = false; transmitting = false; } private void OnDestroy() { if (m_instance == this) { m_instance = null; } } #if UNITY_ANDROID private static AndroidJavaObject GetPlugin() { if (plugin == null) { plugin = new AndroidJavaObject("com.kaasa.ibeacon.BeaconServer"); } return plugin; } #endif public static bool checkTransmissionSupported() { return checkTransmissionSupported(true); } public static bool checkTransmissionSupported(bool shouldLog) { #if UNITY_EDITOR return false; #elif UNITY_IOS return true; #elif UNITY_ANDROID return GetPlugin().Call<bool>("checkTransmissionSupported", shouldLog); #endif } public static void Restart() { StopTransmit(); Transmit(); } [Obsolete("Init() is deprecated, please remove the usage or use Restart() instead.")] public static void Init() { InternInit(true); } [Obsolete("Init(bool) is deprecated, please remove the usage or use Restart() instead.")] public static void Init(bool shouldLog) { InternInit(shouldLog); } private static void InternInit(bool shouldLog) { if (initialized) { Transmit(); return; } if (m_instance == null) { m_instance = FindObjectOfType<iBeaconServer>(); if (m_instance == null) { BluetoothState.Init(); m_instance = GameObject.Find(BluetoothState.NAME).AddComponent<iBeaconServer>(); } } StopTransmit(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { BluetoothState.EnableBluetooth(); if (BluetoothState.GetBluetoothLEStatus() != BluetoothLowEnergyState.POWERED_ON) { throw new iBeaconException("Bluetooth is off and could not be enabled."); } } if (!checkTransmissionSupported(shouldLog)) { throw new iBeaconException("This device does not support transmitting as a beacon."); } #if !UNITY_EDITOR var sb = new StringBuilder(JsonUtility.ToJson(m_instance._region)); sb.Insert(sb.Length - 1, ",\"_txPower\":"); sb.Insert(sb.Length - 1, m_instance._txPower); #if UNITY_IOS if (!InitBeaconServer(sb.ToString(), shouldLog)) { throw new iBeaconException("Server initialization failed."); } #elif UNITY_ANDROID if (!GetPlugin().Call<bool>("Init", sb.ToString(), shouldLog)) { throw new iBeaconException("Server initialization failed."); } #endif #endif initialized = true; Transmit(); } public static void Transmit() { if (!initialized) { InternInit(true); return; } if (transmitting) { return; } #if !UNITY_EDITOR #if UNITY_IOS Transmit(true); #elif UNITY_ANDROID GetPlugin().Call("transmit", true); #endif #endif transmitting = true; } public static void StopTransmit() { if (!transmitting) { return; } #if !UNITY_EDITOR #if UNITY_IOS Transmit(false); #elif UNITY_ANDROID GetPlugin().Call("transmit", false); #endif #endif transmitting = false; } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

エディター側でMajorとMinorの値を0より上の値にすることで解決しました。

投稿2018/02/07 08:56

nakamu

総合スコア82

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問