bool CreateOrRestoreTool(CustomEditorTool customEditorTool, out EditorTool customEditorToolInstance)
        {
            var  toolType  = customEditorTool.editorToolType;
            var  toolOwner = customEditorTool.owner;
            var  targets   = customEditorTool.targets;
            var  target    = customEditorTool.owner.target;
            var  activeIsCustomEditorTool = IsCustomEditorTool(m_ActiveTool);
            bool preservedActiveTool      = false;

            // The only case where a custom editor tool is serialized is when it is the active tool. All other
            // instances are discarded and rebuilt on any tracker rebuild.
            if (activeIsCustomEditorTool && CustomEditorToolIsMatch(toolOwner, toolType, m_ActiveTool))
            {
                preservedActiveTool = true;

                m_ActiveTool.m_Targets = targets;
                m_ActiveTool.m_Target  = target;

                // domain reload - the owning editor was destroyed and therefore we need to reset the EditMode active
                if (m_ActiveTool is EditModeTool && toolOwner.GetInstanceID() != UnityEditorInternal.EditMode.ownerID)
                {
                    UnityEditorInternal.EditMode.EditModeToolStateChanged(toolOwner, ((EditModeTool)m_ActiveTool).editMode);
                }

                customEditorToolInstance = m_ActiveTool;
            }
            else
            {
                customEditorToolInstance = (EditorTool)CreateInstance(toolType, x =>
                {
                    ((EditorTool)x).m_Targets = targets;
                    ((EditorTool)x).m_Target  = target;
                });

                customEditorToolInstance.hideFlags = HideFlags.DontSave;
            }

            var editModeTool = customEditorToolInstance as EditModeTool;

            if (editModeTool != null)
            {
                editModeTool.owner = toolOwner;
            }

            return(preservedActiveTool);
        }
        void RestoreCustomEditorTool()
        {
            var restored = m_ComponentTools.FirstOrDefault(m_PreviousComponentToolCache.IsEqual);

            if (restored != null)
            {
                // todo Use generated Context
                if (m_PreviousComponentToolCache.contextType != null)
                {
                    activeToolContext = GetComponentContext(m_PreviousComponentToolCache.contextType);
                }

                activeTool = restored.GetEditor <EditorTool>();
            }

            m_PreviousComponentToolCache = ComponentToolCache.Empty;
        }
Exemple #3
0
        static bool CustomEditorToolIsMatch(Editor editor, Type toolType, EditorTool tool)
        {
            if (editor == null || toolType != tool.GetType())
            {
                return(false);
            }

            // if it's an EditModeTool we need to be stricter about ownership for backwards compatibility.
            var editModeTool = tool as EditModeTool;

            if (editModeTool != null)
            {
                return(editModeTool.owner == (IToolModeOwner)editor || editModeTool.target == editor.target);
            }

            // otherwise just check if it's a valid type
            return(true);
        }
Exemple #4
0
            public bool IsEqual(EditorTool other)
            {
                if (editorToolType != (other == null ? null : other.GetType()))
                {
                    return(false);
                }

                if (ReferenceEquals(targetObjects, other.m_Targets))
                {
                    return(true);
                }

                if (targetObjects == null || other.m_Targets == null)
                {
                    return(false);
                }

                return(targetObjects.SequenceEqual(other.m_Targets));
            }
Exemple #5
0
            public CustomEditorToolContext(EditorTool tool)
            {
                if (tool != null)
                {
                    editorToolType    = tool.GetType();
                    targetObject      = tool.target;
                    targetObjects     = tool.targets.ToArray();
                    m_EditorToolState = EditorJsonUtility.ToJson(tool);
                }
                else
                {
                    editorToolType    = null;
                    targetObject      = null;
                    targetObjects     = null;
                    m_EditorToolState = null;
                }

                m_EditorToolType = null;
            }
            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;
            }
Exemple #7
0
 static bool IsCustomEditorTool(EditorTool tool)
 {
     return(EditorToolUtility.IsCustomEditorTool(tool != null ? tool.GetType() : null));
 }
Exemple #8
0
 internal static string GetToolMenuPath(EditorTool tool)
 {
     return(GetToolMenuPath(tool != null ? tool.GetType() : typeof(EditorTool)));
 }
 public static bool IsActiveTool(EditorTool tool)
 {
     return(EditorToolManager.activeTool == tool);
 }
 public static void SetActiveTool(EditorTool tool)
 {
     EditorToolManager.activeTool = tool;
 }
Exemple #11
0
 public static bool IsActiveTool(EditorTool tool)
 {
     return(EditorToolContext.activeTool == tool);
 }
Exemple #12
0
 public static void SetActiveTool(EditorTool tool)
 {
     EditorToolContext.activeTool = tool;
 }
 public static bool IsActiveTool(EditorTool tool)
 {
     return(ToolManager.IsActiveTool(tool));
 }
 public static void SetActiveTool(EditorTool tool)
 {
     ToolManager.SetActiveTool(tool);
 }