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.
155 lines
4.1 KiB
155 lines
4.1 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using SpringGUI; |
|
using AX.TrackRecord; |
|
|
|
public class SetAreaAttribute : MonoBehaviour |
|
{ |
|
internal struct PolygonData |
|
{ |
|
public float PrevHeight; |
|
public float CurrHeight; |
|
public float SliderValue; |
|
} |
|
|
|
public static SetAreaAttribute Instance; |
|
public ColorPicker colorPicker; |
|
public MainColorTape mainColorTape; |
|
InputField fieldAreaName; |
|
Slider sliderHeight; |
|
Button btnClose; |
|
GameObject objArea; |
|
|
|
private Dictionary<int, PolygonData> container = new Dictionary<int, PolygonData>(); |
|
private float prevHeight = 0f; |
|
private float currHeight = 0f; |
|
|
|
private void Awake() |
|
{ |
|
Instance = this; |
|
} |
|
// Use this for initialization |
|
void Start() |
|
{ |
|
fieldAreaName = transform.Find("InputField").GetComponent<InputField>(); |
|
fieldAreaName.onValueChanged.AddListener(s => |
|
{ |
|
objArea.GetComponentInChildren<EnemyInfo>().SetName(s); |
|
}); |
|
sliderHeight = transform.Find("SliderK").GetComponent<Slider>(); |
|
sliderHeight.maxValue = 10; |
|
sliderHeight.minValue = 0; |
|
sliderHeight.onValueChanged.AddListener(ChangeAreaHeight); |
|
btnClose = transform.Find("Close").GetComponent<Button>(); |
|
btnClose.onClick.AddListener(CloseSetAttribute); |
|
colorPicker.onPicker.AddListener(ChangeColor); |
|
|
|
} |
|
bool Control = false; |
|
public void SetObjArea(GameObject obj) |
|
{ |
|
objArea = obj; |
|
SetAttri(); |
|
//Control =false; |
|
|
|
var id = obj.GetInstanceID(); |
|
var data = default(PolygonData); |
|
|
|
// 针对不同的区域面片设置正确的值 |
|
if (container.TryGetValue(id, out data)) |
|
{ |
|
if (sliderHeight != null) |
|
{ |
|
sliderHeight.onValueChanged.RemoveAllListeners(); |
|
sliderHeight.value = data.SliderValue; |
|
sliderHeight.onValueChanged.AddListener(ChangeAreaHeight); |
|
} |
|
|
|
prevHeight = data.PrevHeight; |
|
currHeight = data.CurrHeight; |
|
} |
|
else |
|
{ |
|
if (sliderHeight != null) |
|
{ |
|
sliderHeight.onValueChanged.RemoveAllListeners(); |
|
sliderHeight.value = sliderHeight.minValue; |
|
sliderHeight.onValueChanged.AddListener(ChangeAreaHeight); |
|
} |
|
|
|
prevHeight = 0; |
|
currHeight = 0; |
|
|
|
data = new PolygonData(); |
|
data.PrevHeight = prevHeight; |
|
data.CurrHeight = currHeight; |
|
data.SliderValue = sliderHeight == null ? 0 : sliderHeight.value; |
|
|
|
container.Add(id, data); |
|
} |
|
} |
|
|
|
private void SetAttri() |
|
{ |
|
|
|
if (objArea.GetComponentInChildren<EnemyInfo>() && string.IsNullOrEmpty(objArea.GetComponentInChildren<EnemyInfo>().GetName())) |
|
{ |
|
fieldAreaName.text = |
|
objArea.GetComponentInChildren<EnemyInfo>().GetName(); |
|
} |
|
mainColorTape.Color = objArea.GetComponent<PolygonController>().Color; |
|
|
|
|
|
} |
|
|
|
|
|
private void ChangeColor(Color color) |
|
{ |
|
objArea.GetComponent<PolygonController>().Color = color; |
|
} |
|
|
|
|
|
private void ChangeAreaHeight(float a) |
|
{ |
|
currHeight = a; |
|
|
|
var deltaHeight = currHeight - prevHeight; |
|
|
|
if (deltaHeight != 0) |
|
{ |
|
prevHeight = currHeight; |
|
|
|
var controller = objArea.GetComponent<PolygonController>(); |
|
controller.ChangeHeight(deltaHeight); |
|
} |
|
|
|
// 实时记录当前的区域面片数据 |
|
var id = objArea.GetInstanceID(); |
|
var data = container[id]; |
|
data.PrevHeight = prevHeight; |
|
data.CurrHeight = currHeight; |
|
data.SliderValue = sliderHeight.value; |
|
container[id] = data; |
|
} |
|
|
|
public void Ok() |
|
{ |
|
CloseSetAttribute(); |
|
if (RecordManager.Instance.IsRecording) |
|
{ |
|
TrackRecordHelpClass.RECORDPolygonThreeList(objArea); |
|
} |
|
|
|
|
|
} |
|
|
|
public void CloseSetAttribute() |
|
{ |
|
gameObject.SetActive(false); |
|
//Control = true; |
|
//sliderHeight.value = 0; |
|
} |
|
|
|
}
|
|
|