- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
307 lines
10 KiB
C#
307 lines
10 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using XFramework.Objects;
|
|
|
|
public class CarIconInstanceCtrl : DragIcon, IPointerDownHandler
|
|
{
|
|
public Image dir;
|
|
public Text text_PersonCount;
|
|
public Text text_childEquipCount;
|
|
public Text text_under;//显示所属分组/厂区
|
|
|
|
FormationGroupingEnum groupingEnum;//学员编队时所属组别
|
|
//记录车载人员
|
|
public XDictionary<string,int> personNames = new XDictionary<string,int>();
|
|
//记录车载装备
|
|
public XDictionary<string,int> chidlEquipNames = new XDictionary<string,int>();
|
|
int personCount;
|
|
int childEquipCount;
|
|
private bool checkPos;//学员编辑时 需检测摆放位置是否正确
|
|
private string posImageName;//通过射线检测的图片 用来检查位置是否正确
|
|
public CountIconCreaterCtrl creater;//创建该实例的列表图标 后续用于数量更新
|
|
//public UnityAction<int>
|
|
bool isMarked;
|
|
public bool Interactable;//是否可交互 推演状态、位置同步状态下不可交互
|
|
|
|
public float firstCarDistacne;//距离首车的距离
|
|
RectTransform thisRectTransform;
|
|
UnityAction<CarIconInstanceCtrl> markedClickAction;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
thisRectTransform = this.GetComponent<RectTransform>();
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
if (!Interactable) return;
|
|
if (isMarked)//标记模式下不响应UI 且被点击时执行事件
|
|
{
|
|
markedClickAction?.Invoke(this);
|
|
return;
|
|
}
|
|
|
|
if (eventData.button == 0)
|
|
{
|
|
if (checkPos)//学员操作时 检查是否放置在指定区域内
|
|
{
|
|
bool rightPos = CheckPos();
|
|
if (!rightPos&&!isOnMap)//移动状态下位置错误无法放置
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
isOnMap = !isOnMap;//放下/拾起图标
|
|
}
|
|
else
|
|
{
|
|
if (!isOnMap)//移动状态下右键直接删除
|
|
{
|
|
EventCenter.Instance.EventTrigger<CarIconInstanceCtrl, bool>("SelectCarEditor", this, false);
|
|
Destroy(this.gameObject);
|
|
}
|
|
else
|
|
EventCenter.Instance.EventTrigger<CarIconInstanceCtrl>("CarRightButtonEditor", this);
|
|
}
|
|
|
|
if (!isOnMap)//再次拾起
|
|
{
|
|
offsetPos = (Vector2)Input.mousePosition - (Vector2)transform.position;
|
|
this.transform.SetSiblingIndex(this.transform.parent.childCount - 1);
|
|
}
|
|
|
|
if (isOnMap && !isAdded) //首次放下 添加至记录 同时更新面板数量
|
|
{
|
|
isAdded = true;
|
|
EventCenter.Instance.EventTrigger<CarIconInstanceCtrl, bool>("SelectCarEditor", this, true);
|
|
creater?.UpdateCount(-1);
|
|
}
|
|
}
|
|
|
|
//增加车载对象
|
|
public void AddOnboardGO(string goName,CreaterType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case CreaterType.car:
|
|
break;
|
|
case CreaterType.childEquip:
|
|
childEquipCount++;
|
|
if (chidlEquipNames.ContainsKey(goName))
|
|
chidlEquipNames[goName] += 1;
|
|
else
|
|
chidlEquipNames[goName] = 1;
|
|
break;
|
|
case CreaterType.person:
|
|
personCount++;
|
|
if (personNames.ContainsKey(goName))
|
|
personNames[goName] += 1;
|
|
else
|
|
personNames[goName] = 1;
|
|
if(StudentStateManager.Instance.LearnState == LearnState.learning)//训练模式设置人员关系错误是予以提示
|
|
{
|
|
bool result= EditorAppraiser.CheckPerson(goName,groupingEnum);
|
|
if (!result)
|
|
{
|
|
GameMain.Instance.UIManager.ShowPromptText(LocalizationManager.Format("{0}不应当编入{1}", LocalizationManager.DisplayName(goName), LocalizationManager.Get(groupingEnum.ToString())), Color.blue);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
ShowChildCount();
|
|
}
|
|
|
|
//减少车载对象
|
|
void MinusOnboardGO(string goName, CreaterType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case CreaterType.childEquip:
|
|
childEquipCount--;
|
|
chidlEquipNames[goName] -= 1;
|
|
if (chidlEquipNames[goName] <= 0)
|
|
chidlEquipNames.Remove(goName);
|
|
break;
|
|
case CreaterType.person:
|
|
personCount--;
|
|
personNames[goName] -= 1;
|
|
if (personNames[goName] <= 0)
|
|
personNames.Remove(goName);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
ShowChildCount();
|
|
}
|
|
|
|
public void UpdateOnboardGO(string goName,int changeValue)
|
|
{
|
|
CreaterType createrType;
|
|
if (personNames.ContainsKey(goName))
|
|
createrType = CreaterType.person;
|
|
else
|
|
createrType = CreaterType.childEquip;
|
|
|
|
if (changeValue == 1)
|
|
AddOnboardGO(goName, createrType);
|
|
else
|
|
MinusOnboardGO(goName, createrType);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前车辆所属的编队 删除时便于记录
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public FormationGroupingEnum GetGroup()
|
|
{
|
|
return groupingEnum;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化/更新图标相关数据
|
|
/// </summary>
|
|
/// <param name="msg"> </param>
|
|
public override void SetUpdateIconMsg(object msg,string msgType="")
|
|
{
|
|
if (msgType == "Init")
|
|
{
|
|
CarIconIntacneInitData iconData = (CarIconIntacneInitData)msg;
|
|
if (!string.IsNullOrEmpty(iconData.setInTargetImage))
|
|
{
|
|
checkPos = true;
|
|
posImageName = iconData.setInTargetImage;
|
|
}
|
|
chidlEquipNames = iconData.onboardEquipDic;
|
|
childEquipCount = chidlEquipNames.Count;
|
|
personNames = iconData.onboardPersonDic;
|
|
personCount = personNames.Count;
|
|
ShowChildCount();
|
|
dir.transform.localRotation = Quaternion.Euler(0, 0, iconData.angle + 180f);
|
|
text_under.text = "";
|
|
}
|
|
else if (msgType == "UpdatePos")//更新位置和角度
|
|
{
|
|
if (thisRectTransform == null)
|
|
thisRectTransform = this.GetComponent<RectTransform>();
|
|
Vector4 carPos = (Vector4)msg;//xyz位置 W 角度
|
|
thisRectTransform.anchoredPosition = MapHelper.GetAnchorPostionFromWorld(new Vector3(carPos.x,carPos.y,carPos.z));
|
|
dir.transform.localRotation = Quaternion.Euler(0, 0, 180f - carPos.w);
|
|
}
|
|
else if (msgType == "PlanningGroup")//显示当前所属分组
|
|
{
|
|
groupingEnum = (FormationGroupingEnum)msg;
|
|
LocalizationManager.SetFormatted(text_under, "({0})", LocalizationManager.Get(groupingEnum.ToString()));
|
|
if (StudentStateManager.Instance.LearnState == LearnState.learning)//训练模式设置人员关系错误是予以提示
|
|
{
|
|
string carType = text_IconName.text.Split('(')[0];
|
|
bool result = EditorAppraiser.CheckCar(carType, groupingEnum);
|
|
if (!result)
|
|
{
|
|
GameMain.Instance.UIManager.ShowPromptText(LocalizationManager.Format("{0}不应当编入{1}", LocalizationManager.DisplayName(carType), LocalizationManager.Get(groupingEnum.ToString())), Color.blue);
|
|
}
|
|
}
|
|
|
|
}
|
|
else if (msgType == "UnderArea")//显示当前所属厂区
|
|
{
|
|
text_under.text = $"({(string)msg})";
|
|
}
|
|
else if (msgType == "Sub2Init")//科目二图标同步初始化
|
|
{
|
|
text_under.text = "";
|
|
HideChildCount();
|
|
}
|
|
else if (msgType == "SyncPos")//教师端导调同步图标位置
|
|
{
|
|
if (thisRectTransform == null)
|
|
thisRectTransform = this.GetComponent<RectTransform>();
|
|
Vector3 carPos = (Vector3)msg;//x,y Anchored位置 Z 角度
|
|
thisRectTransform.anchoredPosition = (Vector2)carPos;
|
|
dir.transform.localRotation = Quaternion.Euler(0, 0, carPos.z);
|
|
}
|
|
|
|
}
|
|
|
|
private void ShowChildCount()
|
|
{
|
|
text_PersonCount.text = personCount.ToString("0");
|
|
text_childEquipCount.text = childEquipCount.ToString("0");
|
|
}
|
|
|
|
//public int GetPersonCount()
|
|
//{
|
|
// return personCount;
|
|
//}
|
|
|
|
//检查该位置是否可被放置
|
|
private bool CheckPos()
|
|
{
|
|
GetMouseRaycastAll();
|
|
for (int i = 0; i < results.Count; i++)
|
|
{
|
|
string carInstance = results[i].gameObject.name;
|
|
if (carInstance == posImageName)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//开始/关闭标记模式 标记模式下无法拾取车辆图标
|
|
public void SetMarkModel(bool isMarked,UnityAction<CarIconInstanceCtrl> markAction)
|
|
{
|
|
this.isMarked = isMarked;
|
|
markedClickAction = markAction;
|
|
}
|
|
|
|
//显示标记状态
|
|
public void SetMarkedActive(Image markedIcon)
|
|
{
|
|
markedIcon.transform.SetParent(this.transform);
|
|
markedIcon.transform.localEulerAngles = Vector3.one;
|
|
markedIcon.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 25);
|
|
}
|
|
|
|
//获取图标信息
|
|
public OnMapCarData GetCarIconData()
|
|
{
|
|
return new OnMapCarData(text_IconName.text, thisRectTransform.anchoredPosition,
|
|
thisRectTransform.localEulerAngles.z, personNames, chidlEquipNames);
|
|
}
|
|
|
|
|
|
//被删除或者被界面退出清空时调用
|
|
protected override void OnDisable()
|
|
{
|
|
if (!Interactable) return;//进入推演模式后不可交互 此时无需更新
|
|
if (isAdded && checkPos)//学员模式下 已经添加过的车辆 需要更新可创建数量
|
|
{
|
|
creater?.UpdateCount(1);
|
|
}
|
|
}
|
|
|
|
//隐藏车载信息数量
|
|
private void HideChildCount()
|
|
{
|
|
text_PersonCount.text ="";
|
|
text_childEquipCount.text ="";
|
|
}
|
|
|
|
//进入教师端导调同步模式
|
|
public void EnterTeacherSynMode()
|
|
{
|
|
HideChildCount();
|
|
Interactable = false;
|
|
}
|
|
}
|
|
|