Exemple #1
0
        public static UdonSharpBehaviour AddUdonSharpComponent(this GameObject gameObject, System.Type type)
        {
            if (type == typeof(UdonSharpBehaviour))
            {
                throw new System.ArgumentException("Cannot add components of type 'UdonSharpBehaviour', you can only add subclasses of this type");
            }

            if (!typeof(UdonSharpBehaviour).IsAssignableFrom(type))
            {
                throw new System.ArgumentException("Type for AddUdonSharpComponent must be a subclass of UdonSharpBehaviour");
            }

            UdonBehaviour udonBehaviour = gameObject.AddComponent <UdonBehaviour>();

            UdonSharpProgramAsset programAsset = UdonSharpProgramAsset.GetProgramAssetForClass(type);

            udonBehaviour.programSource = programAsset;
            udonBehaviour.AllowCollisionOwnershipTransfer = false;

            SerializedObject   componentAsset = new SerializedObject(udonBehaviour);
            SerializedProperty serializedProgramAssetProperty = componentAsset.FindProperty("serializedProgramAsset");

            serializedProgramAssetProperty.objectReferenceValue = programAsset.SerializedProgramAsset;
            componentAsset.ApplyModifiedPropertiesWithoutUndo();

            UdonSharpBehaviour proxyComponent = UdonSharpEditorUtility.GetProxyBehaviour(udonBehaviour);

            if (EditorApplication.isPlaying)
            {
                udonBehaviour.InitializeUdonContent();
            }

            return(proxyComponent);
        }
Exemple #2
0
    public static void JoinMaster(UdonSharpBehaviour body, int gid, int category)
    {
        T23_Master master = GetMaster(body, gid, category, false);

        if (!master)
        {
            master         = body.gameObject.AddComponent <T23_Master>();
            master.groupID = gid;
        }

        switch (category)
        {
        case 0:
            master.JoinBroadcast(body);
            break;

        case 1:
            master.JoinTrigger(body);
            break;

        case 2:
            master.JoinAction(body);
            break;
        }
    }
Exemple #3
0
    public void _u_UnregisterCallbackReceiver(UdonSharpBehaviour callbackReceiver)
    {
        if (!Utilities.IsValid(callbackReceiver))
        {
            return;
        }
        if (_registeredCallbackReceivers == null)
        {
            _registeredCallbackReceivers = new UdonSharpBehaviour[0];
        }
        int callbackReceiverCount = _registeredCallbackReceivers.Length;

        for (int i = 0; i < callbackReceiverCount; ++i)
        {
            UdonSharpBehaviour currHandler = _registeredCallbackReceivers[i];
            if (callbackReceiver == currHandler)
            {
                UdonSharpBehaviour[] newCallbackReceivers = new UdonSharpBehaviour[callbackReceiverCount - 1];
                for (int j = 0; j < i; ++j)
                {
                    newCallbackReceivers[j] = _registeredCallbackReceivers[j];
                }
                for (int j = i + 1; j < callbackReceiverCount; ++j)
                {
                    newCallbackReceivers[j - 1] = _registeredCallbackReceivers[j];
                }
                _registeredCallbackReceivers = newCallbackReceivers;
                return;
            }
        }
    }
 public void StartTimer(int index, UdonSharpBehaviour targetUdon, string eventName, float delay)
 {
     targetUdons[index] = targetUdon;
     eventNames[index]  = eventName;
     startTimes[index]  = Time.time;
     delayTimes[index]  = delay;
 }
