188 lines
5.7 KiB
C#
188 lines
5.7 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.EventSystems;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System;
|
|||
|
using Module.Log;
|
|||
|
|
|||
|
[RequireComponent(typeof(Image))]
|
|||
|
public class NetDoubleImage : NetImage
|
|||
|
{
|
|||
|
|
|||
|
#region
|
|||
|
private string _LargeImageUrl;
|
|||
|
public string LargeImageUrl
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _LargeImageUrl;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
_LargeImageUrl = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private Texture2D _LargeTexture;
|
|||
|
public Texture2D LargeTexture
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _LargeTexture;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private ulong _PlayerGuid;
|
|||
|
public ulong PlayerGuid
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _PlayerGuid;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SetNetImage(string netImageUrl, string largeImageUrl, ulong playerGuid)
|
|||
|
{
|
|||
|
_PlayerGuid = playerGuid;
|
|||
|
_LargeImageUrl = largeImageUrl;
|
|||
|
_NetImageUrl = netImageUrl;
|
|||
|
|
|||
|
_Image.enabled = false;
|
|||
|
LoadTexture(netImageUrl, SetNetImage, playerGuid, false);
|
|||
|
}
|
|||
|
|
|||
|
public override void SetNetImage(Texture2D cuttedImage, IMAGE_CHECK_STATE imgState)
|
|||
|
{
|
|||
|
if (_ImageChecking != null)
|
|||
|
{
|
|||
|
_ImageChecking.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
if (cuttedImage != null)
|
|||
|
{
|
|||
|
_Image.enabled = true;
|
|||
|
_LargeTexture = cuttedImage;
|
|||
|
|
|||
|
//_NetTexture = GameObject.Instantiate(cuttedImage);
|
|||
|
//_NetTexture.Resize(128, 128);
|
|||
|
//_NetTexture.Apply();
|
|||
|
|
|||
|
_NetTexture = new Texture2D((int)_Image.rectTransform.sizeDelta.x, (int)_Image.rectTransform.sizeDelta.y);
|
|||
|
int minPos = 0;
|
|||
|
int maxPosX = cuttedImage.width - 1;
|
|||
|
int maxPos = cuttedImage.height - 1;
|
|||
|
float rateX = cuttedImage.width / _Image.rectTransform.sizeDelta.x;
|
|||
|
float rateY = cuttedImage.height / _Image.rectTransform.sizeDelta.y;
|
|||
|
for (int i = 0; i < _NetTexture.width; ++i)
|
|||
|
{
|
|||
|
for (int j = 0; j < _NetTexture.height; ++j)
|
|||
|
{
|
|||
|
int sampleX = Mathf.Clamp((int)(i * rateX), minPos, maxPosX);
|
|||
|
int sampleY = Mathf.Clamp((int)(j * rateY), minPos, maxPosX);
|
|||
|
_NetTexture.SetPixel(i, j, _LargeTexture.GetPixel(sampleX, sampleY));
|
|||
|
}
|
|||
|
}
|
|||
|
_NetTexture.Apply();
|
|||
|
|
|||
|
_Image.sprite = Sprite.Create(_NetTexture, new Rect(0, 0, _Image.rectTransform.sizeDelta.x, _Image.rectTransform.sizeDelta.y), new Vector2(0.5f, 0.5f));
|
|||
|
if (imgState == IMAGE_CHECK_STATE.CHECKING && _ImageChecking != null)
|
|||
|
{
|
|||
|
_ImageChecking.gameObject.SetActive(true);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ImageChecking, "ImageChecking2");
|
|||
|
//_Image.sprite = null;
|
|||
|
}
|
|||
|
else if (imgState == IMAGE_CHECK_STATE.BACK)
|
|||
|
{
|
|||
|
_ImageChecking.gameObject.SetActive(true);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ImageChecking, "ImageChecking3");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (imgState == IMAGE_CHECK_STATE.CHECKING && _ImageChecking != null)
|
|||
|
{
|
|||
|
_ImageChecking.gameObject.SetActive(true);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ImageChecking, "ImageChecking1");
|
|||
|
_Image.sprite = null;
|
|||
|
}
|
|||
|
else if (imgState == IMAGE_CHECK_STATE.BACK)
|
|||
|
{
|
|||
|
_ImageChecking.gameObject.SetActive(true);
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ImageChecking, "ImageChecking3");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void CleanUpImage()
|
|||
|
{
|
|||
|
base.CleanUpImage();
|
|||
|
|
|||
|
_LargeImageUrl = "";
|
|||
|
_LargeTexture = null;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region
|
|||
|
|
|||
|
private static List<NetDoubleImage> _UploadingImage;
|
|||
|
private static int _UploadSucessCnt = 0;
|
|||
|
|
|||
|
public static void UploadBlogPic(List<NetDoubleImage> uploadImages, UploadCallBack uploadSucess, UploadCallBack uploadFail)
|
|||
|
{
|
|||
|
_UploadSucessCnt = 0;
|
|||
|
_UploadingImage = uploadImages;
|
|||
|
_UploadSucess = uploadSucess;
|
|||
|
_UploadFail = uploadFail;
|
|||
|
|
|||
|
List<Texture2D> textures = new List<Texture2D>();
|
|||
|
for (int i = 0; i < _UploadingImage.Count; ++i)
|
|||
|
{
|
|||
|
textures.Add(_UploadingImage[i].NetTexture);
|
|||
|
textures.Add(_UploadingImage[i].LargeTexture);
|
|||
|
}
|
|||
|
_UploadingImage[0].StartCoroutine(UploadImage(textures, false));
|
|||
|
|
|||
|
//CG_REQ_ALLOC_BLOG_PIC_FILE_NAME packet = (CG_REQ_ALLOC_BLOG_PIC_FILE_NAME)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ALLOC_BLOG_PIC_FILE_NAME);
|
|||
|
//packet.Count = uploadImages.Count * 2;
|
|||
|
//packet.SendPacket();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public static void RetBlogPicName(GC_RET_ALLOC_BLOG_PIC_FILE_NAME packet)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//private static IEnumerator UploadImages(List<Texture2D> uploadImage, string url)
|
|||
|
//{
|
|||
|
|
|||
|
// WWWForm form = new WWWForm();
|
|||
|
// for (int i = 0; i < uploadImage.Count; ++i)
|
|||
|
// {
|
|||
|
// byte[] bytes = uploadImage[i].EncodeToPNG();
|
|||
|
// form.AddBinaryData("FileUpLoad", bytes, fileName[i], "image/png");
|
|||
|
// }
|
|||
|
|
|||
|
// // Upload to a cgi script
|
|||
|
// WWW w = new WWW(url, form);
|
|||
|
// yield return w;
|
|||
|
// if (!string.IsNullOrEmpty(w.error))
|
|||
|
// {
|
|||
|
// if (_UploadFail != null)
|
|||
|
// _UploadFail.Invoke();
|
|||
|
// print(w.error);
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// if (_UploadSucess != null)
|
|||
|
// _UploadSucess.Invoke();
|
|||
|
// print("Finished Uploading Screenshot");
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|