- Home /
MicInput Conversion to C#
I'm trying to convert the main Javascript MicInput script over to C# and I'm having some issues. I've been able to successfully convert the main MicInputJ file over with no more errors, but I'm having some issues with the VolumeBar class. I'm pretty new to Unity and C#, so this is likely most of my issue. Any help or clarification on what syntax is wrong would be greatly appreciated. See my current script and the errors below.
Errors
Assets/Editor/VolumeBarC.cs(22,76): error CS0119: Expression denotes a
type', where a variable',
value' or method group' was expected
Assets/Editor/VolumeBarC.cs(26,69): error CS1503: Argument
#1' cannot convert object' expression to type
float'`
Assets/Editor/VolumeBarC.cs(22,48): error CS1503: Argument
#2' cannot convert object' expression to type
UnityEngine.Texture'`
Assets/Editor/VolumeBarC.cs(22,48): error CS1502: The best overloaded method match for
UnityEngine.GUILayout.Toggle(bool, UnityEngine.Texture, params UnityEngine.GUILayoutOption[])' has some invalid arguments`
VolumeBarC.cs
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor(typeof(MicControlC))]
public class VolumeBarC : Editor
{
MicControlC ListenToMic;
/////////////////////////////////////////////////////////////////////////////////////////////////
void OnInspectorGUI ()
{
ListenToMic = (MicControlC)target;
float micInputValue = MicControlC.loudness;
ProgressBar (micInputValue, "Loudness");
//show other variables
//Redirect 3D toggle
ListenToMic.ThreeD = GUILayout.Toggle (ListenToMic.ThreeD, GUIContent ("3D sound", "Should the streamed audio be a 3D sound? (Only enable this if you are using the controller to stream sound (VOIP) "));
//when 3D audio is enabled show the fall off settings
if (ListenToMic.ThreeD) {
ListenToMic.VolumeFallOff = EditorGUILayout.FloatField (GUIContent ("Volume falloff", "Set the rate at wich audio volume gets lowered. A lower value will have a slower falloff and thus hearable from a greater distance, while a higher value will make the audio degrate faster and dissapear from a shorter distance"), ListenToMic.VolumeFallOff);
ListenToMic.PanThreshold = EditorGUILayout.FloatField (GUIContent ("PanThreshold", "Set the rate at wich audio PanThreshold gets switched between left or right ear. A lower value will have a faster transition and thus a faster switch, while a higher value will make the transition slower and smoothly switch between the ears. Don't go to smooth though as this will turn your audio to mono channel"), ListenToMic.PanThreshold);
}
//Redirect select ingame
ListenToMic.SelectIngame = GUILayout.Toggle (ListenToMic.SelectIngame, GUIContent ("Select in game", "select the audio source through a GUI ingame"));
//Redirect Mute ingame
ListenToMic.Mute = GUILayout.Toggle (ListenToMic.Mute, GUIContent ("Mute", "when dissabled you can listen to a playback of the microphone"));
//Redirect debug ingame
ListenToMic.debug = GUILayout.Toggle (ListenToMic.debug, GUIContent ("Debug", "This will write the gathered Loudness value to the console during playmode. This is handy if you want if statements to listen at a specific value."));
//Redirect ShozDeviceName ingame
ListenToMic.ShowDeviceName = GUILayout.Toggle (ListenToMic.ShowDeviceName, GUIContent ("Show Device name(s)", "When selected all detected devices will be written to the console during play mode"));
EditorUtility.SetDirty (target);
// Show default inspector property editor
DrawDefaultInspector ();
}
// Custom GUILayout progress bar.
void ProgressBar (float value, string label)
{
// Get a rect for the progress bar using the same margins as a textfield:
Rect rect = GUILayoutUtility.GetRect (18, 18, "TextField");
EditorGUI.ProgressBar (rect, value, label);
EditorGUILayout.Space ();
}
}
I think I just solved it. I needed to have 'new' in front of my GUIContent calls. However, I'm sure there are some other optimizations that can be made. Any suggestions? Or is it good?
Hmm... I'm able to attach the $$anonymous$$icControl to a GameObject, but I don't get the fancy feedback sound bar or the drop downs. Is this a limitation of C# in Unity?
An example of my $$anonymous$$icControlC.cs script is located at: https://gist.github.com/robksawyer/d1aed220e77225928acd
Fixed my issues with $$anonymous$$icControlC.cs. I just needed to move my InputDevice declaration after the actual enum declaration and then add public to the audioListener and InputDevice. Updated the above linked script.