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

129 lines
3.4 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 SkinnedMeshRenderer;
/// <summary>
/// 变电箱门锁
/// </summary>
public Transform Doorlock;
/// <summary>
/// 变电箱左门
/// </summary>
public Transform DoorOfCabinet;
/// <summary>
/// 是否选取/在手上
/// </summary>
bool inhand;
void Start()
{
//PliersAni.Play("线钳");
}
void Update()
{
if (!inhand)
{
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 (Input.GetKeyDown(KeyCode.E))
//{
// PliersAni.Play("钳线");
//}
}
float weight;
/// <summary>
/// 剥线钳动画
/// </summary>
/// <returns></returns>
IEnumerator PliersIE()
{
PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.0849f, 2.696f, 163.5919f),1f);
yield return new WaitForSeconds(1.5f);
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.01f);
PliersSki.SetBlendShapeWeight(0, i);
}
yield return new WaitForSeconds(1f);
StartCoroutine(OpenLock());
}
/// <summary>
/// 打开封印动画
/// </summary>
/// <returns></returns>
IEnumerator OpenLock()
{
for (int i = 0; i < 100; i++)
{
yield return new WaitForSeconds(0.01f);
SkinnedMeshRenderer.SetBlendShapeWeight(0, i);
}
yield return new WaitForSeconds(1f);
SkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.637f, 0.12f, -0.015f), 1f);
yield return new WaitForSeconds(2f);
Destroy(SkinnedMeshRenderer);
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());
}
IEnumerator PliersBack()
{
PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.05f, 2.386f, 163.028f),1.5f);
PliersObj.gameObject.transform.DOLocalRotate(new Vector3(0,90,0),1.5f);
yield return new WaitForSeconds(2f);
PliersObj.gameObject.SetActive(false);
}
}