LostDog。 2019-10-20 12:55 采纳率: 50%
浏览 499

求助大神,U3D开发问题

开发时遇到一个问题,请问:

1.EditorApplication.projectWindowItemOnGUI是什么时候被调用的?

2.传入的两个参数(string guid, Rect selectionRect)分别又是什么?

3.为何不能将EditorApplication.projectWindowItemOnGUI换成ProjectWindowItemCallback的一个对象?

下面代码第一个是自己写的方法,第二个是U3D的EditorApplication类

public class Script2
{
    //首先调用此方法
    [InitializeOnLoadMethod]
    static void InitializeOnLoadMethod()
    {

       // ProjectWindowItemCallback a = new ProjectWindowItemCallback(string guid, Rect selectionRect);
        EditorApplication.projectWindowItemOnGUI = delegate (string guid, Rect selectionRect)
        {

            if (Selection.activeObject && guid == AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Selection.activeObject))) {
                float width = 50f;
                selectionRect.x += (selectionRect.width - width);
                selectionRect.y += 2f;
                selectionRect.width = width;
                GUI.color = Color.red;
                //点击事件
                if(GUI.Button(selectionRect, "click")){
                    Debug.LogFormat("click : {0}", Selection.activeObject.name);
                }
                GUI.color = Color.white;
            }

        };

    }

}
public sealed class EditorApplication
    {
        //
        // 摘要:
        //     Delegate for OnGUI events for every visible list item in the ProjectWindow.
        public static ProjectWindowItemCallback projectWindowItemOnGUI;
        //
        // 摘要:
        //     Delegate for OnGUI events for every visible list item in the HierarchyWindow.
        public static HierarchyWindowItemCallback hierarchyWindowItemOnGUI;
        //
        // 摘要:
        //     Delegate for generic updates.
        public static CallbackFunction update;
        //
        // 摘要:
        //     Delegate which is called once after all inspectors update.
        public static CallbackFunction delayCall;
        //
        // 摘要:
        //     A callback to be raised when an object in the hierarchy changes. Each time an
        //     object is (or a group of objects are) created, renamed, parented, unparented
        //     or destroyed this callback is raised.
        [Obsolete("Use EditorApplication.hierarchyChanged")]
        public static CallbackFunction hierarchyWindowChanged;
        //
        // 摘要:
        //     Callback raised whenever the state of the Project window changes.
        [Obsolete("Use EditorApplication.projectChanged")]
        public static CallbackFunction projectWindowChanged;
        //
        // 摘要:
        //     Callback raised whenever the contents of a window's search box are changed.
        public static CallbackFunction searchChanged;
        //
        // 摘要:
        //     Delegate for changed keyboard modifier keys.
        public static CallbackFunction modifierKeysChanged;
        [Obsolete("Use EditorApplication.playModeStateChanged and/or EditorApplication.pauseStateChanged")]
        public static CallbackFunction playmodeStateChanged;
        //
        // 摘要:
        //     Callback raised whenever the user contex-clicks on a property in an Inspector.
        public static SerializedPropertyCallbackFunction contextualPropertyMenu;

        public EditorApplication();

        //
        // 摘要:
        //     Is editor currently in play mode?
        public static bool isPlaying { get; set; }
        //
        // 摘要:
        //     Is editor currently compiling scripts? (Read Only)
        public static bool isCompiling { get; }
        //
        // 摘要:
        //     True if the Editor is currently refreshing the AssetDatabase.
        public static bool isUpdating { get; }
        //
        // 摘要:
        //     Is editor currently connected to Unity Remote 4 client app.
        public static bool isRemoteConnected { get; }
        //
        // 摘要:
        //     Returns the scripting runtime version currently used by the Editor.
        [StaticAccessor("ScriptingManager", StaticAccessorType.DoubleColon)]
        public static ScriptingRuntimeVersion scriptingRuntimeVersion { get; }
        //
        // 摘要:
        //     Path to the Unity editor contents folder. (Read Only)
        public static string applicationContentsPath { get; }
        //
        // 摘要:
        //     Returns the path to the Unity editor application. (Read Only)
        public static string applicationPath { get; }
        //
        // 摘要:
        //     Returns true if the current project was created as a temporary project.
        public static bool isTemporaryProject { get; }
        //
        // 摘要:
        //     The time since the editor was started. (Read Only)
        public static double timeSinceStartup { get; }
        //
        // 摘要:
        //     Is true if the currently open Scene in the editor contains unsaved modifications.
        [Obsolete("Use Scene.isDirty instead. Use EditorSceneManager.GetScene API to get each open scene")]
        public static bool isSceneDirty { get; }
        //
        // 摘要:
        //     The path of the Scene that the user has currently open (Will be an empty string
        //     if no Scene is currently open). (Read Only)
        [Obsolete("Use EditorSceneManager to see which scenes are currently loaded")]
        public static string currentScene { get; set; }
        //
        // 摘要:
        //     Is editor currently paused?
        [StaticAccessor("GetApplication().GetPlayerLoopController()", StaticAccessorType.Dot)]
        public static bool isPaused { get; set; }
        //
        // 摘要:
        //     Is editor either currently in play mode, or about to switch to it? (Read Only)
        [StaticAccessor("GetApplication()", StaticAccessorType.Dot)]
        public static bool isPlayingOrWillChangePlaymode { get; }

        public static event Action quitting;
        public static event Action<PlayModeStateChange> playModeStateChanged;
        public static event Action<PauseState> pauseStateChanged;
        public static event Action projectChanged;
        public static event Action hierarchyChanged;
        public static event Func<bool> wantsToQuit;

        //
        // 摘要:
        //     Plays system beep sound.
        [FreeFunction("UnityBeep")]
        public static void Beep();
        //
        // 摘要:
        //     Set the hierarchy sorting method as dirty.
        public static void DirtyHierarchyWindowSorting();
        //
        // 摘要:
        //     Switches the editor to Play mode.
        public static void EnterPlaymode();
        //
        // 摘要:
        //     Invokes the menu item in the specified path.
        //
        // 参数:
        //   menuItemPath:
        public static bool ExecuteMenuItem(string menuItemPath);
        //
        // 摘要:
        //     Exit the Unity editor application.
        //
        // 参数:
        //   returnValue:
        public static void Exit(int returnValue);
        //
        // 摘要:
        //     Switches the editor to Edit mode.
        public static void ExitPlaymode();
        //
        // 摘要:
        //     Load the given level additively in play mode asynchronously
        //
        // 参数:
        //   path:
        [Obsolete("Use EditorSceneManager.LoadSceneAsyncInPlayMode instead.")]
        public static AsyncOperation LoadLevelAdditiveAsyncInPlayMode(string path);
        //
        // 摘要:
        //     Load the given level additively in play mode.
        //
        // 参数:
        //   path:
        [Obsolete("Use EditorSceneManager.LoadSceneInPlayMode instead.")]
        public static void LoadLevelAdditiveInPlayMode(string path);
        //
        // 摘要:
        //     Load the given level in play mode asynchronously.
        //
        // 参数:
        //   path:
        [Obsolete("Use EditorSceneManager.LoadSceneAsyncInPlayMode instead.")]
        public static AsyncOperation LoadLevelAsyncInPlayMode(string path);
        //
        // 摘要:
        //     Load the given level in play mode.
        //
        // 参数:
        //   path:
        [Obsolete("Use EditorSceneManager.LoadSceneInPlayMode instead.")]
        public static void LoadLevelInPlayMode(string path);
        //
        // 摘要:
        //     Prevents loading of assemblies when it is inconvenient.
        [StaticAccessor("GetApplication()", StaticAccessorType.Dot)]
        public static void LockReloadAssemblies();
        //
        // 摘要:
        //     Explicitly mark the current opened Scene as modified.
        [Obsolete("Use EditorSceneManager.MarkSceneDirty or EditorSceneManager.MarkAllScenesDirty")]
        public static void MarkSceneDirty();
        //
        // 摘要:
        //     Create a new absolutely empty Scene.
        [Obsolete("Use EditorSceneManager.NewScene (NewSceneSetup.EmptyScene)")]
        public static void NewEmptyScene();
        //
        // 摘要:
        //     Create a new Scene.
        [Obsolete("Use EditorSceneManager.NewScene (NewSceneSetup.DefaultGameObjects)")]
        public static void NewScene();
        //
        // 摘要:
        //     Open another project.
        //
        // 参数:
        //   projectPath:
        //     The path of a project to open.
        //
        //   args:
        //     Arguments to pass to command line.
        public static void OpenProject(string projectPath, params string[] args);
        //
        // 摘要:
        //     Opens the Scene at path.
        //
        // 参数:
        //   path:
        [Obsolete("Use EditorSceneManager.OpenScene")]
        public static bool OpenScene(string path);
        //
        // 摘要:
        //     Opens the Scene at path additively.
        //
        // 参数:
        //   path:
        [Obsolete("Use EditorSceneManager.OpenScene")]
        public static void OpenSceneAdditive(string path);
        //
        // 摘要:
        //     Normally, a player loop update will occur in the editor when the Scene has been
        //     modified. This method allows you to queue a player loop update regardless of
        //     whether the Scene has been modified.
        public static void QueuePlayerLoopUpdate();
        public static void RepaintAnimationWindow();
        //
        // 摘要:
        //     Can be used to ensure repaint of the HierarchyWindow.
        public static void RepaintHierarchyWindow();
        //
        // 摘要:
        //     Can be used to ensure repaint of the ProjectWindow.
        public static void RepaintProjectWindow();
        //
        // 摘要:
        //     Saves all serializable assets that have not yet been written to disk (eg. Materials).
        [Obsolete("Use AssetDatabase.SaveAssets instead (UnityUpgradable) -> AssetDatabase.SaveAssets()", true)]
        public static void SaveAssets();
        //
        // 摘要:
        //     Ask the user if they want to save the open Scene.
        [Obsolete("Use EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo")]
        public static bool SaveCurrentSceneIfUserWantsTo();
        //
        // 摘要:
        //     Save the open Scene.
        //
        // 参数:
        //   path:
        //     The file path to save at. If empty, the current open Scene will be overwritten,
        //     or if never saved before, a save dialog is shown.
        //
        //   saveAsCopy:
        //     If set to true, the Scene will be saved without changing the currentScene and
        //     without clearing the unsaved changes marker.
        //
        // 返回结果:
        //     True if the save succeeded, otherwise false.
        [Obsolete("Use EditorSceneManager.SaveScene")]
        public static bool SaveScene(string path, bool saveAsCopy);
        //
        // 摘要:
        //     Save the open Scene.
        //
        // 参数:
        //   path:
        //     The file path to save at. If empty, the current open Scene will be overwritten,
        //     or if never saved before, a save dialog is shown.
        //
        //   saveAsCopy:
        //     If set to true, the Scene will be saved without changing the currentScene and
        //     without clearing the unsaved changes marker.
        //
        // 返回结果:
        //     True if the save succeeded, otherwise false.
        [Obsolete("Use EditorSceneManager.SaveScene")]
        public static bool SaveScene();
        //
        // 摘要:
        //     Save the open Scene.
        //
        // 参数:
        //   path:
        //     The file path to save at. If empty, the current open Scene will be overwritten,
        //     or if never saved before, a save dialog is shown.
        //
        //   saveAsCopy:
        //     If set to true, the Scene will be saved without changing the currentScene and
        //     without clearing the unsaved changes marker.
        //
        // 返回结果:
        //     True if the save succeeded, otherwise false.
        [Obsolete("Use EditorSceneManager.SaveScene")]
        public static bool SaveScene(string path);
        //
        // 摘要:
        //     Sets the path that Unity should store the current temporary project at, when
        //     the project is closed.
        //
        // 参数:
        //   path:
        //     The path that the current temporary project should be relocated to when closing
        //     it.
        [NativeThrows]
        public static void SetTemporaryProjectKeepPath(string path);
        //
        // 摘要:
        //     Perform a single frame step.
        [StaticAccessor("GetApplication().GetPlayerLoopController()", StaticAccessorType.Dot)]
        public static void Step();
        //
        // 摘要:
        //     Must be called after LockReloadAssemblies, to reenable loading of assemblies.
        [StaticAccessor("GetApplication()", StaticAccessorType.Dot)]
        public static void UnlockReloadAssemblies();

        //
        // 摘要:
        //     Delegate to be called for every visible list item in the ProjectWindow on every
        //     OnGUI event.
        //
        // 参数:
        //   guid:
        //
        //   selectionRect:
        public delegate void ProjectWindowItemCallback(string guid, Rect selectionRect);
        //
        // 摘要:
        //     Delegate to be called for every visible list item in the HierarchyWindow on every
        //     OnGUI event.
        //
        // 参数:
        //   instanceID:
        //
        //   selectionRect:
        public delegate void HierarchyWindowItemCallback(int instanceID, Rect selectionRect);
        //
        // 摘要:
        //     Delegate to be called from EditorApplication callbacks.
        public delegate void CallbackFunction();
        //
        // 摘要:
        //     Delegate to be called from EditorApplication contextual inspector callbacks.
        //
        // 参数:
        //   menu:
        //     The contextual menu which is about to be shown to the user.
        //
        //   property:
        //     The property for which the contextual menu is shown.
        public delegate void SerializedPropertyCallbackFunction(GenericMenu menu, SerializedProperty property);
    }
  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-29 21:54
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    关于您的问题,以下是一些可能的答案:

    1. EditorApplication.projectWindowItemOnGUI 是在每次编辑器窗口上的项目窗口的列表项上触发一个事件。它接收两个参数:guid 和 Rect selectionRect。Guid 可以是任何字符串,而 Rect selectionRect 是一个包含矩形信息的对象。

    2. guid 是在事件中传递给 projectWindowItemOnGUI 的参数。它是一个字符串,用于标识项目窗口中的某个列表项。

    3. selectionRect 是另一个参数,用于指定在列表项上绘制内容的位置和大小。它是由 Rect 类型的对象表示的矩形区域。

    4. EditorApplication.projectWindowItemOnGUI 不应该替换为 ProjectWindowItemCallback 的实例。这是因为这个方法是在每个可见的项目窗口列表项上执行事件处理程序,而 ProjectWindowItemCallback 是一个委托,它接受两个参数,而不是一个具体类型的委托。

    如果您有具体的代码片段或上下文,请提供更多信息,以便我为您提供更精确的帮助。

    评论

报告相同问题?