123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- public class ArcTeleport : MonoBehaviour
- {
- private void Start()
- {
- this.m_nBackTrailCount = this.m_nTrailCount;
- this.m_trWarpCircle = base.transform.Find("WarpCircle");
- NDebug.Assert(this.m_trWarpCircle != null, "WarpCircleが見つかりません。");
- this.m_Circle_Size = this.m_trWarpCircle.localScale;
- this.m_trWarpCircle.gameObject.SetActive(false);
- this.m_Line_Obj = new GameObject();
- this.m_Line_Obj.name = "Teleport_Line";
- this.m_Line_Obj.AddComponent<SkinnedMeshRenderer>();
- SkinnedMeshRenderer component = this.m_Line_Obj.GetComponent<SkinnedMeshRenderer>();
- component.sharedMesh = new Mesh();
- component.sharedMesh.name = "Line_Mesh";
- this.Mesh_Setting(component);
- this.Bone_Setting(component);
- component.material = new Material(Resources.Load<Shader>(this.m_Line_Shader_Path));
- this.m_Line_Tex = Resources.Load<Texture>(this.m_Line_Texture_Path);
- this.m_Line_Tex_Gray = Resources.Load<Texture>(this.m_Gray_Texture_Path);
- component.material.SetTexture("_MainTex", this.m_Line_Tex);
- this.m_Line_Material = component.material;
- component.sharedMesh.RecalculateNormals();
- component.sharedMesh.RecalculateBounds();
- this.m_Line_Obj.transform.parent = base.transform;
- this.m_Line_Obj.SetActive(false);
- }
- private void Mesh_Setting(SkinnedMeshRenderer render)
- {
- Vector3[] array = new Vector3[this.m_nTrailCount * 4];
- Vector2[] array2 = new Vector2[this.m_nTrailCount * 4];
- List<int> list = new List<int>();
- int i;
- for (i = 0; i < this.m_nTrailCount; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- array[i * 4 + j].x = Mathf.Cos(3.14159274f * (float)j) * this.m_Line_Width / 2f * (float)(1 - j / 2);
- array[i * 4 + j].y = Mathf.Cos(3.14159274f * (float)j) * this.m_Line_Width / 2f * (float)(j / 2);
- array[i * 4 + j].z = this.m_fLineLength * ((float)i / (float)(this.m_nTrailCount - 1)) - this.m_fLineLength / 2f;
- array2[i * 4 + j].x = (float)i / (float)(this.m_nTrailCount - 1);
- array2[i * 4 + j].y = (float)(j % 2);
- }
- if (i != 0)
- {
- int k;
- for (k = 0; k < 2; k++)
- {
- int[] source = new int[]
- {
- 0,
- 1,
- 5,
- 0,
- 5,
- 4
- };
- list.AddRange(from e in source
- select e + k * 2 + (i - 1) * 4);
- }
- }
- }
- render.sharedMesh.vertices = array;
- render.sharedMesh.uv = array2;
- render.sharedMesh.triangles = list.ToArray();
- }
- private void Bone_Setting(SkinnedMeshRenderer render)
- {
- this.m_Line_Bones = new Transform[this.m_nTrailCount];
- Matrix4x4[] array = new Matrix4x4[this.m_nTrailCount];
- BoneWeight[] array2 = new BoneWeight[this.m_nTrailCount * 4];
- for (int i = 0; i < this.m_nTrailCount; i++)
- {
- GameObject gameObject = new GameObject();
- this.m_Line_Bones[i] = gameObject.transform;
- this.m_Line_Bones[i].name = "Line_Bone";
- this.m_Line_Bones[i].parent = this.m_Line_Obj.transform;
- this.m_Line_Bones[i].position = Vector3.forward * (this.m_fLineLength * ((float)i / (float)(this.m_nBackTrailCount - 1)) - this.m_fLineLength / 2f);
- array[i] = this.m_Line_Bones[i].worldToLocalMatrix * this.m_Line_Obj.transform.localToWorldMatrix;
- for (int j = 0; j < 4; j++)
- {
- array2[i * 4 + j] = new BoneWeight
- {
- boneIndex0 = i,
- weight0 = 1f
- };
- }
- }
- render.bones = this.m_Line_Bones;
- render.sharedMesh.bindposes = array;
- render.sharedMesh.boneWeights = array2;
- }
- public void SetCallBackOnMove(ArcTeleport.dgOnMove f_dgMove)
- {
- this.m_dgOnMove = f_dgMove;
- }
- public void WarpSelecting()
- {
- this.m_bPush = true;
- }
- public bool IsWarpSelecting()
- {
- return this.m_bPush;
- }
- public void WarpDicide()
- {
- this.m_bPush = false;
- }
- public void WarpCancel()
- {
- this.m_bBackPush = (this.m_bPush = false);
- }
- private void OnEnable()
- {
- this.WarpCancel();
- }
- private void OnDisable()
- {
- this.WarpCancel();
- }
- private IEnumerator Circle_Animation()
- {
- this.m_trWarpCircle.localScale = Vector3.forward * this.m_Circle_Size.z;
- float timer = 0f;
- for (;;)
- {
- timer += Time.deltaTime;
- if (timer >= this.m_Anime_Time)
- {
- break;
- }
- this.m_trWarpCircle.localScale = Vector3.forward * this.m_Circle_Size.z + new Vector3(this.m_Circle_Size.x, this.m_Circle_Size.y, 0f) * timer / this.m_Anime_Time;
- yield return null;
- }
- yield break;
- yield break;
- }
- private Vector3 Circle_Angle()
- {
- Vector3 result = Vector3.zero;
- Vector3 toDirection = this.m_trWarpCircle.position - GameMain.Instance.MainCamera.GetPos();
- toDirection.y = 0f;
- toDirection.Normalize();
- result = Quaternion.FromToRotation(Vector3.forward, toDirection).eulerAngles;
- result.x = (result.z = 0f);
- return result;
- }
- private IEnumerator Line_Flash()
- {
- float timer = 0f;
- Color line_color = Color.white;
- string tex_name = this.m_Line_Tex.name;
- for (;;)
- {
- timer += Time.deltaTime;
- float time_rate = Mathf.Abs(Mathf.Cos(0.0174532924f * (180f * (timer / this.m_Flash_Time))));
- if (!this.m_trWarpCircle.gameObject.activeSelf)
- {
- if (tex_name != this.m_Line_Tex_Gray.name)
- {
- this.m_Line_Material.SetTexture("_MainTex", this.m_Line_Tex_Gray);
- tex_name = this.m_Line_Tex_Gray.name;
- }
- }
- else if (tex_name != this.m_Line_Tex.name)
- {
- this.m_Line_Material.SetTexture("_MainTex", this.m_Line_Tex);
- tex_name = this.m_Line_Tex.name;
- }
- line_color.a = Mathf.Lerp(1f, this.m_Min_Alpha, time_rate);
- this.m_Line_Material.SetColor("_Color", line_color);
- yield return null;
- }
- yield break;
- }
- private void Update()
- {
- bool flag = false;
- if (GameMain.Instance.MainCamera.IsFadeProc())
- {
- this.m_bBackHit = (this.m_bBackPush = (this.m_bPush = false));
- base.StopCoroutine("Line_Flash");
- this.m_Line_Obj.SetActive(false);
- return;
- }
- if (this.m_bPush)
- {
- if (this.m_nBackTrailCount != this.m_nTrailCount)
- {
- this.m_nBackTrailCount = this.m_nTrailCount;
- }
- if (!this.m_Line_Obj.activeSelf)
- {
- base.StartCoroutine("Line_Flash");
- }
- this.m_Line_Obj.SetActive(true);
- Vector3 normalized = this.m_trParent.forward.normalized;
- Debug.DrawLine(this.m_trParent.position, this.m_trParent.position + normalized * 1f, Color.green);
- Vector3 vector = new Vector3(normalized.x, 0f, normalized.z);
- Vector3 normalized2 = vector.normalized;
- Debug.DrawLine(this.m_trParent.position, this.m_trParent.position + normalized2 * 1f, Color.cyan);
- float num = Vector3.Angle(normalized, normalized2);
- if (normalized.y < normalized2.y)
- {
- num *= -1f;
- }
- Vector3 zero = Vector3.zero;
- float num2 = Vector3.Angle(Vector3.forward, normalized2);
- if (normalized2.x < 0f)
- {
- num2 *= -1f;
- }
- Quaternion rotation = Quaternion.Euler(0f, num2, 0f);
- Vector3 zero2 = Vector3.zero;
- float num3 = this.m_Defo_Display_Length;
- for (float num4 = this.m_fLineSplitLength; num4 < this.m_fLineLength; num4 += this.m_fLineSplitLength)
- {
- float num5 = this.m_fVelocity * Mathf.Cos(num * 0.0174532924f) * num4;
- float num6 = this.m_fVelocity * Mathf.Sin(num * 0.0174532924f) * num4 - 0.5f * this.m_fGravity * (num4 * num4);
- Vector3 vector2 = this.m_trParent.position + rotation * zero;
- Vector3 vector3 = this.m_trParent.position + rotation * new Vector3(0f, num6, num5);
- Debug.DrawLine(vector2, vector3);
- zero.Set(0f, num6, num5);
- if (!flag)
- {
- this.m_ray.origin = vector2;
- this.m_ray.direction = vector3 - vector2;
- if (Physics.Raycast(this.m_ray, out this.m_hit, Vector3.Distance(vector2, vector3), 512))
- {
- flag = true;
- this.m_vHitPos = this.m_hit.point;
- this.m_trWarpCircle.transform.rotation = Quaternion.Euler(this.m_Fixed_Angle);
- if (!this.m_trWarpCircle.gameObject.activeSelf)
- {
- base.StartCoroutine("Circle_Animation");
- }
- this.m_trWarpCircle.gameObject.SetActive(true);
- this.m_trWarpCircle.position = this.m_vHitPos;
- num3 = num4;
- }
- }
- }
- if (this.m_nTrailCount > 0)
- {
- float num7 = num3 / (float)this.m_nTrailCount;
- if (num7 <= 0f)
- {
- num7 = 1f;
- }
- zero = Vector3.zero;
- float num8 = num7;
- for (int i = 0; i < this.m_nTrailCount; i++)
- {
- num8 += num7;
- float num9 = this.m_fVelocity * Mathf.Cos(num * 0.0174532924f) * num8;
- float num10 = this.m_fVelocity * Mathf.Sin(num * 0.0174532924f) * num8 - 0.5f * this.m_fGravity * (num8 * num8);
- Vector3 vector4 = this.m_trParent.position + rotation * zero;
- Vector3 end = this.m_trParent.position + rotation * new Vector3(0f, num10, num9);
- Debug.DrawLine(vector4, end, Color.blue);
- zero.Set(0f, num10, num9);
- this.m_Line_Bones[i].position = vector4;
- }
- }
- }
- else
- {
- if (this.m_bBackPush && this.m_bBackHit && this.m_dgOnMove != null)
- {
- this.m_dgOnMove(this.m_vHitPos, this.Circle_Angle());
- }
- base.StopCoroutine("Line_Flash");
- this.m_Line_Obj.SetActive(false);
- }
- if (!flag)
- {
- this.m_trWarpCircle.localScale = this.m_Circle_Size;
- this.m_trWarpCircle.gameObject.SetActive(false);
- base.StopCoroutine("Circle_Animation");
- }
- this.m_bBackHit = flag;
- this.m_bBackPush = this.m_bPush;
- }
- public bool m_bPush;
- private bool m_bBackPush;
- public Transform m_trParent;
- public float m_fGravity = 0.98f;
- public float m_fVelocity = 100f;
- public float m_fLineLength = 10f;
- public float m_fLineSplitLength = 0.1f;
- public int m_nTrailCount = 10;
- private int m_nBackTrailCount;
- public ArcTeleport.dgOnMove m_dgOnMove;
- private Vector3 m_vHitPos;
- private Ray m_ray = default(Ray);
- private RaycastHit m_hit;
- private bool m_bBackHit;
- private Transform m_trWarpCircle;
- [SerializeField]
- [Header("ワープサークルの固定角度")]
- private Vector3 m_Fixed_Angle = Vector3.right * -90f;
- [SerializeField]
- [Header("サークルのアニメーション時間")]
- private float m_Anime_Time = 0.75f;
- private Vector3 m_Circle_Size;
- private string m_Line_Shader_Path = "Shaders/Telepot_Line";
- private GameObject m_Line_Obj;
- private Transform[] m_Line_Bones;
- private string m_Line_Texture_Path = "SteamVR/ArcTeleport";
- private string m_Gray_Texture_Path = "SteamVR/ArcTeleport_Gray";
- private Texture m_Line_Tex;
- private Texture m_Line_Tex_Gray;
- [SerializeField]
- [Header("ラインの横幅")]
- private float m_Line_Width = 0.1f;
- [SerializeField]
- [Header("表示するラインの長さの基準値")]
- private float m_Defo_Display_Length = 5.5f;
- [SerializeField]
- [Header("点滅時間")]
- private float m_Flash_Time = 1.5f;
- [SerializeField]
- [Range(0f, 1f)]
- private float m_Min_Alpha = 0.4f;
- private Material m_Line_Material;
- public delegate void dgOnMove(Vector3 f_vPosWorld, Vector3 f_vRotWorld);
- }
|