private void MainSectionInvokesContainerMethodContainer(WeaponProjectile.Invoke currentInvoke, SerializedProperty currentInvokeProperty) { List <string> names = new List <string>(); string methodName = string.Empty; bool methodExists = false; Color color = GUI.color; names.Add("Not Specified"); if (currentInvoke.source) { System.Reflection.MethodInfo[] methodInfos = currentInvoke.source.GetClass().GetMethods(); for (int a = 0; a < methodInfos.Length; a++) { if (methodInfos[a].Name != "CancelInvoke" && methodInfos[a].Name != "IsInvoking" && methodInfos[a].Name != "GetComponent" && methodInfos[a].Name != "GetComponentInChildren" && methodInfos[a].Name != "GetComponentsInChildren" && methodInfos[a].Name != "GetComponentInParent" && methodInfos[a].Name != "GetComponentsInParent" && methodInfos[a].Name != "GetComponents") { System.Reflection.ParameterInfo[] parameterInfos = methodInfos[a].GetParameters(); if (currentInvoke.methodName == methodInfos[a].Name) { if (currentInvoke.methodIndex == 0) { methodName = methodInfos[a].Name; } methodExists = true; } if (parameterInfos.Length == 0) { names.Add(methodInfos[a].Name + " ()"); } if (parameterInfos.Length == 1) { if (parameterInfos[0].ParameterType == typeof(float)) { names.Add(methodInfos[a].Name + " (float)"); continue; } if (parameterInfos[0].ParameterType == typeof(int)) { names.Add(methodInfos[a].Name + " (int)"); continue; } if (parameterInfos[0].ParameterType == typeof(bool)) { names.Add(methodInfos[a].Name + " (bool)"); continue; } if (parameterInfos[0].ParameterType == typeof(Vector3)) { names.Add(methodInfos[a].Name + " (vector3)"); continue; } } if (parameterInfos.Length == 2 && parameterInfos[0].ParameterType == typeof(Vector3) && parameterInfos[1].ParameterType == typeof(Quaternion)) { names.Add(methodInfos[a].Name + " (vector3,quaternion)"); continue; } } } } GUI.enabled = currentInvoke.source; EditorGUILayout.BeginVertical("Box"); { EditorGUILayout.BeginHorizontal(); { if (currentInvoke.methodIndex > 0 && !methodExists) { currentInvoke.methodIndex = 0; } GUI.color = currentInvoke.source ? (currentInvoke.methodIndex > 0 && methodExists ? Color.green : Color.red) : Color.yellow; GUILayout.Box(GUIContent.none, GUILayout.Width(12), GUILayout.Height(12)); GUI.color = color; GUILayout.Label("Method Name"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); if (currentInvoke.source && methodName != string.Empty) { for (int a = 1; a < names.Count; a++) { if (methodName == names[a].Replace(" ()", string.Empty).Replace(" (float)", string.Empty).Replace(" (int)", string.Empty).Replace(" (bool)", string.Empty).Replace(" (vector3)", string.Empty).Replace(" (vector3,quaternion)", string.Empty)) { currentInvoke.methodIndex = a; } } } EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(currentInvokeProperty.FindPropertyRelative("methodName"), GUIContent.none, true); EditorGUI.BeginChangeCheck(); int index = EditorGUILayout.Popup(currentInvoke.methodIndex, names.ToArray()); if (index >= 0 && EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Inspector"); currentInvoke.methodName = index < names.Count ? names[index].Replace("Not Specified", string.Empty).Replace(" ()", string.Empty).Replace(" (float)", string.Empty).Replace(" (int)", string.Empty).Replace(" (bool)", string.Empty).Replace(" (vector3)", string.Empty).Replace(" (vector3,quaternion)", string.Empty) : string.Empty; currentInvoke.methodIndex = index; } } EditorGUILayout.EndHorizontal(); if (currentInvoke.source) { System.Reflection.MethodInfo methodInfo = currentInvoke.source.GetClass().GetMethod(currentInvoke.methodName); if (methodInfo != null) { System.Reflection.ParameterInfo[] parameterInfos = methodInfo.GetParameters(); if (parameterInfos.Length == 1) { if (parameterInfos[0].ParameterType == typeof(float)) { EditorGUILayout.PropertyField(currentInvokeProperty.FindPropertyRelative("floatValue"), true); } if (parameterInfos[0].ParameterType == typeof(int)) { EditorGUILayout.PropertyField(currentInvokeProperty.FindPropertyRelative("intValue"), true); } if (parameterInfos[0].ParameterType == typeof(bool)) { EditorGUILayout.PropertyField(currentInvokeProperty.FindPropertyRelative("boolValue"), true); } } } } } EditorGUILayout.EndVertical(); GUI.enabled = true; }
private void MainSectionInvokesContainer() { EditorGUILayout.BeginVertical("Box"); { EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Invokes", "Box", GUILayout.ExpandWidth(true))) { weaponProjectiles[0].invokesIsExpanded = !weaponProjectiles[0].invokesIsExpanded; GUI.FocusControl(null); } GUI.enabled = weaponProjectiles[0].invokes.Count != 0; if (GUILayout.Button("X", GUILayout.Width(20), GUILayout.Height(20))) { Undo.RecordObject(target, "Inspector"); weaponProjectiles[0].invokes.Clear(); GUI.FocusControl(null); } GUI.enabled = true; } EditorGUILayout.EndHorizontal(); if (weaponProjectiles[0].invokesIsExpanded) { for (int a = 0; a < weaponProjectiles[0].invokes.Count; a++) { WeaponProjectile.Invoke currentInvoke = weaponProjectiles[0].invokes[a]; EditorGUILayout.BeginVertical("Box"); { EditorGUILayout.BeginHorizontal(); { GUILayout.Box(a.ToString("000")); if (GUILayout.Button(currentInvoke.name, "Box", GUILayout.ExpandWidth(true))) { currentInvoke.isExpanded = !currentInvoke.isExpanded; GUI.FocusControl(null); } GUI.enabled = a != 0; if (GUILayout.Button("▲", GUILayout.Width(20), GUILayout.Height(20))) { Undo.RecordObject(target, "Inspector"); WeaponProjectile.Invoke previous = weaponProjectiles[0].invokes[a - 1]; weaponProjectiles[0].invokes[a - 1] = currentInvoke; weaponProjectiles[0].invokes[a] = previous; GUI.FocusControl(null); break; } GUI.enabled = a != weaponProjectiles[0].invokes.Count - 1; if (GUILayout.Button("▼", GUILayout.Width(20), GUILayout.Height(20))) { Undo.RecordObject(target, "Inspector"); WeaponProjectile.Invoke next = weaponProjectiles[0].invokes[a + 1]; weaponProjectiles[0].invokes[a + 1] = currentInvoke; weaponProjectiles[0].invokes[a] = next; GUI.FocusControl(null); break; } GUI.enabled = true; if (GUILayout.Button("-", GUILayout.Width(20), GUILayout.Height(20))) { Undo.RecordObject(target, "Inspector"); weaponProjectiles[0].invokes.RemoveAt(a); GUI.FocusControl(null); break; } } EditorGUILayout.EndHorizontal(); if (weaponProjectiles[0].invokes[a].isExpanded) { SerializedProperty currentInvokeProperty = serializedObject.FindProperty("invokes").GetArrayElementAtIndex(a); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(20); EditorGUILayout.BeginVertical("Box"); { EditorGUIUtility.labelWidth = 100; EditorGUILayout.PropertyField(currentInvokeProperty.FindPropertyRelative("name"), true); EditorGUILayout.PropertyField(currentInvokeProperty.FindPropertyRelative("source"), true); MainSectionInvokesContainerMethodContainer(currentInvoke, currentInvokeProperty); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); } EditorGUILayout.BeginHorizontal("Box"); { EditorGUIUtility.labelWidth = 40; EditorGUILayout.PropertyField(serializedObject.FindProperty("invokesName"), new GUIContent("Name"), true); EditorGUIUtility.labelWidth = 0; if (GUILayout.Button("+", GUILayout.Width(20), GUILayout.Height(20))) { Undo.RecordObject(target, "Inspector"); weaponProjectiles[0].invokes.Add(new WeaponProjectile.Invoke()); weaponProjectiles[0].invokes[weaponProjectiles[0].invokes.Count - 1].name = weaponProjectiles[0].invokesName; GUI.FocusControl(null); } } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); }