12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using SC.XR.Unity;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Rendering;
- public class SafetyAreaCommandBuffer : SingletonMono<SafetyAreaCommandBuffer>
- {
- public Mesh quadMesh;
- public Material quadMaterial;
- public Material blitMaterial;
- //public Color clearColor;
- private CommandBuffer commandBuffer;
- private float fadeValue;
- private bool isLoading = false;
- // Start is called before the first frame update
- IEnumerator Start()
- {
- yield return new WaitUntil(()=>API_GSXR_Slam.GSXR_Is_SlamInitialized() && API_GSXR_Slam.GSXR_Get_EyeCameras().Count != 0);
- commandBuffer = new CommandBuffer();
- commandBuffer.name = "LQRCommandBufferTest";
-
- }
- public void AddLoading()
- {
- if (API_GSXR_Slam.GSXR_Get_EyeCameras().Count == 0) return;
- RemoveLoading();
- fadeValue = 0f;
- isLoading = true;
- List<Camera> cameraList = API_GSXR_Slam.GSXR_Get_EyeCameras();
- for (int i = 0; i < cameraList.Count; i++)
- {
- Camera camera = cameraList[i];
- camera.AddCommandBuffer(CameraEvent.AfterEverything, commandBuffer);
- }
- }
- public void RemoveLoading()
- {
- if (!isLoading) return;
- isLoading = false;
- List<Camera> cameraList = API_GSXR_Slam.GSXR_Get_EyeCameras();
- for (int i = 0; i < cameraList.Count; i++)
- {
- Camera camera = cameraList[i];
- camera.RemoveCommandBuffer(CameraEvent.AfterEverything, commandBuffer);
- }
- }
- private void Update()
- {
- if (isLoading)
- {
- fadeValue += Time.deltaTime;
- if (fadeValue > 2f)
- {
- RemoveLoading();
- }
- }
- }
- private float rotateValue = 0f;
- // Update is called once per frame
- void LateUpdate()
- {
- if (!isLoading) return;
- if (commandBuffer == null) return;
- if (API_GSXR_Slam.GSXR_Get_Head() == null) return;
- commandBuffer.Clear();
- commandBuffer.ClearRenderTarget(true, true, Color.black);
- if (fadeValue > 0.5f)
- {
- Matrix4x4 matrix = new Matrix4x4();
- matrix.SetTRS(API_GSXR_Slam.GSXR_Get_Head().position + API_GSXR_Slam.GSXR_Get_Head().forward * 15f,
- Quaternion.Euler(API_GSXR_Slam.GSXR_Get_Head().rotation.eulerAngles.x, API_GSXR_Slam.GSXR_Get_Head().rotation.eulerAngles.y, rotateValue += 250 * Time.deltaTime),
- Vector3.one * 0.8f);
- commandBuffer.DrawMesh(quadMesh, matrix, quadMaterial);
- }
- }
- }
|