c# - Enable and disable Renderer or Canvas not working -
every 5 seconds need take photo , display in world. part working fine. once photo taken need disappear 1 second after. that's i'm stuck. i've gotten disappear cant new picture reappear when function called again.
any ideas?
i've tried:
m_canvasrenderer.enabled = false; m_canvasrenderer.enabled = true; m_canvas = null; m_canvas.setactive(false); m_canvas.setactive(true);
with no luck
public class photocaptureexample : monobehaviour { gesturerecognizer m_gesturerecognizer; gameobject m_canvas = null; renderer m_canvasrenderer = null; photocapture m_photocaptureobj; cameraparameters m_cameraparameters; bool m_capturingphoto = false; texture2d m_texture = null; void start() { initialize(); invokerepeating("takephoto", 5.0f, 5.0f); //startcoroutine(takephoto()); } void takephoto() { if (m_capturingphoto) { return; } m_capturingphoto = true; m_photocaptureobj.takephotoasync(onphotocaptured); } void onphotocaptured(photocapture.photocaptureresult result, photocaptureframe photocaptureframe) { // m_canvasrenderer.enabled = true; if (m_canvas == null) { m_canvas = gameobject.createprimitive(primitivetype.quad); m_canvas.name = "photocapturecanvas"; m_canvasrenderer = m_canvas.getcomponent<renderer>() renderer; m_canvasrenderer.material = new material(shader.find("ar/holographicimageblend")); } matrix4x4 cameratoworldmatrix; photocaptureframe.trygetcameratoworldmatrix(out cameratoworldmatrix); matrix4x4 worldtocameramatrix = cameratoworldmatrix.inverse; matrix4x4 projectionmatrix; photocaptureframe.trygetprojectionmatrix(out projectionmatrix); photocaptureframe.uploadimagedatatotexture(m_texture); m_texture.wrapmode = texturewrapmode.clamp; m_canvasrenderer.sharedmaterial.settexture("_maintex", m_texture); m_canvasrenderer.sharedmaterial.setmatrix("_worldtocameramatrix", worldtocameramatrix); m_canvasrenderer.sharedmaterial.setmatrix("_cameraprojectionmatrix", projectionmatrix); m_canvasrenderer.sharedmaterial.setfloat("_vignettescale", 1.0f); // position canvas object in front // of real world web camera. vector3 position = cameratoworldmatrix.getcolumn(3) - cameratoworldmatrix.getcolumn(2); // rotate canvas object faces user. quaternion rotation = quaternion.lookrotation(-cameratoworldmatrix.getcolumn(2), cameratoworldmatrix.getcolumn(1)); m_canvas.transform.position = position; m_canvas.transform.rotation = rotation; m_capturingphoto = false; float counter = 0; float target = 1; while (counter < target) { counter += time.deltatime; } // m_canvasrenderer.enabled = false; } }
Comments
Post a Comment