質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

265閲覧

Unityで再生した後にONにしていた機能をOFFにしたい

ehuronkon35

総合スコア33

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2018/10/25 03:18

Unityで再生した後にONにしていた機能をOFFにしたい
イメージ説明

これはFOVE0のカメラのインターフェースです。

この中の「Fove Interface」の中の
「Client uses...」の
「Orientation」のチャックを再生した後に外したいです。

そのためにはどうすればいいか教えていただきたいです。

このスクリプトはこれです。

C#

1using Fove.Managed; 2using System; 3using System.Collections; 4using System.Collections.Generic; 5 6namespace UnityEngine 7{ 8 9 public sealed class FoveInterface : FoveInterfaceBase 10 { 11 [Tooltip( 12 "INTERMEDIATE: Use this prefab as a template for creating eye cameras. Useful if you want custom shaders, etc...")] 13 [SerializeField] private Camera eyeCameraPrototype = null; 14 15 [SerializeField] private bool useCameraPrefab = false; 16 17 [Tooltip( 18 "ADVANCED: Use this if you are wanting to take (almost) full control of the camera system... use at own risk")] 19 [SerializeField] private Camera leftEyeOverride = null; 20 21 [Tooltip( 22 "ADVANCED: Use this if you are wanting to take (almost) full control of the camera system... use at own risk")] 23 [SerializeField] private Camera rightEyeOverride = null; 24 25 [Tooltip( 26 "ADVANCED: Use this if you are wanting to take (almost) full control of the camera system... use at own risk")] 27 [SerializeField] private bool useCameraOverride = false; 28 29 [SerializeField] private int antialiasSampleCount = 1; 30 [SerializeField] private bool overrideAntialiasing = false; 31 32 [SerializeField] private bool enableRendering = true; 33 34 private Camera _leftCamera, _rightCamera; 35 private GameObject _leftCameraObject, _rightCameraObject; 36 private bool _hasCameras = false; 37 private FoveEyeCamera _leftFoveEye, _rightFoveEye; 38 39 private static List<FoveInterface> _sAllLegacyInterfaces; 40 41 private GameObject SetupDummyViewCameraObject(float ipd, EFVR_Eye whichEye) 42 { 43 GameObject temp = new GameObject(); 44 temp.name = string.Format("FOVE Eye ({0})", whichEye); 45 temp.transform.parent = transform; 46 temp.transform.localPosition = new Vector3(ipd, eyeHeight, eyeForward) * worldScale; 47 temp.transform.localRotation = UnityEngine.Quaternion.identity; 48 return temp; 49 } 50 51 52 private Camera SetupFoveViewCamera(float ipd, EFVR_Eye whichEye, out GameObject go, out FoveEyeCamera ec) 53 { 54 GameObject temp = null; 55 Camera cam = null; 56 Camera mirror = GetComponent<Camera>(); 57 58 if (useCameraOverride && useCameraPrefab) 59 { 60 Debug.LogError("You can not use a prefab and override cameras at the same time!"); 61 } 62 63 if (useCameraOverride) 64 { 65 if (leftEyeOverride != null && rightEyeOverride != null) 66 { 67 if (whichEye == EFVR_Eye.Left) 68 { 69 cam = leftEyeOverride; 70 } 71 else if (whichEye == EFVR_Eye.Right) 72 { 73 cam = rightEyeOverride; 74 } 75 else 76 { 77 Debug.LogError("Camera Override in unforseen state"); 78 } 79 temp = cam.gameObject; 80 _nearClip = leftEyeOverride.nearClipPlane; 81 _farClip = leftEyeOverride.farClipPlane; 82 83 //sanity check 84 if (leftEyeOverride.nearClipPlane != rightEyeOverride.nearClipPlane || 85 leftEyeOverride.farClipPlane != rightEyeOverride.farClipPlane) 86 { 87 Debug.LogWarning("Left and Right eye clip planes differ, using left plane for VR!"); 88 } 89 90 //the mirror camera is the portal/preview view for unity etc - useful for use when there is no compositor. 91 if (mirror != null) 92 { 93 mirror.nearClipPlane = _nearClip; 94 mirror.farClipPlane = _farClip; 95 } 96 } 97 else 98 { 99 Debug.LogError("Both Camera Overrides must be assiged if using override mode."); 100 } 101 } 102 103 // Use a camera prefab if set to do so and one is available 104 if (useCameraPrefab) 105 { 106 if (eyeCameraPrototype != null) 107 { 108 if (eyeCameraPrototype.GetComponent<FoveInterface>() != null) 109 { 110 Debug.LogError("FoveInterface's eye camera prototype has another FoveInterface component attached. " + whichEye); 111 go = null; 112 ec = null; 113 return null; 114 } 115 cam = Instantiate(eyeCameraPrototype); 116 _nearClip = cam.nearClipPlane; 117 _farClip = cam.farClipPlane; 118 119 temp = cam.gameObject; 120 121 if (mirror != null) 122 { 123 mirror.nearClipPlane = _nearClip; 124 mirror.farClipPlane = _farClip; 125 } 126 } 127 } 128 129 cam.fieldOfView = 95.0f; 130 131 ec = temp.GetComponent<FoveEyeCamera>(); 132 if (ec == null) 133 { 134 ec = temp.AddComponent<FoveEyeCamera>(); 135 } 136 137 ec.whichEye = whichEye; 138 ec.suppressProjectionUpdates = suppressProjectionUpdates; 139 ec.foveInterfaceBase = this; 140 141 142 temp.name = string.Format("FOVE Eye ({0})", whichEye); 143 temp.transform.parent = transform; 144 145 UpdateCameraSettings(temp, ec, ipd); 146 147 go = temp; 148 return cam; 149 } 150 151 private void UpdateCameraSettings(GameObject cameraObject, FoveEyeCamera eyeCam, float iod) 152 { 153 cameraObject.transform.localPosition = new Vector3(iod, eyeHeight, eyeForward) * worldScale; 154 cameraObject.transform.localRotation = Quaternion.identity; 155 156 eyeCam.resolutionScale = oversamplingRatio; 157 158 if (overrideAntialiasing) 159 { 160 eyeCam.antiAliasing = antialiasSampleCount; 161 } 162 else 163 { 164 if (QualitySettings.antiAliasing > 0) 165 { 166 eyeCam.antiAliasing = QualitySettings.antiAliasing; 167 } 168 else 169 { 170 eyeCam.antiAliasing = 1; 171 } 172 } 173 } 174 175 public override bool RefreshSetup() // called before any Start methods 176 { 177 if (!base.RefreshSetup()) 178 return false; 179 180 // Initialize the extra-legacy static list of all legacy interfaces 181 if (_sAllLegacyInterfaces == null) 182 { 183 _sAllLegacyInterfaces = new List<FoveInterface>(); 184 } 185 if (!_sAllLegacyInterfaces.Contains(this)) 186 { 187 _sAllLegacyInterfaces.Add(this); 188 } 189 190 if (!ConnectCompositor()) 191 return false; 192 193 // Use the legacy screen blit shader, but make sure to use the right version to fix (or not) 194 // a screen inversion bug that happened until version 5.6. 195 { 196 var unityVersion = Application.unityVersion; 197 var versionBits = unityVersion.Split('.'); 198 199 if (versionBits.Length < 2) 200 { 201 Debug.LogWarning("FoveInterface: Unrecognized Unity version: " + unityVersion); 202 } 203 204 var uMajor = int.Parse(versionBits[0]); 205 var uMinor = int.Parse(versionBits[1]); 206 207 string shaderString = "Fove/EyeShader"; 208 209 // Before Unity 5.6, there was a bug with antialiasing when blitting to the screen that would invert 210 // the texture. If running on Unity below 5.6, swap the blit texture if AA detected. 211 if (QualitySettings.antiAliasing != 0 && uMajor < 6 && uMinor < 6) 212 { 213 shaderString = "Fove/EyeShaderInverted"; 214 } 215 _screenBlitMaterial = new Material(Shader.Find(shaderString)); 216 } 217 218 return true; 219 } 220 221 protected override void StartHelper() 222 { 223 base.StartHelper(); 224 225 if (enableRendering) 226 { 227 StartCoroutine(RenderCoroutine()); 228 } 229 } 230 public override bool ConnectCompositor() 231 { 232 if (!base.ConnectCompositor()) 233 return false; 234 235 if (!_hasCameras) 236 { 237 // LEFT eye 238 if (_leftCamera == null) 239 { 240 _leftCamera = SetupFoveViewCamera(-usedIOD * 0.5f, EFVR_Eye.Left, out _leftCameraObject, out _leftFoveEye); 241 } 242 else 243 { 244 UpdateCameraSettings(_leftCameraObject, _leftFoveEye, -usedIOD * 0.5f); 245 } 246 247 // RIGHT eye 248 if (_rightCamera == null) 249 { 250 _rightCamera = SetupFoveViewCamera(usedIOD * 0.5f, EFVR_Eye.Right, out _rightCameraObject, out _rightFoveEye); 251 } 252 else 253 { 254 UpdateCameraSettings(_rightCameraObject, _rightFoveEye, usedIOD * 0.5f); 255 } 256 257 if (_leftCamera == null || _rightCamera == null) 258 { 259 Debug.LogError("Error refreshing FoveInterface (Legacy) setup: One or more eye cameras weren't initialized."); 260 enabled = false; 261 return false; 262 } 263 264 // Disable eye cameras if we aren't meant to be rendering anything 265 if (!enableRendering) 266 { 267 _leftFoveEye.enabled = false; 268 _rightFoveEye.enabled = false; 269 } 270 271 // Disable the mirror camera 272 Camera mirror = GetComponent<Camera>(); 273 if (mirror != null) 274 { 275 mirror.cullingMask = 0; 276 mirror.stereoTargetEye = StereoTargetEyeMask.None; 277 } 278 279 if (eyeCameraPrototype != null) 280 { 281 if (eyeCameraPrototype.gameObject.activeInHierarchy) 282 { 283 eyeCameraPrototype.gameObject.SetActive(false); 284 } 285 } 286 _hasCameras = true; 287 } 288 else 289 { 290 _leftCameraObject.SetActive(true); 291 _rightCameraObject.SetActive(true); 292 } 293 294 _leftFoveEye.Compositor = _compositor; 295 _rightFoveEye.Compositor = _compositor; 296 297 return true; 298 } 299 300 public new static Quaternion GetHMDRotation_Immediate() 301 { 302 if (_sAllLegacyInterfaces.Count > 0) 303 { 304 return ((FoveInterfaceBase) _sAllLegacyInterfaces[0]).GetHMDRotation_Immediate(); 305 } 306 return Quaternion.identity; 307 } 308 309 } 310} 311

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2018/10/25 03:21

回答依頼いただいて申し訳ないのですがいずれのタグも私の方では持ち合わせがないので他の方に回していただければと
guest

回答1

0

ベストアンサー

C#

1 protected override void StartHelper() 2 { 3 base.StartHelper(); 4 5 if (enableRendering) 6 { 7 StartCoroutine(RenderCoroutine()); 8 } 9 10 orientation = false; 11 }

再生した直後で良いならば上記の様にorientation = false;を追記するだけで良いのではないでしょうか。

投稿2018/10/25 05:35

編集2018/10/25 05:36
Hawn

総合スコア1222

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ehuronkon35

2018/10/25 05:59

回答ありがとうございます!! すいません、このコードはどこに書くとできますかね。。。 Unityの理解が浅くてすいません。。
ehuronkon35

2018/10/25 06:08

ありがとうございます!! それを追記するだけでできました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問