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.
180 lines
5.9 KiB
180 lines
5.9 KiB
1 year ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using UniRx;
|
||
|
using AX.ImageViewer;
|
||
|
|
||
|
public class EquipmentRoomAttributePanel : UIView<EquipmentRoom,EquipmentRoomReactive>
|
||
|
{
|
||
|
//名称
|
||
|
public Text NameText;
|
||
|
public InputField NameInput;
|
||
|
//位置
|
||
|
public Text LocationText;
|
||
|
public InputField LocationInput;
|
||
|
//详情
|
||
|
public Text DetailsText;
|
||
|
public InputField DetailsInput;
|
||
|
//图片类型
|
||
|
public OriginalImageType ImageType;
|
||
|
//图片面板
|
||
|
public Image ImagePanel;
|
||
|
//全景开关
|
||
|
public Toggle ImageTypeToggle;
|
||
|
//查看原图
|
||
|
public Button ViewButton;
|
||
|
public OpenImage OpenImageFile;
|
||
|
//保存按钮
|
||
|
public Button SaveButton;
|
||
|
|
||
|
private string PostUrl;
|
||
|
private string GetUrl;
|
||
|
public override void Awake()
|
||
|
{
|
||
|
base.Awake();
|
||
|
#region DataSource Bind
|
||
|
//名称
|
||
|
DataSource.Name.SubscribeToText(NameText).AddTo(gameObject);
|
||
|
DataSource.Name.SubscribeToText(NameInput).AddTo(gameObject);
|
||
|
NameInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Name.Value = s);
|
||
|
//位置
|
||
|
DataSource.Location.SubscribeToText(LocationText).AddTo(gameObject);
|
||
|
DataSource.Location.SubscribeToText(LocationInput).AddTo(gameObject);
|
||
|
LocationInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Location.Value = s);
|
||
|
//详情
|
||
|
DataSource.Details.SubscribeToText(DetailsText).AddTo(gameObject);
|
||
|
DataSource.Details.SubscribeToText(DetailsInput).AddTo(gameObject);
|
||
|
DetailsInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Details.Value = s);
|
||
|
//图片类型
|
||
|
DataSource.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 =>
|
||
|
{
|
||
|
DataSource.ImageType.Value = b ? OriginalImageType.Panorama : OriginalImageType.Normal;
|
||
|
}).AddTo(gameObject);
|
||
|
#endregion
|
||
|
#region Button Click
|
||
|
//保存
|
||
|
SaveButton.onClick.AsObservable().Subscribe(onClick =>
|
||
|
{
|
||
|
SaveData();
|
||
|
}).AddTo(gameObject);
|
||
|
//查看原图
|
||
|
ViewButton.onClick.AsObservable().Subscribe(onClick =>
|
||
|
{
|
||
|
ViewImage();
|
||
|
}).AddTo(gameObject);
|
||
|
//上传图片
|
||
|
OpenImageFile.OnLoadTextureFinished = texture =>
|
||
|
{
|
||
|
UploadImage(texture);
|
||
|
};
|
||
|
|
||
|
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
|
||
|
.Subscribe(_ => Hide());
|
||
|
#endregion
|
||
|
}
|
||
|
public override void Show()
|
||
|
{
|
||
|
base.Show();
|
||
|
ImagePanel.sprite = AssetManager.Instance.DefaultSprite;
|
||
|
switch (EquipmentManager.Instance.CreationType)
|
||
|
{
|
||
|
case EquipmentType.FireControlRoom:
|
||
|
PostUrl= string.Format(HttpManager.Instance.PostFireControlRoomsById, DataSource.Id);
|
||
|
GetUrl= string.Format(HttpManager.Instance.GetFireControlRoomsById, DataSource.Id);
|
||
|
break;
|
||
|
case EquipmentType.PumpRoomAndWaterTank:
|
||
|
PostUrl = string.Format(HttpManager.Instance.PostPumpRoomsById, DataSource.Id);
|
||
|
GetUrl = string.Format(HttpManager.Instance.GetPumpRoomsById, DataSource.Id);
|
||
|
break;
|
||
|
}
|
||
|
LoadData();
|
||
|
GetComponent<AttributePanelControl>().ResetPanel();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 加载数据
|
||
|
/// <summary>
|
||
|
private void LoadData()
|
||
|
{
|
||
|
Debug.Log(GetUrl);
|
||
|
//string url = string.Format(HttpManager.Instance.GetFireControlRoomsById,DataSource.Id);
|
||
|
HttpManager.Instance.Get<EquipmentRoom>(GetUrl, d =>
|
||
|
{
|
||
|
DataSource.SetData(d);
|
||
|
GetImage();
|
||
|
});
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 保存数据
|
||
|
/// <summary>
|
||
|
private void SaveData()
|
||
|
{
|
||
|
//string url = string.Format(HttpManager.Instance.PostFireControlRoomsById, DataSource.Id);
|
||
|
HttpManager.Instance.Post(PostUrl, DataSource.GetData());
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 上传图片
|
||
|
/// <summary>
|
||
|
private void UploadImage(Texture2D texture)
|
||
|
{
|
||
|
HttpManager.Instance.PostImage($"{ DataSource.Id}.jpg", texture, a =>
|
||
|
{
|
||
|
DataSource.ImageUrl.Value = a?.ObjectName;
|
||
|
});
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取图片
|
||
|
/// <summary>
|
||
|
private void GetImage()
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(DataSource.ImageUrl.Value))
|
||
|
{
|
||
|
Debug.Log(DataSource.ImageUrl.Value);
|
||
|
HttpManager.Instance.GetImage($"{ DataSource.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;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 查看原图
|
||
|
/// <summary>
|
||
|
private void ViewImage()
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(DataSource.ImageUrl.Value))
|
||
|
{
|
||
|
HttpManager.Instance.GetImage(DataSource.ImageUrl.Value, texture =>
|
||
|
{
|
||
|
switch (DataSource.ImageType.Value)
|
||
|
{
|
||
|
case OriginalImageType.Normal:
|
||
|
ImageViewer.Load(texture);
|
||
|
break;
|
||
|
case OriginalImageType.Panorama:
|
||
|
PanoramicViewer.Load(texture);
|
||
|
break;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
MessageBox.Show("未上传图片!", Color.white, 3f);
|
||
|
}
|
||
|
}
|
||
|
}
|