Exemple #5
0
        public void ExecuteTests()
        {
            tester.TestAssertion("GetComponent<Transform>()", GetComponent <Transform>() != null);

            BoxCollider[] colliders = GetComponentsInChildren <BoxCollider>();

            tester.TestAssertion("GetComponentsInChildren<BoxCollider>()", colliders.Length == 2);

            tester.TestAssertion("GetComponentInChildren<PlayerModSetter>()", GetComponentInChildren <NameOf>() != null);

            NameOf[] nameOfs = GetComponentsInChildren <NameOf>();

            tester.TestAssertion("GetComponentsInChildren<PlayerModSetter>()", nameOfs.Length == 3);

            tester.TestAssertion("GetComponentsInChildren<MeshRenderer>()", GetComponentsInChildren <MeshRenderer>().Length == 2);

            UdonSharpBehaviour getBehaviour = (UdonSharpBehaviour)modObject.GetComponent(typeof(UdonBehaviour));

            tester.TestAssertion("Get UdonBehaviour typeof(UdonBehaviour)", getBehaviour != null);

            long typeID = GetUdonTypeID <NameOf>();

            tester.TestAssertion("Type ID matches", typeID == getBehaviour.GetUdonTypeID());

            tester.TestAssertion("Correct number of UdonBehaviours on gameobject", modObject.GetComponents(typeof(UdonBehaviour)).Length == 4);

            //Debug.Log(getBehaviour.GetUdonTypeID());
            //Debug.Log(getBehaviour.GetUdonTypeName());

            //foreach (Component behaviour in modObject.GetComponents(typeof(UdonBehaviour)))
            //{
            //    Debug.Log("Component name: " + ((UdonSharpBehaviour)behaviour).GetUdonTypeName());
            //}
        }
        public static UdonSharpBehaviour GetProxyBehaviour(UdonBehaviour udonBehaviour, ProxySerializationPolicy proxySerializationPolicy)
        {
            if (udonBehaviour == null)
            {
                throw new System.ArgumentNullException("Source Udon Behaviour cannot be null");
            }

            if (udonBehaviour.programSource == null)
            {
                throw new System.ArgumentNullException("Program source on UdonBehaviour cannot be null");
            }

            UdonSharpProgramAsset udonSharpProgram = udonBehaviour.programSource as UdonSharpProgramAsset;

            if (udonSharpProgram == null)
            {
                throw new System.ArgumentException("UdonBehaviour must be using an UdonSharp program");
            }

            UdonSharpBehaviour proxyBehaviour = FindProxyBehaviour(udonBehaviour, proxySerializationPolicy);

            if (proxyBehaviour)
            {
                return(proxyBehaviour);
            }

            // We've failed to find an existing proxy behaviour so we need to create one
            System.Type scriptType = udonSharpProgram.GetClass();

            if (scriptType == null)
            {
                return(null);
            }

            SetIgnoreEvents(true);

            try
            {
                proxyBehaviour           = (UdonSharpBehaviour)udonBehaviour.gameObject.AddComponent(scriptType);
                proxyBehaviour.hideFlags = HideFlags.DontSaveInBuild |
#if !UDONSHARP_DEBUG
                                           HideFlags.HideInInspector |
#endif
                                           HideFlags.DontSaveInEditor;
                proxyBehaviour.enabled = false;
            }
            finally
            {
                SetIgnoreEvents(false);
            }

            SetBackingUdonBehaviour(proxyBehaviour, udonBehaviour);

            _proxyBehaviourLookup.Add(udonBehaviour, proxyBehaviour);

            CopyUdonToProxy(proxyBehaviour, proxySerializationPolicy);

            return(proxyBehaviour);
        }
Exemple #7
0
        public static UdonBehaviour CreateBehaviourForProxy(UdonSharpBehaviour udonSharpBehaviour)
        {
            UdonBehaviour backingBehaviour = GetBackingUdonBehaviour(udonSharpBehaviour);

            CopyProxyToUdon(udonSharpBehaviour);

            return(backingBehaviour);
        }
