ShanxiKnowledgeBase/SXElectricityInformationAcq.../Assets/taoruiqi/Pliers.cs

288 lines
9.1 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 剥线钳
/// </summary>
public class Pliers : MonoBehaviour
{
/// <summary>
/// 剥线钳物体
/// </summary>
public GameObject PliersObj;
/// <summary>
/// 剥线钳动画
/// </summary>
public SkinnedMeshRenderer PliersSki;
/// <summary>
/// 柜门外封印动画
/// </summary>
public SkinnedMeshRenderer ElectricBoxSkinnedMeshRenderer;
/// <summary>
/// 电箱里端子排右边封印
/// </summary>
public SkinnedMeshRenderer RightSkinnedMeshRenderer;
/// <summary>
/// 电箱端子排里面左边封印
/// </summary>
public SkinnedMeshRenderer LeftSkinnedMeshRenderer;
/// <summary>
/// 集中器盖右边封印
/// </summary>
public SkinnedMeshRenderer RconcentratorSMR;
/// <summary>
/// 集中器盖左边封印
/// </summary>
public SkinnedMeshRenderer LconcentratorSMR;
/// <summary>
/// 变电箱门锁
/// </summary>
public Transform Doorlock;
/// <summary>
/// 变电箱左门
/// </summary>
public Transform DoorOfCabinet;
/// <summary>
/// 是否在梯子上
/// </summary>
bool Onladder ;
void Start()
{
Init();
}
void Init()
{
PliersSki.SetBlendShapeWeight(0, 0);
//PliersAni.Play("线钳");
}
void Update()
{
if (!Onladder)
{
if (Input.GetMouseButtonDown(0))
{//Camera.transform.forward
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool raycast = Physics.Raycast(ray, out hit);
if (raycast)
{
if (hit.collider.gameObject.name == "柜门_封印")
{
StartCoroutine(PliersIE());
Debug.Log(hit.collider.gameObject.name);
}
if (hit.collider.gameObject.name == "接线盒_封印R")
{
StartCoroutine(JunctionBoxRight());
Debug.Log(hit.collider.gameObject.name);
}
if (hit.collider.gameObject.name == "接线盒_封印L")
{
StartCoroutine(JunctionBoxLeft());
Debug.Log(hit.collider.gameObject.name);
}
if (hit.collider.gameObject.name == "集中器_封印R")
{
StartCoroutine(RightRconcentrator());
Debug.Log(hit.collider.gameObject.name);
}
if (hit.collider.gameObject.name == "集中器_封印_L")
{
StartCoroutine(LeftRconcentrator());
Debug.Log(hit.collider.gameObject.name);
}
}
}
}
}
float weight;
/// <summary>
/// 剥线钳动画
/// </summary>
/// <returns></returns>
IEnumerator PliersIE()
{
PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.33844f, 2.033f, -1.043f),1f);
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);
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);
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.DOMove(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.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 = 100; i >= 0; i--)
{
yield return new WaitForSeconds(0.001f);
PliersSki.SetBlendShapeWeight(0, i);
}
yield return new WaitForSeconds(0.5f);
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), 1f);
yield return new WaitForSeconds(1.5f);
StartCoroutine(PliersBack());
RightSkinnedMeshRenderer.gameObject.SetActive(false);
// Destroy(RightSkinnedMeshRenderer);
}
/// <summary>
/// 接线盒左边封印
/// </summary>
/// <returns></returns>
IEnumerator JunctionBoxLeft()
{
//PliersObj.gameObject.SetActive(true);
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(1.5f);
for (int i = 100; i >= 0; i--)
{
yield return new WaitForSeconds(0.001f);
PliersSki.SetBlendShapeWeight(0, i);
}
yield return new WaitForSeconds(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.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 = 100; i >= 0; i--)
{
yield return new WaitForSeconds(0.001f);
PliersSki.SetBlendShapeWeight(0, i);
}
yield return new WaitForSeconds(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.066f, 0.0611f, -0.1134f), 0.5f);
yield return new WaitForSeconds(1f);
StartCoroutine(PliersBack());
RconcentratorSMR.gameObject.SetActive(false);
}
/// <summary>
/// 集中器左边封印
/// </summary>
/// <returns></returns>
IEnumerator LeftRconcentrator()
{
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 = 100; i >= 0; i--)
{
yield return new WaitForSeconds(0.001f);
PliersSki.SetBlendShapeWeight(0, i);
}
yield return new WaitForSeconds(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);
}
}