上海虹口龙之梦项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

138 lines
3.9 KiB

using UnityEngine;
using UnityEngine.UI;
using UniRx;
using AX.ImageViewer;
public class AdjacentImagePanel : UIView
{
public Text TitleText;
public Orientation orientation;
//图片类型
public OriginalImageType ImageType;
//图片面板
public Image ImagePanel;
//全景开关
public Toggle ImageTypeToggle;
//查看原图
public Button ViewButton;
public OpenImage OpenImageFile;
//保存按钮
public Button SaveButton;
public BuildingAdjacentReactive Data;
public override void Awake()
{
base.Awake();
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
.Subscribe(_ => Hide());
}
public void OnRefresh()
{
Data = UIManager.Instance.GetView<AdjacentInfoPanel>().Data.Find(item => item.Id.Value == orientation.ToString());
Data.ImageType.Subscribe(data =>
{
switch (data)
{
case OriginalImageType.Normal:
ImageTypeToggle.isOn = false;
break;
case OriginalImageType.Panorama:
ImageTypeToggle.isOn = true;
break;
}
}).AddTo(gameObject);
ImageTypeToggle.OnValueChangedAsObservable().Subscribe(b =>
{
Data.ImageType.Value = b ? OriginalImageType.Panorama : OriginalImageType.Normal;
}).AddTo(gameObject);
//ImageTypeToggle.onValueChanged.RemoveAllListeners();
//查看原图
ViewButton.onClick.AsObservable().Subscribe(onClick =>
{
ViewImage();
});
//上传图片
OpenImageFile.OnLoadTextureFinished = texture =>
{
UploadImage(texture);
};
//保存
SaveButton.onClick.AsObservable().Subscribe(onClick =>
{
SaveData();
}).AddTo(gameObject);
LoadData();
}
public void SaveData()
{
string url = string.Format(HttpManager.Instance.PostBuildingAdjoinsById, Data.Id.Value);
HttpManager.Instance.Post(url, Data.GetData());
}
public void UploadImage(Texture2D texture)
{
HttpManager.Instance.PostImage($"Adjoin{orientation}.jpg", texture, a =>
{
Data.ImageUrl.Value = a?.ObjectName;
});
}
public void LoadData()
{
string url = string.Format(HttpManager.Instance.GetBuildingAdjoinsById, Data.Id.Value);
HttpManager.Instance.Get<BuildingAdjacent>(url, d =>
{
Data.SetData(d);
GetImage();
});
}
public void GetImage()
{
if (!string.IsNullOrEmpty(Data.ImageUrl.Value))
{
//HttpManager.Instance.GetImage($"{ Data.ImageUrl.Value}?x-image-process=image/resize,m_lfit,h_200,w_300", texture =>
HttpManager.Instance.GetImage($"{ Data.ImageUrl.Value}?x-oss-process=image/resize,h_200", texture =>
{
ImagePanel.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
ImagePanel.preserveAspect = true;
});
}
else
{
ImagePanel.sprite = AssetManager.Instance.DefaultSprite;
}
}
public void ViewImage()
{
if (!string.IsNullOrEmpty(Data.ImageUrl.Value))
{
HttpManager.Instance.GetImage(Data.ImageUrl.Value, texture =>
{
switch (Data.ImageType.Value)
{
case OriginalImageType.Normal:
ImageViewer.Load(texture);
break;
case OriginalImageType.Panorama:
PanoramicViewer.Load(texture);
break;
}
});
}
else
{
MessageBox.Show("未上传图片!", Color.white, 3f);
}
}
}