using System.Collections; using System.Collections.Generic; using UnityEngine; using LzFramework.FSM.Msg; namespace DisComputer { /* *@func 零件控制器 * @author lz * @data 2020/06/01 */ public class SpareItemControl : MonoBehaviour { //类型 public SpareType type; [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 EnableLoadColor() { Outline triggerLine = triggerGo.GetComponent(); if (triggerLine) { triggerLine.enabled = true; } MessageContainer.SendMessage(arrowTagTargte, this, MsgName.TipViewShowArrow); } /// /// 隐藏安装外发光轮廓 /// public void DisableLoadColor() { Outline triggerLine = triggerGo.GetComponent(); if (triggerLine) { triggerLine.enabled = false; } } /// /// 取消外发光 /// public void DisableAllOutLine() { if (isMainNull()) { for (int i = 0; i < mainSpareGos.Length; i++) { Outline outline = mainSpareGos[i].GetComponent(); outline.enabled = false; } MessageContainer.SendMessage(arrowTagTargte, this,MsgName.TipViewHideArrow); } } /// /// 显示外发光 /// public void ShowOutline() { if (isMainNull()) { for (int i = 0; i < mainSpareGos.Length; i++) { Outline outline = mainSpareGos[i].GetComponent(); outline.enabled = true; } MessageContainer.SendMessage(arrowTagTargte, this,MsgName.TipViewShowArrow); } } /// /// 激活注册类型 /// /// public void ActiveRegistType(SpareType _type) { //Debug.LogFormat(">>>>>>>>>> 注册当前零件类型成功 {0}",_type); triggerGo.SetActive(true); if(GameConfig.state == GameState.Load) { EnableLoadColor(); }else { } type = _type; } /// /// 接收安装零件信息 /// @sender MouseControl /// public void OnRecSpareColliderMessage(Grid grid) { if (grid.chectSpareTag.Contains(type.ToString())) { //Debug.LogFormat("{0}与{1}当前目标匹配成功", grid.chectSpareTag, type); if (spareAnimation.IsCompareTag(grid)) { MouseControl.Instance.SpareLoading(()=> { spareAnimation.OnLoadAct(); DisableLoadColor(); triggerGo.SetActive(false); type = SpareType.Null; }); }else { // Debug.LogFormat("{0}与{1}当前目标不匹配", grid.chectSpareTag, type); } } } /// /// 接收子物体发射的消息 /// @sender MouseControl /// public void OnRecChildColliderMessage(ToolItem item) { 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); type = SpareType.Null; }); } } else { //Debug.LogFormat("{0}与{1}当前目标不匹配", item.chectSpareTag, type); } } /// /// 发光体是否为空 /// /// bool isMainNull() { if (mainSpareGos.Length > 0) return true; else return false; } } }