Example #1
0
    //public Text selectedObjectText;

    //List<string> poseEstimationTechniques = new List<string>() { "ARKit","Attached Tracker","Calibration" };

    void Start()
    {
        debugPanelObject.SetActive(showingDebug);
        optionsPanelObject.SetActive(showingOptions);
        ARCameraManager = GameObject.FindObjectOfType <UnityARCameraManager>();
        //selectedObjectText = poseEstimationDropdownObject.GetComponentInChildren<Text>();
    }
Example #2
0
 // Initialize plane setup
 void Awake()
 {
     if (m_HitObject != null)
     {
         m_HitObject.SetActive(false);
     }
     if (m_SceneObject != null)
     {
         m_SceneObject.SetActive(false);
     }
     if (m_MessageFindPlane != null)
     {
         m_MessageFindPlane.SetActive(true);
     }
     if (m_PointCloudParticles != null)
     {
         m_PointCloudParticles.SetActive(true);
     }
     if (m_MessagePlaceObject != null)
     {
         m_MessagePlaceObject.SetActive(false);
     }
     if (m_ARCameraManager != null && m_ARGeneratePlanes != null)
     {
         arCameraManager = m_ARCameraManager.GetComponent <UnityARCameraManager>();
     }
 }
Example #3
0
    // Use this for initialization
    void Start()
    {
        networkText   = networkTextObject.GetComponent <Text>();
        framerateText = framerateTextObject.GetComponent <Text>();
        gameStateText = gameStateTextObject.GetComponent <Text>();

        positionARKitText   = positionARKitObject.GetComponent <Text>();
        rotationARKitText   = rotationARKitObject.GetComponent <Text> ();
        positionTrackerText = positionTrackerObject.GetComponent <Text> ();
        rotationTrackerText = rotationTrackerObject.GetComponent <Text> ();
        positionEngineText  = positionEngineObject.GetComponent <Text> ();
        rotationEngineText  = rotationEngineObject.GetComponent <Text> ();
        positionCParentText = positionCParentObject.GetComponent <Text>();
        rotationCParentText = rotationCParentObject.GetComponent <Text>();

        positionARKitText.text   = "ARKit Pos";
        rotationARKitText.text   = "ARKit Rot";
        positionTrackerText.text = "Tracker Pos";
        rotationTrackerText.text = "Tracker Rot";
        positionEngineText.text  = "Engine Pos";
        rotationEngineText.text  = "Engine Rot";

        networkText.text = "Network Status";

        ARManager    = GameObject.FindObjectOfType <UnityARCameraManager>();
        playerHealth = playerHealthObject.GetComponent <PlayerHealth>();
        henge        = hengeObject.GetComponent <Henge>();
        gameManager  = FindObjectOfType <GameManager>();

        //frameTimes = new Queue<float>();
    }
Example #4
0
 public UnityARAnchorManager(UnityARGeneratePlane plane, GameObject hitParent, UnityARHitTestExample sharp, UnityARCameraManager camera_manager)
 {
     planeAnchorMap = new LinkedListDictionary <string, ARPlaneAnchorGameObject> ();
     UnityARSessionNativeInterface.ARAnchorAddedEvent   += AddAnchor;
     UnityARSessionNativeInterface.ARAnchorUpdatedEvent += UpdateAnchor;
     UnityARSessionNativeInterface.ARAnchorRemovedEvent += RemoveAnchor;
     generatedPlane      = plane;
     hitScript           = sharp;
     Camera_managerScrpt = camera_manager;
 }
Example #5
0
    // Use this for initialization
    void Start()
    {
        if (LocationService.Instance != null)
        {
            LocationService.Instance.LocationServiceText      = textUi;
            LocationService.Instance.LocationServiceDeltaText = deltaUi;
            LocationService.Instance.StartUpdate();
        }

        cameraManager = GameObject.Find("ARCameraManager").GetComponent <UnityARCameraManager>();
    }
