108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
using System;
|
|
using AibisDream.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class PipelineProduct : MonoBehaviour, IInteraction
|
|
{
|
|
private static readonly int AddColorFade = Shader.PropertyToID("_AddColorFade");
|
|
|
|
private EventTriggerEx _trigger;
|
|
private SpriteRenderer _renderer;
|
|
private Material _material;
|
|
private PipelineSystem _pipelineSystem;
|
|
|
|
private float _speed = 0.1f;
|
|
private Transform[] _wayPoints;
|
|
private int _curIndex;
|
|
|
|
public CheckData CheckData { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
_trigger = GetComponent<EventTriggerEx>();
|
|
_renderer = GetComponent<SpriteRenderer>();
|
|
_material = _renderer.material;
|
|
|
|
_trigger.Register(EventTriggerType.PointerEnter, OnPointerEnter);
|
|
_trigger.Register(EventTriggerType.PointerExit, OnPointerExit);
|
|
_trigger.Register(EventTriggerType.PointerDown, OnPointerDown);
|
|
}
|
|
|
|
public void Init(Transform[] wayPoints, CheckData checkData, PipelineSystem pipelineSystem)
|
|
{
|
|
_pipelineSystem = pipelineSystem;
|
|
|
|
transform.position = wayPoints[0].position;
|
|
_wayPoints = wayPoints;
|
|
|
|
CheckData = checkData;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
Move();
|
|
}
|
|
|
|
private void Move()
|
|
{
|
|
// 判断是否到达当前目标点
|
|
if (Vector3.Distance(transform.localPosition, _wayPoints[_curIndex].localPosition) < 0.05f)
|
|
{
|
|
_curIndex++;
|
|
if (_curIndex >= _wayPoints.Length)
|
|
{
|
|
// 自我销毁并计数
|
|
_pipelineSystem.OnProductEnd(this, false);
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 移动到当前目标点
|
|
transform.localPosition = Vector3.MoveTowards(transform.localPosition, _wayPoints[_curIndex].localPosition, Time.deltaTime * _speed);
|
|
}
|
|
|
|
public void CheckPass()
|
|
{
|
|
_pipelineSystem.OnProductEnd(this, true);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
private void OnPointerEnter(BaseEventData eventData)
|
|
{
|
|
// TODO 增加悬浮效果
|
|
transform.localScale = Vector3.one * 1.1f;
|
|
}
|
|
|
|
private void OnPointerExit(BaseEventData eventData)
|
|
{
|
|
// TODO 消除悬浮效果
|
|
transform.localScale = Vector3.one;
|
|
}
|
|
|
|
private void OnPointerDown(BaseEventData eventData)
|
|
{
|
|
// TODO 增加点击效果
|
|
_pipelineSystem.Selected(this);
|
|
_material.SetFloat(AddColorFade, 1);
|
|
}
|
|
|
|
public void Deselect()
|
|
{
|
|
_material.SetFloat(AddColorFade, 0);
|
|
}
|
|
|
|
#region 交互接口
|
|
public bool IsActive => true;
|
|
public bool IsAvailable => gameObject.activeInHierarchy;
|
|
public GameObject GetGameObject()
|
|
{
|
|
return gameObject;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |