protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); receiver = e.Parameter as RCReceiver; receiver.LostEvent += Receiver_LostEvent; }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); receiver = e.Parameter as RCReceiver; receiver.LostEvent += Receiver_LostEvent; _timer.Interval = TimeSpan.FromMilliseconds(100); _timer.Tick += _timer_Tick; _timer.Start(); Gamepad.GamepadAdded += Gamepad_GamepadAdded; Gamepad.GamepadRemoved += Gamepad_GamepadRemoved; }
public override void OnInspectorGUI() { RCReceiver myTarget = (RCReceiver)target; Component[] allComponents; string[] _choices; string[] _propertyChoice; string[] _serverChoice; string addressName; // OSC Address addressName = ""; // --------------------------------------------------------- [ COMPONENTS ] // get components from gameobject allComponents = myTarget.GetComponents <Component>(); _choices = new string[allComponents.Length]; int i = 0; foreach (Component component in allComponents) // create a list of components { _choices[i] = (string)component.GetType().Name; i++; } // Display popup int oldComponentIndex = myTarget._componentIndex; myTarget._componentIndex = EditorGUILayout.Popup("Component to control", myTarget._componentIndex, _choices); // reset components if (oldComponentIndex != myTarget._componentIndex) { myTarget.address = ""; myTarget._controlIndex = 0; myTarget._generalIndex = 0; } //Component childrenComponents; myTarget.objectComponent = myTarget.GetComponent(allComponents[myTarget._componentIndex].GetType()); Type typeComponent = myTarget.objectComponent.GetType(); const BindingFlags flags = /*BindingFlags.NonPublic | */ BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; // let the user choose what to control int oldControlIndex = myTarget._controlIndex; String[] exposeOptions = { "Properties", "Methods", "Fields" }; myTarget._controlIndex = EditorGUILayout.Popup("Control", myTarget._controlIndex, exposeOptions); // reset control if (oldControlIndex != myTarget._controlIndex) { myTarget.address = ""; myTarget._generalIndex = 0; } if (myTarget._controlIndex == 0) // properties { // To retrieve the properties PropertyInfo[] properties = typeComponent.GetProperties(flags); if (properties.Length > 0) // check if we have properties { _propertyChoice = new string[properties.Length]; i = 0; foreach (PropertyInfo propertyInfo in properties) { // TODO: Select the CanWrite property to constraint the selection _propertyChoice[i] = (string)propertyInfo.Name; i++; } // Pop up for choosing the control properties int old_index = myTarget._generalIndex; myTarget._generalIndex = EditorGUILayout.Popup("Property to control", myTarget._generalIndex, _propertyChoice); myTarget.propertyObject = properties[myTarget._generalIndex]; if (old_index != myTarget._generalIndex) { myTarget.address = ""; } myTarget.relativeAt = EditorGUILayout.Toggle("Relative to source", myTarget.relativeAt); // UPDATE the address field addressName = "/" + myTarget.transform.name + "_" + myTarget.propertyObject.Name; } } else if (myTarget._controlIndex == 1) // METHODS { // --------------------------------------------------------- [ METHODS ] // To retrieve the blendshapes MethodInfo[] methods = typeComponent.GetMethods(flags); _propertyChoice = new string[methods.Length]; i = 0; foreach (MethodInfo methodInfo in methods) { _propertyChoice[i] = (string)methodInfo.Name; i++; } myTarget._generalIndex = EditorGUILayout.Popup("Method to control", myTarget._generalIndex, _propertyChoice); if (methods.Length > myTarget._generalIndex) { myTarget.methodObject = methods [myTarget._generalIndex]; addressName = "/" + myTarget.transform.name; myTarget._extra = EditorGUILayout.IntField("Blendshape Index", myTarget._extra); } } else if (myTarget._controlIndex == 2) { // --------------------------------------------------------- [ FIELDS ] // Check for variables only if there are no main properties FieldInfo[] fields = typeComponent.GetFields(flags); int sizeField = fields.Length; _propertyChoice = new string[sizeField]; i = 0; foreach (FieldInfo fieldInfo in fields) { _propertyChoice[i] = (string)fieldInfo.Name; i++; } myTarget._generalIndex = EditorGUILayout.Popup("Variable to control", myTarget._generalIndex, _propertyChoice); if (fields.Length > myTarget._generalIndex) { myTarget.fieldObject = fields[myTarget._generalIndex]; } addressName = "/" + myTarget.transform.name; } // check if there is new addresses if (addressName == myTarget.address || myTarget.address == null) { myTarget.address = EditorGUILayout.TextField("OSC Address", addressName); } else { // get the manually wroten address if (myTarget.address.Length > 0) { addressName = myTarget.address; } myTarget.address = EditorGUILayout.TextField("OSC Address", addressName); } // TODO: Please optimize this // create a dialog for a list of known addresses int addresses = EditorPrefs.GetInt("Addresses"); if (addresses > 0) { string[] addrOSC = new string[addresses + 1]; addrOSC[0] = myTarget.address.Replace("/", "\\"); for (int a = 0; a < addresses; a++) { /* Future implementation of TUIO * string tempAddress = EditorPrefs.GetString ("address" + a.ToString ()); * if (tempAddress == "/tuio/2Dcur") */ addrOSC[a + 1] = (EditorPrefs.GetString("address" + a.ToString())); } int indexAddress = myTarget._addressIndex; myTarget._addressIndex = EditorGUILayout.Popup("Last addresses", myTarget._addressIndex, addrOSC); if (indexAddress != myTarget._addressIndex) // change the address { myTarget.address = addrOSC[myTarget._addressIndex].Replace("\\", "/"); myTarget._addressIndex = 0; } } // Check for avaiable ports OSC[] instancesOSC; instancesOSC = FindObjectsOfType(typeof(OSC)) as OSC[]; _serverChoice = new string[instancesOSC.Length]; // Search for avaiable ports! if (instancesOSC.Length > 0 && instancesOSC.Length > myTarget._portIndex) { i = 0; foreach (OSC item in instancesOSC) { _serverChoice[i] = item.getPortIN().ToString(); i++; } myTarget._portIndex = EditorGUILayout.Popup("Input Port", myTarget._portIndex, _serverChoice); myTarget.RCPortInPort = instancesOSC [myTarget._portIndex]; } else { Debug.Log("No active ports! Please drag OSC script into scene and setup ports"); } //******************** // // // TODO: this procedure should be optimized in the future if (myTarget._controlIndex == 0) { #if UNITY_EDITOR myTarget.enableMapping = EditorGUILayout.Toggle("Enable Mapping", myTarget.enableMapping); if (myTarget.enableMapping) { bool initList = false; bool resetMapping = false; myTarget.learnOut = EditorGUILayout.Toggle("Learn", myTarget.learnOut); resetMapping = EditorGUILayout.Toggle("Reset", resetMapping); if (resetMapping) { resetMapping = false; myTarget.minRange.Clear(); myTarget.maxRange.Clear(); myTarget.minRange = resetList(myTarget.propertyObject, myTarget.objectComponent, 0); myTarget.maxRange = resetList(myTarget.propertyObject, myTarget.objectComponent, 1); myTarget.learnOut = false; } Type type; type = myTarget.propertyObject.GetValue(myTarget.objectComponent, null).GetType(); if (myTarget.minRange != null && myTarget.maxRange != null) { if (myTarget.minRange.Count > 0 && myTarget.maxRange.Count > 0) { for (int a = 0; a < 2; a++) { string label = ""; List <float> tempList = new List <float> (); if (a == 0) { tempList = myTarget.minRange; label = "Min"; } if (a == 1) { tempList = myTarget.maxRange; label = "Max"; } if (type == typeof(float) || type == typeof(int)) { float minValue = tempList [0]; minValue = EditorGUILayout.FloatField(label, minValue); tempList [0] = minValue; } else if (type == typeof(Vector2)) { Vector2 minVec = convertVector2(tempList); minVec = EditorGUILayout.Vector2Field(label, minVec); tempList = convertList(minVec); } else if (type == typeof(Vector3)) { Vector3 minVec = convertVector3(tempList); minVec = EditorGUILayout.Vector3Field(label, minVec); tempList = convertList(minVec); } else if (type == typeof(Vector4)) { Vector4 minVec = convertVector4(tempList); minVec = EditorGUILayout.Vector4Field(label, minVec); myTarget.minRange = convertList(minVec); } if (a == 0) { myTarget.minRange = tempList; } if (a == 1) { myTarget.maxRange = tempList; } } } else { initList = true; } } else { initList = true; } if (myTarget.learnOut) { if (myTarget.minRange != null && myTarget.maxRange != null) { if (myTarget.minRange.Count > 0 && myTarget.maxRange.Count > 0) { List <float> listObjectTemp; listObjectTemp = propConvertList(myTarget.propertyObject, myTarget.objectComponent); if (myTarget.minRange.Count == listObjectTemp.Count && myTarget.maxRange.Count == listObjectTemp.Count) { for (int x = 0; x < listObjectTemp.Count; x++) { if (listObjectTemp [x] < myTarget.minRange [x]) { myTarget.minRange [x] = listObjectTemp [x]; } if (listObjectTemp [x] > myTarget.maxRange [x]) { myTarget.maxRange [x] = listObjectTemp [x]; } } } } } else { initList = true; } } if (initList) { myTarget.minRange = resetList(myTarget.propertyObject, myTarget.objectComponent, 0); myTarget.maxRange = resetList(myTarget.propertyObject, myTarget.objectComponent, 1); } } #endif } else if (myTarget._controlIndex == 1) { #if UNITY_EDITOR if (myTarget.methodObject != null) { if (myTarget.methodObject.Name == "SetBlendShapeWeight") { myTarget.enableMapping = EditorGUILayout.Toggle("Enable Mapping", myTarget.enableMapping); } } if (myTarget.enableMapping) { bool initList = false; bool resetMapping = false; myTarget.learnOut = EditorGUILayout.Toggle("Learn", myTarget.learnOut); resetMapping = EditorGUILayout.Toggle("Reset", resetMapping); if (resetMapping) { resetMapping = false; myTarget.minRange.Clear(); myTarget.maxRange.Clear(); myTarget.learnOut = false; } if (myTarget.methodObject != null) { if (myTarget.methodObject.Name == "SetBlendShapeWeight") { GameObject objectTemp = myTarget.gameObject; SkinnedMeshRenderer meshTemp = objectTemp.GetComponent <SkinnedMeshRenderer>(); Mesh m = meshTemp.sharedMesh; if (myTarget.minRange != null && myTarget.maxRange != null) { // if there is not enought values in the list, lets create new if (myTarget.minRange != null && myTarget.maxRange != null) { if (myTarget.minRange.Count < m.blendShapeCount || myTarget.maxRange.Count < m.blendShapeCount) { initList = true; } else { float minValue = myTarget.minRange [myTarget._extra]; minValue = EditorGUILayout.FloatField("min", minValue); myTarget.minRange[myTarget._extra] = minValue; float maxValue = myTarget.maxRange [myTarget._extra]; maxValue = EditorGUILayout.FloatField("max", maxValue); myTarget.maxRange[myTarget._extra] = maxValue; if (myTarget.learnOut) { if (meshTemp.GetBlendShapeWeight(myTarget._extra) < myTarget.minRange[myTarget._extra]) { myTarget.minRange[myTarget._extra] = meshTemp.GetBlendShapeWeight(myTarget._extra); } if (meshTemp.GetBlendShapeWeight(myTarget._extra) > myTarget.maxRange[myTarget._extra]) { myTarget.maxRange[myTarget._extra] = meshTemp.GetBlendShapeWeight(myTarget._extra); } } } } else { initList = true; } } else { initList = true; } if (initList) { if (myTarget.minRange == null || myTarget.maxRange == null) { myTarget.minRange = new List <float>(); myTarget.maxRange = new List <float>(); } for (i = myTarget.minRange.Count; i < m.blendShapeCount; i++) { myTarget.minRange.Add(0); myTarget.maxRange.Add(1); } } } } } #endif } //********************************** }
private void Receiver_lost(object finder, RCReceiver receiver) { receivers.Remove(receiver); OnPropertyChanged("receivers"); }
private void Receiver_discovered(object finder, RCReceiver receiver) { receivers.Add(receiver); OnPropertyChanged("receivers"); }
public override void OnInspectorGUI() { RCReceiver myTarget = (RCReceiver)target; Component[] allComponents; string[] _choices; string[] _propertyChoice; string[] _serverChoice; string addressName; // OSC Address addressName = ""; // --------------------------------------------------------- [ COMPONENTS ] // get components from gameobject allComponents = myTarget.GetComponents <Component>(); _choices = new string[allComponents.Length]; int i = 0; foreach (Component component in allComponents) // create a list of components { _choices[i] = (string)component.GetType().Name; i++; } // Display popup int oldComponentIndex = myTarget._componentIndex; myTarget._componentIndex = EditorGUILayout.Popup("Component to control", myTarget._componentIndex, _choices); // reset components if (oldComponentIndex != myTarget._componentIndex) { myTarget.address = ""; myTarget._controlIndex = 0; myTarget._generalIndex = 0; } //Component childrenComponents; myTarget.objectComponent = myTarget.GetComponent(allComponents[myTarget._componentIndex].GetType()); Type typeComponent = myTarget.objectComponent.GetType(); const BindingFlags flags = /*BindingFlags.NonPublic | */ BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; // let the user choose what to control int oldControlIndex = myTarget._controlIndex; String[] exposeOptions = { "Properties", "Methods", "Fields" }; myTarget._controlIndex = EditorGUILayout.Popup("Control", myTarget._controlIndex, exposeOptions); // reset control if (oldControlIndex != myTarget._controlIndex) { myTarget.address = ""; myTarget._generalIndex = 0; } if (myTarget._controlIndex == 0) // properties { // To retrieve the properties PropertyInfo[] properties = typeComponent.GetProperties(flags); if (properties.Length > 0) // check if we have properties { _propertyChoice = new string[properties.Length]; i = 0; foreach (PropertyInfo propertyInfo in properties) { // TODO: Select the CanWrite property to constraint the selection _propertyChoice[i] = (string)propertyInfo.Name; i++; } // Pop up for choosing the control properties int old_index = myTarget._generalIndex; myTarget._generalIndex = EditorGUILayout.Popup("Property to control", myTarget._generalIndex, _propertyChoice); myTarget.propertyObject = properties[myTarget._generalIndex]; if (old_index != myTarget._generalIndex) { myTarget.address = ""; } myTarget.relativeAt = EditorGUILayout.Toggle("Relative to source", myTarget.relativeAt); // UPDATE the address field addressName = "/" + myTarget.transform.name + "_" + myTarget.propertyObject.Name; } } else if (myTarget._controlIndex == 1) // METHODS { // --------------------------------------------------------- [ METHODS ] // To retrieve the blendshapes MethodInfo[] methods = typeComponent.GetMethods(flags); _propertyChoice = new string[methods.Length]; i = 0; foreach (MethodInfo methodInfo in methods) { _propertyChoice[i] = (string)methodInfo.Name; i++; } myTarget._generalIndex = EditorGUILayout.Popup("Method to control", myTarget._generalIndex, _propertyChoice); myTarget.methodObject = methods[myTarget._generalIndex]; addressName = "/" + myTarget.transform.name; myTarget._extra = EditorGUILayout.IntField("Extra Int", myTarget._extra); } else if (myTarget._controlIndex == 2) { // --------------------------------------------------------- [ FIELDS ] // Check for variables only if there are no main properties FieldInfo[] fields = typeComponent.GetFields(flags); _propertyChoice = new string[fields.Length]; i = 0; foreach (FieldInfo fieldInfo in fields) { _propertyChoice[i] = (string)fieldInfo.Name; i++; } myTarget._generalIndex = EditorGUILayout.Popup("Variable to control", myTarget._generalIndex, _propertyChoice); addressName = "/" + myTarget.transform.name; } // check if there is new addresses if (addressName == myTarget.address || myTarget.address == null) { myTarget.address = EditorGUILayout.TextField("OSC Address", addressName); } else { // get the manually wroten address if (myTarget.address.Length > 0) { addressName = myTarget.address; } myTarget.address = EditorGUILayout.TextField("OSC Address", addressName); } // Pop up for choosing the input port // TODO: Should check if the port is active or not (the script), maybe in the future an editor way to create the ports RCPortIn[] instancesRCPortIn; instancesRCPortIn = FindObjectsOfType(typeof(RCPortIn)) as RCPortIn[]; _serverChoice = new string[instancesRCPortIn.Length]; if (instancesRCPortIn.Length > 0) { i = 0; foreach (RCPortIn item in instancesRCPortIn) { _serverChoice[i] = item.port.ToString(); i++; } } myTarget._portIndex = EditorGUILayout.Popup("Input Port", myTarget._portIndex, _serverChoice); myTarget.RCPortInPort = instancesRCPortIn [myTarget._portIndex]; }