Example #6
0
        Camera GetARKitCamera()
        {
            Camera ret = null;
            UnityARCameraManager ARKitManager = FindObjectOfType <UnityARCameraManager>();

            if (ARKitManager != null)
            {
                ret = ARKitManager.m_camera;
            }
            return(ret);
        }
Example #7
0
    public void LeftLocation()
    {
        StopUpdate();
        GameObject bye = Resources.Load <GameObject>("Prefabs/ByeScreen");
        GameObject currentInstanceBye = Instantiate(bye, bye.transform.position, Quaternion.identity);
        GameObject canvas             = GameObject.Find("Canvas");

        currentInstanceBye.transform.SetParent(canvas.transform, false);
        UnityARCameraManager cameraManager = GameObject.Find("ARCameraManager").GetComponent <UnityARCameraManager>();

        cameraManager.ToggleVideo();
    }
Example #8
0
 private static void SetupUnityARCameraManager(Camera mainCamera)
 {
     if (mainCamera != null)
     {
         GameObject           arCameraManagerObject = new GameObject("ARCameraManager");
         UnityARCameraManager arCamManager          = arCameraManagerObject.AddComponent <UnityARCameraManager> ();
         arCamManager.m_camera = mainCamera;
     }
     else
     {
         Debug.LogError("MainCamera gameobject not referenced in WRLDARKitSetupHelper.");
     }
 }
Example #9
0
    void Start()
    {
        //Debug.Log ("Starting Network Interface... <TextManager found>:" + (textManager != null) + " <ARCameraManager found>:" + (ARCameraManager != null));
        HealBeam   = HealBeamObject.GetComponent <Beam>();
        DamageBeam = DamageBeamObject.GetComponent <Beam>();

        ConnectButton   = ConnectButtonObject;
        gameManager     = FindObjectOfType <GameManager>();
        ARCameraManager = FindObjectOfType <UnityARCameraManager>();
        textManager     = FindObjectOfType <TextManager> ();

        IPinputField = IPinputFieldObject;
    }
Example #10
0
    public void YesButton()
    {
        GameObject wlc = GameObject.FindGameObjectWithTag("Welcome");

        Destroy(wlc);
        LocationService.Instance.SetHomeCoords();
        GameObject ui = Resources.Load <GameObject>("Prefabs/UI");
        GameObject currentInstance = Instantiate(ui, ui.transform.position, Quaternion.identity);
        GameObject canvas          = GameObject.Find("Canvas");

        currentInstance.transform.SetParent(canvas.transform, false);
        UnityARCameraManager cameraManager = GameObject.Find("ARCameraManager").GetComponent <UnityARCameraManager>();

        cameraManager.enabled = true;
    }
Example #11
0
            private void Start()
            {
#if UNITY_EDITOR
                // Disable AR in editor
                if (Camera.main != null)
                {
                    Camera.main.clearFlags = CameraClearFlags.Color;
                    UnityARVideo arVideo = Camera.main.GetComponent <UnityARVideo>();
                    if (arVideo != null)
                    {
                        arVideo.enabled = false;
                    }
                    Transform parent = Camera.main.transform.parent;
                    if (parent != null)
                    {
                        UnityARCameraManager arCameraManager = parent.GetComponentInChildren <UnityARCameraManager>();
                        if (arCameraManager != null)
                        {
                            arCameraManager.enabled = false;
                        }
                    }
                }
                AR3DOFCameraManager ar3dof = GetComponent <AR3DOFCameraManager>();
                if (ar3dof != null)
                {
                    ar3dof.enabled = false;
                }
#endif
                // Initialize the game object we'll use to
                // represent plane anchors
                if (planePrefab != null)
                {
                    UnityARUtility.InitializePlanePrefab(planePrefab);
                }

                // Initialize the anchor manager
                mUnityARAnchorManager = new UnityARAnchorManager();

                // Start the AR kit session
                ARKitWorldTackingSessionConfiguration sessionConfig = new ARKitWorldTackingSessionConfiguration(
                    UnityARAlignment.UnityARAlignmentCamera,
                    UnityARPlaneDetection.Horizontal
                    );
                sessionConfig.enableLightEstimation = true;
                UnityARSessionRunOption sessionRunOptions = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
                UnityARSessionNativeInterface.GetARSessionNativeInterface().Pause();                 // Stops current run
                UnityARSessionNativeInterface.GetARSessionNativeInterface().RunWithConfigAndOptions(sessionConfig, sessionRunOptions);
            }
