/// <summary> /// Draws the tool buttons pannel /// </summary> /// <param name="tool"></param> private void DrawToolButton(ShapeEditorTool tool) { Color lastColor = GUI.backgroundColor; Color buttonColor = (tool == _currentTool ? new Color(0.4f, 1.0f, 1.0f) : Color.white); GUI.backgroundColor = buttonColor; if (GUILayout.Button(tool.content, GUILayout.Width(TOOL_BUTTON_SIZE), GUILayout.Height(TOOL_BUTTON_SIZE))) { SetTool(tool); } GUI.backgroundColor = lastColor; }
/// <summary> /// Find every shape tools /// </summary> private void FindShapeEditorTools() { SortedList <int, ShapeEditorTool> tools = new SortedList <int, ShapeEditorTool>(); foreach (Type type in Assembly.GetAssembly(typeof(ShapeEditorTool)).GetTypes().Where(mType => mType.IsClass && !mType.IsAbstract && mType.IsSubclassOf(typeof(ShapeEditorTool)))) { GUIContent content = new GUIContent(); ShapeEditorTool tool = (ShapeEditorTool)Activator.CreateInstance(type, this); int order = 10000; //Get tool identity var toolIdentity = (ShapeToolAttribute)Attribute.GetCustomAttribute(tool.GetType(), typeof(ShapeToolAttribute)); if (toolIdentity != null) { content.text = toolIdentity.Name; content.tooltip = toolIdentity.Tooltip; Texture tex = (Texture)AssetDatabase.LoadAssetAtPath(toolIdentity.IconPath, typeof(Texture)); if (tex != null) { content.image = tex; } order = toolIdentity.Order; } else { content.text = tool.GetType().Name; } tool.SetEditor(this); //Set the owner editor tool.content = content; tools.Add(order, tool); } _shapeTools = new ShapeEditorTool[tools.Count]; for (int i = 0; i < tools.Count; i++) { _shapeTools[i] = tools.ElementAt(i).Value; } if (_shapeTools.Length > 0) { _currentTool = _shapeTools[0]; } }
/// <summary> /// Set the current tool, disable if equal to the parameter /// </summary> /// <param name="tool"></param> private void SetTool(ShapeEditorTool tool) { if (tool != _currentTool) { _currentTool = tool; } else { _currentTool = null; } enabledSelection = true; //By default enable the selection on change tool if (_currentTool != null) { _currentTool.Init(); //Initialize the tool } else { if (_shapeTools.Length > 0) { _currentTool = _shapeTools[0]; } } }