예제 #1
0
    void OnGUI()
    {
        if (connectionStatus == XBikeEventReceiver.ConnectionStatus.Disconnected)
        {
            if (GUI.Button(new Rect(Screen.width / 2 - 50.0f, Screen.height - 50.0f, 100.0f, 30.0f), "Connect"))
            {
#if UNITY_EDITOR
                SendMessageForEachListener("OnXBikeConnectionStatusChange", "1");
#elif UNITY_ANDROID
                XBikeEventReceiver.Connect();
#endif
            }
        }
        else if (connectionStatus == XBikeEventReceiver.ConnectionStatus.Connecting)
        {
            GUI.Label(new Rect(Screen.width / 2 - 30.0f, Screen.height / 2 - 15.0f, 65.0f, 30.0f), "Connecting");
            if (GUI.Button(new Rect(Screen.width / 2 - 50.0f, Screen.height - 50.0f, 100.0f, 30.0f), "Disconnected"))
            {
                Application.LoadLevel("Stage1Scene");
#if UNITY_EDITOR
                SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
#elif UNITY_ANDROID
                XBikeEventReceiver.Disconnect();
#endif
            }
        }
        else if (connectionStatus == XBikeEventReceiver.ConnectionStatus.Connected)
        {
            Application.LoadLevel("Stage1Scene");
            GUI.BeginGroup(new Rect(Screen.width / 2 - 50.0f, Screen.height - 100.0f, 100.0f, 100.0f));
            GUILayout.BeginVertical();

            if (sportStatus == XBikeEventReceiver.SportStatus.Stop)
            {
                if (GUILayout.Button("Start sport"))
                {
                    StartSport();
                }
                if (GUILayout.Button("Disconnected"))
                {
#if UNITY_EDITOR
                    SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
#elif UNITY_ANDROID
                    XBikeEventReceiver.Disconnect();
#endif
                }
            }
            else if (sportStatus == XBikeEventReceiver.SportStatus.Start)
            {
                if (GUILayout.Button("Pause sport"))
                {
                    PauseSport();
                }
                if (GUILayout.Button("Stop sport"))
                {
                    StopSport();
                }
                if (GUILayout.Button("Disconnected"))
                {
#if UNITY_EDITOR
                    SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
#elif UNITY_ANDROID
                    XBikeEventReceiver.Disconnect();
#endif
                }
            }
            else if (sportStatus == XBikeEventReceiver.SportStatus.Pause)
            {
                if (GUILayout.Button("Start sport"))
                {
                    StartSport();
                }
                if (GUILayout.Button("Disconnected"))
                {
#if UNITY_EDITOR
                    SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
#elif UNITY_ANDROID
                    XBikeEventReceiver.Disconnect();
#endif
                }
            }
            GUILayout.EndVertical();
            GUI.EndGroup();

            if (sportStatus == XBikeEventReceiver.SportStatus.Start)
            {
                // Show current sport data
                GUI.Label(new Rect(50.0f, 30.0f, 200.0f, Screen.height - 30.0f), XBikeEventReceiver.Data.ToString());
                // Show left an buuton status
                GUI.Label(new Rect(500.0f, 30.0f, 150.0f, 200.0f), "Left Button : " + XBikeEventReceiver.Left.ToString());
                GUI.Label(new Rect(500.0f, 60.0f, 150.0f, 200.0f), "Right Button : " + XBikeEventReceiver.Right.ToString());

                resistanceValue = GUI.HorizontalSlider(new Rect(Screen.width / 2 - 50.0f, 20.0f, 100.0f, 30.0f), resistanceValue, 1.0f, 8.0f);
                GUI.Label(new Rect(Screen.width / 2 - 50.0f, 60.0f, 100.0f, 30.0f), ((int)resistanceValue).ToString());
                if (GUI.Button(new Rect(Screen.width / 2 - 50.0f, 90.0f, 100.0f, 30.0f), "Set resistance"))
                {
                    XBikeEventReceiver.SetResistance((int)resistanceValue);
                }
            }
        }
    }