Example #12
0
        private void Start()
        {
#if UNITY_IOS
            // Ensure that ARkit reset the tracking when the scene gets restarted
            UnityARCameraManager    arkitCameraManager = FindObjectOfType <UnityARCameraManager>();
            UnityARSessionRunOption options            = new UnityARSessionRunOption();
            options = UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors | UnityARSessionRunOption.ARSessionRunOptionResetTracking;
            UnityARSessionNativeInterface nativeInterface = UnityARSessionNativeInterface.GetARSessionNativeInterface();

            ARKitWorldTrackingSessionConfiguration config = new ARKitWorldTrackingSessionConfiguration();
            config.planeDetection        = arkitCameraManager.planeDetection;
            config.alignment             = arkitCameraManager.startAlignment;
            config.getPointCloudData     = arkitCameraManager.getPointCloud;
            config.enableLightEstimation = arkitCameraManager.enableLightEstimation;
            nativeInterface.RunWithConfigAndOptions(config, options);
#endif
        }
Example #13
0
    public static void UpdateTrackerPose(Vector3 pos, Quaternion rot)
    {
        if (ARCameraManager == null)
        {
            ARCameraManager = FindObjectOfType <UnityARCameraManager>();
        }

        if (ARCameraManager != null)
        {
            ARCameraManager.updateTrackerPosition(pos);
            ARCameraManager.updateTrackerRotation(rot);

            textManager.updateTrackerPositionString(pos, headsetPos);
            textManager.updateTrackerRotationString(rot, headsetRot);
        }
        else
        {
            Debug.LogError("Attempting to update tracker pose but ARCameraManager is null.");
        }
    }
Example #14
0
    private void Start()
    {
        if (mainCamera == null)
        {
            mainCamera = Camera.main;
        }

        if (mainDirectionalLight == null)
        {
            mainDirectionalLight = Object.FindObjectOfType <Light>();
        }

        mainCamera.clearFlags    = CameraClearFlags.Depth;
        mainCamera.nearClipPlane = 0.01f;

        if (mainCamera.gameObject.GetComponent <UnityARVideo>() == null)
        {
            UnityARVideo unityARVideo = mainCamera.gameObject.AddComponent <UnityARVideo>();
            unityARVideo.m_ClearMaterial = clearMaterial;
        }

        if (mainCamera.gameObject.GetComponent <UnityARCameraNearFar>() == null)
        {
            mainCamera.gameObject.AddComponent <UnityARCameraNearFar>();
        }

        if (mainCamera.gameObject.GetComponent <UnityARCameraManager>() == null)
        {
            UnityARCameraManager unityARCameraManager = mainCamera.gameObject.AddComponent <UnityARCameraManager>();
            unityARCameraManager.m_camera = mainCamera;
        }

        if (mainDirectionalLight.gameObject.GetComponent <UnityARAmbient>() == null)
        {
            mainDirectionalLight.gameObject.AddComponent <UnityARAmbient>();
        }

        UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
    }
