unity OnWillCreateAsset 请求DeveloperName

Unity OnWillCreateAsset ask for DeveloperName

在 unity 中创建新脚本时,我有一个脚本可以更改各种信息,生成附加到文件的版权信息,但是虽然大多数信息是静态的或程序确定的活动程序员的名字不能以任何一种方式确定,我试图在实际创建资产之前显示一个弹出窗口,询问开发人员的姓名,但我当前的方法只提供了一个错误,有没有办法解决这个问题?

using UnityEngine;
using UnityEditor;

/*   Project Name : Project Venom
 *    Script Name : ScriptKeywordProcessor
 *    Script Path : /Editor/ScriptKeywordProcessor.cs
 *  Script Author : FaalFaazDov || Raistlin M. Thoreson
 *     Created On : 08/29/2016 12:46
 *    Modified On : 09/28/2016 18:25
 *        Version : 1.1.0
 */

 /*************************************************************************
 *
 * Biophase Entertainment
 * __________________
 *
 *  [2016] Biophase Entertainment
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Biophase Entertainment and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Biophase Entertainment
 * and its suppliers and may be covered by Canadian and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information, reproduction of this material or attempting
 * to read the content of these files is strictly forbidden unless prior written
 * permission is obtained from Biophase Entertainment.
 *
 */

internal sealed class ScriptKeywordProcessor : UnityEditor.AssetModificationProcessor {

 public string DeveloperName = "";

 public static void OnWillCreateAsset(string path) {

        EditorWindow window = EditorWindow.CreateInstance<ScriptKeywordProcessor> ();
        window.Show ();

 }

 void OnGUI() {

        GUILayout.Label ("Developer Name", EditorStyles.boldLabel);
        DeveloperName = GUILayout.TextField (DeveloperName, 100);

 }

}

我收到的错误是

Assets/Editor/ScriptKeywordProcessor.cs(39,38): error CS0309: The type ScriptKeywordProcessor must be convertible to UnityEngine.ScriptableObject in order to use it as parameter T in the generic type or method UnityEngine.ScriptableObject.CreateInstance<T>()

根据您的代码,ScriptKeywordProcessor 不是继承自 ScriptableObjectEditorWindow

您需要定义另一个继承自 EditorWindow 的 class 来执行 GUI 工作。然后在ScriptKeywordProcessor.

OnWillCreateAsset方法中打开你的window