Beispiel #1
0
    public override void load(SavableData data)
    {
        if (data is PadData)
        {
            PadData savableData = (PadData)(data);

            gameObject.SetActive(savableData.active);
            ID = savableData.ID;
            transform.position = savableData.pos;
            transform.rotation = savableData.rot;

            if (savableData.testRefID != String.Empty)
            {
                testRef = SavableBehaviour.GetObject(savableData.testRefID)?.GetComponent <RefSerialzationTest>();
            }
            else
            {
                testRef = null;
            }
        }
        else
        {
            Debug.LogError("Passed data is of invalid type");
        }
    }
    /// <summary>
    /// ボタン押下取得
    /// </summary>
    /// <param name="button"></param>
    /// <param name="controlIndex"></param>
    /// <returns></returns>
    public static bool GetPress(Button button, Index controlIndex = Index.Active)
    {
        if (controlIndex == Index.Any)
        {
            for (int iPad = 0; iPad < (int)Index.Num; iPad++)
            {
                PadData p = instance.padData[(int)iPad];
                if (p.Now[(int)button] == true)
                {
                    return(true);
                }
            }
            return(false);
        }
        else if (controlIndex == Index.Active)
        {
            controlIndex = (Index)instance.ActivePadIndex;
        }

        //string code = GetButtonName(button, controlIndex);
        //return Input.GetButton(code);

        PadData pad = instance.padData[(int)controlIndex];

        return(pad.Now[(int)button] == true);
    }
    private void UpdateX360(ref PadData pad, Index iPad, Button button)
    {
        // L2/R2がアナログなので。。。
        switch (button)
        {
        case Button.LT:
        {
            if (GetAxis(Axis.LRTrigger, (Index)iPad).y > 0.5f)
            {
                pad.Now[(int)Button.LT] = true;
            }
            else
            {
                pad.Now[(int)Button.LT] = false;
            }
        }
        break;

        case Button.RT:
        {
            if (GetAxis(Axis.LRTrigger, (Index)iPad).y < -0.5f)
            {
                pad.Now[(int)Button.RT] = true;
            }
            else
            {
                pad.Now[(int)Button.RT] = false;
            }
        }
        break;
        }
    }
Beispiel #4
0
        static TestArrowData()
        {
            var spPadDataTask = PadData.LoadPadData("dance-single", "dance-single.json");
            var dpPadDataTask = PadData.LoadPadData("dance-double", "dance-double.json");

            Task.WaitAll(spPadDataTask, dpPadDataTask);
            SPPadData = spPadDataTask.Result;
            DPPadData = dpPadDataTask.Result;
        }
