首页 > 解决方案 > 为什么在编辑器类型脚本中它永远不会到达断点?

问题描述

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class GetPrefabs : Editor
{
    public GameObject[] prefabs;

    // Start is called before the first frame update
    void Start()
    {
        prefabs = (GameObject[])Resources.LoadAll("Assets/Test/Animations/");
    }

    // Update is called once per frame
    void Update()
    {
        prefabs = (GameObject[])Resources.LoadAll("Assets/Test/Animations/");
    }
}

首先,我尝试将脚本放在 Assets/Test/Editor 中,但它不起作用,然后我将脚本移动到 Assets/Editor 但它不起作用,要么它永远不会到达我在 Update 或 in 中放置的断点开始。

标签: c#unity3d

解决方案


GetPrefabs 派生自编辑器。Start() 和 Update() 是 MonoBehaviour 方法(即,如果您从 MonoBehaviour 派生,Unity 会查找它们)。您应该查看编辑器类的 Unity 文档并从其列表中选择适当的方法 - https://docs.unity3d.com/ScriptReference/Editor.html


推荐阅读