private void OnGetAttributeCallback(string errorJson, string resultJson) { this.getting = false; // The callback might occur after the behaviour was disabled if (!this.enabled) { return; } if (errorJson != null) { CommandError error = VLJsonUtility.FromJson <CommandError>(errorJson); Debug.LogWarning("[vlUnitySDK] OnGetAttributeCallback: " + error.message); return; } GetAttributeResult result = VLJsonUtility.FromJson <GetAttributeResult>(resultJson); if (this.parameterValue != result.value) { this.parameterValue = result.value; switch (this.internalParameterType) { case ParameterType.String: this.stringValueChangedEvent.Invoke(result.value); break; case ParameterType.Int: this.intValueChangedEvent.Invoke( Convert.ToInt32(result.value, CultureInfo.InvariantCulture)); this.floatValueChangedEvent.Invoke( Convert.ToSingle(result.value, CultureInfo.InvariantCulture)); break; case ParameterType.Float: this.floatValueChangedEvent.Invoke( Convert.ToSingle(result.value, CultureInfo.InvariantCulture)); break; case ParameterType.Bool: this.boolValueChangedEvent.Invoke( VLRuntimeParameterBehaviour.ToBoolean(result.value)); break; default: Debug.LogWarning("[vlUnitySDK] OnGetAttributeCallback: Unknown parameter type"); break; } } }
private static void DispatchGetAttributeCallback(string errorJson, string resultJson, IntPtr clientData) { try { GCHandle gcHandle = GCHandle.FromIntPtr(clientData); VLRuntimeParameterBehaviour behaviour = (VLRuntimeParameterBehaviour)gcHandle.Target; behaviour.OnGetAttributeCallback(errorJson, resultJson); } catch (Exception e) // Catch all exceptions, because this is a callback // invoked from native code { Debug.LogError("[vlUnitySDK] " + e.GetType().Name + ": " + e.Message); } }