path | 指定相对于项目根目录的文件路径。 |
bool
如果 Unity 成功地使文件在版本控制系统中可编辑,则返回 true
。否则返回 false
。
在版本控制中使文件成为“打开以进行编辑”。
版本控制系统可能配置为每次仅允许一个人员
编辑特定类型的文件,以避免在多个人员编辑相同文件时会出现的合并冲突。
在这种情况下,必须“打开”该文件进行编辑(也称为“签出”)以确保此时
有编辑文件的权限。使用此函数可在支持它的版本控制系统中使文件“打开以进行编辑”。
在 Unity 项目文件夹外部或不在受版本控制的文件夹(例如“Library”或“Temp”)下的文件路径
始终被视为可编辑。MakeEditable
对于这些文件返回 /true/,否则不执行任何操作。
引用非本地包文件夹的文件路径始终被视为不可编辑。MakeEditable
对于这些文件返回 /false/。
没有版本控制系统处于活动状态时,项目中的文件路径全都被视为已可编辑。MakeEditable
返回 /true/,否则不执行任何操作。
使用版本控制系统(例如 Perforce Helix)时,MakeEditable
会对文件触发“签出”
操作,除非文件已可编辑。对于尚未添加到版本控制地文件,MakeEditable/
会将它们添加到版本控制。
如果设置了预先签出回调,则 Unity 会在 MakeEditable
中调用它。
请参阅 PreCheckoutCallback 以了解更多详细信息。
using UnityEngine; using UnityEditor;
public class ExampleScript : MonoBehaviour { [MenuItem("Example/Checkout Selected Asset")] public static void MenuExample() { var path = AssetDatabase.GetAssetPath(Selection.activeObject); var ok = AssetDatabase.MakeEditable(path); if (!ok) Debug.LogError($"Could not make {path} editable"); } }
paths | 指定相对于项目根目录的文件路径的数组。 |
prompt | 要向用户显示的对话框提示(如果需要执行版本控制操作)。如果为 /null/(默认值),则不显示任何提示。 |
outNotEditablePaths | 无法设为可编辑的文件路径的输出列表。 |
bool
如果 Unity 成功地使所有文件在版本控制系统中可编辑,则返回 true
。
在版本控制中使文件列表打开以进行编辑。
MakeEditable
的多文件变体,如果需要执行签出/添加版本控制
操作,也可以选择向用户显示提示。如果用户取消对话框,
Unity 不会使文件可编辑。如果 Unity 编辑器在批处理模式下运行,则 Unity 不会
显示对话框,而是如同用户接受了对话框提示一样进行操作。
如果传递 outNotEditablePaths
列表,则此函数会使用 Unity 可以设为可编辑的文件路径进行填充。
using System.Linq; using UnityEngine; using UnityEditor;
public class ExampleScript : MonoBehaviour { [MenuItem("Example/Checkout Selected Assets")] public static void MenuExample() { var guids = Selection.assetGUIDs; var paths = guids.Select(AssetDatabase.GUIDToAssetPath).ToArray(); var ok = AssetDatabase.MakeEditable(paths, "These files need to be checked out"); if (!ok) Debug.LogError("Could not make some files editable"); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.