예제 #2
0
    void OnGUI()
    {
        //GUI style setting
        GUIStyle labelStyle = new GUIStyle();

                #if UNITY_EDITOR
        labelStyle.fontSize = 20;
        float buttonWidth = 150.0f;
                #elif UNITY_ANDROID
        labelStyle.fontSize = 50;
        float buttonWidth = 300.0f;
                #endif
        labelStyle.alignment        = TextAnchor.MiddleCenter;
        labelStyle.normal.textColor = Color.white;

        GUIStyle buttonStyle = new GUIStyle();
                #if UNITY_EDITOR
        buttonStyle.fontSize   = 20;
        buttonStyle.fixedWidth = 120;
                #elif UNITY_ANDROID
        buttonStyle.fontSize   = 50;
        buttonStyle.fixedWidth = 300;
                #endif
        buttonStyle.alignment = TextAnchor.MiddleCenter;
        //buttonStyle.wordWrap = true;
        buttonStyle.stretchWidth      = true;
        buttonStyle.normal.textColor  = Color.black;
        buttonStyle.normal.background = buttonTexture;

        if (connectionStatus == XBikeEventReceiver.ConnectionStatus.Disconnected)
        {
            if (GUI.Button(new Rect(Screen.width / 2 - buttonWidth / 2, Screen.height - 100.0f, buttonWidth, 40.0f), "Connect", buttonStyle))
            {
                                #if UNITY_EDITOR
                SendMessageForEachListener("OnXBikeConnectionStatusChange", "1");
                                #elif UNITY_ANDROID
                XBikeEventReceiver.Connect();
                                #endif
            }
        }
        else if (connectionStatus == XBikeEventReceiver.ConnectionStatus.Connecting)
        {
            GUI.Label(new Rect(Screen.width / 2 - buttonWidth / 2, Screen.height / 2 - 30.0f, buttonWidth, 40.0f), "Connecting", labelStyle);
            if (GUI.Button(new Rect(Screen.width / 2 - buttonWidth / 2, Screen.height - 100.0f, buttonWidth, 40.0f), "Disconnected", buttonStyle))
            {
                        #if UNITY_EDITOR
                SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
                        #elif UNITY_ANDROID
                XBikeEventReceiver.Disconnect();
                        #endif
            }
        }
        else if (connectionStatus == XBikeEventReceiver.ConnectionStatus.Connected)
        {
            GUI.BeginGroup(new Rect(Screen.width / 2 - buttonWidth / 2, Screen.height - 200.0f, buttonWidth, 100.0f));
            GUILayout.BeginVertical();

            if (sportStatus == XBikeEventReceiver.SportStatus.Stop)
            {
                if (GUILayout.Button("Start sport", buttonStyle))
                {
                    StartSport();
                }
                if (GUILayout.Button("Disconnected", buttonStyle))
                {
                                #if UNITY_EDITOR
                    SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
                                #elif UNITY_ANDROID
                    XBikeEventReceiver.Disconnect();
                                #endif
                }
            }

            /*else if (sportStatus == XBikeEventReceiver.SportStatus.Start)
             * {
             *              if (GUILayout.Button("Pause sport", buttonStyle))
             *      {
             *              PauseSport();
             *      }
             *              if (GUILayout.Button("Stop sport", buttonStyle))
             *      {
             *              StopSport();
             *      }
             *              if (GUILayout.Button("Disconnected", buttonStyle))
             *      {
             #if UNITY_EDITOR
             *              SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
             #elif UNITY_ANDROID
             *              XBikeEventReceiver.Disconnect();
             #endif
             *      }
             * }*/
            else if (sportStatus == XBikeEventReceiver.SportStatus.Pause)
            {
                if (GUILayout.Button("Start sport", buttonStyle))
                {
                    StartSport();
                }
                if (GUILayout.Button("Disconnected", buttonStyle))
                {
                                #if UNITY_EDITOR
                    SendMessageForEachListener("OnXBikeConnectionStatusChange", "0");
                                #elif UNITY_ANDROID
                    XBikeEventReceiver.Disconnect();
                                #endif
                }
            }
            GUILayout.EndVertical();
            GUI.EndGroup();

            if (sportStatus == XBikeEventReceiver.SportStatus.Start)
            {
                // Show current sport data
                //GUI.Label(new Rect(30.0f, 30.0f, 200.0f, Screen.height - 30.0f), XBikeEventReceiver.Data.ToString(), buttonStyle);
                // Show left an buuton status
                //GUI.Label(new Rect(500.0f, 30.0f, 150.0f, 200.0f), "Left Button : " + XBikeEventReceiver.Left.ToString(), style);
                //GUI.Label(new Rect(500.0f, 60.0f, 150.0f, 200.0f), "Right Button : " + XBikeEventReceiver.Right.ToString(), style);

                /*if(GUI.Button(new Rect(Screen.width - 200.0f, 30.0f, buttonWidth, 50.0f), playerMode, buttonStyle)){
                 *      if (playerMode == "划船中") {
                 *              playerMode = "釣魚中";
                 *              Vector3 pos = m_transform.position + rodDistance;
                 *              m_rodTransform.position = pos;
                 *              m_rodTransform.rotation = m_transform.rotation;
                 *              m_rodTransform.eulerAngles += rodInitialAngles;
                 *              m_rod.SetActive (true);
                 *      } else {
                 *              playerMode = "划船中";
                 *              m_rodTransform.Translate (10000, 10000, 10000);
                 *              m_rod.SetActive (false);
                 *      }
                 * }*/
                //GUI.Label (new Rect (Screen.width / 2 - 50.0f, 30.0f, 100.0f, 30.0f), "已經釣到了 " + fishNumber.ToString () + " 隻魚", labelStyle);
                //GUI.Label (new Rect (Screen.width / 2 - 50.0f, 90.0f, 100.0f, 30.0f), "魚餌深度 : " + depth.ToString (), labelStyle);
                //GUI.Label (new Rect (Screen.width / 2 - 50.0f, 150.0f, 100.0f, 30.0f), "捲線速度 : " + reelingSpeed.ToString (), labelStyle);
                //GUI.Label (new Rect (Screen.width - 200.0f, 120.0f, 100.0f, 30.0f), "拋線準備 : " + isRodReady.ToString (), labelStyle);
                //GUI.Label (new Rect (Screen.width - 200.0f, 170.0f, 100.0f, 30.0f), "正在釣魚 : " + isFishing.ToString (), labelStyle);
                //GUI.Label (new Rect (Screen.width - 200.0f, 220.0f, 100.0f, 30.0f), "捲線方向 : " + (int)XBikeEventReceiver.Data.RPMDirection, labelStyle);
                //resistanceValue = GUI.HorizontalSlider(new Rect(Screen.width/2 - 50.0f, 20.0f, 100.0f, 30.0f), resistanceValue, 1.0f, 8.0f);
                //GUI.Label(new Rect(Screen.width/2 - 50.0f, 60.0f, 100.0f, 30.0f), "Resistance Value : " + ((int)resistanceValue).ToString(), labelStyle);

                /*if (GUI.Button(new Rect(Screen.width/2 - 50.0f, 90.0f, 100.0f, 30.0f), "Set resistance"))
                 * {
                 *      XBikeEventReceiver.SetResistance((int)resistanceValue);
                 * }*/
            }
        }
    }