Beispiel #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));
        }
Beispiel #2
0
        public static void RestorePreviousPersistentTool()
        {
            var last = EditorToolContext.GetLastTool(x => x && !EditorToolUtility.IsCustomEditorTool(x.GetType()));

            if (last != null)
            {
                SetActiveTool(last);
            }
            else
            {
                SetActiveTool <MoveTool>();
            }
        }
            public ComponentToolCache(EditorToolContext context, EditorTool tool)
            {
                bool customTool    = IsCustomEditorTool(tool);
                bool customContext = IsCustomToolContext(context);

                if (customTool || customContext)
                {
                    toolType      = customTool ? tool.GetType() : null;
                    contextType   = customContext ? context.GetType() : null;
                    targetObject  = tool.target;
                    targetObjects = tool.targets.ToArray();
                }
                else
                {
                    toolType      = null;
                    contextType   = null;
                    targetObject  = null;
                    targetObjects = null;
                }

                m_ToolType    = null;
                m_ContextType = null;
            }
Beispiel #4
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>());
        }
 static bool IsCustomToolContext(EditorToolContext context)
 {
     return(context != null && context.GetType() != typeof(GameObjectToolContext));
 }
Beispiel #6
0
 public static bool IsActiveContext(EditorToolContext context)
 {
     return(EditorToolManager.activeToolContext == context);
 }
Beispiel #7
0
 public static void RestorePreviousTool()
 {
     EditorToolContext.RestorePreviousTool();
 }