Exemple #8
0
        public static bool IsProxyBehaviour(UdonSharpBehaviour behaviour)
        {
            if (behaviour == null)
            {
                return(false);
            }

            return(GetBackingUdonBehaviour(behaviour) != null);
        }
            public static bool EventInterceptor(UdonSharpBehaviour __instance)
            {
                if (UdonSharpEditorUtility.IsProxyBehaviour(__instance) || shouldSkipEventsMethod())
                {
                    return(false);
                }

                return(true);
            }
    public int _u_WebRequestPost(string uri, UdonSharpBehaviour usb, bool autoConvertToUTF16, bool returnUTF16String, string[] keys, string[] values)
    {
        if (keys != null && keys.Length != values.Length)
        {
            Debug.LogError("[UdonMIDIWebHandler] Incorrect number of key/value arguments for POST request!  Keys length: " + keys.Length + " Values length: " + values.Length);
            return(CONNECTION_ID_REQUEST_INVALID);
        }

        int connectionID = _u_getAvailableConnectionID();

        if (connectionID >= 0)
        {
            connectionRequesters[connectionID]     = usb;
            connectionIsWebSocket[connectionID]    = false;
            connectionReturnsStrings[connectionID] = returnUTF16String;
            connectionsOpen++;
            _u_SendCallback("_u_OnUdonMIDIWebHandlerConnectionCountChanged");

            // Allow for full range of Basic Multilingual Plane UTF16 characters.
            // (queries will be properly percent encoded by the helper program)
            // Base64 encode the data because the output log doesn't
            // play nice with certain special characters.  Also so a new log line can't be spoofed.
            byte[] utf16Bytes = _u_EncodingUnicodeGetBytes(uri);

            string args = "";
            if (keys != null && values != null)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    string keyEncoded, valueEncoded;
                    if (keys[i] == "")
                    {
                        keyEncoded = "=";                // Empty string key or value in post? Sure why not
                    }
                    else
                    {
                        keyEncoded = Convert.ToBase64String(_u_EncodingUnicodeGetBytes(keys[i]));
                    }
                    if (values[i] == "")
                    {
                        valueEncoded = "=";
                    }
                    else
                    {
                        valueEncoded = Convert.ToBase64String(_u_EncodingUnicodeGetBytes(values[i]));
                    }
                    args += " " + keyEncoded + " " + valueEncoded;
                }
            }

            Debug.Log("[Udon-MIDI-Web-Helper] POST " + connectionID + " " + Convert.ToBase64String(utf16Bytes) + (autoConvertToUTF16 ? " UTF16" : "UTF8") + args);
            commandsSent++;
        }
        return(connectionID);
    }
Exemple #11
0
 public void TestTrigger()
 {
     if (triggerTitles.Count > 0)
     {
         ComponentSet       set   = GetComponentSet(triggerSet, triggerTitles[0]);
         UdonSharpBehaviour proxy = UdonSharpEditorUtility.FindProxyBehaviour(set.component);
         UdonSharpEditorUtility.CopyProxyToUdon(proxy, ProxySerializationPolicy.All);
         set.component.SendCustomEvent("Trigger");
         UdonSharpEditorUtility.CopyUdonToProxy(proxy, ProxySerializationPolicy.All);
     }
 }
Exemple #12
0
 public static bool MakeSureItsAnUdonBehaviour(UdonSharpBehaviour udonSharpBehaviour)
 {
     //if not udon behaviour
     if (UdonSharpEditor.UdonSharpEditorUtility.GetBackingUdonBehaviour(udonSharpBehaviour) == null)
     {
         GetUdonBehaviour(udonSharpBehaviour.GetType(), udonSharpBehaviour.gameObject);
         DestroyImmediate(udonSharpBehaviour);
         return(false);
     }
     return(true);
 }
 private void Trigger(UdonSharpBehaviour target, string eventName)
 {
     if (target)
     {
         target.SendCustomEvent(eventName);
     }
     if (audioSource && audioClip)
     {
         audioSource.PlayOneShot(audioClip);
     }
 }
Exemple #14
0
        private static UdonSharpBehaviour GetProxyBehaviour_Internal(UdonBehaviour udonBehaviour)
        {
            if (udonBehaviour == null)
            {
                throw new ArgumentNullException(nameof(udonBehaviour));
            }

            UdonSharpBehaviour proxyBehaviour = FindProxyBehaviour_Internal(udonBehaviour);

            return(proxyBehaviour);
        }
