122 lines
3.2 KiB
C#
122 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
using System;
|
|
|
|
|
|
public class MonsUIItem : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
public Text indexText;
|
|
public InputField timeText;
|
|
public List<InputField> values;
|
|
public Button playBtn;
|
|
public CustomItemData data;
|
|
public int index;
|
|
public void Init(CustomItemData _data)
|
|
{
|
|
data = _data;
|
|
index = _data.index;
|
|
indexText.text = index.ToString();
|
|
timeText.text = _data.time.ToString();
|
|
|
|
for (int i = 0; i < _data.values.Count; i++)
|
|
{
|
|
int num = i;
|
|
//初始化
|
|
values[i].text = _data.values[_data.values.Count - 1 - i].ToString();
|
|
//修改事件
|
|
values[num].onEndEdit.AddListener(str =>
|
|
{
|
|
if (str != "")
|
|
{
|
|
int a = int.Parse(str);
|
|
if (a >= 0 && a <= 1000)
|
|
{
|
|
_data.values[_data.values.Count - 1 - num] = a;
|
|
return;
|
|
}
|
|
}
|
|
//格式错误
|
|
values[num].text = _data.values[_data.values.Count - 1 - num].ToString();
|
|
});
|
|
}
|
|
playBtn.onClick.AddListener(MonsPlay);
|
|
timeText.onEndEdit.AddListener(str =>
|
|
{
|
|
if (str != "")
|
|
{
|
|
int a=int.Parse(str);
|
|
if (a > 0)
|
|
{
|
|
data.time = a;
|
|
return;
|
|
}
|
|
}
|
|
|
|
//格式错误
|
|
timeText.text = data.time.ToString();
|
|
});
|
|
}
|
|
|
|
private void MonsPlay()
|
|
{
|
|
if (CustomPanel.robot.GetComponent<Robot>().isPlaying==true)
|
|
{
|
|
Debug.Log("请先停止运行");
|
|
return;
|
|
}
|
|
if (CustomPanel.instance.isPlayAction == true)
|
|
{
|
|
Debug.Log("请先停止运行");
|
|
return;
|
|
}
|
|
|
|
RobotMotorValues values = new RobotMotorValues();
|
|
for (int i = 0; i < CustomPanel.instance. items.Count; i++)
|
|
{
|
|
CustomPanel.instance.items[i].IsActivation(false);
|
|
}
|
|
values.time = data.time;
|
|
List<int> list = new List<int>();
|
|
for (int j = data.values.Count - 1; j >= 0; j--)
|
|
{
|
|
list.Add(data.values[j]);
|
|
}
|
|
values.values = list.ToArray();
|
|
|
|
RobotManager.idsValue = values.values;
|
|
RobotManager.time = values.time;
|
|
CustomPanel.robot.GetComponent<Robot>().DoBusServo(new Motion(values), Activation);
|
|
}
|
|
void Activation()
|
|
{
|
|
for (int i = 0; i < CustomPanel.instance.items.Count; i++)
|
|
{
|
|
CustomPanel.instance.items[i].IsActivation(true);
|
|
}
|
|
}
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
CustomPanel.FreshCurrItem(gameObject);
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
playBtn.gameObject.SetActive(false);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|
|
public class MonsUIData
|
|
{
|
|
public int index;
|
|
public int time;
|
|
public List<int> values;
|
|
} |