Beispiel #5
0
    public override SavableData save()
    {
        PadData savableData = new PadData();

        savableData.ID     = SavableBehaviour.GetID(this);
        savableData.active = gameObject.activeSelf;
        savableData.pos    = transform.position;
        savableData.rot    = transform.rotation;

        SavableBehaviour testRefSavable = testRef?.GetComponent <SavableBehaviour>();

        if (testRefSavable != null)
        {
            savableData.testRefID = testRefSavable.ID;
        }
        else
        {
            savableData.testRefID = System.String.Empty;
        }

        return(savableData);
    }
    /// <summary>
    /// ボタントリガー取得(押し始め)
    /// </summary>
    /// <param name="button"></param>
    /// <param name="controlIndex"></param>
    /// <returns></returns>
    public static bool GetTrigger(Button button, Index controlIndex = Index.Active)
    {
        if (controlIndex == Index.Any)
        {
            for (int iPad = 0; iPad < (int)Index.Num; iPad++)
            {
                PadData p = instance.padData[(int)iPad];
                if (p.Prev[(int)button] == false && p.Now[(int)button] == true)
                {
                    return(true);
                }
            }
            return(false);
        }
        else if (controlIndex == Index.Active)
        {
            controlIndex = (Index)instance.ActivePadIndex;
        }

        PadData pad = instance.padData[(int)controlIndex];

        return(pad.Prev[(int)button] == false && pad.Now[(int)button] == true);
    }
    /// <summary>
    /// returns a specified axis
    /// </summary>
    /// <param name="axis">One of the analogue sticks, or the dpad</param>
    /// <param name="controlIndex">The controller number</param>
    /// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param>
    /// <returns></returns>
    public static Vector2 GetAxis(Axis axis, Index controlIndex = Index.Active, bool raw = false)
    {
        if (controlIndex == Index.Active)
        {
            controlIndex = (Index)instance.ActivePadIndex;
        }


        PadData pad = instance.padData[(int)controlIndex];

        string xName = "", yName = "";

        switch (axis)
        {
        case Axis.POV:
            xName = "Player" + (int)controlIndex + "_DX" + pad.PovX;
            yName = "Player" + (int)controlIndex + "_DY" + pad.PovY;
            break;

        case Axis.LeftStick:
            xName = "Player" + (int)controlIndex + "_LX";
            yName = "Player" + (int)controlIndex + "_LY";
            break;

        case Axis.RightStick:
            xName = "Player" + (int)controlIndex + "_RX" + pad.RightAxisX;
            yName = "Player" + (int)controlIndex + "_RY" + pad.RightAxisY;
            break;

        case Axis.LRTrigger:
            xName = "Player" + (int)controlIndex + "_LRTrigger" + pad.LRTriggerAxis;
            yName = "Player" + (int)controlIndex + "_LRTrigger" + pad.LRTriggerAxis;
            break;
        }

        Vector2 axisXY = Vector3.zero;

        try
        {
            if (raw == false)
            {
                axisXY.x = Input.GetAxis(xName);
                if (axis == Axis.POV)
                {
                    axisXY.y = -Input.GetAxis(yName);
                }
                else
                {
                    axisXY.y = Input.GetAxis(yName);
                }
                // todo:ズレ補正

                /*
                 * if (axis == Axis.LeftStick)
                 * {
                 *      axisXY -= pad.LAxisOffset;
                 * }
                 * else if (axis == Axis.RightStick)
                 * {
                 *      axisXY -= pad.RAxisOffset;
                 * }
                 */

                // デッド・ゾーン

                /*
                 * if (axis == Axis.LeftStick)
                 * {
                 *      if (Mathf.Abs(axisXY.x) < Mathf.Abs(pad.LAxisOffset.x) + DEAD_ZONE)
                 *      {
                 *              axisXY.x = 0;
                 *      }
                 *      if (Mathf.Abs(axisXY.y) < Mathf.Abs(pad.LAxisOffset.y) + DEAD_ZONE)
                 *      {
                 *              axisXY.y = 0;
                 *      }
                 * }
                 * if (axis == Axis.RightStick)
                 * {
                 *      if (Mathf.Abs(axisXY.x) < Mathf.Abs(pad.RAxisOffset.x) + DEAD_ZONE)
                 *      {
                 *              axisXY.x = 0;
                 *      }
                 *      if (Mathf.Abs(axisXY.y) < Mathf.Abs(pad.RAxisOffset.y) + DEAD_ZONE)
                 *      {
                 *              axisXY.y = 0;
                 *      }
                 * }
                 */

                if (axis == Axis.LeftStick || axis == Axis.RightStick)
                {
                    // 360パッド等はY軸のUP方向の移動量が少なくて綺麗な円にならないので補正
                    //if (pad.isXbox)
                    {
                        axisXY.y *= 1.2f;
                    }


                    // 極座標変換 + デッドゾーン処理(非線形)
                    //http://www.kawaz.org/blogs/isekaf/2013/12/23/564/
                    float angle = Mathf.Atan2(axisXY.y, axisXY.x);
                    float power = Mathf.Sqrt(Mathf.Pow(axisXY.x, 2) + Mathf.Pow(axisXY.y, 2));

                    //power = power * power;
                    // デッドゾーン
                    if (power < 0.15f)
                    {
                        power = 0.0f;
                    }

                    axisXY = new Vector2(power * Mathf.Cos(angle), power * Mathf.Sin(angle));



                    if (power > 1.0f)
                    {
                        axisXY /= axisXY.magnitude;
                    }
                }
            }
            else
            {
                axisXY.x = Input.GetAxis(xName);

                if (axis == Axis.POV)
                {
                    axisXY.y = -Input.GetAxis(yName);
                }
                else
                {
                    axisXY.y = Input.GetAxis(yName);
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
            Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
        }
        return(axisXY);
    }
    /// <summary>
    /// 定期更新
    /// </summary>
    public void Update()
    {
        for (int iPad = 0; iPad < (int)Index.Num; iPad++)
        {
            PadData pad = padData[(int)iPad];

            for (int button = 0; button < (int)Button.MAX; button++)
            {
                pad.Prev[button] = pad.Now[button];

                // ボタンチェック
                int convButton = pad.ConvTable[button];
                if (GetRawButton(convButton, (Index)iPad))
                {
                    pad.Now[button] = true;
                }
                else
                {
                    pad.Now[button] = false;
                }

                //---------------------------
                // Xbox360コントローラ固有
                //---------------------------
                if (pad.isXbox == true)
                {
                    UpdateX360(ref pad, (Index)iPad, (Button)button);
                }


                // 左スティックを方向キーとして使う
                // L2/R2がアナログなので。。。
                const float StickSlide = 0.5f;
                switch ((Button)button)
                {
                case Button.UP:
                    if (GetAxis(Axis.LeftStick, (Index)iPad).y <= -StickSlide ||
                        GetAxis(Axis.POV, (Index)iPad).y <= -StickSlide)
                    {
                        pad.Now[(int)Button.UP] = true;
                    }
                    else
                    {
                        pad.Now[(int)Button.UP] = false;
                    }
                    break;

                case Button.DOWN:
                    if (GetAxis(Axis.LeftStick, (Index)iPad).y >= StickSlide ||
                        GetAxis(Axis.POV, (Index)iPad).y >= StickSlide)
                    {
                        pad.Now[(int)Button.DOWN] = true;
                    }
                    else
                    {
                        pad.Now[(int)Button.DOWN] = false;
                    }
                    break;

                case Button.LEFT:
                    if (GetAxis(Axis.LeftStick, (Index)iPad).x <= -StickSlide ||
                        GetAxis(Axis.POV, (Index)iPad).x <= -StickSlide)
                    {
                        pad.Now[(int)Button.LEFT] = true;
                    }
                    else
                    {
                        pad.Now[(int)Button.LEFT] = false;
                    }
                    break;

                case Button.RIGHT:

                    if (GetAxis(Axis.LeftStick, (Index)iPad).x >= StickSlide ||
                        GetAxis(Axis.POV, (Index)iPad).x >= StickSlide)
                    {
                        pad.Now[(int)Button.RIGHT] = true;
                    }
                    else
                    {
                        pad.Now[(int)Button.RIGHT] = false;
                    }
                    break;
                }

                // ボタンを押してたら履歴に入れる
                if (pad.Now[button] == true && pad.Prev[button] != true)
                {
                    pad.PadHistory.Enqueue((Button)button);
                    if (pad.PadHistory.Count > 32)
                    {
                        pad.PadHistory.Dequeue();
                    }
                }


                //---------------------------
                // キーリピート処理
                //---------------------------
                pad.Repeat[button] = false;
                if (pad.Prev[button] == false && pad.Now[button] == true)
                {
                    pad.RepeatWait[button] = REPEAT_WAIT;
                    pad.Repeat[button]     = true;
                }
                else if (pad.Prev[button] == true && pad.Now[button] == true)
                {
                    pad.RepeatWait[button] -= Time.deltaTime;
                    if (pad.RepeatWait[button] < 0.0f)
                    {
                        pad.RepeatWait[button] = REPEAT_INTERVAL;
                        pad.Repeat[button]     = true;
                    }
                }
                else if (pad.Prev[button] == false && pad.Now[button] == false)
                {
                    pad.RepeatWait[button] = 0;
                    pad.Repeat[button]     = false;
                }
            }
        }


        //Debug.Log("Update");
    }
    // Use this for initialization
    void Start()
    {
        // 設定取得
        ActivePadIndex = PlayerPrefs.GetInt("ActivePad");


        string[] JoyName = Input.GetJoystickNames();

        for (int iPad = 0; iPad < (int)Index.Num; iPad++)
        {
            padData[iPad] = new PadData();
            PadData p = padData[iPad];

            for (int i = 0; i < (int)Axis.MAX - 1; i++)
            {
                p.posHistory[i] = new PadData.PosHistory();
            }


            // とりあえず連番で初期化
            for (int ibtn = 0; ibtn < (int)Button.MAX; ibtn++)
            {
                p.ConvTable[ibtn] = ibtn;
            }

            //try
            {
                if (iPad > JoyName.Length - 1)
                {
                    continue;
                }
                p.JoyStickName = JoyName[iPad];



                p.RightAxisX = PlayerPrefs.GetString(p.JoyStickName + "_RightAxisX");
                p.RightAxisY = PlayerPrefs.GetString(p.JoyStickName + "_RightAxisY");
                p.PovX       = PlayerPrefs.GetString(p.JoyStickName + "_PovX");
                p.PovY       = PlayerPrefs.GetString(p.JoyStickName + "_PovY");

                p.RAxisOffset.x = PlayerPrefs.GetFloat(p.JoyStickName + "_RightAxisX_off");
                p.RAxisOffset.y = PlayerPrefs.GetFloat(p.JoyStickName + "_RightAxisY_off");
                p.LAxisOffset.x = PlayerPrefs.GetFloat(p.JoyStickName + "_LeftAxisX_off");
                p.LAxisOffset.y = PlayerPrefs.GetFloat(p.JoyStickName + "_LeftAxisY_off");

                // 変換テーブル
                if (PlayerPrefs.HasKey(p.JoyStickName + "_" + Enum.GetName(typeof(Button), 0)))
                {
                    Debug.Log("パッド変換テーブル見っけ");

                    for (int i = 0; i < (int)Button.MAX; i++)
                    {
                        p.ConvTable[i] = PlayerPrefs.GetInt(p.JoyStickName + "_" + Enum.GetName(typeof(Button), i));
                    }
                }


                if (PlayerPrefs.GetInt(p.JoyStickName + "_isXbox") == 0)
                {
                    // 初回
                    // 360コントローラを名前で判定
                    if (p.JoyStickName.IndexOf("XBOX 360") >= 0)
                    {
                        p.isXbox = true;
                    }
                }
                else
                {
                    p.isXbox = PlayerPrefs.GetInt(p.JoyStickName + "_isXbox") == 2;
                }
            }
            //catch (Exception ex)
            {
                //	Debug.Log(ex.Message);
            }
        }
    }
Beispiel #10
0
        // Download and display the Pad Data
        private void GetPadData()
        {
            // Get pad Data
            uri    = new System.Uri("http://player.xmradio.com/padData/pad_data_servlet.jsp?all_channels=true&remote=true");
            webreq = (HttpWebRequest)WebRequest.Create(uri);
            webreq.CookieContainer = xmCookies;
            // Get the response
            try
            {
                webres    = (HttpWebResponse)webreq.GetResponse();
                resStream = webres.GetResponseStream();
                response  = new StreamReader(resStream).ReadToEnd();
            }
            catch (System.Net.WebException e)
            {
                SnapStream.Logging.WriteLog(e.ToString());
                _header.Text = "Login Error";
                loggedin     = false;
            }

            try
            {
                // Get channels and pad data
                string whatson = response.Substring(response.IndexOf("{"));
                whatson = whatson.Replace("{", "");
                whatson = whatson.Replace("}", "");
                whatson = whatson.Replace(")", "");
                whatson = whatson.Replace("]", "");
                whatson = whatson.Replace(";", "");
                string[] pdata = whatson.Split('"');
                padDataList = new ArrayList();
                for (int i = 0; i < pdata.Length - 1; i = i + 6)
                {
                    PadData  cPadData = new PadData();
                    string   temp     = pdata[i].Substring(pdata[i].IndexOf(':') + 1);
                    string[] tempA    = temp.Split(',');
                    cPadData.Channel = int.Parse(tempA[0].Trim());                     // channel
                    cPadData.Artist  = replaceAscii(pdata[i + 1].Trim());              // artist
                    cPadData.Song    = replaceAscii(pdata[i + 3].Trim());              // song
                    cPadData.Album   = replaceAscii(pdata[i + 5].Trim());              // album
                    padDataList.Add(cPadData);

                    // Update header if playing
                    if (wmp.playState == WMPLib.WMPPlayState.wmppsPlaying)
                    {
                        if (currentChannel == cPadData.Channel)
                        {
                            _header.Text      = "Playing: " + cPadData.Song;
                            _header2.Text     = "   " + cPadData.Artist + " (" + cPadData.Album + ")";
                            _logo2.Background = fi.DirectoryName + "\\Images\\" + cPadData.Channel.ToString() + ".png";
                        }
                    }
                    else if (wmp.playState == WMPLib.WMPPlayState.wmppsBuffering)
                    {
                        _header.Text      = "Buffering";
                        _header2.Text     = "";
                        _logo2.Background = fi.DirectoryName + "\\Images\\" + "blackpixel.png";
                    }
                    else if (wmp.playState == WMPLib.WMPPlayState.wmppsTransitioning)
                    {
                        _header.Text      = "Changing Channels";
                        _header2.Text     = "";
                        _logo2.Background = fi.DirectoryName + "\\Images\\" + "blackpixel.png";
                    }
                    else
                    {
                        _header.Text      = "";
                        _header2.Text     = "";
                        _logo2.Background = fi.DirectoryName + "\\Images\\" + "blackpixel.png";
                    }
                }
            }
            catch (Exception e)
            {
                SnapStream.Logging.WriteLog("XMRadio: " + e.ToString());
            }
            // Sort the channels
            padDataList.Sort(new PadDataComparer());
        }
        // Download and display the Pad Data
        private void GetPadData()
        {
            // Get pad Data
            uri = new System.Uri("http://player.xmradio.com/padData/pad_data_servlet.jsp?all_channels=true&remote=true");
            webreq = (HttpWebRequest)WebRequest.Create(uri);
            webreq.CookieContainer = xmCookies;
            // Get the response
            try
            {
                webres = (HttpWebResponse)webreq.GetResponse();
                resStream = webres.GetResponseStream();
                response = new StreamReader( resStream ).ReadToEnd();
            }
            catch (System.Net.WebException e)
            {
                SnapStream.Logging.WriteLog(e.ToString());
                _header.Text = "Login Error";
                loggedin = false;
            }

            try
            {
                // Get channels and pad data
                string whatson = response.Substring(response.IndexOf("{"));
                whatson = whatson.Replace("{","");
                whatson = whatson.Replace("}","");
                whatson = whatson.Replace(")","");
                whatson = whatson.Replace("]","");
                whatson = whatson.Replace(";","");
                string[] pdata = whatson.Split('"');
                padDataList = new ArrayList();
                for (int i = 0; i < pdata.Length-1; i = i + 6)
                {
                    PadData cPadData = new PadData();
                    string temp = pdata[i].Substring(pdata[i].IndexOf(':')+1);
                    string[] tempA = temp.Split(',');
                    cPadData.Channel = int.Parse(tempA[0].Trim()); // channel
                    cPadData.Artist = replaceAscii(pdata[i+1].Trim()); // artist
                    cPadData.Song = replaceAscii(pdata[i+3].Trim()); // song
                    cPadData.Album = replaceAscii(pdata[i+5].Trim()); // album
                    padDataList.Add(cPadData);

                    // Update header if playing
                    if (wmp.playState == WMPLib.WMPPlayState.wmppsPlaying)
                    {
                        if (currentChannel == cPadData.Channel)
                        {
                            _header.Text = "Playing: " + cPadData.Song;
                            _header2.Text = "   " + cPadData.Artist + " (" + cPadData.Album + ")";
                            _logo2.Background = fi.DirectoryName + "\\Images\\" + cPadData.Channel.ToString() + ".png";
                        }
                    }
                    else if (wmp.playState == WMPLib.WMPPlayState.wmppsBuffering)
                    {
                        _header.Text = "Buffering";
                        _header2.Text = "";
                        _logo2.Background = fi.DirectoryName + "\\Images\\" + "blackpixel.png";
                    }
                    else if (wmp.playState == WMPLib.WMPPlayState.wmppsTransitioning)
                    {
                        _header.Text = "Changing Channels";
                        _header2.Text = "";
                        _logo2.Background = fi.DirectoryName + "\\Images\\" + "blackpixel.png";
                    }
                    else
                    {
                        _header.Text = "";
                        _header2.Text = "";
                        _logo2.Background = fi.DirectoryName + "\\Images\\" + "blackpixel.png";
                    }
                }
            }
            catch (Exception e)
            {
                SnapStream.Logging.WriteLog("XMRadio: " + e.ToString());
            }
            // Sort the channels
            padDataList.Sort( new PadDataComparer() );
        }
 public void Init(Pad pad, PadData data)
 {
     this.pad  = pad;
     this.data = data;
 }