using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 十字螺丝 /// public class Tool_Screw : Tool_Base, PointInterface { /// /// 是否已拧紧 /// public bool isInstall; /// /// 上螺丝位置 /// public Transform installPos; /// /// 安装状态时Y的local值 /// public float initPostionY; /// /// 螺丝拆装事件回调 /// private Action installAction; /// /// 螺丝判断条件回调 /// private Func checkCanMove; /// /// 验电笔验电角度 /// private Vector3 testPenAng = Vector3.zero; /// /// 验电笔验电角度(不设置为原角度,设置则为设置的角度) /// public Vector3 TestPenAng { get { if (testPenAng == Vector3.zero) return installPos.localEulerAngles - new Vector3(0, 0, transform.localEulerAngles.y - 180); else return testPenAng; } set => testPenAng = value; } public GameObject circileLeft; public GameObject circileRight; protected LineRenderer lineRenderer; protected override void OnAwake() { base.OnAwake(); } public void AddinstallAction(Action action) { this.installAction = action; } public void AddCheckAction(Func checkCanMove) { this.checkCanMove = checkCanMove; } /// /// 螺丝是否可以拧 /// /// public bool CanMove() { if (checkCanMove == null) { return true; } else { return checkCanMove.Invoke(); } } /// /// 被拧紧 /// /// public void BeInstalled() { //动画 isMoving = true; transform.DOLocalMoveZ(3.815f, 2.0f) .OnUpdate(() => { transform.RotateAroundLocal(Vector3.forward, -0.1f); }) .OnComplete(() => { Debug.Log("螺丝已拧紧"); isInstall = true; isMoving = false; installAction?.Invoke(true); CallScoreAction(true); triggerAction?.Invoke(triggerName, true); }); } /// /// 被拧松 /// /// public void BeUnInstalled() { //动画 isMoving = true; transform.DOLocalMoveZ(3.8382f, 2.0f) .OnUpdate(() => { transform.RotateAroundLocal(Vector3.forward, 0.1f); }) .OnComplete(() => { Debug.Log("螺丝已拧松"); isInstall = false; isMoving = false; installAction?.Invoke(false); CallScoreAction(false); triggerAction?.Invoke(triggerName, true); }); } public Transform GetPoint() { return null; } public string curretTriggerName() { return triggerName; } protected override void OnMDown() { base.OnMDown(); if (isInstall && LiveSceneManager.Instance.currentTool != null) { BeUnInstalled(); } else { if (circileLeft.activeInHierarchy) { BeInstalled(); } else { circileLeft.SetActive(true); lineRenderer = circileLeft.GetComponent(); lineRenderer.enabled = true; lineRenderer.SetPosition(0, circileLeft.transform.position); } } StepManager.Instance.FinishStep(triggerName); } private void Update() { if (circileLeft.activeInHierarchy && lineRenderer != null && !circileRight.activeInHierarchy) { lineRenderer.SetPosition(1, LiveSceneManager.Instance.spawnToolPos.position); } } // if (Input.GetMouseButtonDown(0)) // { // //点击螺丝验电 // Ray tmpray = Camera.main.ScreenPointToRay(Input.mousePosition); // if (Physics.Raycast(tmpray, out RaycastHit hit)) // { // //螺丝 // Tool_Screw ts = hit.transform.GetComponent(); // if (ts != null) // { // //螺丝判断条件,是否可以拧 // if (ts.CanMove()) // { // if (ts.isInstall) // { // ts.BeUnInstalled(); // } // else // { // ts.BeInstalled(); // } // } // } // } // } //} }