protected override JobHandle OnUpdate(JobHandle inputDeps) { if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.Mouse0)) { UnityEngine.Debug.Log("System Updated"); JobHandle jobHandle = new TriggerObjects { objects = GetComponentDataFromEntity <TriggerObject>(true), velocityGroup = GetComponentDataFromEntity <PhysicsVelocity>(), colorGroup = GetComponentDataFromEntity <MaterialColor>(), }.Schedule(stepPhysicsWorldSystem.Simulation, ref buildPhysicsWorldSystem.PhysicsWorld, inputDeps); return(jobHandle); } return(default);
private void Update() { var fitToScanOverlay = FitToScanOverlay; if (fitToScanOverlay != null) { var hasActiveObjects = false; var hasTriggerObjects = TriggerObjects != null && TriggerObjects.Any(); if (hasTriggerObjects) { hasActiveObjects = _gameObjects.Any(x => x != null && x.activeSelf); } fitToScanOverlay.SetActive(hasTriggerObjects && !hasActiveObjects); } }
private void AddImageAnchor(ARImageAnchor arImageAnchor) { Debug.LogFormat("image anchor added[{0}] : tracked => {1}", arImageAnchor.Identifier, arImageAnchor.IsTracked); int index; if (arImageAnchor.ReferenceImageName != null && int.TryParse(arImageAnchor.ReferenceImageName, out index) && index >= 0) { TriggerObject triggerObject; if (TriggerObjects != null && TriggerObjects.TryGetValue(index, out triggerObject)) { Debug.LogFormat("Index {0} trigger object {1}", index, triggerObject != null); while (index >= _gameObjects.Count) { _gameObjects.Add(null); } var arObjectState = ArBehaviour.ArObjectState; if (arObjectState != null && _gameObjects[index] == null) { lock (arObjectState) { GameObject newGameObject; var result = ArBehaviour.CreateArObject( arObjectState, triggerObject.gameObject, null, transform, triggerObject.poi, triggerObject.poi.id, out newGameObject ); if (!ArBehaviourPosition.IsEmpty(result)) { ArBehaviour.ErrorMessage = result; return; } _gameObjects[index] = newGameObject; newGameObject.SetActive(true); } } } } }
/// <summary> /// The Unity Update method. /// </summary> protected override void Update() { base.Update(); // Exit the app when the 'back' button is pressed. if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } // Check that motion tracking is tracking. if (Session.Status != SessionStatus.Tracking) { return; } if (!HasTriggerImages) { return; } // Get updated augmented images for this frame. Session.GetTrackables <AugmentedImage>(_tempAugmentedImages, TrackableQueryFilter.Updated); // Create visualizers and anchors for updated augmented images that are tracking and do not previously // have a visualizer. Remove visualizers for stopped images. foreach (var image in _tempAugmentedImages) { AugmentedImageVisualizer visualizer = null; _visualizers.TryGetValue(image.DatabaseIndex, out visualizer); if (image.TrackingState == TrackingState.Tracking && visualizer == null) { TriggerObject triggerObject = null; if (!TriggerObjects.TryGetValue(image.DatabaseIndex, out triggerObject)) { ErrorMessage = "No trigger object for database index " + image.DatabaseIndex; } // Create an anchor to ensure that ARCore keeps tracking this augmented image. Anchor anchor = image.CreateAnchor(image.CenterPose); visualizer = Instantiate(AugmentedImageVisualizerPrefab, anchor.transform); visualizer.Image = image; visualizer.TriggerObject = triggerObject; visualizer.ArBehaviour = this; _visualizers.Add(image.DatabaseIndex, visualizer); } else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { _visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } } // Show the fit-to-scan overlay if there are no images that are Tracking. foreach (var visualizer in _visualizers.Values) { if (visualizer.Image.TrackingState == TrackingState.Tracking) { FitToScanOverlay.SetActive(false); return; } } FitToScanOverlay.SetActive(true); }