Web报错:路径问题
This commit is contained in:
@ -22,10 +22,12 @@ public class RawImageController : MonoBehaviour
|
||||
path = ImagePath + Name;
|
||||
RawImage = transform.GetChild(0).GetComponent<RawImage>();
|
||||
|
||||
transform.Find("L_Button").GetComponent<Button>().onClick.AddListener(() => {
|
||||
transform.Find("L_Button").GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
ImageController(-1);
|
||||
});
|
||||
transform.Find("R_Button").GetComponent<Button>().onClick.AddListener(() => {
|
||||
transform.Find("R_Button").GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
ImageController(1);
|
||||
});
|
||||
|
||||
@ -33,7 +35,8 @@ public class RawImageController : MonoBehaviour
|
||||
ImageDataUpate();
|
||||
}
|
||||
|
||||
private void ImageController(int index) {
|
||||
private void ImageController(int index)
|
||||
{
|
||||
CurrentIndex += index;
|
||||
int i = CurrentIndex % Images.Count;
|
||||
|
||||
@ -45,25 +48,34 @@ public class RawImageController : MonoBehaviour
|
||||
{
|
||||
ImageUpdate(i);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
ImageUpdate(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void ImageDataUpate() {
|
||||
private void ImageDataUpate()
|
||||
{
|
||||
Images.Clear();
|
||||
|
||||
string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files) {
|
||||
if (file.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) {
|
||||
Images.Add(GetTextureByString(SetImageToString(file)));
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Images.Add(GetTextureByString(SetImageToString(file)));
|
||||
WebRequsetTool.Inst.GetTexture(file, (texture) =>
|
||||
{
|
||||
Images.Add(texture);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ImageController(0);
|
||||
}
|
||||
|
||||
private void ImageUpdate(int i) {
|
||||
private void ImageUpdate(int i)
|
||||
{
|
||||
RawImage.texture = Images[i];
|
||||
}
|
||||
|
||||
@ -91,9 +103,9 @@ public class RawImageController : MonoBehaviour
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,26 @@ public class WebRequsetTool : Singleton<WebRequsetTool>
|
||||
StartCoroutine(PostRequest(url, data, action));
|
||||
}
|
||||
|
||||
public void GetTexture(string url, UnityAction<Texture2D> action)
|
||||
{
|
||||
StartCoroutine(GetRequestTexture(url, action));
|
||||
}
|
||||
|
||||
IEnumerator GetRequestTexture(string url, UnityAction<Texture2D> action)
|
||||
{
|
||||
UnityWebRequest unityWebRequestTexture = UnityWebRequestTexture.GetTexture(url);
|
||||
yield return unityWebRequestTexture.SendWebRequest();
|
||||
|
||||
if (unityWebRequestTexture.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.LogError(unityWebRequestTexture.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
action?.Invoke(DownloadHandlerTexture.GetContent(unityWebRequestTexture));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 完成网络GET请求
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user