Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Accessing Game Objects inside of # IF/ENDIFs

Part of my program has to be inside # If ! UNITY_EDITOR because it uses parts of the Windows API. In this same region of code, I'd like to mess with game objects and modify text. Is this possible? Or can you not do this inside if # IF / ENDIFS? I've tried to do this, but it doesn't seem to work.

Answers

  • stepan_stulovstepan_stulov ✭✭✭
    edited August 2017

    Part of my program has to be inside # If ! UNITY_EDITOR because it uses parts of the Windows API.

    Hey, @TetraTalon.

    UNITY_EDITOR signifies whether or not you're running your app as an actual build or from within the Editor and in itself has nothing to do with what platform you're developing for (although there are some overlaps).

    Check these links for details:

    https://forums.hololens.com/discussion/comment/15459#Comment_15459
    https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

    Building the future of holographic navigation. We're hiring.

  • @stepan_stulov , I've seen other people handle my situation in this same way though (like here: https://forums.hololens.com/discussion/578/hololens-udp-server). I don't need it to be specific to the platform, just need it to compile outside of the editor, but I'm curious if all my traditional Unity methods such as game object manipulation will still work if it's on anything other than a UNITY_EDITOR block.

  • stepan_stulovstepan_stulov ✭✭✭
    edited August 2017

    @TetraTalon

    They will work. Basically everything that comes from UnityEngine namespace using will work on every supported Unity platform. In Editor or in the build.

    Building the future of holographic navigation. We're hiring.

  • @stepan_stulov said:
    @TetraTalon

    They will work. Basically everything that comes from UnityEngine namespace using will work on every supported Unity platform. In Editor or in the build.

    The code I have below doesn't seem to tho. I'm trying to figure out if it's an issue with my connection or what.

    `using UnityEngine;
    using System;
    using System.IO;

    if !UNITY_EDITOR

    using Windows.Networking.Sockets;
    using Windows.Networking;

    endif

    public class UDPListen : MonoBehaviour
    {
    public TextMesh test;
    public string port;
    public GameObject turn;
    //public string word;
    public bool rec;

    if !UNITY_EDITOR

    DatagramSocket socket;
    // use this for initialization
    async void Start()
    {
    
        Debug.Log("Waiting for a connection...");
    
        socket = new DatagramSocket();
        socket.MessageReceived += Socket_MessageReceived;
    
        try
        {
            HostName serverHost = new HostName("172.30.98.97");
            await socket.BindEndpointAsync(serverHost , port);
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
            Debug.Log(SocketError.GetStatus(e.HResult).ToString());
            return;
        }
    
        Debug.Log("exit start");
    
    }
    

    endif

    // Update is called once per frame
    void Update()
    {
        if (rec)
        {
            test.text = "worked";
        }
    }
    

    if !UNITY_EDITOR

    private async void Socket_MessageReceived(Windows.Networking.Sockets.DatagramSocket sender,
        Windows.Networking.Sockets.DatagramSocketMessageReceivedEventArgs args)
    {
        //Read the message that was received from the UDP echo client.
        Destroy(turn);
        Stream streamIn = args.GetDataStream().AsStreamForRead();
        StreamReader reader = new StreamReader(streamIn);
        string message = await reader.ReadLineAsync();
        rec = true;
        //word = message;
        test.text = message;
        Debug.Log("MESSAGE: " + message);
    }
    

    endif

    }`

  • stepan_stulovstepan_stulov ✭✭✭
    edited August 2017

    Would you mind being more specific to what exactly doesn't work? Are you testing this code in Editor? If so, you have almost no code to test, as most of it is excluded from running there. Literally the only line to execute in Editor is:

    if (rec)
    {
    test.text = "worked";
    }
    

    And rec variable is always false.

    Also

    The code I have below doesn't seem to tho. I'm trying to figure out if it's an issue with my connection or what.

    Yes, it's not from UnityEngine namespace, so not sure what you mean with "tho". Would you mind clarifying?

    Building the future of holographic navigation. We're hiring.

Sign In or Register to comment.