static void SelectionGroupToolAttributeCache_OnLoad() { m_toolAttributeMap.Clear(); foreach (MethodInfo methodInfo in m_toolMethods) { SelectionGroupToolAttribute attr = methodInfo.GetCustomAttribute<SelectionGroupToolAttribute>(); m_toolMethodInfoMap[attr.toolId] = methodInfo; m_toolAttributeMap[attr.toolId] = attr; } }
void DrawTools(float rightAlignedX, float y, ISelectionGroup group) { Assert.Greater(group.EnabledTools.Count, 0); const int TOOL_X_DIFF = 18; const int TOOL_HEIGHT = 18; int numEnabledTools = group.EnabledTools.Count; Rect rect = new Rect(0, y, TOOL_X_DIFF, TOOL_HEIGHT); int i = 0; foreach (string toolId in group.EnabledTools) { SelectionGroupToolAttribute attr = null; MethodInfo methodInfo = null; bool found = SelectionGroupToolAttributeCache.TryGetAttribute(toolId, out attr); Assert.IsTrue(found); found = SelectionGroupToolAttributeCache.TryGetMethodInfo(toolId, out methodInfo); Assert.IsTrue(found); GUIContent content = EditorGUIUtility.IconContent(attr.icon); content.tooltip = attr.description; rect.x = rightAlignedX - ((numEnabledTools - i) * TOOL_X_DIFF); if (GUI.Button(rect, content, miniButtonStyle)) { try { methodInfo.Invoke(null, new object[] { group }); } catch (System.Exception e) { Debug.LogException(e); } } ++i; } }
//---------------------------------------------------------------------------------------------------------------------- internal static bool TryGetAttribute(string id, out SelectionGroupToolAttribute attribute) { return m_toolAttributeMap.TryGetValue(id, out attribute); }