Exemple #15
0
        public static void DestroyImmediate(UdonSharpBehaviour behaviour)
        {
            UdonBehaviour udonBehaviour = UdonSharpEditorUtility.GetBackingUdonBehaviour(behaviour);

            if (udonBehaviour)
            {
                Undo.DestroyObjectImmediate(udonBehaviour);
            }

            Undo.DestroyObjectImmediate(behaviour);
        }
        public static void DestroyImmediate(UdonSharpBehaviour behaviour)
        {
            UdonBehaviour backingBehaviour = GetBackingUdonBehaviour(behaviour);

            Object.DestroyImmediate(behaviour);

            if (backingBehaviour)
            {
                _proxyBehaviourLookup.Remove(backingBehaviour);
                Object.DestroyImmediate(backingBehaviour);
            }
        }
        public static UdonSharpBehaviour AddUdonSharpComponent(this GameObject gameObject, System.Type type)
        {
            if (type == typeof(UdonSharpBehaviour))
            {
                throw new System.ArgumentException("Cannot add components of type 'UdonSharpBehaviour', you can only add subclasses of this type");
            }

            if (!typeof(UdonSharpBehaviour).IsAssignableFrom(type))
            {
                throw new System.ArgumentException("Type for AddUdonSharpComponent must be a subclass of UdonSharpBehaviour");
            }

            UdonBehaviour udonBehaviour = gameObject.AddComponent <UdonBehaviour>();

            UdonSharpProgramAsset programAsset = UdonSharpProgramAsset.GetProgramAssetForClass(type);

            udonBehaviour.programSource = programAsset;
#pragma warning disable CS0618 // Type or member is obsolete
            udonBehaviour.SynchronizePosition             = false;
            udonBehaviour.AllowCollisionOwnershipTransfer = false;
#pragma warning restore CS0618 // Type or member is obsolete

            switch (programAsset.behaviourSyncMode)
            {
            case BehaviourSyncMode.Continuous:
                udonBehaviour.SyncMethod = Networking.SyncType.Continuous;
                break;

            case BehaviourSyncMode.Manual:
                udonBehaviour.SyncMethod = Networking.SyncType.Manual;
                break;

            case BehaviourSyncMode.None:
                udonBehaviour.SyncMethod = Networking.SyncType.None;
                break;
            }

            SerializedObject   componentAsset = new SerializedObject(udonBehaviour);
            SerializedProperty serializedProgramAssetProperty = componentAsset.FindProperty("serializedProgramAsset");

            serializedProgramAssetProperty.objectReferenceValue = programAsset.SerializedProgramAsset;
            componentAsset.ApplyModifiedPropertiesWithoutUndo();

            UdonSharpBehaviour proxyComponent = UdonSharpEditorUtility.GetProxyBehaviour(udonBehaviour);

            if (EditorApplication.isPlaying)
            {
                udonBehaviour.InitializeUdonContent();
            }

            return(proxyComponent);
        }
Exemple #18
0
 private void DrawDefaultGUI(UdonSharpBehaviour t)
 {
     if (UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target, false, false))
     {
         return;
     }
     base.OnInspectorGUI();
     UTStyles.HorizontalLine();
     if (GUILayout.Button("Show UdonToolkit Inspector", UTStyles.smallButton))
     {
         drawDefaultInspector = false;
     }
 }
Exemple #19
0
        void HandleInput(Event guiEvent, UdonSharpBehaviour destination)
        {
            Ray     mouseRay        = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition);
            float   drawPlaneHeight = 0;
            float   dstToDrawPlane  = (drawPlaneHeight - mouseRay.origin.y) / mouseRay.direction.y;
            Vector3 mousePosition   = mouseRay.GetPoint(dstToDrawPlane);

            if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 &&
                guiEvent.modifiers == EventModifiers.None)
            {
                HandleLeftMouseDown(mousePosition, destination);
            }
        }
