Unity未在事件字段中显示公共方法

时间:2018-05-02 09:58:30

标签: unity3d events

我在Unity 2017中有一个课程,只在检查员中显示一些公共方法。

using System.Collections.Generic;
using UnityEngine;

public class Inventory : MonoBehaviour 
{

    List<ShipPart> _inventory;
    int currentInvPosition = 0;
    bool invExists = false;

    // Use this for initialization
    void Start () {
        CreateInventory(0, 0);
    }

    // Show all inventory parts as gameobjects
    public void CreateInventory(int quality, int part) 
    {
        ...
    }

    void DestroyInventory()
    {
        ...
    }

    public void ScrollInvLeft()
    {
        ...
    }

    public void ScrollInvRight()
    {
        ...
    }

    void UpdateInv(float offset)
    {
        ...
    }

    public void AddInventoryItem(ShipPart newShipPart) 
    {
        ... 
    }

    public void RemoveInventoryItem(ShipPart oldShipPart) 
    {
        ...
    }

    public void Test1(){}
    public void Test2(int i){}

}

我认为可能是因为隐形方法有参数,所以我添加了最后两个方法。但是在检查员中可以看到它们!

我试图从下拉UI元素调用方法,但也从一个按钮进行测试,但也看不到它们。

enter image description here

我做错了什么?

1 个答案:

答案 0 :(得分:3)

here所示,如果要在检查器中为事件提供函数,则该函数必须满足以下要求:

  1. 该功能必须为public
  2. 该函数的返回类型必须为void
  3. 该功能必须采用一个参数
  4. 如果函数采用一个参数,则后者必须是以下类型之一:
    • int
    • float
    • string
    • bool
    • UnityEngine.Object或从UnityEngine.Object继承的任何类型(例如GameObjectMonoBehaviourScriptableObject,...)