357 lines
13 KiB
C#
357 lines
13 KiB
C#
using DefaultNamespace.ProcessMode;
|
||
using DG.Tweening;
|
||
using MotionFramework;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
/// <summary>
|
||
/// 剥线钳
|
||
/// </summary>
|
||
public class Pliers : MonoBehaviour
|
||
{
|
||
[Header("剥线钳物体")]
|
||
/// <summary>
|
||
/// 剥线钳物体
|
||
/// </summary>
|
||
public GameObject PliersObj;
|
||
|
||
[Header("剥线钳动画")]
|
||
/// <summary>
|
||
/// 剥线钳动画
|
||
/// </summary>
|
||
public SkinnedMeshRenderer PliersSki;
|
||
|
||
[Header("柜门外封印动画")]
|
||
/// <summary>
|
||
/// 柜门外封印动画
|
||
/// </summary>
|
||
public SkinnedMeshRenderer ElectricBoxSkinnedMeshRenderer;
|
||
|
||
[Header("电箱里端子排右边封印")]
|
||
/// <summary>
|
||
/// 电箱里端子排右边封印
|
||
/// </summary>
|
||
public SkinnedMeshRenderer RightSkinnedMeshRenderer;
|
||
|
||
[Header("电箱端子排里面左边封印")]
|
||
/// <summary>
|
||
/// 电箱端子排里面左边封印
|
||
/// </summary>
|
||
public SkinnedMeshRenderer LeftSkinnedMeshRenderer;
|
||
|
||
[Header("集中器盖右边封印")]
|
||
/// <summary>
|
||
/// 集中器盖右边封印
|
||
/// </summary>
|
||
public SkinnedMeshRenderer RconcentratorSMR;
|
||
|
||
[Header("集中器盖左边封印")]
|
||
/// <summary>
|
||
/// 集中器盖左边封印
|
||
/// </summary>
|
||
public SkinnedMeshRenderer LconcentratorSMR;
|
||
|
||
[Header("变电箱门锁")]
|
||
/// <summary>
|
||
/// 变电箱门锁
|
||
/// </summary>
|
||
public Transform Doorlock;
|
||
|
||
[Header("工具解绑的父物体")]
|
||
/// <summary>
|
||
/// 工具解绑的父物体
|
||
/// </summary>
|
||
public GameObject PlayerCamera;
|
||
|
||
[Header("变电箱左门")]
|
||
/// <summary>
|
||
/// 变电箱左门
|
||
/// </summary>
|
||
public Transform DoorOfCabinet;
|
||
|
||
[Header("是否在梯子上")]
|
||
/// <summary>
|
||
/// 是否在梯子上
|
||
/// </summary>
|
||
bool Onladder ;
|
||
|
||
[Header("斜口钳钳开每个封印位置")]
|
||
/// <summary>
|
||
/// 斜口钳钳开每个封印位置
|
||
/// </summary>
|
||
public Transform[] InteractivePliersTrans;
|
||
|
||
|
||
[Header("斜口钳的原始位置")]
|
||
/// <summary>
|
||
/// 斜口钳的原始位置
|
||
/// </summary>
|
||
private Vector3 originalPosition;
|
||
|
||
[Header(" 斜口钳的原始旋转")]
|
||
/// <summary>
|
||
/// 斜口钳的原始旋转
|
||
/// </summary>
|
||
private Quaternion originalRotation;
|
||
void Start()
|
||
{
|
||
Init();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化
|
||
/// </summary>
|
||
void Init()
|
||
{
|
||
PliersSki.SetBlendShapeWeight(0, 100);
|
||
//PliersAni.Play("线钳");
|
||
originalPosition = PliersObj.transform.localPosition;
|
||
originalRotation = PliersObj.transform.localRotation;
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
//判断在梯子上
|
||
if (!Onladder)
|
||
{
|
||
if (Input.GetMouseButtonDown(0))
|
||
{
|
||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
RaycastHit hit;
|
||
bool raycast = Physics.Raycast(ray, out hit);
|
||
if (raycast)
|
||
{
|
||
if (hit.collider.gameObject.name == "柜门_封印")
|
||
{
|
||
PliersObj.gameObject.transform.SetParent(null);
|
||
StartCoroutine(PliersIE());
|
||
Debug.Log(hit.collider.gameObject.name);
|
||
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
||
}
|
||
if (hit.collider.gameObject.name == "接线盒_封印R")
|
||
{
|
||
PliersObj.gameObject.transform.SetParent(null);
|
||
StartCoroutine(JunctionBoxRight());
|
||
Debug.Log(hit.collider.gameObject.name);
|
||
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
||
}
|
||
if (hit.collider.gameObject.name == "接线盒_封印L")
|
||
{
|
||
PliersObj.gameObject.transform.SetParent(null);
|
||
StartCoroutine(JunctionBoxLeft());
|
||
Debug.Log(hit.collider.gameObject.name);
|
||
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
||
}
|
||
if (hit.collider.gameObject.name == "集中器_封印R")
|
||
{
|
||
PliersObj.gameObject.transform.SetParent(null);
|
||
StartCoroutine(RightRconcentrator());
|
||
Debug.Log(hit.collider.gameObject.name);
|
||
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
||
}
|
||
if (hit.collider.gameObject.name == "集中器_封印_L")
|
||
{
|
||
PliersObj.gameObject.transform.SetParent(null);
|
||
StartCoroutine(LeftRconcentrator());
|
||
Debug.Log(hit.collider.gameObject.name);
|
||
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject.name);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
float weight;
|
||
|
||
/// <summary>
|
||
/// 剥线钳动画
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator PliersIE()
|
||
{
|
||
//PliersObj.gameObject.transform.position = InteractivePliersTrans[0].gameObject.transform.position;
|
||
PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[0].gameObject.transform.position, InteractivePliersTrans[3].gameObject.transform.rotation);
|
||
yield return new WaitForSeconds(1f);
|
||
//PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90,90,0),1.5f);
|
||
//yield return new WaitForSeconds(2f);
|
||
for (int i = 100; i >= 0; i--)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
PliersSki.SetBlendShapeWeight(0, i);
|
||
}
|
||
yield return new WaitForSeconds(0.1f);
|
||
//PliersObj.gameObject.transform.SetParent(PlayerCamera.transform);
|
||
StartCoroutine(OpenLock());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开柜门封印动画
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator OpenLock()
|
||
{
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
ElectricBoxSkinnedMeshRenderer.SetBlendShapeWeight(0, i);
|
||
}
|
||
yield return new WaitForSeconds(0.1f);
|
||
ElectricBoxSkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.637f, 0.12f, -0.015f), 0.5f);
|
||
yield return new WaitForSeconds(1f);
|
||
ElectricBoxSkinnedMeshRenderer.gameObject.SetActive(false);
|
||
DoorOfCabinet.gameObject.GetComponent<BoxCollider>().enabled = false; //关闭电箱左门碰撞,防止斜口钳碰上
|
||
//gameObject.transform.Find("变电箱_门").GetComponent<BoxCollider>().enabled = false;
|
||
StartCoroutine(OpenDoor());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 电箱门动画
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator OpenDoor()
|
||
{
|
||
//yield return new WaitForSeconds(0.5f);
|
||
Doorlock.transform.DOLocalRotate(new Vector3(160, 0, 0), 1f);
|
||
yield return new WaitForSeconds(1.5f);
|
||
DoorOfCabinet.transform.DOLocalRotate(new Vector3(-90, 0, 160), 2f);
|
||
StartCoroutine(PliersBack());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 剥线钳返回原点动画
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator PliersBack()
|
||
{
|
||
PliersObj.gameObject.transform.SetParent(PlayerCamera.transform);
|
||
yield return new WaitForSeconds(0.5f);
|
||
PliersObj.gameObject.transform.localPosition = originalPosition;
|
||
PliersObj.gameObject.transform.localRotation = originalRotation;
|
||
PliersSki.SetBlendShapeWeight(0, 100);
|
||
//PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.05f, 2.386f, 163.028f),1f);
|
||
//PliersObj.gameObject.transform.DORotate(new Vector3(0,90,0),1f);
|
||
//yield return new WaitForSeconds(1.5f);
|
||
//PliersObj.gameObject.SetActive(false);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 接线盒右边封印
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator JunctionBoxRight()
|
||
{
|
||
//PliersObj.gameObject.transform.position = InteractivePliersTrans[1].gameObject.transform.position;
|
||
PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[1].gameObject.transform.position, InteractivePliersTrans[1].gameObject.transform.rotation);
|
||
//PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f);
|
||
//yield return new WaitForSeconds(1f);
|
||
//PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1497f, 1.888f, -1.3079f), 0.5f);
|
||
yield return new WaitForSeconds(1f);
|
||
for (int i = 25; i >= 0; i--)//更改斜口钳开口速度改i的值,越小越快
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
PliersSki.SetBlendShapeWeight(0, i);
|
||
}
|
||
yield return new WaitForSeconds(0.1f);
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
RightSkinnedMeshRenderer.SetBlendShapeWeight(0, i);
|
||
}
|
||
RightSkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.0746f, 0.0004f, -0.0416f), 0.5f);
|
||
yield return new WaitForSeconds(1.5f);
|
||
StartCoroutine(PliersBack());
|
||
RightSkinnedMeshRenderer.gameObject.SetActive(false);
|
||
// Destroy(RightSkinnedMeshRenderer);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 接线盒左边封印
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator JunctionBoxLeft()
|
||
{
|
||
// PliersObj.gameObject.transform.position = InteractivePliersTrans[2].gameObject.transform.position;
|
||
PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[2].gameObject.transform.position, InteractivePliersTrans[2].gameObject.transform.rotation);
|
||
//PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f);
|
||
//yield return new WaitForSeconds(0.8f);
|
||
//PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1672f, 1.8637f, -1.4392f), 1f);
|
||
yield return new WaitForSeconds(1f);
|
||
for (int i = 25; i >= 0; i--)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
PliersSki.SetBlendShapeWeight(0, i);
|
||
}
|
||
yield return new WaitForSeconds(0.1f);
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
LeftSkinnedMeshRenderer.SetBlendShapeWeight(0, i);
|
||
}
|
||
LeftSkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(-0.0744f, -0.0247f, -0.043f), 0.5f);
|
||
yield return new WaitForSeconds(1f);
|
||
StartCoroutine(PliersBack());
|
||
LeftSkinnedMeshRenderer.gameObject.SetActive(false);
|
||
//Destroy(LeftSkinnedMeshRenderer);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 旧集中器右边封印
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator RightRconcentrator()
|
||
{
|
||
//PliersObj.gameObject.transform.position = InteractivePliersTrans[3].gameObject.transform.position;
|
||
//PliersObj.gameObject.transform.rotation = InteractivePliersTrans[3].gameObject.transform.rotation;
|
||
PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[3].gameObject.transform.position, InteractivePliersTrans[3].gameObject.transform.rotation);
|
||
//PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f);
|
||
//yield return new WaitForSeconds(1.2f);
|
||
//PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1687f, 2.1218f, -1.4082f), 1f);
|
||
yield return new WaitForSeconds(1f);
|
||
for (int i = 25; i >= 0; i--)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
PliersSki.SetBlendShapeWeight(0, i);
|
||
}
|
||
yield return new WaitForSeconds(0.1f);
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
RconcentratorSMR.SetBlendShapeWeight(0, i);
|
||
}
|
||
RconcentratorSMR.gameObject.transform.DOLocalMove(new Vector3(0.1151f, 0.0243f, -0.1134f), 0.5f);
|
||
yield return new WaitForSeconds(1f);
|
||
StartCoroutine(PliersBack());
|
||
RconcentratorSMR.gameObject.SetActive(false);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 旧集中器左边封印
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
IEnumerator LeftRconcentrator()
|
||
{
|
||
//PliersObj.gameObject.transform.position = InteractivePliersTrans[4].gameObject.transform.position;
|
||
PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[4].gameObject.transform.position, InteractivePliersTrans[4].gameObject.transform.rotation);
|
||
//PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f);
|
||
//yield return new WaitForSeconds(1.2f);
|
||
//PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1683f, 2.1293f, -1.5439f), 1f);
|
||
yield return new WaitForSeconds(1f);
|
||
for (int i = 25; i >= 0; i--)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
PliersSki.SetBlendShapeWeight(0, i);
|
||
}
|
||
yield return new WaitForSeconds(0.1f);
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
yield return new WaitForSeconds(0.001f);
|
||
LconcentratorSMR.SetBlendShapeWeight(0, i);
|
||
}
|
||
LconcentratorSMR.gameObject.transform.DOLocalMove(new Vector3(-0.0659f, 0.0829f, -0.1134f), 0.5f);
|
||
yield return new WaitForSeconds(1f);
|
||
StartCoroutine(PliersBack());
|
||
LconcentratorSMR.gameObject.SetActive(false);
|
||
}
|
||
}
|