// Use this for initialization void Awake() { if (!text2D) { text2D = labelRoot.GetComponentInChildren <Text>(); } thisFrameScale = labelRoot.localScale; labelStartLossyScale = labelRoot.lossyScale; if (!shaderIndexIDsSet) { FindShaderIndexes(); } #if !ZED_LWRP && !ZED_HDRP Camera.onPreCull += OnCameraPreRender; #elif ZED_LWRP RenderPipelineManager.beginCameraRendering += LWRPBeginCamera; #elif ZED_HDRP ZEDManager manager = FindObjectOfType <ZEDManager>(); labelFacingCamera = manager.GetLeftCamera(); RenderPipelineManager.beginFrameRendering += HDRPBeginFrame; #endif }
// Use this for initialization void Start() { //Cache the ZED's left camera for occlusion testing purposes if (zedManager == null) { zedManager = FindObjectOfType <ZEDManager>(); } // Set the default position of the Drone to the one he spawned at. nextposition = transform.position; //Set the countdown timer to fire a laser lasershottimer = SecondsBetweenLaserShots; // Set the audio source. audiosource = GetComponent <AudioSource>(); if (audiosource != null && clips.Length > 2) { audiosource.clip = clips[2]; audiosource.volume = 1f; audiosource.Play(); } // If these variables aren't set, look for their objects by their default name. Transform[] children = transform.GetComponentsInChildren <Transform>(); foreach (var child in children) { if (child.name == "Drone_Mesh") { meshrenderer = child.GetComponent <Renderer>(); } else if (child.name == "MuzzleFlash_FX") { muzzleflashfx = child.GetComponent <ParticleSystem>(); } else if (child.name == "Damage_FX") { damagefx = child; } else if (child.name == "Laser_Anchor") { laseranchor = child; } else if (child.name == "Gun_Arm") { dronearm = child; } else if (child.name == "Point_Light") { gunlight = child.GetComponent <Light>(); } } //If the _target isn't set, set it to the PlayerDamageReceiver, assuming there is one in the scene. if (!target) { target = FindObjectOfType <PlayerDamageReceiver>().transform; guntarget = target.position; } }
void Start() { if (zedManager == null) { zedManager = FindObjectOfType <ZEDManager>(); if (ZEDManager.GetInstances().Count > 1) //We chose a ZED arbitrarily, but there are multiple cams present. Warn the user. { Debug.Log("Warning: " + gameObject.name + "'s zedManager was not specified, so the first available ZEDManager instance was " + "assigned. However, there are multiple ZEDManager's in the scene. It's recommended to specify which ZEDManager you want to " + "use to display a point cloud."); } } if (zedManager != null) { zed = zedManager.zedCamera; } if (_pointMaterial == null) { _pointMaterial = new Material(Resources.Load("Materials/PointCloud/Mat_ZED_FusedPC_Point") as Material); } if (_diskMaterial == null) { _diskMaterial = new Material(Resources.Load("Materials/PointCloud/Mat_ZED_FusedPC_Disk") as Material); } _diskMaterial.hideFlags = HideFlags.DontSave; _pointMaterial.hideFlags = HideFlags.DontSave; zedManager.OnGrab += startMap; }
// Start is called before the first frame update void Start() { ZEDManager manager = FindObjectOfType(typeof(ZEDManager)) as ZEDManager; LeftCamera = manager.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); surfacePlacementManager = FindObjectOfType(typeof(SurfacePlacementManager)) as SurfacePlacementManager; }
private IEnumerator Start() { isMoving = false; if (!zedManager) { zedManager = FindObjectOfType <ZEDManager>(); if (ZEDManager.GetInstances().Count > 1) //They let the plugin auto-assign a ZED but there are multiple ZED's. Warn the user. { UnityEngine.Debug.Log("Warning: ZEDTransformController's zedManager field was not specified, but there are multiple ZEDManagers in the scene " + "so first available ZED was assigned. This can cause the object to move relative to the wrong camera. " + "It's recommended to assign the desired ZEDManager in the Inspector."); } } //Find the available VR controllers and assigning them to our List. yield return(new WaitForSeconds(1f)); var trackers = FindObjectsOfType <ZEDControllerTracker>(); foreach (ZEDControllerTracker_DemoInputs tracker in trackers) { objectTrackers.Add(tracker); } if (repositionAtStart) //If the user wants, move the object in front of the ZED once it's initialized. { zedManager.OnZEDReady += RepositionInFrontOfZED; } }
void Start() { if (!planetarium) { planetarium = GameObject.Find("Planetarium"); } currentscale = planetarium.transform.localScale.x; suncontainer = planetarium.transform.Find("Sun").gameObject; sunlight = suncontainer.GetComponent <Light>(); currentlightrange = sunlight.range * (1 / currentscale); manager = planetarium.transform.parent.GetComponentInChildren <ZEDManager>(); spotLightSun = suncontainer.transform.Find("SunSpotLight").GetComponent <Light>(); halolightsun = suncontainer.transform.Find("SunHaloLight").GetComponent <Light>(); currentlightrangesunspot = spotLightSun.range * (1 / currentscale); currentlightrangesunhalo = halolightsun.range * (1 / currentscale); #if __ENABLE__SOUND__ currentMaxSoundDistanceJupiter = jupiterSound.maxDistance * (1 / currentScale); currentMaxSoundDistanceSun = sunSound.maxDistance * (1 / currentScale); #endif }
/// <summary> /// This function is called every fixed framerate frame /// Here we take care of enabling & disabling the laser pointer. /// </summary> private void FixedUpdate() { //If we have been moved by the baseball bat if (IsMoving) { //Look for our next position based on our current velocity. Vector3 predictedPos = centerpoint.position + (rb.velocity * (Time.deltaTime * 2.5f)); transform.rotation = Quaternion.LookRotation(rb.velocity.normalized); //Collision check with the real world at that next position. foreach (ZEDManager manager in ZEDManager.GetInstances()) //Check all active cameras. { if (ZEDSupportFunctions.HitTestAtPoint(manager.zedCamera, manager.GetLeftCamera(), predictedPos)) { //We hit something, but is it a flat surface? if (planeManager.DetectPlaneAtHit(manager, manager.GetLeftCamera().WorldToScreenPoint(predictedPos))) { bunnyspawner.SpawnUI(predictedPos); IsMoving = false; } else//If not, bounce off of it but still show the flag. { IsMoving = false; //Not moving anymore, so update our state. bunnyspawner.SpawnUI(predictedPos); //Start spawning the UI on our current location. rb.velocity = Vector3.Reflect(rb.velocity / 2, transform.forward); //Bounce off the surface we hit } break; //If it hit the real world in one camera's view, no need to check the other cameras. } } } }
// Update is called once per frame void Update() { foreach (ZEDManager manager in ZEDManager.GetInstances()) { DrawAsteroids(manager); } }
// Bring in everything from the ZED Plugin void Start() { planeDetectionManager = FindObjectOfType(typeof(ZEDPlaneDetectionManager)) as ZEDPlaneDetectionManager; planeDetectionManager = planeDetectionManager.GetComponent <ZEDPlaneDetectionManager>(); manager = FindObjectOfType(typeof(ZEDManager)) as ZEDManager; zedCamera = manager.zedCamera; }
/// <summary> /// Start this instance. /// </summary> private void Start() { manager = GameObject.FindObjectOfType(typeof(ZEDManager)) as ZEDManager; if (manager && manager.GetLeftCameraTransform()) { LeftCamera = manager.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); } zedCam = sl.ZEDCamera.GetInstance(); isReady = false; //Create a holder for all the planes holder = new GameObject(); holder.name = "[ZED Planes]"; holder.transform.parent = this.transform; holder.transform.position = Vector3.zero; holder.transform.rotation = Quaternion.identity; StaticBatchingUtility.Combine(holder); //initialize Vertices/Triangles with enough length planeMeshVertices = new Vector3[65000]; planeMeshTriangles = new int[65000]; floorPlaneGO = new ZEDPlaneGameObject(); hitPlaneGOList = new List <ZEDPlaneGameObject> (); SetPlaneRenderer(); }
/// <summary> /// Handles movements and collisions on a constant basis. /// </summary> void FixedUpdate() { //Calculate where the object should move this frame Vector3 newpos = transform.position + transform.rotation * Vector3.forward * (speed * Time.deltaTime); //Collisions with the real World. As the object moves, collisions checks are made each frame at the next position. Vector3 collisionpoint; Vector3 collisionnormal; //First, test the primary ZED. Collisions will look the most accurate if calculated from this one. bool primaryhit = ZEDSupportFunctions.HitTestOnRay(zedManager.zedCamera, cam, newpos, transform.rotation, Vector3.Distance(transform.position, newpos), distanceBetweenRayChecks, out collisionpoint, false, realWorldThickness); if (primaryhit) { //Call the function to resolve the impact. This allows us to easily override what happens on collisions with classes that inherit this one. ZEDSupportFunctions.GetNormalAtWorldLocation(zedManager.zedCamera, collisionpoint, sl.REFERENCE_FRAME.WORLD, cam, out collisionnormal); OnHitRealWorld(collisionpoint, collisionnormal); } if (!primaryhit && testCollisionsUsingAllZEDs) //If set to true, test the rest of the ZEDs as well. { foreach (ZEDManager manager in ZEDManager.GetInstances()) { if (manager == zedManager) { continue; //If it's the primary ZED, skip as we've already tested that one. } if (ZEDSupportFunctions.HitTestOnRay(manager.zedCamera, manager.GetMainCamera(), newpos, transform.rotation, Vector3.Distance(transform.position, newpos), distanceBetweenRayChecks, out collisionpoint, false, realWorldThickness)) { //Call the function to resolve the impact. This allows us to easily override what happens on collisions with classes that inherit this one. ZEDSupportFunctions.GetNormalAtWorldLocation(manager.zedCamera, collisionpoint, sl.REFERENCE_FRAME.WORLD, manager.GetMainCamera(), out collisionnormal); OnHitRealWorld(collisionpoint, collisionnormal); break; //No need to test the rest of the ZEDs. } } } //Collisions with virtual objects //Cast a ray to check collisions between here and the intended move point for virtual objects. RaycastHit hitinfo; if (Physics.Raycast(transform.position, newpos - transform.position, out hitinfo, Vector3.Distance(transform.position, newpos))) { //Call the function to resolve the impact. This allows us to easily override what happens on collisions with classes that inherit this one. OnHitVirtualWorld(hitinfo); } //Move it to this new place transform.position = newpos; //Tick down its lifespan and check if we should destroy it. lifespan -= Time.deltaTime; if (lifespan <= 0f) { Destroy(gameObject); } }
// Use this for initialization void Awake() { ZedManager = FindObjectOfType <ZEDManager>(); LeftCamera = ZedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); Cursor.visible = true; //Make sure cursor is visible so we can click on the world accurately. }
// Use this for initialization void Awake() { ZedManager = FindObjectOfType <ZEDManager>(); LeftCamera = ZedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); // Show cursor Cursor.visible = true; }
// Use this for initialization void Awake() { //zedManager = gameObject.transform.parent.GetComponentInChildren<ZEDManager>(); zedManager = ZEDManager.GetInstance(sl.ZED_CAMERA_ID.CAMERA_ID_01); LeftCamera = zedManager.GetLeftCameraTransform().gameObject.GetComponent <Camera>(); Cursor.visible = true; //Make sure cursor is visible so we can click on the world accurately. }
// Use this for initialization void Start() { zedManager = FindObjectOfType <ZEDManager> (); //Set the countdown Timer; respawncountdown = respawnTimer; //Get the ZED camera cam = zedManager.GetMainCamera(); }
// Use this for initialization void Start() { zedManager = FindObjectOfType <ZEDManager> (); //Set the countdown Timer; respawncountdown = respawnTimer; //Get the ZED camera leftcamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>(); }
// Called with GameObject.SendMessage() for the menu. // Changes depth occlusion setting and reset the camera so that it takes effect public void toggleDepthOcclusion() { ZEDManager manager = FindObjectOfType(typeof(ZEDManager)) as ZEDManager; manager.depthOcclusion = !manager.depthOcclusion; // This updates the depth occlusion setting immediately, otherwise you'll have to wait for the camera to do it automatically manager.Reset(); }
void Start() { if (!manager) { manager = ZEDManager.Instance; } CreateAsteroids(listPositionsOrigin, amount, radius, offset); //Create all type 1 asteroids. CreateAsteroids(listPositionsOrigin2, amount, radius, offset); //Create all type 2 asteroids. }
// Use this for initialization void Start() { if (!zedManager) { zedManager = FindObjectOfType <ZEDManager>(); } zedManager.OnObjectDetection += Visualize3DBoundingBoxes; zedManager.OnZEDReady += OnZEDReady; }
/// <summary> /// Constructor that assigns values required for transformations later on. /// This is necessary because detections are frozen in a particular frame, and results should not change /// in subsequent frames when the camera moves. /// </summary> /// <param name="odata">Raw sl.ObjectData data that this instance represents.</param> /// <param name="viewingmanager">ZEDManager assigned to the ZED camera that detected the object.</param> /// <param name="campos">World position of the left ZED camera when the object was detected.</param> /// <param name="camrot">World rotation of the left ZED camera when the object was detected.</param> public DetectedObject(ObjectDataSDK odata, ZEDManager viewingmanager, Vector3 campos, Quaternion camrot) { objectData = odata; detectingZEDManager = viewingmanager; camPositionAtDetection = campos; camRotationAtDetection = camrot; maskMat = new ZEDMat(odata.mask); //maskTexture = ZEDMatToTexture_CPU(maskMat); }
private void OnEnable() { manager = (ZEDManager)target; resolution = manager.resolution; depthmode = manager.depthMode; usespatialmemory = manager.enableSpatialMemory; usedepthocclusion = manager.depthOcclusion; usepostprocessing = manager.postProcessing; }
private void DrawAsteroids(ZEDManager manager) { Camera leftcamera = manager.GetLeftCamera(); Camera rightcamera = manager.GetRightCamera(); //Update positions and draw asteroids of type 1 UpdatePosition(listPositionsOrigin, listPositions); Graphics.DrawMeshInstanced(asteroidsType1.GetComponent <MeshFilter>().sharedMesh, 0, asteroidsType1.GetComponent <MeshRenderer>().sharedMaterial, listPositions, listPositions.Length, null, UnityEngine.Rendering.ShadowCastingMode.Off, false, gameObject.layer, leftcamera); if (manager.IsStereoRig) { Graphics.DrawMeshInstanced(asteroidsType1.GetComponent <MeshFilter>().sharedMesh, 0, asteroidsType1.GetComponent <MeshRenderer>().sharedMaterial, listPositions, listPositions.Length, null, UnityEngine.Rendering.ShadowCastingMode.Off, false, gameObject.layer, rightcamera); } //Update positions and draw asteroids of type 2 UpdatePosition(listPositionsOrigin2, listPositions2); Graphics.DrawMeshInstanced(asteroidsType2.GetComponent <MeshFilter>().sharedMesh, 0, asteroidsType2.GetComponent <MeshRenderer>().sharedMaterial, listPositions2, listPositions2.Length, null, UnityEngine.Rendering.ShadowCastingMode.Off, false, gameObject.layer, leftcamera); if (manager.IsStereoRig) { Graphics.DrawMeshInstanced(asteroidsType2.GetComponent <MeshFilter>().sharedMesh, 0, asteroidsType2.GetComponent <MeshRenderer>().sharedMaterial, listPositions2, listPositions2.Length, null, UnityEngine.Rendering.ShadowCastingMode.Off, false, gameObject.layer, rightcamera); } }
private void Start() { GlobalScript globals = GameObject.Find("Globals").GetComponent <GlobalScript>(); resolution_preset = globals.resolution_preset; range_preset = globals.range_preset; isFilteringEnable = globals.isFilteringEnable; isTextured = globals.isTextured; manager = GameObject.FindObjectOfType(typeof(ZEDManager)) as ZEDManager; spatialMapping = new ZEDSpatialMapping(transform, sl.ZEDCamera.GetInstance(), manager); }
/// <summary> /// Creates canvas(es) and canvas elements depending on whether the ZED rig is mono (ZED_Rig_Mono) /// or stereo (ZED_Rig_Stereo). /// </summary> private void Awake() { zedManager = GetComponent <ZEDManager> (); oldInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST; if (!zedManager.IsStereoRig) //Without VR, we use a Screen Space - Overlay canvas. { //Instantiate the mono warning prefab and set basic settings for it. warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform); warningmono.SetActive(true); warningmono.GetComponent <Canvas> ().renderMode = RenderMode.ScreenSpaceCamera; warningmono.GetComponent <Canvas> ().worldCamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>(); textmono = warningmono.GetComponentInChildren <UnityEngine.UI.Text>(); textmono.color = Color.white; if (!sl.ZEDCamera.CheckPlugin()) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } imagemono = warningmono.transform.GetChild(0).GetChild(1).gameObject; imagemono.transform.parent.gameObject.SetActive(true); ready = false; } else //In VR, we use two Screen Space - Camera canvases, one for each eye. { //Instantiate the left warning prefab and set basic settings for it. warningleft = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetLeftCameraTransform()); warningleft.SetActive(true); warningleft.GetComponent <Canvas>().worldCamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>(); warningleft.GetComponent <Canvas>().planeDistance = 1; textleft = warningleft.GetComponentInChildren <UnityEngine.UI.Text>(); textleft.color = Color.white; imageleft = warningleft.transform.GetChild(0).GetChild(1).gameObject; imageleft.transform.parent.gameObject.SetActive(true); //Instantiate the right warning prefab and set basic settings for it. warningright = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetRightCameraTransform()); warningright.SetActive(true); warningright.GetComponent <Canvas>().worldCamera = zedManager.GetRightCameraTransform().GetComponent <Camera>(); warningright.GetComponent <Canvas>().planeDistance = 1; textright = warningright.GetComponentInChildren <UnityEngine.UI.Text>(); textright.color = Color.white; imageright = warningright.transform.GetChild(0).GetChild(1).gameObject; imageright.transform.parent.gameObject.SetActive(true); if (!sl.ZEDCamera.CheckPlugin()) //Warn the use there's no SDK installed. { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } ready = false; } }
// Use this for initialization void Awake() { if (!zedManager) { zedManager = FindObjectOfType <ZEDManager> (); //Selects the first available ZEDManager if none was set before. } if (zedManager) { zedManager.OnZEDReady += EnableThisObject; } }
private void Start() { if (!zedManager) { zedManager = FindObjectOfType <ZEDManager>(); } if (zedManager) { zedLeftCam = zedManager.GetLeftCamera(); } }
public void Reset() { ZEDManager zedManager = null; zedManager = transform.parent.gameObject.GetComponent <ZEDManager>(); if (zedManager != null) { zedManager.videoMode = sl.RESOLUTION.HD1080; } SetDefaultValues(); }
public void Reset() //When the Unity editor Reset button is used. { ZEDManager zedManager = null; zedManager = transform.parent.gameObject.GetComponent <ZEDManager>(); if (zedManager != null) { zedManager.resolution = sl.RESOLUTION.HD1080; Debug.Log("Resolution set to HD1080 for better result"); } SetDefaultValues(); }
/// <summary> /// Sets references not set in ZEDManager.CreateZEDRigDisplayer(), sets materials, /// adjusts final plane scale, loads the ZED calibration offset and other misc. values. /// </summary> void Start() { hasVRDevice = hasXRDevice(); //iterate until we found the ZED Manager parent... Transform ObjParent = gameObject.transform; int tries = 0; while (manager == null && tries < 50) { if (ObjParent != null) { manager = ObjParent.GetComponent <ZEDManager> (); } if (manager == null && ObjParent != null) { ObjParent = ObjParent.parent; } tries++; } if (manager != null) { manager.OnZEDReady += ZEDReady; zedCamera = manager.zedCamera; } else { return; } leftScreen = ZEDEyeLeft.GetComponent <ZEDRenderingPlane>(); rightScreen = ZEDEyeRight.GetComponent <ZEDRenderingPlane>(); finalLeftEye = finalCameraLeft.GetComponent <Camera>(); finalRightEye = finalCameraRight.GetComponent <Camera>(); rightMaterial = quadRight.GetComponent <Renderer>().material; leftMaterial = quadLeft.GetComponent <Renderer>().material; finalLeftEye.SetReplacementShader(leftMaterial.shader, ""); finalRightEye.SetReplacementShader(rightMaterial.shader, ""); float plane_dist = (float)sl.Constant.PLANE_DISTANCE; scale(quadLeft.gameObject, new Vector2(1.78f * plane_dist, 1.0f * plane_dist)); scale(quadRight.gameObject, new Vector2(1.78f * plane_dist, 1.0f * plane_dist)); zedReady = false; Camera.onPreRender += PreRender; LoadHmdToZEDCalibration(); }
/// <summary> /// Checks if another ArUcoDrone is in front of the drone and within range. /// Will also check if there's a real object in the way, if checkRealWorldObstaclesBeforeShooting is true. /// </summary> /// <returns>True if there's a valid target in front of the drone.</returns> private bool IsAimingAtTarget() { //First make sure there's a valid virtual target in front of the drone. Ray ray = new Ray(shootAnchorObject.position, shootAnchorObject.rotation * Vector3.forward); RaycastHit[] hits = Physics.RaycastAll(ray, shootRangeMeters); bool foundvirtualtarget = false; float nearestdist = Mathf.Infinity; foreach (RaycastHit hit in hits) { ArUcoDrone otherdrone = hit.transform.GetComponent <ArUcoDrone>(); if (otherdrone != null && otherdrone != this) { foundvirtualtarget = true; if (hit.distance < nearestdist) { nearestdist = hit.distance; } } } if (!foundvirtualtarget) { return(false); } if (checkRealWorldObstaclesBeforeShooting) //Make sure there's not a real-world obstacle in the way of the target. { //If there is one, check to make sure there's not a real-world object in the way. Vector3 collisionpoint; //Not used but required for HitTestOnRay function. foreach (ZEDManager manager in ZEDManager.GetInstances()) { bool hitreal = ZEDSupportFunctions.HitTestOnRay(manager.zedCamera, manager.GetLeftCamera(), shootAnchorObject.transform.position, shootAnchorObject.transform.rotation, nearestdist, 0.01f, out collisionpoint, false, 0.1f); if (hitreal) { return(false); } } return(true); } else { return(true); //We're not checking against the real world, and we already found a virtual object, so fire. } }