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.
200 lines
7.0 KiB
200 lines
7.0 KiB
using AX.InputSystem; |
|
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class TruckSkillsControl : MonoBehaviour |
|
{ |
|
public TruckSkillsEnum Skill; |
|
protected GameObject chooseObj; |
|
static Dictionary<TruckSkillsEnum, TruckSkillsControl> SkillList = new Dictionary<TruckSkillsEnum, TruckSkillsControl>(); |
|
private bool isSelected; |
|
/// <summary> |
|
/// 设置选中高亮 |
|
/// </summary> |
|
protected bool IsSelected |
|
{ |
|
get |
|
{ |
|
return isSelected; |
|
} |
|
|
|
set |
|
{ |
|
isSelected = value; |
|
this.transform.GetChild(0).gameObject.SetActive(value);//设置高亮 |
|
} |
|
} |
|
/// <summary> |
|
/// 设置按钮可用 |
|
/// </summary> |
|
public bool IsInteractable |
|
{ |
|
get { return this.GetComponent<Button>().interactable; } |
|
set |
|
{ |
|
this.GetComponent<Button>().interactable = value; |
|
} |
|
} |
|
|
|
public void RespondFun() |
|
{ |
|
var GameObjID = chooseObj.GetComponent<CloneGameObjInfo>().GameObjID; |
|
var TruckMessages = chooseObj.GetComponent<TruckMessages>(); |
|
switch (Skill) |
|
{ |
|
case TruckSkillsEnum.Debarkation: |
|
//IsInteractable = false; |
|
//chooseObj.GetComponent<TruckMessages>().EnabledSkills &= ~Skill; |
|
break; |
|
case TruckSkillsEnum.SprayWater: |
|
IsSelected = !IsSelected; |
|
SetIsSelected(TruckSkillsEnum.SprayFoam, false); |
|
TruckMessages.CurrentSkill &= ~TruckSkillsEnum.SprayFoam; |
|
//MessageDispatcher.SendMessage(GameObjID, "WaterSwitch", IsSelected); |
|
//if (IsSelected) |
|
break; |
|
case TruckSkillsEnum.SprayFoam: |
|
IsSelected = !IsSelected; |
|
SetIsSelected(TruckSkillsEnum.SprayWater, false); |
|
TruckMessages.CurrentSkill &= ~TruckSkillsEnum.SprayWater; |
|
//MessageDispatcher.SendMessage(GameObjID, "WaterSwitch", IsSelected); |
|
//if (IsSelected) |
|
// MessageDispatcher.SendMessage(GameObjID, Skill.ToString()); |
|
break; |
|
case TruckSkillsEnum.FixedSupport: |
|
IsSelected = !IsSelected; |
|
IsInteractable = false; |
|
TruckMessages.EnabledSkills &= ~Skill; |
|
TruckMessages.EnabledSkills ^= (TruckSkillsEnum.AutomaticLiftArm | TruckSkillsEnum.PackUpTheLiftArm); |
|
break; |
|
case TruckSkillsEnum.AutomaticLiftArm: |
|
IsSelected = !IsSelected; |
|
break; |
|
case TruckSkillsEnum.PackUpTheLiftArm: |
|
TruckMessages.EnabledSkills &= ~(Skill | TruckSkillsEnum.AutomaticLiftArm); |
|
TruckMessages.EnabledSkills ^= TruckSkillsEnum.FixedSupport; |
|
SetIsSelected(TruckSkillsEnum.AutomaticLiftArm | TruckSkillsEnum.FixedSupport, false); |
|
TruckMessages.CurrentSkill &= ~(TruckSkillsEnum.AutomaticLiftArm | TruckSkillsEnum.FixedSupport); |
|
break; |
|
case TruckSkillsEnum.ForcibleEntry: |
|
IsSelected = !IsSelected; |
|
break; |
|
case TruckSkillsEnum.Illumination: |
|
IsSelected = !IsSelected; |
|
break; |
|
case TruckSkillsEnum.DischargeSmoke: |
|
IsSelected = !IsSelected; |
|
break; |
|
case TruckSkillsEnum.AutoSwing: //自动摇摆 |
|
IsSelected = !IsSelected; |
|
break; |
|
case TruckSkillsEnum.SelectTarget: |
|
|
|
break; |
|
case TruckSkillsEnum.SprayPowder: |
|
|
|
break; |
|
default: |
|
break; |
|
} |
|
SetInteractable(TruckMessages.EnabledSkills, true); |
|
if (IsSelected) |
|
{ |
|
TruckMessages.CurrentSkill |= Skill; |
|
} |
|
else |
|
{ |
|
TruckMessages.CurrentSkill &= ~Skill; |
|
} |
|
MessageDispatcher.SendMessage(GameObjID, Skill.ToString(), IsSelected); |
|
if (RecordEvent.IsRecord()) |
|
{ |
|
string json = JsonUtility.ToJson(new PowerSkillRecordEventData() |
|
{ |
|
GameId = GameObjID, |
|
EnabledSkills = (int)TruckMessages.EnabledSkills, |
|
CurrentSkill = (int)TruckMessages.CurrentSkill, |
|
Skill = Skill.ToString(), |
|
ArgData = IsSelected |
|
}); |
|
RecordEvent.AddEventData(chooseObj.GetComponent<CloneGameObjInfo>().gameObjType, RecordEventType.TruckSkill, json); |
|
} |
|
} |
|
static void SetInteractable(TruckSkillsEnum skills, bool Interactable) |
|
{ |
|
foreach (var item in SkillList) |
|
{ |
|
if ((item.Key & skills) != 0) |
|
{ |
|
item.Value.IsInteractable = Interactable; |
|
} |
|
else { item.Value.IsInteractable = false; } |
|
} |
|
} |
|
static void SetIsSelected(TruckSkillsEnum skills, bool Selected) |
|
{ |
|
foreach (var item in SkillList) |
|
{ |
|
if ((item.Key & skills) != 0) |
|
{ |
|
item.Value.IsSelected = Selected; |
|
} |
|
} |
|
} |
|
void Awake() |
|
{ |
|
MessageDispatcher.AddListener("SetTrcukSkills", SetUI); |
|
SkillList.Add(Skill, this); |
|
MessageDispatcher.AddListener("CloneSelected", ClearSkill); |
|
GetComponent<Button>().onClick.AddListener(RespondFun); |
|
} |
|
void OnDisable() |
|
{ |
|
ClearSkill(); |
|
} |
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("SetTrcukSkills", SetUI); |
|
MessageDispatcher.RemoveListener("CloneSelected", ClearSkill); |
|
SkillList.Clear(); |
|
} |
|
|
|
private void ClearSkill(IMessage obj) |
|
{ |
|
ClearSkill(); |
|
} |
|
void ClearSkill() |
|
{ |
|
if (Skill == TruckSkillsEnum.AutomaticLiftArm && chooseObj) |
|
{ |
|
if ((chooseObj.GetComponent<TruckMessages>().CurrentSkill & TruckSkillsEnum.AutomaticLiftArm) != 0) |
|
{ |
|
IsSelected = false; |
|
InputManager.skill = false; |
|
//InputManager.AutoArm = false; |
|
CursorManager.GetInstance.SetNormalType(); |
|
chooseObj.GetComponent<TruckMessages>().CurrentSkill &= ~TruckSkillsEnum.AutomaticLiftArm; |
|
} |
|
} |
|
} |
|
private void SetUI(IMessage obj) |
|
{ |
|
chooseObj = (GameObject)obj.Data; |
|
IsInteractable = false; |
|
IsSelected = false; |
|
var skills = chooseObj.GetComponent<TruckMessages>().TruckSkills; |
|
var CurrentSkill = chooseObj.GetComponent<TruckMessages>().CurrentSkill; |
|
this.gameObject.SetActive((skills & Skill) != 0); |
|
SetInteractable(chooseObj.GetComponent<TruckMessages>().EnabledSkills, true); |
|
IsSelected = (CurrentSkill & Skill) != 0; |
|
//if ((CurrentSkill & (TruckSkillsEnum.FixedSupport | TruckSkillsEnum.AutomaticLiftArm)) != 0) |
|
//{ |
|
// if (!RecordEvent.IsReplay()) |
|
// TruckSkillSPanel.GetInstance.TruckArmPanel.SetActive(true); |
|
//} |
|
} |
|
}
|
|
|