Exemple #20
0
    public void JoinAction(UdonSharpBehaviour baseComponent)
    {
        ComponentSet set = JoinUdonComponent(baseComponent, actionTitles);

        actionSet.Add(set);
        actionTitles.Add(set.title);
        OrderComponents();
        shouldMoveComponents = true;

        UdonBehaviour udon = UdonSharpEditorUtility.GetBackingUdonBehaviour(baseComponent);

        DestroyImmediate(udon);
    }
Exemple #21
0
        public void AddEventListener(UdonSharpBehaviour eventListener, uint bank, uint bitmask, string syncValueName, string prevValueName, string valueChangeEvent)
        {
            eventListeners    = (Component[])AppendObject(eventListeners, eventListener);
            banks             = AppendUint(banks, bank);
            bitmaskList       = AppendUint(bitmaskList, bitmask);
            syncValueNames    = AppendString(syncValueNames, syncValueName);
            prevValueNames    = AppendString(prevValueNames, prevValueName);
            valueChangeEvents = AppendString(valueChangeEvents, valueChangeEvent);

            eventListenerCount = eventListeners.Length;

            Log("Info", $"{eventListener} listening bank:{bank} bitmask:{bitmask}");;
        }
Exemple #22
0
        private void HandleChangeCallback(UdonSharpBehaviour t, string changedCallback, SerializedProperty prop, SerializedProperty otherProp, object[] output)
        {
            if (changedCallback == null)
            {
                return;
            }
            var m = cT.GetMethod(changedCallback, methodFlags);

            if (m == null)
            {
                return;
            }
            var arrVal      = new List <SerializedProperty>();
            var otherArrVal = new List <SerializedProperty>();

            var appended = output.ToList().Prepend(serializedObject).ToArray();

            for (int j = 0; j < prop.arraySize; j++)
            {
                arrVal.Add(prop.GetArrayElementAtIndex(j));
            }

            if (otherProp == null)
            {
                if (m.GetParameters().Length == 1)
                {
                    m.Invoke(t, new object[] { arrVal.ToArray() });
                    return;
                }
                m.Invoke(t,
                         m.GetParameters().Length > 2
            ? appended
            : new object[] { serializedObject, arrVal.ToArray() });
                return;
            }

            for (int j = 0; j < otherProp.arraySize; j++)
            {
                otherArrVal.Add(otherProp.GetArrayElementAtIndex(j));
            }

            if (m.GetParameters().Length == 2)
            {
                m.Invoke(t, new object[] { arrVal.ToArray(), otherArrVal.ToArray() });
                return;
            }
            m.Invoke(t,
                     m.GetParameters().Length > 3
        ? appended
        : new object[] { serializedObject, arrVal.ToArray(), otherArrVal.ToArray() });
        }
        private static UdonSharpBehaviour ConvertToUdonSharpComponent(UdonBehaviour[] behaviours, System.Type type, ProxySerializationPolicy proxySerializationPolicy)
        {
            foreach (UdonBehaviour behaviour in behaviours)
            {
                UdonSharpBehaviour udonSharpBehaviour = ConvertToUdonSharpComponentIntnl(behaviour, type, proxySerializationPolicy);

                if (udonSharpBehaviour)
                {
                    return(udonSharpBehaviour);
                }
            }

            return(null);
        }
Exemple #24
0
        void HandleLeftMouseDown(Vector3 mousePosition, UdonSharpBehaviour destination)
        {
            var roomGuiPosition =
                HandleUtility.WorldToGUIPoint(destination.transform.position);
            var mouseGuiPosition = HandleUtility.WorldToGUIPoint(mousePosition);
            var clickCloseToDestinationGameObject = Vector2.Distance(roomGuiPosition, mouseGuiPosition) < 10f;

            if (clickCloseToDestinationGameObject)
            {
                Selection.SetActiveObjectWithContext(destination.gameObject,
                                                     destination);
                EditorGUIUtility.PingObject(destination);
            }
        }
        public static UdonBehaviour CreateBehavourForProxy(UdonSharpBehaviour udonSharpBehaviour)
        {
            UdonBehaviour backingBehaviour = GetBackingUdonBehaviour(udonSharpBehaviour);

            if (backingBehaviour == null)
            {
                backingBehaviour = udonSharpBehaviour.gameObject.AddComponent <UdonBehaviour>();
                backingBehaviour.programSource = GetUdonSharpProgramAsset(udonSharpBehaviour);
            }

            CopyProxyToUdon(udonSharpBehaviour);

            return(backingBehaviour);
        }