Example #15
0
    /* These private static objects are used to reference object in the AR scene instead
     * of calling GameObject.GetComponent<Type>() or GameObject.FindObjectOfType<Type>()
     * every time they are needed.
     */


    /*
     * This function is called on the frame when a script is enabled just before any of
     * the Update methods is called the first time. Here, any static objects that are
     * needed must be fetched from either the scene directly with any of the following
     * commands, or through the linked public GameObjects.
     * Examples are shown in the method.
     */

    void Start()
    {
        ARCameraManager = GameObject.FindObjectOfType <UnityARCameraManager>();
        textManager     = GameObject.FindObjectOfType <TextManager> ();

        /*
         * Finding the UnityARCameraManager script:
         * Finding the TextManager script:
         * This is possible because it is unique; only one instance exists in the scene.
         * The result of the static function GameObject.FindObjectOfType is allocated
         * to the static UnityARCameraManager object so that it can easily be used
         * within this class.
         */

        IPinputField = IPinputFieldObject.GetComponent <Text>();

        /*
         * Finding the input field Text object which an IP address is typed into:
         * This is possible because the GameObject IPinputFieldObject has a component
         * of type Text. It can be retrieved using the dynamic function GetComponent<Text>
         */
    }
Example #16
0
 void Start()
 {
     ARCameraManager = GameObject.FindObjectOfType <UnityARCameraManager>();
 }
    // -- // -- // -- // -- // -- // -- // -- // -- // -- // -- //

    void Start()
    {
        if (!isInterfaceEnabled)
        {
            return;
        }

        if (!yuvMaterial)
        {
            Debug.LogError("ARKit-interface cannot start: YuvMaterial is not set.");
            return;
        }

        // modify the main camera in the scene
        Camera currentCamera = MultiARInterop.GetMainCamera();

        if (!currentCamera)
        {
            GameObject currentCameraObj = new GameObject("Main Camera");
            currentCameraObj.tag = "MainCamera";

            currentCamera = currentCameraObj.AddComponent <Camera>();
        }

        // reset camera position & rotation
        currentCamera.transform.position = Vector3.zero;
        currentCamera.transform.rotation = Quaternion.identity;

        // set camera parameters
        currentCamera.clearFlags    = CameraClearFlags.Depth;
        currentCamera.nearClipPlane = 0.1f;
        currentCamera.farClipPlane  = 30f;

        // reference to the AR main camera
        mainCamera = currentCamera;

        // add camera parent
        if (currentCamera.transform.parent == null)
        {
            GameObject cameraParent = new GameObject("CameraParent");
            currentCamera.transform.SetParent(cameraParent.transform);
            DontDestroyOnLoad(cameraParent);
        }
        else
        {
            DontDestroyOnLoad(currentCamera.transform.root.gameObject);
        }

        // add the needed camera components
        arVideoRenderer = currentCamera.gameObject.AddComponent <UnityARVideo>();
        arVideoRenderer.m_ClearMaterial = yuvMaterial;
        backgroundMat = yuvMaterial;

        currentCamera.gameObject.AddComponent <UnityARCameraNearFar>();

        // modify the directional light
        Light currentLight = MultiARInterop.GetDirectionalLight();

        if (!currentLight)
        {
            GameObject currentLightObj = new GameObject("Directional light");

            currentLight      = currentLightObj.AddComponent <Light>();
            currentLight.type = LightType.Directional;
        }

        // reset light position & rotation
        currentLight.transform.position = Vector3.zero;
        currentLight.transform.rotation = Quaternion.Euler(40f, 40f, 0f);
        DontDestroyOnLoad(currentLight.gameObject);

        // set light parameters
        //currentLight.lightmapBakeType = LightmapBakeType.Mixed;
        currentLight.color = new Color32(255, 254, 244, 255);

        // add the ar-light component
        currentLight.gameObject.AddComponent <MultiARDirectionalLight>();

        // reference to the AR directional light
        //directionalLight = currentLight;

        // create camera manager
        GameObject camManagerObj = new GameObject("ARCameraManager");

        DontDestroyOnLoad(camManagerObj);

        UnityARCameraManager camManager = camManagerObj.AddComponent <UnityARCameraManager>();

        camManager.m_camera = currentCamera;

        camManager.startAlignment = cameraAlignment;
        camManager.planeDetection = UnityARPlaneDetection.HorizontalAndVertical;

        //Debug.Log("arImageDatabase: " + (arImageDatabase != null ? arImageDatabase.resourceGroupName : "-"));
        if (arImageDatabase != null)
        {
            camManager.detectionImages = arImageDatabase;
            Debug.Log("camManager.detectionImages set to: " + arImageDatabase);
        }

        // allow relocalization after session interruption
        UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true;

        // get ar-data
        MultiARInterop.MultiARData arData = arManager ? arManager.GetARData() : null;

        // check for point cloud getter
        if (arManager && arManager.pointCloudPrefab != null)
        {
            arData.pointCloudData      = new Vector3[0];
            arData.pointCloudLength    = 0;
            arData.pointCloudTimestamp = 0.0;
        }

        // create surface renderer
        if (arManager && arData != null)
        {
            arData.surfaceRendererRoot      = new GameObject();
            arData.surfaceRendererRoot.name = "SurfaceRenderer";
            DontDestroyOnLoad(arData.surfaceRendererRoot);
        }

//		// check for tracked plane display
//		if(arManager.displayTrackedSurfaces && trackedPlanePrefab)
//		{
//			UnityARUtility.InitializePlanePrefab(trackedPlanePrefab);
//		}

        // add needed events
        UnityARSessionNativeInterface.ARFrameUpdatedEvent           += ARFrameUpdated;
        UnityARSessionNativeInterface.ARSessionTrackingChangedEvent += ARSessionTrackingChanged;

        UnityARSessionNativeInterface.ARAnchorAddedEvent   += PlaneAnchorAdded;
        UnityARSessionNativeInterface.ARAnchorUpdatedEvent += PlaneAnchorUpdated;
        UnityARSessionNativeInterface.ARAnchorRemovedEvent += PlaneAnchorRemoved;

        UnityARSessionNativeInterface.ARUserAnchorAddedEvent   += UserAnchorAdded;
        UnityARSessionNativeInterface.ARUserAnchorRemovedEvent += UserAnchorRemoved;

        // create ARCoreSession component, if the cloud functionality is used
        GoogleARCore.ARCoreSession arCoreSession = gameObject.GetComponent <GoogleARCore.ARCoreSession>();
        if (arCoreSession == null)
        {
            TextAsset cloudApiKey = Resources.Load("RuntimeSettings/CloudServicesApiKey") as TextAsset;

            if (cloudApiKey != null)
            {
                arCoreSession = gameObject.AddComponent <GoogleARCore.ARCoreSession>();
            }
        }

        // interface is initialized
        isInitialized = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (level > -1)
        {
            timePerSpawn = initSpawnTime / Mathf.Sqrt(level + 1);
        }

        if (arUtility == null)
        {
            arUtility = FindObjectOfType <UnityARCameraManager>();
        }
        else
        {
            arUtility.planeDetection        = UnityARPlaneDetection.Horizontal;
            arUtility.getPointCloud         = false;
            arUtility.enableLightEstimation = false;
        }
        exists = exists || GetComponent <UnityARHitTestExample>().DoesExist();
        if (exists)
        {
            if (GetComponent <UnityARHitTestExample>().enabled)
            {
                planePlacer.SetActive(false);
                arUtility.planeDetection = UnityARPlaneDetection.None;
            }
            GetComponent <UnityARHitTestExample>().enabled = false;
            GetComponent <MeshRenderer>().enabled          = true;
            timer += Time.deltaTime;
            if (level > -1 && gameOn && currentUFOs.Count < waves[level] && timer > timePerSpawn)
            {
                timer = 0f;
                GameObject myUfo = Instantiate(ufo);
                Vector3    dir   = new Vector3(Random.Range(-1f, 1f), Random.Range(0f, 1f), Random.Range(-1f, 1f));
                myUfo.transform.position = transform.position + dir.normalized * 3;
                currentUFOs.Add(myUfo);
                GetComponent <AudioSource>().PlayOneShot(ufoSpawn, 0.3f);
            }
            if (gameOn && level > -1 && currentUFOs.Count >= waves[level])
            {
                bool found = false;
                foreach (GameObject u in currentUFOs)
                {
                    if (u != null)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    gameOn = false;
                    GetComponent <AudioSource>().PlayOneShot(victory);
                }
                if (gameOn == false && level == waves.Length - 1)
                {
                    victoryPanel.SetActive(true);
                }
            }
        }
        else
        {
            GetComponent <MeshRenderer>().enabled = false;
        }
        GetComponent <MeshRenderer>().materials[0].color = Color.HSVToRGB(0.492f * health / 100f, 0.37f, 1f);
        if (health <= 0)
        {
            gameOverPanel.SetActive(true);
        }
        if (placingObject != null && placingObject.GetComponentInChildren <UnityARHitTestExample>().DoesExist())
        {
            placingObject = null;
            placeText.SetActive(false);
        }
        moneyText.GetComponent <Text>().text  = money + " D";
        healthText.GetComponent <Text>().text = "" + health;
        levelText.GetComponent <Text>().text  = "" + (level + 1);
        if (gameOn)
        {
            levelText.GetComponent <Text>().color = Color.green;
        }
        else
        {
            levelText.GetComponent <Text>().color = Color.white;
        }
    }
