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.
239 lines
8.2 KiB
239 lines
8.2 KiB
1 year ago
|
using AX.ImageViewer;
|
||
|
using UniRx;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class EquipmentAttributePanel : UIView<CloneObject,CloneObjectReactive>
|
||
|
{
|
||
|
//标题
|
||
|
public Text TitleText;
|
||
|
//位置
|
||
|
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;
|
||
|
|
||
|
public GameObject ControllerPanel;
|
||
|
public Toggle ControlTogle;
|
||
|
public Slider ControlSizeSlider;
|
||
|
|
||
|
private string url;
|
||
|
public override void Awake()
|
||
|
{
|
||
|
base.Awake();
|
||
|
#region DataSource Bind
|
||
|
DataSource.Address.SubscribeToText(LocationText).AddTo(gameObject);
|
||
|
DataSource.Address.SubscribeToText(LocationInput).AddTo(gameObject);
|
||
|
DataSource.Discription.SubscribeToText(DetailsText).AddTo(gameObject);
|
||
|
DataSource.Discription.SubscribeToText(DetailsInput).AddTo(gameObject);
|
||
|
DataSource.ImageType.Subscribe(data =>
|
||
|
{
|
||
|
switch (data)
|
||
|
{
|
||
|
case OriginalImageType.Normal:
|
||
|
ImageTypeToggle.isOn = false;
|
||
|
break;
|
||
|
case OriginalImageType.Panorama:
|
||
|
ImageTypeToggle.isOn = true;
|
||
|
break;
|
||
|
}
|
||
|
}).AddTo(gameObject);
|
||
|
DataSource.ImageUrl.Subscribe(url =>
|
||
|
{
|
||
|
GetImage();
|
||
|
}).AddTo(gameObject);
|
||
|
DetailsInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Discription.Value = s);
|
||
|
LocationInput.OnValueChangedAsObservable().Subscribe(s => DataSource.Address.Value = s);
|
||
|
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();
|
||
|
});
|
||
|
//关闭
|
||
|
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
|
||
|
.Subscribe(_ => Hide());
|
||
|
//上传图片
|
||
|
OpenImageFile.OnLoadTextureFinished = texture =>
|
||
|
{
|
||
|
UploadImage(texture);
|
||
|
};
|
||
|
|
||
|
//控制器
|
||
|
ControlTogle.OnValueChangedAsObservable()
|
||
|
.Subscribe(value =>
|
||
|
{
|
||
|
var go = SelectionManager.Instance.Sets.Find(o => o.name == DataSource.Id.Value);
|
||
|
if (go != null)
|
||
|
{
|
||
|
if (go.GetComponent<ModelMeshEditor>())
|
||
|
{
|
||
|
if (value)
|
||
|
{
|
||
|
go.GetComponent<ModelMeshEditor>().pointScale = ControlSizeSlider.value;
|
||
|
go.GetComponent<ModelMeshEditor>().CreateEditorPoint();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
go.GetComponent<ModelMeshEditor>().DeleteEditorPoint();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
});
|
||
|
//控制器大小
|
||
|
ControlSizeSlider.OnValueChangedAsObservable()
|
||
|
.Subscribe(value =>
|
||
|
{
|
||
|
var go = SelectionManager.Instance.Sets.Find(o => o.name == DataSource.Id.Value);
|
||
|
if (go != null)
|
||
|
{
|
||
|
if (go.GetComponent<ModelMeshEditor>())
|
||
|
{
|
||
|
go.GetComponent<ModelMeshEditor>().pointScale = value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
});
|
||
|
#endregion
|
||
|
}
|
||
|
public override void Show()
|
||
|
{
|
||
|
base.Show();
|
||
|
|
||
|
switch (EquipmentManager.Instance.CreationType)
|
||
|
{
|
||
|
case EquipmentType.FireClimbingSite:
|
||
|
TitleText.text = "登高作业面";
|
||
|
ControllerPanel.SetActive(true);
|
||
|
url = string.Format(HttpManager.Instance.PostFireClimbingSitesById, DataSource.Id.Value);
|
||
|
break;
|
||
|
case EquipmentType.HazardSource:
|
||
|
TitleText.text = "危险源";
|
||
|
ControllerPanel.SetActive(false);
|
||
|
url = string.Format(HttpManager.Instance.PostHazardSourcesById, DataSource.Id.Value);
|
||
|
break;
|
||
|
case EquipmentType.NoParking:
|
||
|
TitleText.text = "禁停区";
|
||
|
ControllerPanel.SetActive(true);
|
||
|
url = string.Format(HttpManager.Instance.PostNoParkingAreasById, DataSource.Id.Value);
|
||
|
break;
|
||
|
case EquipmentType.KeyArea:
|
||
|
TitleText.text = "重点提示";
|
||
|
ControllerPanel.SetActive(false);
|
||
|
url = string.Format(HttpManager.Instance.PostImportantLocationsById, DataSource.Id.Value);
|
||
|
break;
|
||
|
case EquipmentType.ImageMarked:
|
||
|
TitleText.text = "图片标注";
|
||
|
ControllerPanel.SetActive(false);
|
||
|
url = string.Format(HttpManager.Instance.PostImageMarkersById, DataSource.Id.Value);
|
||
|
break;
|
||
|
case EquipmentType.EscapeWin:
|
||
|
TitleText.text = "逃生窗";
|
||
|
ControllerPanel.SetActive(false);
|
||
|
url = string.Format(HttpManager.Instance.PostEscapeWinsById, DataSource.Id.Value);
|
||
|
break;
|
||
|
case EquipmentType.BreakPoint:
|
||
|
TitleText.text = "破拆点";
|
||
|
ControllerPanel.SetActive(false);
|
||
|
url = string.Format(HttpManager.Instance.PostBreakPointsById, DataSource.Id.Value);
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
|
||
|
GetComponent<AttributePanelControl>().ResetPanel();
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 保存数据
|
||
|
/// </summary>
|
||
|
public void SaveData()
|
||
|
{
|
||
|
GameObject tempGo = EquipmentManager.SpawObjects[EquipmentManager.Instance.CreationType][DataSource.Id.Value];
|
||
|
DataSource.Position.Value = tempGo.transform.position;
|
||
|
DataSource.Rotation.Value = tempGo.transform.rotation.eulerAngles;
|
||
|
if(tempGo.transform.Find("Scene/Plane"))
|
||
|
DataSource.MeshVertices.Value = tempGo.transform.Find("Scene/Plane").GetComponent<MeshFilter>()?.mesh.vertices;
|
||
|
HttpManager.Instance.Post(url, DataSource.GetData());
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 上传图片
|
||
|
/// </summary>
|
||
|
public void UploadImage(Texture2D texture)
|
||
|
{
|
||
|
HttpManager.Instance.PostImage($"{DataSource.Id}.jpg", texture, a =>
|
||
|
{
|
||
|
DataSource.ImageUrl.Value = a?.ObjectName;
|
||
|
});
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取图片
|
||
|
/// </summary>
|
||
|
void GetImage()
|
||
|
{
|
||
|
if (!string.IsNullOrEmpty(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>
|
||
|
public 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);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|