私はこのエラーを取得する:Unity ArgumentOutOfRangeException:引数が範囲外です。パラメータ名:I
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: i
System.Text.RegularExpressions.MatchCollection.get_Item (Int32 i)
ServerTime.SplitString (UnityEngine.WWW www) (at Assets/Script/Common/ServerTime.cs:48)
ServerTime+<GetTime>c__IteratorB.MoveNext() (at Assets/Script/Common/ServerTime.cs:31)
エラーリンク:
time = string.Format("{0}:{1}:{2} {3}:{4}:{5}"
マイコード:
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public class ServerTime : MonoBehaviour{
private string url = "http://www.beijing-time.org/time.asp";
private string time = string.Empty;
public delegate void GetTimeBackCall(string time);
private static GetTimeBackCall call;
public void GetServerTime(GetTimeBackCall backCall)
{
call = backCall;
StartCoroutine("GetTime");
}
public IEnumerator GetTime()
{
//Debug.Log("Start Requesting server time");
while (true)
{
WWW www = new WWW(url);
yield return www; //Blocked here, waiting for a response after the return
if (www.isDone && string.IsNullOrEmpty(www.error) && www.text.Length >= 10)
{
SplitString(www);
break;
}
//Debug.Log("Re-request the server time");
}
yield return new WaitForFixedUpdate();
}
private void SplitString(WWW www)
{
//Use regular matching expression
string patten = @"[0-9]{1,};";
Regex regex = new Regex(patten);
MatchCollection result = regex.Matches(www.text);
//Time Organizational
time = string.Format("{0}:{1}:{2} {3}:{4}:{5}"
, result[0].Value.TrimEnd(';')
, result[1].Value.TrimEnd(';')
, result[2].Value.TrimEnd(';')
, result[3].Value.TrimEnd(';')
, result[4].Value.TrimEnd(';')
, result[5].Value.TrimEnd(';')
);
if(time.Length >= 10)
{
call(time);
}
//Debug.Log("EU:" + time);
}
}
エラーから、私はそれが6未満であると思われるから – Dmihawk