Exemple #26
0
 private UdonSharpBehaviour[] AddUdonSharpBehaviourArray(UdonSharpBehaviour[] array, UdonSharpBehaviour value, int index)
 {
     UdonSharpBehaviour[] new_array = new UdonSharpBehaviour[array.Length + 1];
     array.CopyTo(new_array, 0);
     for (int i = 0; i < index; i++)
     {
         new_array[i] = array[i];
     }
     new_array[index] = value;
     for (int i = index + 1; i < new_array.Length; i++)
     {
         new_array[i] = array[i - 1];
     }
     return(new_array);
 }
Exemple #27
0
        // GetComponents
        private static T[] GetUdonSharpComponentsInherited <T>(Component[] behaviours) where T : UdonSharpBehaviour
        {
            long targetID = UdonSharpBehaviour.GetUdonTypeID <T>();

            int arraySize = 0;

            foreach (UdonBehaviour behaviour in (UdonBehaviour[])behaviours)
            {
            #if UNITY_EDITOR
                if (behaviour.GetProgramVariableType(CompilerConstants.UsbTypeIDArrayHeapKey) == null)
                {
                    continue;
                }
            #endif
                object idValue = behaviour.GetProgramVariable(CompilerConstants.UsbTypeIDArrayHeapKey);
                if (idValue != null)
                {
                    if (Array.IndexOf((Array)idValue, targetID) != -1)
                    {
                        arraySize++;
                    }
                }
            }

            Component[] foundBehaviours = new Component[arraySize];
            int         targetIdx       = 0;

            foreach (UdonBehaviour behaviour in (UdonBehaviour[])behaviours)
            {
            #if UNITY_EDITOR
                if (behaviour.GetProgramVariableType(CompilerConstants.UsbTypeIDArrayHeapKey) == null)
                {
                    continue;
                }
            #endif
                object idValue = behaviour.GetProgramVariable(CompilerConstants.UsbTypeIDArrayHeapKey);
                if (idValue != null)
                {
                    if (Array.IndexOf((Array)idValue, targetID) != -1)
                    {
                        foundBehaviours[targetIdx++] = behaviour;
                    }
                }
            }

            return((T[])foundBehaviours);
        }
        public static UdonSharpBehaviour AddComponent(GameObject gameObject, System.Type type)
        {
            if (type == typeof(UdonSharpBehaviour))
            {
                throw new System.ArgumentException("Cannot add components of type 'UdonSharpBehaviour', you can only add subclasses of this type");
            }

            if (!typeof(UdonSharpBehaviour).IsAssignableFrom(type))
            {
                throw new System.ArgumentException("Type for AddUdonSharpComponent must be a subclass of UdonSharpBehaviour");
            }

            UdonBehaviour udonBehaviour = Undo.AddComponent <UdonBehaviour>(gameObject);

            UdonSharpProgramAsset programAsset = UdonSharpProgramAsset.GetProgramAssetForClass(type);

            udonBehaviour.programSource = programAsset;
#pragma warning disable CS0618 // Type or member is obsolete
            udonBehaviour.AllowCollisionOwnershipTransfer = false;
#pragma warning restore CS0618 // Type or member is obsolete

            SerializedObject   componentAsset = new SerializedObject(udonBehaviour);
            SerializedProperty serializedProgramAssetProperty = componentAsset.FindProperty("serializedProgramAsset");

            serializedProgramAssetProperty.objectReferenceValue = programAsset.SerializedProgramAsset;
            componentAsset.ApplyModifiedProperties();

            System.Type scriptType = programAsset.GetClass();

            UdonSharpBehaviour proxyComponent = (UdonSharpBehaviour)Undo.AddComponent(udonBehaviour.gameObject, scriptType);
            proxyComponent.hideFlags = HideFlags.DontSaveInBuild |
#if !UDONSHARP_DEBUG
                                       HideFlags.HideInInspector |
#endif
                                       HideFlags.DontSaveInEditor;
            proxyComponent.enabled = false;

            UdonSharpEditorUtility.SetBackingUdonBehaviour(proxyComponent, udonBehaviour);
            UdonSharpEditorUtility.CopyUdonToProxy(proxyComponent, ProxySerializationPolicy.AllWithCreateUndo);

            if (EditorApplication.isPlaying)
            {
                udonBehaviour.InitializeUdonContent();
            }

            return(proxyComponent);
        }
    public int _u_WebSocketOpen(string uri, UdonSharpBehaviour usb, bool autoConvertToUTF16, bool returnUTF16String)
    {
        int connectionID = _u_getAvailableConnectionID();

        if (connectionID >= 0)
        {
            connectionRequesters[connectionID]     = usb;
            connectionIsWebSocket[connectionID]    = true;
            connectionReturnsStrings[connectionID] = returnUTF16String;
            connectionsOpen++;
            _u_SendCallback("_u_OnUdonMIDIWebHandlerConnectionCountChanged");
            byte[] utf16Bytes = _u_EncodingUnicodeGetBytes(uri);
            Debug.Log("[Udon-MIDI-Web-Helper] WSOPEN " + connectionID + " " + Convert.ToBase64String(utf16Bytes) + (autoConvertToUTF16 ? " UTF16" : ""));
            commandsSent++;
        }
        return(connectionID);
    }
