究其根本,原因在于,能在unity面板上识别的变量,public不是唯一的条件,另外一个条件是可序列化
比如你声明了如下一个类
1
2
3
4
5
6
7
8
9
|
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Wave { public GameObject prefab; public int count; public float rate; } |
在另外一个类中进行声明时如下:
1
|
public Wave[] waves; |
这样在unity面板中自然看不到,因为你自己随意声明的类没有继承自序列化类,
只需要声明继承即可,如下所示
1
2
3
4
5
6
7
8
9
10
|
using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class Wave { public GameObject prefab; public int count; public float rate; } |
补充:C#类修饰符public和internal
当在命名空间建了一个类时,默认修饰符号是internal。
作用:
在当前命名空间内可以实现对类的调用。
当类的修饰符是public时,表明该类不仅在当前命名空间可以被调用,在其它命名空间也可以被调用。如:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
using system; using ...; namespace s1 { internal class A { .... } class B { A a= new A(); //ok } } |
但是 下述代码则会提示错误:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
using system; using ...; namespace s1 { internal class A { .... } } using system; using ...; using s1; namespace s2 { class B { A a= new A(); //error,as A is an internal which can only be called in its packet } } |
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。
原文链接:https://blog.csdn.net/qq_40666620/article/details/102066389