开发时遇到一个问题,请问:
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);
}