Пример #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.");
            }

            if (EditorToolUtility.IsComponentEditor(type))
            {
                var tool = EditorToolManager.GetComponentTool(type);

                if (tool == null)
                {
                    throw new InvalidOperationException("The current selection does not contain any objects editable " +
                                                        $"by the component tool of type: {type}");
                }
                SetActiveTool(tool);
                return;
            }

            SetActiveTool((EditorTool)EditorToolManager.GetSingleton(type));
        }
Пример #2
0
        public static void SetActiveContext(Type context)
        {
            if (context != null && (!typeof(EditorToolContext).IsAssignableFrom(context) || context.IsAbstract))
            {
                throw new ArgumentException("Type must be assignable to EditorToolContext, and not abstract.", "context");
            }

            var ctx = context != null ? context : typeof(GameObjectToolContext);

            if (EditorToolUtility.IsComponentEditor(ctx))
            {
                var instance = EditorToolManager.GetComponentContext(ctx);
                if (instance == null)
                {
                    throw new InvalidOperationException("The current selection does not contain any objects editable " +
                                                        $"by the component tool of type: {context}");
                }
                EditorToolManager.activeToolContext = instance;
            }
            else
            {
                EditorToolManager.activeToolContext = EditorToolManager.GetSingleton(ctx) as EditorToolContext;
            }
        }