Example #19
0
    private void SetCamera()
    {
        UnityARCameraManager manager = GetComponent <UnityARCameraManager>();

        manager.m_camera = TeleportalAr.Shared.CurrentCamera;
    }
Example #20
0
        // Use this for initialization
        void Start()
        {
            //try to find missing references
            if (objectManager == null)
            {
                try
                {
                    objectManager = FindObjectOfType <ObjectManager>().gameObject;
                }
                catch (System.Exception)
                {
                    Debug.LogWarning("Unable to find Object Manager script. " +
                                     "Either include script, or manually populate object manager field.");
                    //throw;
                }
            }
            if (cropBox == null)
            {
                try
                {
                    cropBox = FindObjectOfType <BoxMaskMaterialAligner>();
                }
                catch (System.Exception)
                {
                    Debug.LogWarning("Unable to find Box Mask Material Aligner script. " +
                                     "If using a crop box, either include script, or manually populate Crop Box field.");
                    //throw;
                }
            }
            if (managedObject == null)
            {
                try
                {
                    managedObject = FindObjectOfType <SnappedObject>().gameObject;
                }
                catch (System.Exception)
                {
                    Debug.LogWarning("Unable to find Snapped Object script. " +
                                     "If using a crop box, either include script, or manually populate Managed Object field.");
                    //throw;
                }
            }

            //grab all the plan snaps, ALL OF THEM!! (including inactive)
            planSnaps = GetComponentsInChildren <PlanSnap>(true);

            //check for ARKit setup
#if UNITY_IOS
            try
            {
                UnityARCameraManager cameraManager = FindObjectOfType <UnityARCameraManager>();
                if (cameraManager.detectionImages == null)
                {
                    Debug.LogWarning("No reference image set found. Define image set in your Unity AR Camera Manager.");
                }
            }
            catch (System.Exception)
            {
                Debug.LogWarning("No Unity AR Camera Manager found. Your scene doesn't seem to be setup for AR.");
                //throw;
            }
#endif

            //populates collection for turning on/off at activation/deactivation
            planSnaps = GetComponentsInChildren <PlanSnap>(true);

            ResetPlanSnaps();

            //subscribe to ARMarker events
            ARMarker.changeMarker += ClearContent;
            ARMarker.changeMarker += ResetPlanSnaps;
        }
 void Start()
 {
     m_ARCameraManager = GameObject.Find("ARCameraManager").GetComponent <UnityARCameraManager>();
 }