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; /// /// 是否带电 /// [ReconnetAtrribute] public bool hasElectricity; /// /// 安装状态时Y的local值 /// public float initPostionY; /// /// 螺丝拆装事件回调 /// private Action installAction; /// /// 螺丝判断条件回调 /// private Func checkCanMove; /// /// 夹子位置 /// public Transform jiaZiPos; /// /// 电压值 /// public float ElectricityVlaue=226; /// /// 验电笔验电角度 /// 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; } protected override void OnAwake() { base.OnAwake(); jiaZiPos = Instantiate(installPos, this.transform); jiaZiPos.localEulerAngles = Vector3.zero; jiaZiPos.localScale = new Vector3(0.5f, 0.5f, 0.5f); } public void AddinstallAction(Action action) { this.installAction = action; } public void AddCheckAction(Func checkCanMove) { this.checkCanMove = checkCanMove; } //protected override void OnMDown() //{ // base.OnMDown(); //} /// /// 螺丝是否可以拧 /// /// public bool CanMove() { if (checkCanMove == null) { return true; } else { return checkCanMove.Invoke(); } } /// /// 被拧紧 /// /// public void BeInstalled(Tool_Screwdriver screwdriver) { //动画 transform.DOLocalMoveY(initPostionY, 1) .OnUpdate(() => { transform.RotateAroundLocal(Vector3.up, -1); screwdriver.transform.RotateAroundLocal(Vector3.up, -10); }) .OnComplete(() => { Debug.Log("螺丝已拧紧"); isInstall = true; isMoving = false; screwdriver.isMoving = false; installAction?.Invoke(true); screwdriver.ReBackHead(); CallScoreAction(true); triggerAction?.Invoke(triggerName, true); }); } /// /// 被拧松 /// /// public void BeUnInstalled(Tool_Screwdriver screwdriver) { //动画 transform.DOLocalMoveY(initPostionY - 0.02f, 1) .OnUpdate(() => { transform.RotateAroundLocal(Vector3.up, 1); screwdriver.transform.RotateAroundLocal(Vector3.up, 10); }) .OnComplete(() => { Debug.Log("螺丝已拧松"); isInstall = false; isMoving = false; screwdriver.isMoving = false; installAction?.Invoke(false); screwdriver.ReBackHead(); CallScoreAction(false); triggerAction?.Invoke(triggerName, true); }); } public Transform GetPoint() { return jiaZiPos; } public string curretTriggerName() { return triggerName; } }