读一读

使用JsonUtility解析json时,需要提供一个允许序列化的对象类,对应的对上json的数据名称和数据类型。

[Serializable]
public class UIPanelInfo {
	public string panelTypeString;
	public string path;
}
//对应json
{"panelTypeString":"systemPanel","path":"Panel/systemPanel"}

-----------------------------------------------------------------
[Serializable]
public class UIPanelJson {
	public List<UIPanelInfo> uiPanelInfoList;
}
//对应json
{
"uiPanelInfoList":[
	{"panelTypeString":"bagPanel","path":"Panel/bagPanel"}
	{"panelTypeString":"systemPanel","path":"Panel/systemPanel"}
	]
}

[Serializable]表名类是可以序列化的,此特性在System命名空间里


使用JsonUtility解析json文件时,注意json文件要以对象开头

也就是说,json要第一层要以{}包裹也就是对象的形式,不能用[]开头

{
    "uiPanelInfoList":[
	{"panelTypeString":"bagPanel","path":"Panel/bagPanel"},
	{"panelTypeString":"shopPanel","path":"Panel/shopPanel"},
	{"panelTypeString":"systemPanel","path":"Panel/systemPanel"}
    ]
}



Vector3.Lerp( Vector3.Lerp(P0,P1,t), Vector3.Lerp(P1,P2,t) ,t );
B(t) = (1-t)((1-t)P0 + tP1) + t((1-t)P1 + tP2);
//化简
B(t) = (1-t)²P0 + 2(1-t)tP1 + t²P2;

//求导,获取切线加速度
B′(t) = 2(1-t)(P1-P0) + 2t(P2-P1);


这样子可以用B(t)公式替代线性插值。


Vector3.Lerp(p0,p1,t); //线性插值
B(t) = (1-t)P0 + tP1 = P0 + t(p1-p0);

一阶的贝塞尔曲线其实就是线性的一段插值


void Reset(){
    
}

这个方法当组件创建或点击Inspect的重置按钮时调用,不过只在编辑模式下有用。

一般用来给一些值提供常用的默认值。


先在Hierarchy中制作组合好预设需要的样子,然后拖拽这个GameObject到Project文件位置,这样,预设就生成了,同时Hierarchy的原物体名字变成蓝色。


public class Ball:MonoBehaviour{
    
    void OnBecameInvisible(){
        Destroy(this.gameObject);
    }
}

OnBecameInvisible函数会在游戏对象移动到画面之外时调用的方法。


将挂载了脚本的空物体制作成Prefab,用来动态生成且生成一次

//Loader.cs  加载管理Prefab

public GameObject ManagerObject;
void Awake(){
    if(GameManager.Instance == null){
        GameObject go = Instantiate(ManagerObject);
        DontDestroyOnLoad(go);
    }
}

平常的脚本组件都可以通过来下面禁用组件

component.enable = false;

而刚体使用的方法为:

rigidbody.Sleep();//沉睡
rigidbody.WakeUp();//醒来

GameObject go = GameObject.FindGameObjectWithTag ("Player");
GameObject[] go = GameObject.FindGameObjectsWithTag ("Player");

两个方法都是GameObject的静态方法,一个查找单个物体,一个查找多个物体