Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Omni_Owl · Mar 16, 2019 at 05:04 PM · photonaugmented-realitygooglecloud

How does Google Expect you to use Cloud Anchors in ARCore with Photon?

I'm really racking my brain here trying to understand how I should do this. I'm trying to do a multiplayer AR game, using ARCore with Cloud Anchors for my Master's Thesis.

Using Photon 2, the flow is this:

  • Master client makes a room.

  • Master client starts looking for surfaces, using ARCore.

  • Eventually Master Client has found some surfaces and will be placing an Anchor, to attach the Game Arena to.

  • When this anchor is placed, Photon should show the Arena that is now spawned but consistently in AR across devices.

  • The way to do this, as I understand it, is to share the initial Anchor used by the host.

At least, that's how it is in my head.

But I am hitting a snag here. I have never used Photon before so I am in doubt on what parts Photon should do and what parts I pass to Google (I already have some code that makes a room that multiple people can join).

Their Cloud Anchor example is written with UNet and I can't quite figure out how to do the translation to Photon. Frankly I shouldn't use the UNet example either way as UNet is discontinued now.

When my Pong Launcher makes the room, the following happens:

ARPongLauncher.cs

 public override void OnJoinedRoom()
 {
     if (IsDialogShown == true)
     {
         IsDialogShown = false;
         DialogAnimator.SetBool("IsHidden", true);
     }
     SnackbarText.text = $"Successfully joined {PhotonNetwork.CurrentRoom.Name}";
     LobbyScreen.SetActive(false);
     TopBar.SetActive(true);
 
     PlayerCountText.text = $"{PhotonNetwork.PlayerList.Length}";
     if (PhotonNetwork.LocalPlayer.IsMasterClient)
     {
         ARPongMasterClient masterClient = PlayerPrefab.AddComponent<ARPongMasterClient>();
         masterClient.searchMessage = "Searching for Surfaces...";
         masterClient.AnchorPrefabName = AnchorPrefabName;
         masterClient.FirstPersonCamera = PlayerPrefab.GetComponentInChildren<Camera>();
         masterClient.SnackbarText = SnackbarText;
         masterClient.m_ARCoreWorldOriginHelper = PlayerPrefab.GetComponentInChildren<ARCoreWorldOriginHelper>();
         masterClient.OnAnchorHosted += Handle_OnAnchorHosted;
     }
 }

Then in the client I do this:

MasterClient.cs

 public event EventHandler<string> OnAnchorHosted;
 public override void Start()
 {
     m_CurrentMode = ApplicationMode.Hosting;
 }
 
 public override void Update()
 {
     base.Update();
 
     if (m_LastPlacedAnchor == null)
     {
         Touch touch;
         if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
         {
             return;
         }
 
         if (Application.platform != RuntimePlatform.IPhonePlayer)
         {
             TrackableHit hit;
             if (m_ARCoreWorldOriginHelper.Raycast(
                 touch.position.x, touch.position.y,
                 TrackableHitFlags.PlaneWithinPolygon, out hit))
             {
                 m_LastPlacedAnchor = hit.Trackable.CreateAnchor(hit.Pose);
             }
         }
     }
 
     if (m_LastPlacedAnchor != null)
     {
         if (!m_IsOriginPlaced)
         {
             SetWorldOrigin(m_LastPlacedAnchor.transform);
             _InstantiateAnchor();
             OnAnchorInstantiated();
         }
     }
 }

SetWorldOrigin is from the base class:

ARPongAbstractClient.cs

         /// <summary>
         /// Sets the apparent world origin so that the Origin of Unity's World Coordinate System coincides with the
         /// Anchor. This function needs to be called once the Cloud Anchor is either hosted or resolved.
         /// </summary>
         /// <param name="anchorTransform">Transform of the Cloud Anchor.</param>
         internal void SetWorldOrigin(Transform anchorTransform)
         {
             if (m_IsOriginPlaced)
             {
                 return;
             }
 
             m_IsOriginPlaced = true;
 
             if (Application.platform != RuntimePlatform.IPhonePlayer)
             {
                 m_ARCoreWorldOriginHelper.SetWorldOrigin(anchorTransform);
             }
         }[/code]
 
 And so we finally end up at these methods back in the ARPongMasterClient:
 [code=CSharp]private void _InstantiateAnchor()
 {
     // Instantiate Anchor model at the hit pose.
     GameObject anchorObject = PhotonNetwork.Instantiate(AnchorPrefabName, Vector3.zero, Quaternion.identity, 0);
     anchorObject.transform.parent = m_LastPlacedAnchor.transform;
 
     // TODO Get anchor id and host in Google Cloud
 }
 
 /// <summary>
 /// Callback indicating that the Cloud Anchor was instantiated and the host request was made.
 /// </summary>
 private void OnAnchorInstantiated()
 {
     if (m_AnchorAlreadyInstantiated)
     {
         return;
     }
 
     m_AnchorAlreadyInstantiated = true;
     SnackbarText.text = "Hosting Cloud Anchor...";
 }

Here is where I am stuck, currently. I don't know what to do from here. Any help would be appreciated :c

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

177 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Colliding plugins[arcore_client.aar] error when building after importing Mapbox SDK 0 Answers

i can't see other player with photon cloud server,I Can't see each other player in photon cloud 2 Answers

How to build project with google cloud (kubernetes, VM) rather than with SourceTree-git 0 Answers

How to get Google cloud message after offline? 0 Answers

Project upgraded from Google Cardboard to GoogleVR runs in Unity but fails when building for iOS (XCode or Unity Cloud Build) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges