UIPackage.AddPackage("UI/Extension"); 加載Resources下的文件
GComponent _mainView; 爲當前的組件
GGroup _btnGroup; 在fgui上建好的一個組,裏面是多種按鈕文件之類的
Stage.inst.onKeyDown.Add(OnKeyDown); 在圖集上添加一個響應事件
_mainView = this.GetComponent<UIPanel>().ui; 用這種方式獲得該panel中的UI界面
_btnGroup = _mainView.GetChild("g0").asGroup; 在UI界面上加一個組合的組件
_g1 = UIPackage.CreateObject("Transition", "BOSS").asCom; 創建一個組件,這裏是一個動畫組件,根據他的包名還有在FGUI上的組件名,因爲create出來的是object類型的,所以需要裝換爲組件類型,這裏FGUI提供了簡單的.asCom
_g5.GetTransition("t0").SetHook("play_num_now", __playNum); 開始_g5上的t0動畫,play_num_now是添加的一個標籤,根據這個標籤訪問到那個幀,並使用__playNum函數去修改他們的值或者數據之類的,主要用於裝備分數的增加等
_mainView.GetChild("btn0").onClick.Add(() => { __play(_g1); }); 爲當前的"btn0"按鍵添加一個事件,這裏用的是拉姆達表達式,一般都會用拉姆達表達式。
也可以直接這樣: _mainView.GetChild("btn3").onClick.Add(__play4);
void __play(GComponent target)
{
_btnGroup.visible = false; //可見變爲false
GRoot.inst.AddChild(target); //給組件列表加子組件
Transition t = target.GetTransition("t0");
//play(int times,int delay,PlayCompleteCallback onComplete) times,爲該動畫的播放次數,delay,循環多少次,complete爲方法後的響應
t.Play(() =>
{
_btnGroup.visible = true;
GRoot.inst.RemoveChild(target);//將子組件從組建列表中移除
});
}
使用dotween來對動畫中的數據進行修改。
GTween.To(_startValue, _endValue, 0.3f).SetEase(EaseType.Linear)
.OnUpdate((GTweener tweener) => { _g5.GetChild("value").text = "" + Mathf.Floor(tweener.value.x); });
SetEase(EaseType.Linear)爲將數據能實現一個一個的加的過度效果。
進行界面的加載
IEnumerator DoLoad(string sceneName)
{
GRoot.inst.AddChild(_cutSceneView);
GProgressBar pb = _cutSceneView.GetChild("pb").asProgress;
pb.value = 0;
#if UNITY_5_3_OR_NEWER
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
#else
AsyncOperation op = Application.LoadLevelAsync(sceneName);
#endif
float startTime = Time.time;
while (!op.isDone || pb.value != 100)
{
int value = (int)((Time.time - startTime) * 100f / 3f);
if (value > 100)
value = 100;
pb.value = value;
yield return null;
}
GRoot.inst.RemoveChild(_cutSceneView);
GRoot.inst.AddChild(_mainView);
}