You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
4.3 KiB
106 lines
4.3 KiB
3 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
/// <summary>
|
||
|
/// 设置泄漏点朝向
|
||
|
/// </summary>
|
||
|
public class SetFireDire : MonoBehaviour {
|
||
|
|
||
|
public void SetDirec(RaycastHit hit)
|
||
|
{
|
||
|
SetFireYScale( hit);
|
||
|
StartCoroutine(delay(hit));
|
||
|
}
|
||
|
|
||
|
IEnumerator delay(RaycastHit hit)
|
||
|
{
|
||
|
yield return new WaitForEndOfFrame();
|
||
|
Transform transCenter = hit.collider.transform.Find("Center");
|
||
|
if (transCenter==null)
|
||
|
{
|
||
|
GameObject obj = new GameObject("Center");
|
||
|
obj.transform.SetParent(hit.collider.transform);
|
||
|
obj.transform.localEulerAngles = Vector3.zero;
|
||
|
obj.transform.localPosition = Vector3.zero;
|
||
|
transCenter = obj.transform;
|
||
|
}
|
||
|
Vector3 vec1, vec2;
|
||
|
vec1 = hit.point- new Vector3(transCenter.position.x,hit.point.y,transCenter.position.z);
|
||
|
vec2 =transform.forward;
|
||
|
vec1 = vec1.normalized;
|
||
|
float fangxiang = (Vector3.Cross(vec2, vec1).y > 0 ? 1 : -1);
|
||
|
float jiaJiao = Vector3.Angle(vec2, vec1);
|
||
|
if (name.Contains("guanTiFire"))
|
||
|
{
|
||
|
transform.eulerAngles = new Vector3(0, /*180 - */jiaJiao * fangxiang-180, 0);
|
||
|
// transform.localPosition += new Vector3(0, 4, (-1f * fangxiang));
|
||
|
}
|
||
|
else {
|
||
|
transform.eulerAngles = new Vector3(0, jiaJiao * fangxiang, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
///// <summary>
|
||
|
///// 设置Y轴缩放,使火焰可以流到地面
|
||
|
///// </summary>
|
||
|
void SetFireYScale(RaycastHit hitGuanTi)
|
||
|
{ // 设置Y轴长度,是它能流掉地面
|
||
|
if (name.Contains("guanTiFire"))
|
||
|
{
|
||
|
Transform ranyou = transform.Find("ranyou");
|
||
|
float particleLength = /*(ranyou.position.y * .9f - transform.position.y)*/ transform.Find("Oil").GetComponent<MeshFilter>().sharedMesh.bounds.size.z * 2;
|
||
|
Ray ray = new Ray(ranyou.position, -transform.up);
|
||
|
RaycastHit hitinfo;
|
||
|
if (Physics.Raycast(ray, out hitinfo, 100, LayerMask.GetMask("dimian")))
|
||
|
{//碰到地面层
|
||
|
float length = -hitinfo.collider.transform.position.y + ranyou.position.y;
|
||
|
float scale1 = length / particleLength;//燃油粒子高度/粒子整体高度,得到一个缩放比
|
||
|
|
||
|
transform.localScale *= (scale1 * scale1);
|
||
|
// Debug.Log("油罐高度:" + hitGuanTi.collider.bounds.size.y + " 粒子现在的长度:" + (ranyou.position.y-hitinfo.collider.transform.position.y) );
|
||
|
|
||
|
//TODO 如果缩放过高,会使燃油的高度超出油罐的高度,此时需要调整
|
||
|
ResetParticlePos(ranyou.position.y - hitinfo.collider.transform.position.y, hitGuanTi.collider.bounds.size.y, hitinfo);
|
||
|
|
||
|
Transform transRanyou = transform.Find("RanYou");
|
||
|
transRanyou.position = new Vector3(transRanyou.position.x, hitinfo.point.y + .15f, transRanyou.position.z);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void ResetParticlePos(float particleLength,float oilTankHeight,RaycastHit hitGround)
|
||
|
{
|
||
|
//当缩放完成后,如果粒子的最高点高于油罐高度,则需要对粒子高度进行重新的调整
|
||
|
if (particleLength<oilTankHeight*0.8f)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
//Debug.Log("transform.position:" + transform.position + " " + (-oilTankHeight * .9f + hitGround.collider.bounds.size.y));
|
||
|
//Debug.Log("transform.localposition:" + transform.localPosition);
|
||
|
transform.position = new Vector3(transform.localPosition.x,(-oilTankHeight * .9f + hitGround.collider.bounds.size.y) , transform.localPosition.z);
|
||
|
transform.localScale = new Vector3(transform.localScale.x,2f,transform.localScale.z);
|
||
|
transform.Find("text").localScale /= transform.localScale.x*1.1f;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public void SetRanYouPos()
|
||
|
{
|
||
|
Transform ranyou = transform.Find("ranyou");
|
||
|
Ray ray = new Ray(ranyou.position, -transform.up);
|
||
|
RaycastHit hitinfo;
|
||
|
if (Physics.Raycast(ray, out hitinfo, 100, LayerMask.GetMask("dimian")))
|
||
|
{//碰到地面层
|
||
|
|
||
|
Transform transRanyou = transform.Find("RanYou");
|
||
|
transRanyou.position = new Vector3(transRanyou.position.x, hitinfo.point.y + .15f, transRanyou.position.z);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|