Ejemplo n.º 1
0
        public static void SetActiveTool(Type type)
        {
            if (!typeof(EditorTool).IsAssignableFrom(type) || type.IsAbstract)
            {
                throw new ArgumentException("Type must be assignable to EditorTool, and not abstract.");
            }

            var attrib = EditorToolUtility.GetEditorToolAttribute(type);

            if (attrib?.targetType != null)
            {
                var tool = EditorToolContext.GetCustomEditorToolOfType(type);

                if (tool == null)
                {
                    throw new InvalidOperationException("The current selection does not contain any objects editable by the CustomEditor tool \"" + type + ".\"");
                }

                SetActiveTool(tool);

                return;
            }

            SetActiveTool(EditorToolContext.GetSingleton(type));
        }
Ejemplo n.º 2
0
        internal static EditorTool GetEditorToolWithEnum(Tool type)
        {
            if (type == Tool.View)
            {
                return(EditorToolContext.GetSingleton <ViewModeTool>());
            }
            if (type == Tool.Transform)
            {
                return(EditorToolContext.GetSingleton <TransformTool>());
            }
            if (type == Tool.Move)
            {
                return(EditorToolContext.GetSingleton <MoveTool>());
            }
            if (type == Tool.Rotate)
            {
                return(EditorToolContext.GetSingleton <RotateTool>());
            }
            if (type == Tool.Scale)
            {
                return(EditorToolContext.GetSingleton <ScaleTool>());
            }
            if (type == Tool.Rect)
            {
                return(EditorToolContext.GetSingleton <RectTool>());
            }
            if (type == Tool.Custom)
            {
                var tool = EditorToolContext.GetLastTool(x => GetEnumWithEditorTool(x) == Tool.Custom);
                if (tool != null)
                {
                    return(tool);
                }
            }

            return(EditorToolContext.GetSingleton <NoneTool>());
        }