using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; namespace DisComputer { /* *@func 零件控制器 * @author lz * @date 2020/06/01 */ public class SpareItemControl : MonoBehaviour { //类型 public SpareType type; //零件详细信息 public SpareInfo spareInfo; [Header("拆卸触发器")] public GameObject triggerGo; [Header("零件主体")] public GameObject[] mainSpareGos; [Header("外发光颜色")] public Color outLineColor; [Header("安装指引发光颜色")] public Color loadOutLineColor; //零件动画 public SpareAnimationBase spareAnimation; //箭头指引标注体 public Transform arrowTagTargte; // Start is called before the first frame update void Start() { triggerGo.SetActive(false); InitColor(); DisableAllOutLine(); } void InitColor() { if (isMainNull()) { for (int i = 0; i < mainSpareGos.Length; i++) { Outline outline = mainSpareGos[i].AddComponent(); outline.OutlineColor = outLineColor; } } Outline triggerLine = triggerGo.AddComponent(); triggerLine.OutlineColor = loadOutLineColor; triggerLine.OutlineWidth = 3; triggerLine.enabled = false; } /// /// 显示箭头提示 /// public void ShowArrowTip() { if (arrowTagTargte != null) { MessageContainer.SendMessage(arrowTagTargte, this, MsgName.TipViewShowArrow); } } /// /// 隐藏箭头提示 /// public void HideArrowTip() { if(arrowTagTargte != null) { //MessageContainer.SendMessage(arrowTagTargte, this, MsgName.TipViewHideArrow); } } /// /// 显示安装外发光轮廓 /// public void EnableLoadColor() { Outline triggerLine = triggerGo.GetComponent(); if (triggerLine) { triggerLine.enabled = true; } } /// /// 隐藏安装外发光轮廓 /// public void DisableLoadColor() { Outline triggerLine = triggerGo.GetComponent(); if (triggerLine) { triggerLine.enabled = false; } triggerGo.SetActive(false); } /// /// 取消拆除外发光 /// public void DisableAllOutLine() { if (isMainNull()) { for (int i = 0; i < mainSpareGos.Length; i++) { Outline outline = mainSpareGos[i].GetComponent(); if (outline != null) { outline.enabled = false; } } } } /// /// 显示拆除外发光 /// public void ShowOutline() { if (isMainNull()) { for (int i = 0; i < mainSpareGos.Length; i++) { Outline outline = mainSpareGos[i].GetComponent(); if (outline != null) { outline.enabled = true; } } } } /// /// 激活注册类型 /// /// public void ActiveRegistType(SpareType _type) { //Debug.LogFormat(">>>>>>>>>> 注册当前零件类型成功 {0}",_type); triggerGo.SetActive(true); if(GameConfig.state == GameState.Load) { EnableLoadColor(); ShowOutline(); } else { ShowOutline(); } type = _type; } /// /// 接收安装零件信息 /// @sender MouseControl /// public void OnRecSpareColliderMessage(Grid grid) { if (isBaseOnReced) return; if (grid.spareInfo.fitId == GameDataConfig.Instance.pcId) { if (grid.chectSpareTag.Contains(type.ToString())) { //Debug.LogFormat("{0}与{1}当前目标匹配成功", grid.chectSpareTag, type); if (spareAnimation.IsCompareTag(grid)) { MouseControl.Instance.SpareLoading(() => { spareAnimation.OnLoadAct(); DisableLoadColor(); HideArrowTip(); triggerGo.SetActive(false); type = SpareType.Null; }); } else { // Debug.LogFormat("{0}与{1}当前目标不匹配", grid.chectSpareTag, type); } } }else { //Debug.Log("型号不匹配,请选择别的零件!!!"); MessageContainer.SendMessage(unFitTipStr(grid), this, MsgName.TipViewShowPoint); } } /// /// 接收子物体发射的消息 /// @sender MouseControl /// public void OnRecChildColliderMessage(ToolItem item) { if (isBaseOnReced) return; if (item.chectSpareTag.Contains(type.ToString())) { //Debug.LogFormat("{0}与{1}当前目标匹配成功", item.chectSpareTag, type); if (spareAnimation.IsCompareTag(item)) { MouseControl.Instance.ToolLoading(()=> { spareAnimation.OnUnLoadAct(); triggerGo.SetActive(false); HideArrowTip(); type = SpareType.Null; }); } } else { //Debug.LogFormat("{0}与{1}当前目标不匹配", item.chectSpareTag, type); } } /// /// 是否已接收消息 /// protected bool isBaseOnReced; /// /// 接收拆除消息 /// @sender MouseControl /// /// public virtual void OnRecUnloadColliderMsg(ToolItem item) { } /// /// 接收按照消息 /// @sender MouseControl /// /// public virtual void OnRecLoadColliderMsg(Grid grid) { } /// /// 发光体是否为空 /// /// protected bool isMainNull() { if (mainSpareGos.Length > 0) return true; else return false; } protected string unFitTipStr(Grid grid) { string val = ""; switch (grid.type) { case SpareType.Cpu: val = "当前所选cpu接口与主板不匹对,请选择其他型号"; break; case SpareType.DianYuan: val = "当前所选电源与主板功耗不匹对,请选择其他型号"; break; case SpareType.GuangQu: val = "当前所选光驱不支持该机型,请选择其他型号"; break; case SpareType.JiXiang: val = "当前所选机箱不支持该机型,请选择其他型号"; break; case SpareType.NeiCun: val = "当前所选内存条与主板接口不匹对,请选择其他型号"; break; case SpareType.XianKa: val = "当前所选显卡与主板接口不匹对,请选择其他型号"; break; case SpareType.YingPan: val = "当前所选硬盘,主板不支持,请选择其他型号"; break; case SpareType.ZhuBan: val = "当前所选主板不匹对该机箱,请选择其他型号"; break; } return val; } } }