c# - How do I remedy this type does not exist in type error? -
i need value script keep getting error says
the type name 'head' not exist in type 'steamvr_camera'.
my code:
using unityengine; using system.collections; using unityengine.vr; public class hmdhelper : monobehaviour { private steamvr_camera.head.localposition hmdlocalpos; //error thrown here. void start() { } // update called once per frame void update() { if (input.getkeydown("g")) { autorotate(); } } void autorotate() { hmdlocalpos = inputtracking.getlocalposition(head); debug.log(hmdlocalpos); } }
what have fix error?
this script retrieved other value (hmdlocalpos
) from...
//========= copyright 2014, valve corporation, rights reserved. =========== // // purpose: adds steamvr render support existing camera objects // //============================================================================= using unityengine; using system.collections; using system.reflection; using valve.vr; [requirecomponent(typeof(camera))] public class steamvr_camera : monobehaviour { [serializefield] private transform _head; public transform head { { return _head; } } public transform offset { { return _head; } } // legacy public transform origin { { return _head.parent; } } [serializefield] private transform _ears; public transform ears { { return _ears; } } public ray getray() { return new ray(_head.position, _head.forward); } public bool wireframe = false; [serializefield] private steamvr_cameraflip flip; #region materials static public material blitmaterial; // using single shared offscreen buffer render scene. needs larger // backbuffer account distortion correction. default resolution // gives 1:1 sized pixels in center of view, quality can adjusted or // down using following scale value balance performance. static public float sceneresolutionscale = 1.0f; static private rendertexture _scenetexture; static public rendertexture getscenetexture(bool hdr) { var vr = steamvr.instance; if (vr == null) return null; int w = (int)(vr.scenewidth * sceneresolutionscale); int h = (int)(vr.sceneheight * sceneresolutionscale); int aa = qualitysettings.antialiasing == 0 ? 1 : qualitysettings.antialiasing; var format = hdr ? rendertextureformat.argbhalf : rendertextureformat.argb32; if (_scenetexture != null) { if (_scenetexture.width != w || _scenetexture.height != h || _scenetexture.antialiasing != aa || _scenetexture.format != format) { debug.log(string.format("recreating scene texture.. old: {0}x{1} msaa={2} [{3}] new: {4}x{5} msaa={6} [{7}]", _scenetexture.width, _scenetexture.height, _scenetexture.antialiasing, _scenetexture.format, w, h, aa, format)); object.destroy(_scenetexture); _scenetexture = null; } } if (_scenetexture == null) { _scenetexture = new rendertexture(w, h, 0, format); _scenetexture.antialiasing = aa; #if (unity_5_3 || unity_5_2 || unity_5_1 || unity_5_0) // openvr assumes floating point render targets linear unless otherwise specified. var colorspace = (hdr && qualitysettings.activecolorspace == colorspace.gamma) ? ecolorspace.gamma : ecolorspace.auto; steamvr.unity.setcolorspace(colorspace); #endif } return _scenetexture; } #endregion #region enable / disable void ondisable() { steamvr_render.remove(this); } void onenable() { #if !(unity_5_3 || unity_5_2 || unity_5_1 || unity_5_0) // convert camera rig native openvr integration. var t = transform; if (head != t) { expand(); t.parent = origin; while (head.childcount > 0) head.getchild(0).parent = t; destroyimmediate(head.gameobject); _head = t; } if (flip != null) { destroyimmediate(flip); flip = null; } if (!steamvr.usingnativesupport) { enabled = false; return; } #else // bail if no hmd connected var vr = steamvr.instance; if (vr == null) { if (head != null) { head.getcomponent<steamvr_gameview>().enabled = false; head.getcomponent<steamvr_trackedobject>().enabled = false; } if (flip != null) flip.enabled = false; enabled = false; return; } // ensure rig set expand(); if (blitmaterial == null) { blitmaterial = new material(shader.find("custom/steamvr_blit")); } // set remaining hmd specific settings var camera = getcomponent<camera>(); camera.fieldofview = vr.fieldofview; camera.aspect = vr.aspect; camera.eventmask = 0; // disable mouse events camera.orthographic = false; // force perspective camera.enabled = false; // manually rendered steamvr_render if (camera.actualrenderingpath != renderingpath.forward && qualitysettings.antialiasing > 1) { debug.logwarning("msaa supported in forward rendering path. (disabling msaa)"); qualitysettings.antialiasing = 0; } // ensure game view camera hdr setting matches var headcam = head.getcomponent<camera>(); if (headcam != null) { headcam.hdr = camera.hdr; headcam.renderingpath = camera.renderingpath; } #endif ears.getcomponent<steamvr_ears>().vrcam = this; steamvr_render.add(this); } #endregion #region functionality ensure steamvr_camera component last component on object void awake() { forcelast(); } static hashtable values; public void forcelast() { if (values != null) { // restore values on new instance foreach (dictionaryentry entry in values) { var f = entry.key fieldinfo; f.setvalue(this, entry.value); } values = null; } else { // make sure it's last component var components = getcomponents<component>(); // first make sure there aren't other steamvr_cameras on object. (int = 0; < components.length; i++) { var c = components[i] steamvr_camera; if (c != null && c != this) { if (c.flip != null) destroyimmediate(c.flip); destroyimmediate(c); } } components = getcomponents<component>(); #if !(unity_5_3 || unity_5_2 || unity_5_1 || unity_5_0) if (this != components[components.length - 1]) { #else if (this != components[components.length - 1] || flip == null) { if (flip == null) flip = gameobject.addcomponent<steamvr_cameraflip>(); #endif // store off values restored on new instance values = new hashtable(); var fields = gettype().getfields(bindingflags.instance | bindingflags.nonpublic | bindingflags.public); foreach (var f in fields) if (f.ispublic || f.isdefined(typeof(serializefield), true)) values[f] = f.getvalue(this); var go = gameobject; destroyimmediate(this); go.addcomponent<steamvr_camera>().forcelast(); } } } #endregion #region expand / collapse object hierarchy #if unity_editor public bool isexpanded { { return head != null && transform.parent == head; } } #endif const string eyesuffix = " (eye)"; const string earssuffix = " (ears)"; const string headsuffix = " (head)"; const string originsuffix = " (origin)"; public string basename { { return name.endswith(eyesuffix) ? name.substring(0, name.length - eyesuffix.length) : name; } } // object hierarchy creation make easy parent other objects appropriately, // otherwise gets called on demand @ runtime. remaining initialization // performed @ startup, once hmd has been identified. public void expand() { var _origin = transform.parent; if (_origin == null) { _origin = new gameobject(name + originsuffix).transform; _origin.localposition = transform.localposition; _origin.localrotation = transform.localrotation; _origin.localscale = transform.localscale; } if (head == null) { _head = new gameobject(name + headsuffix, typeof(steamvr_gameview), typeof(steamvr_trackedobject)).transform; head.parent = _origin; head.position = transform.position; head.rotation = transform.rotation; head.localscale = vector3.one; head.tag = tag; var camera = head.getcomponent<camera>(); camera.clearflags = cameraclearflags.nothing; camera.cullingmask = 0; camera.eventmask = 0; camera.orthographic = true; camera.orthographicsize = 1; camera.nearclipplane = 0; camera.farclipplane = 1; camera.useocclusionculling = false; } if (transform.parent != head) { transform.parent = head; transform.localposition = vector3.zero; transform.localrotation = quaternion.identity; transform.localscale = vector3.one; while (transform.childcount > 0) transform.getchild(0).parent = head; var guilayer = getcomponent<guilayer>(); if (guilayer != null) { destroyimmediate(guilayer); head.gameobject.addcomponent<guilayer>(); } var audiolistener = getcomponent<audiolistener>(); if (audiolistener != null) { destroyimmediate(audiolistener); _ears = new gameobject(name + earssuffix, typeof(steamvr_ears)).transform; ears.parent = _head; ears.localposition = vector3.zero; ears.localrotation = quaternion.identity; ears.localscale = vector3.one; } } if (!name.endswith(eyesuffix)) name += eyesuffix; } public void collapse() { transform.parent = null; // move children , components head camera. while (head.childcount > 0) head.getchild(0).parent = transform; var guilayer = head.getcomponent<guilayer>(); if (guilayer != null) { destroyimmediate(guilayer); gameobject.addcomponent<guilayer>(); } if (ears != null) { while (ears.childcount > 0) ears.getchild(0).parent = transform; destroyimmediate(ears.gameobject); _ears = null; gameobject.addcomponent(typeof(audiolistener)); } if (origin != null) { // if created origin originally, destroy now. if (origin.name.endswith(originsuffix)) { // reparent children don't accidentally delete them. var _origin = origin; while (_origin.childcount > 0) _origin.getchild(0).parent = _origin.parent; destroyimmediate(_origin.gameobject); } else { transform.parent = origin; } } destroyimmediate(head.gameobject); _head = null; if (name.endswith(eyesuffix)) name = name.substring(0, name.length - eyesuffix.length); } #endregion #if (unity_5_3 || unity_5_2 || unity_5_1 || unity_5_0) #region render callbacks void onprerender() { if (flip) flip.enabled = (steamvr_render.top() == && steamvr.instance.graphicsapi == egraphicsapiconvention.api_directx); var headcam = head.getcomponent<camera>(); if (headcam != null) headcam.enabled = (steamvr_render.top() == this); if (wireframe) gl.wireframe = true; } void onpostrender() { if (wireframe) gl.wireframe = false; } void onrenderimage(rendertexture src, rendertexture dest) { if (steamvr_render.top() == this) { int eventid; if (steamvr_render.eye == evreye.eye_left) { // gpu started on work avoid bubbles @ top of frame. steamvr_utils.queueeventonrenderthread(steamvr.unity.k_nrendereventid_flush); eventid = steamvr.unity.k_nrendereventid_submitl; } else { eventid = steamvr.unity.k_nrendereventid_submitr; } // queue call on render thread submit our render target compositor. steamvr_utils.queueeventonrenderthread(eventid); } graphics.setrendertarget(dest); steamvr_camera.blitmaterial.maintexture = src; gl.pushmatrix(); gl.loadortho(); steamvr_camera.blitmaterial.setpass(0); gl.begin(gl.quads); gl.texcoord2(0.0f, 0.0f); gl.vertex3(-1, 1, 0); gl.texcoord2(1.0f, 0.0f); gl.vertex3( 1, 1, 0); gl.texcoord2(1.0f, 1.0f); gl.vertex3( 1, -1, 0); gl.texcoord2(0.0f, 1.0f); gl.vertex3(-1, -1, 0); gl.end(); gl.popmatrix(); graphics.setrendertarget(null); } #endregion #endif }
how fix this? thank you.
the type wrong. needs vector3
.
private vector3 hmdlocalpos; void start() { hdmlocalpos = steamvr_camera.head.localposition; }
edit:
replace hdmlocalpos
property reference steamvr_camera
, access it's properties this:
public steamvr_camera steamcam; // popuplate via inspector or find() (or similar) void start() { // access steamcam.head.localposition = }
i think want (to change head.localposition of camera).
Comments
Post a Comment