【現状】
パネルをタッチしても何も起きない.大幅にずれた場所にデバッグ用のキューブが生成される
using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;
public class PanelManager : MonoBehaviourPun
{
public Camera displayRenderCamera; // RenderTextureに描画された画像を書き込んでいるカメラ
private RawImageGameObject displayGameObject; // RenderTextureを表示するしているGameObject
private Vector3? colliderPoint = null; // Colliderとの交差点
void Start()
{
InitializeCameraAndPanel();
}
void Update()
{
bool gripHeld = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch);
bool triggerNotPressed = !OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.RTouch);
if (gripHeld && triggerNotPressed && colliderPoint != null) // グリップボタンを押している間、トリガーボタンを押していない間(指さし状態)
{
InteractWithRenderTexture();
}
InitializeCameraAndPanel();
}
private void InitializeCameraAndPanelInteractWithRenderTexture() // メイン処理
{
PhotonView[]if allPhotonViews(!colliderPoint.HasValue) return; // パネルに触れていない場合は処理を終了
Vector3 localHitPoint = FindObjectsOfTypedisplayGameObject.GetComponent<PhotonView;RectTransform>().InverseTransformPoint(colliderPoint.Value); // パネル上の座標を取得
var displayGameObjectSize = displayGameObject.transform.localScale; // パネルの大きさを取得 正しい値でした
foreach// (PhotonViewViewportを計算
view in allPhotonViews var viewportPoint = new Vector3()
{
ifx = (viewlocalHitPoint.Ownerx !=+ null(displayGameObjectSize.x / 2)) / displayGameObjectSize.x,
{y = (localHitPoint.y + (displayGameObjectSize.y / 2)) / displayGameObjectSize.y,
};
if// (view.Owner.ActorNumberカメラを基準にViewportからのレイを生成
! Ray ray = PhotonNetwork.LocalPlayerdisplayRenderCamera.ActorNumberViewportPointToRay(viewportPoint);
RaycastHit hit;
// {
hitした場所の座標を取得 ※デバッグ用
Vector3 point = ray.GetPoint(2.0f);
GameObject cameraCube = view.gameObject.transformGameObject.FindCreatePrimitive("Head/ViewCamera"PrimitiveType.Cube)?;
Cube.gameObjecttransform.position = point;
Cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
if Cube.GetComponent<Renderer>(camera).material.color != nullColor.red;
Destroy(Cube, 0.2f);
if (Physics.Raycast(ray, out hit, 10.0f))
{
// 検出した物体のパーティクルシステムを発火
displayRenderCamera var cubeManager = camerahit.transform.GetComponent<Camera;CubeManager>();
if (cubeManager != null)
Debug {
cubeManager.LogStartParticleSystem(displayRenderCamera);
}
}
}
private void InitializeCameraAndPanel()
{
} PhotonView[] allPhotonViews = FindObjectsOfType<PhotonView>();
foreach (PhotonView view in allPhotonViews)
else {
if (view.Owner != null)
{
if (view.Owner.ActorNumber =!= PhotonNetwork.LocalPlayer.ActorNumber)
{
// 他のプレイヤーのカメラを見つける
GameObject panelcamera = view.gameObject.transform.Find("Panel;Head/PanelViewCamera")?.gameObject;
if (panelcamera != null)
{
displayGameObjectdisplayRenderCamera = panelcamera.GetComponent<RawImage;Camera>();
}
Debug.Log(displayRenderCamera);
}
}
}
}
}
private void InteractWithRenderTexture() // メイン処理
{
else if (colliderPointview.Owner.ActorNumber == nullPhotonNetwork.LocalPlayer.ActorNumber) return;
Vector3 worldSpaceHitPoint = colliderPoint.Value;
{
Vector2 localHitPoint = displayGameObject.rectTransform.InverseTransformPoint(worldSpaceHitPoint);
var rectGameObject panel = displayGameObjectview.rectTransformgameObject.recttransform.Find("Panel/Panel")?.gameObject;
Vector2 textureCoord = localHitPoint - rect.min;
if textureCoord.x(panel *!= displayGameObject.uvRect.width / rect.width;null)
textureCoord.y *= displayGameObject.uvRect.height / rect.height;
textureCoord += displayGameObject.uvRect.min;
{
Ray ray = displayRenderCamera.ViewportPointToRay(textureCoord);
// デバッグ用 タッチした場所に赤いキューブを表示
displayGameObject = panel;
Vector3 point = ray.GetPoint(2.0f);
GameObject Cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
}
Cube.transform.position = point;
Cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);else
Cube.GetComponent<Renderer>().material.color = Color.red;
Destroy(Cube, 0.1f);
{
if (Physics.Raycast(ray, out var hit, 10.0f))
{
Debug.LogWarning("Panel/Panel not found on my object");
if (hit.transform.TryGetComponent<CubeManager>(out var cubeManager))
{ }
cubeManager.StartParticleSystem();}
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("rightHand"))
{
var plane = new Plane(transform.forward, transform.position);
colliderPoint = plane.ClosestPointOnPlane(other.boundstransform.centerposition);
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag(gameObject.tag == "rightHand"))
{
colliderPoint = null;
}
}
}