static void OnDidReloadScripts() { KiltUtils.GetAssemblyTypesDict(true); //Force Refresh Dict }
public static SerializableType SerializableTypePopupInternal(Rect p_rect, string p_label, SerializableType p_value, System.Type p_filterType, bool p_guiLayout, bool p_acceptGenericDefinition, bool p_acceptAbstractDefinition = false, bool p_acceptNull = true) { Color v_oldColor = GUI.backgroundColor; SerializableType v_return = new SerializableType(); try { Vector2 v_offset = new Vector2(10, 16); Rect v_labelRect = new Rect(p_rect.x, p_rect.y, p_rect.width / 3.0f, v_offset.y); Rect v_assemblyRect = new Rect(v_labelRect.x + v_labelRect.width, p_rect.y, 30, v_offset.y); Rect v_typeRect = new Rect(v_assemblyRect.x + v_assemblyRect.width, p_rect.y, Mathf.Max(0, p_rect.width - (v_labelRect.width + v_assemblyRect.width)), v_offset.y); AOTDictionaryKV <Assembly, System.Type[]> v_assemblyTypesDict = KiltUtils.GetAssemblyTypesDict(false); List <Assembly> v_assemblies = new List <Assembly>(); Assembly v_currentAssembly = p_value == null || p_value.CastedType == null? null : p_value.CastedType.Assembly; //Filter Assemblies foreach (AOTKeyValuePair <Assembly, System.Type[]> v_pair in v_assemblyTypesDict) { if (v_pair != null && v_pair.Key != null) { if (AssemblyContainsFilteredType(v_pair.Key, p_filterType, p_acceptGenericDefinition, p_acceptAbstractDefinition)) { v_assemblies.Add(v_pair.Key); } try { if (v_currentAssembly == null && p_value.StringType.Contains(v_pair.Key.FullName)) { v_currentAssembly = v_pair.Key; } } catch {} } } if (p_acceptNull) { v_assemblies.Insert(0, null); } if (p_guiLayout) { EditorGUILayout.BeginHorizontal(); } //Draw Label if (p_value.CastedType != null && p_value.CastedType.GetGenericArguments().Length > 0) { if (p_guiLayout) { p_value.FoldOut = EditorGUILayout.Foldout(p_value.FoldOut, p_label); } else { p_value.FoldOut = EditorGUI.Foldout(v_labelRect, p_value.FoldOut, p_label); } } else { if (p_guiLayout) { GUILayout.Label(p_label); } else { GUI.Label(v_labelRect, p_label); } } //Draw Popup Select Assembly int v_selectedIndex = v_assemblies.IndexOf(v_currentAssembly); GUI.backgroundColor = v_selectedIndex > 0 || (!p_acceptNull && v_selectedIndex >= 0)? new Color(0.2f, 1, 0.5f) : new Color(1, 0.2f, 0.5f); if (p_guiLayout) { v_selectedIndex = EditorGUILayout.Popup(v_selectedIndex, v_assemblies.GetStringList().ToArray(), GUILayout.Width(30)); } else { v_selectedIndex = EditorGUI.Popup(v_assemblyRect, v_selectedIndex, v_assemblies.GetStringList().ToArray()); } Assembly v_newAssembly = v_assemblies.Count > v_selectedIndex && v_selectedIndex >= 0? v_assemblies[v_selectedIndex] : null; bool v_assemblyChanged = false; if (v_newAssembly != v_currentAssembly) { v_currentAssembly = v_newAssembly; v_assemblyChanged = true; } GUI.backgroundColor = v_oldColor; //Filter Types in Assembly List <System.Type> v_assemblyTypes = new List <System.Type>(); if (v_currentAssembly != null) { foreach (System.Type v_type in v_assemblyTypesDict.GetValueByKey(v_currentAssembly)) { if (v_type != null && (!v_type.IsGenericTypeDefinition || p_acceptGenericDefinition) && (!v_type.IsAbstract || p_acceptAbstractDefinition) && (p_filterType == null || KiltUtils.IsSameOrSubClassOrImplementInterface(v_type, p_filterType))) { v_assemblyTypes.Add(v_type); } } } if (p_acceptNull) { v_assemblyTypes.Insert(0, null); } //Set Selected Index SetTypeSelectedIndex(ref v_assemblyTypes, ref p_value, ref v_selectedIndex, v_assemblyChanged, p_acceptNull); //Draw Popup Select Type GUI.backgroundColor = v_selectedIndex > 0 || (!p_acceptNull && v_selectedIndex >= 0)? new Color(0.2f, 0.8f, 0) : new Color(0.8f, 0.2f, 0); if (p_guiLayout) { v_selectedIndex = EditorGUILayout.Popup(v_selectedIndex, v_assemblyTypes.GetStringList().ToArray()); } else { v_selectedIndex = EditorGUI.Popup(v_typeRect, v_selectedIndex, v_assemblyTypes.GetStringList().ToArray()); } v_selectedIndex = EditorGUI.Popup(v_typeRect, v_selectedIndex, v_assemblyTypes.GetStringList().ToArray()); System.Type v_currentType = v_assemblyTypes.Count > v_selectedIndex && v_selectedIndex >= 0? v_assemblyTypes[v_selectedIndex] : null; GUI.backgroundColor = v_oldColor; //Apply Values v_return.CastedType = p_value != null && TypeImplementGenericTypeDefinition(p_value.CastedType, v_currentType)? p_value.CastedType : v_currentType; v_return.StringType = p_value != null && TypeImplementGenericTypeDefinition(p_value.CastedType, v_currentType)? p_value.StringType : v_return.StringType; if (v_return.CastedType == null) { v_return.StringType = v_currentAssembly != null? ", " + (v_currentAssembly.FullName) : null; } if (p_guiLayout) { EditorGUILayout.EndHorizontal(); } //Generic Drawer Type Definition DrawGenericParametersSelector(ref v_currentAssembly, ref p_value, ref v_return, ref v_currentType, ref p_rect, v_offset, p_guiLayout, p_acceptAbstractDefinition); v_return.FoldOut = p_value.CastedType.GetGenericArguments().Length > 0? p_value.FoldOut : true; } catch {} return(v_return); }