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.

228 lines
5.8 KiB

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>();
outline.OutlineColor = outLineColor;
}
}
Outline triggerLine = triggerGo.AddComponent<Outline>();
triggerLine.OutlineColor = loadOutLineColor;
triggerLine.OutlineWidth = 3;
triggerLine.enabled = false;
}
/// <summary>
/// 显示安装外发光轮廓
/// </summary>
public void EnableLoadColor()
{
Outline triggerLine = triggerGo.GetComponent<Outline>();
if (triggerLine)
{
triggerLine.enabled = true;
}
MessageContainer.SendMessage(arrowTagTargte, this, MsgName.TipViewShowArrow);
}
/// <summary>
/// 隐藏安装外发光轮廓
/// </summary>
public void DisableLoadColor()
{
Outline triggerLine = triggerGo.GetComponent<Outline>();
if (triggerLine)
{
triggerLine.enabled = false;
}
}
/// <summary>
/// 取消外发光
/// </summary>
public void DisableAllOutLine()
{
if (isMainNull())
{
for (int i = 0; i < mainSpareGos.Length; i++)
{
Outline outline = mainSpareGos[i].GetComponent<Outline>();
outline.enabled = false;
}
MessageContainer.SendMessage(arrowTagTargte, this,MsgName.TipViewHideArrow);
}
}
/// <summary>
/// 显示外发光
/// </summary>
public void ShowOutline()
{
if (isMainNull())
{
for (int i = 0; i < mainSpareGos.Length; i++)
{
Outline outline = mainSpareGos[i].GetComponent<Outline>();
outline.enabled = true;
}
MessageContainer.SendMessage(arrowTagTargte, this,MsgName.TipViewShowArrow);
}
}
/// <summary>
/// 激活注册类型
/// </summary>
/// <param name="_type"></param>
public void ActiveRegistType(SpareType _type)
{
//Debug.LogFormat(">>>>>>>>>> 注册当前零件类型成功 {0}",_type);
triggerGo.SetActive(true);
if(GameConfig.state == GameState.Load)
{
EnableLoadColor();
}else
{
}
type = _type;
}
/// <summary>
/// 接收安装零件信息
/// @sender MouseControl
/// </summary>
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);
}
}
}
/// <summary>
/// 接收子物体发射的消息
/// @sender MouseControl
/// </summary>
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);
}
}
/// <summary>
/// 发光体是否为空
/// </summary>
/// <returns></returns>
bool isMainNull()
{
if (mainSpareGos.Length > 0) return true;
else
return false;
}
}
}