Exemple #30
0
        public void ExecuteTests()
        {
            string testStr = string.Concat("a", "bc", "d", "e", "fg", "hij", "klmn", "opq", "rstuv", "wx", "yz");

            tester.TestAssertion("Params arrays", testStr == "abcdefghijklmnopqrstuvwxyz");

            string joinedStr  = string.Join(", ", new[] { "Hello", "test", "join" });
            string joinedStr2 = string.Join(", ", "Hello", "test", "join");

            tester.TestAssertion("Param parameter without expanding", joinedStr == "Hello, test, join");
            tester.TestAssertion("Param parameter with expanding", joinedStr2 == "Hello, test, join");

            string formatStr = string.Format("{0}, {1}", this, this);

            tester.TestAssertion("FormatStr 1", formatStr == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            string formatStr2 = string.Format("{0}", this);

            tester.TestAssertion("FormatStr 2", formatStr2 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            var    objArr     = new object[] { this };
            string formatStr3 = string.Format("{0}", objArr);

            tester.TestAssertion("FormatStr 3", formatStr3 == "MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("String Join Objects params", string.Join(", ", this, this, this, this) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");
            tester.TestAssertion("String Join Objects array", string.Join(", ", new object[] { this, this, this, this }) == "MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour), MethodCalls (VRC.Udon.UdonBehaviour)");

            tester.TestAssertion("Split test", "a b c d".Split(new [] { ' ' }, System.StringSplitOptions.None).Length == 4);

            enabled = false;
            tester.TestAssertion("UdonBehaviour enabled", enabled == false);
            enabled = true;

            UdonSharpBehaviour self = this;

            self.enabled = false;
            tester.TestAssertion("UdonSharpBehaviour ref enabled", self.enabled == false);
            self.enabled = true;

            UdonBehaviour selfUdon = (UdonBehaviour)(Component)this;

            selfUdon.enabled = false;
            tester.TestAssertion("UdonBehaviour ref enabled", selfUdon.enabled == false);
            selfUdon.enabled = true;
        }