Exemplo n.º 1
0
    //创建伤害数字
    public void CreateHurtWords(Protomsg.MsgPlayerHurt hurt)
    {
        //Vector2 pt = World2FairyUIPoint();
        //pt.x += UnityEngine.Random.Range(-30, 30);
        //如果是加钻石
        //Debug.Log("------CreateHurtWords:" + hurt);
        if (hurt.GetDiamond > 0)
        {
            ShowGetDiamond(hurt.GetDiamond);
            return;
        }

        //如果是加金币
        if (hurt.GetGold > 0)
        {
            ShowGetGold(hurt.GetGold);
            return;
        }



        GComponent words = UIPackage.CreateObject("GameUI", "HurtInfo").asCom;
        WordsInfo  wd    = AddWordsInfo(words);

        wd.RandomX(-30, 30);

        //1,直接加到GRoot显示出来
        GRoot.inst.AddChild(words);
        GRoot.inst.SetChildIndex(words, 1);
        //words.xy = pt;
        words.GetChild("num").asTextField.text = hurt.HurtAllValue + "";
        if (this == GameScene.Singleton.GetMyMainUnit())
        {
            //自己受伤
            if (hurt.HurtAllValue < 0)
            {
                FairyGUI.Transition trans = words.GetTransition("down");
                trans.Play();
                trans.SetHook("over", () => {
                    RemoveWordsInfo(wd);
                });
            }
            else//加血
            {
                words.GetChild("num").asTextField.color = new Color(0.1f, 1.0f, 0.1f);
                FairyGUI.Transition trans = words.GetTransition("up");
                trans.Play();
                trans.SetHook("over", () => {
                    RemoveWordsInfo(wd);
                    //GameObject.Destroy(words);
                });
            }
        }
        else
        {
            //伤害别人
            if (hurt.IsCrit != 1)
            {
                words.GetChild("num").asTextField.color = new Color(1.0f, 1.0f, 1.0f);
            }
            FairyGUI.Transition trans = words.GetTransition("up");
            trans.Play();
            trans.SetHook("over", () => {
                RemoveWordsInfo(wd);
                //words.Dispose();
                //GameObject.Destroy(words);
            });
        }
    }
Exemplo n.º 2
0
    IEnumerator LoadUIPackage()
    {
        string url = Application.streamingAssetsPath.Replace("\\", "/") + "/fairygui-examples/bundleusage.ab";

        if (Application.platform != RuntimePlatform.Android)
        {
            url = "file:///" + url;
        }

#if UNITY_5_4_OR_NEWER
#if UNITY_2018_1_OR_NEWER
        UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url);
#else
        UnityWebRequest www = UnityWebRequest.GetAssetBundle(url);
#endif
#if UNITY_2017_2_OR_NEWER
        yield return(www.SendWebRequest());
#else
        yield return(www.Send());
#endif

        if (!www.isNetworkError && !www.isHttpError)
        {
            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
#else
        WWW www = new WWW(url);
        yield return(www);

        if (string.IsNullOrEmpty(www.error))
        {
            AssetBundle bundle = www.assetBundle;
#endif
            if (bundle == null)
            {
                Debug.LogWarning("Run Window->Build FairyGUI example Bundles first.");
                yield return(0);
            }
            UIPackage.AddPackage(bundle);

            _mainView = UIPackage.CreateObject("BundleUsage", "Main").asCom;
            _mainView.fairyBatching = true;
            _mainView.SetSize(GRoot.inst.width, GRoot.inst.height);
            _mainView.AddRelation(GRoot.inst, RelationType.Size);

            GRoot.inst.AddChild(_mainView);
            _mainView.GetTransition("t0").Play();
        }
        else
        {
            Debug.LogError(www.error);
        }
    }

    void OnKeyDown(EventContext context)
    {
        if (context.inputEvent.keyCode == KeyCode.Escape)
        {
            Application.Quit();
        }
    }
}
Exemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        //赋值组件
        mainComponent       = GetComponent <UIPanel>().ui;
        tankViewComponent   = mainComponent.GetChild("tankViewComponent").asCom;
        selectModeComponent = mainComponent.GetChild("selectModeComponent").asCom;
        roomListComponent   = UIPackage.CreateObject("BattleCity8102", "RoomList_Component").asCom;
        //设置钱
        moneyTextField = mainComponent.GetChild("moneyTextField").asTextField;
        mainComponent.GetChild("configButton").asButton.displayObject.layer = 0;
        mainComponent.GetChildIndex(mainComponent.GetChild("configButton").asButton);

        moneyTextField.text = money.ToString();
        //设置经验
        experienceBar       = mainComponent.GetChild("experienceBar").asProgress;
        experienceBar.value = experience;

        //给按钮注册监听
        //设置按钮按下,显示设置窗口
        configWindow = new ConfigWindow(50);//初始音量设置为50
        mainComponent.GetChild("configButton").asButton.onClick.Add(() => {
            configWindow.Show();
        });

        //返回按钮按下,返回主页面
        mainComponent.GetChild("returnButton").asButton.onClick.Add(() => {
            //关闭窗口,移除房间列表组件,将模式选择组件渲染先于经验条
            if (roomInfoWindow != null)
            {
                roomInfoWindow.Dispose();
            }
            roomListComponent.GetChild("entryRoomButton").asButton.enabled = false;
            currentRoom = null;//当前选中房间为空
            mainComponent.RemoveChild(roomListComponent);
            mainComponent.AddChild(selectModeComponent);
            mainComponent.SetChildIndexBefore(selectModeComponent, mainComponent.GetChildIndex(experienceBar));

            mainComponent.GetChild("configButton").asButton.visible = true;
            mainComponent.GetChild("returnButton").asButton.visible = false;
        });

        //对战按钮按下,加载roomConponent
        selectModeComponent.GetChild("LANBattleButton").onClick.Add(() => {
            //隐藏设置按钮,显示返回按钮
            mainComponent.GetChild("configButton").asButton.visible = false;
            mainComponent.GetChild("returnButton").asButton.visible = true;

            BattleButtonOnClick(roomListComponent);
        });

        //进入房间按钮按下,显示TankListWindow
        roomListComponent.GetChild("entryRoomButton").asButton.enabled = false;//防止不选房间进行点击
        roomListComponent.GetChild("entryRoomButton").asButton.onClick.Add(() => {
            if (roomInfoWindow != null)
            {
                roomInfoWindow.Dispose();//关闭房间信息窗口
            }
            tankListWindow = new TankListWindow(tankNum);
            tankListWindow.Show();
        });

        //创建房间时弹窗,创建完成循环发送房间信息
        roomListComponent.GetChild("createRoomButton").asButton.onClick.Add(() => {
            MainUI.player.isHost = true;
            createRmWindow       = new CreateRmWindow();
            createRmWindow.Show();
        });

        //刷新时清空当前房间,播放动效,查询房间,重新渲染列表
        Transition t = roomListComponent.GetTransition("t0");

        roomListComponent.GetChild("refreshButton").asButton.onClick.Add(() => {
            currentRoom = null;
            roomListComponent.GetChild("entryRoomButton").asButton.enabled = false;
            t.ChangePlayTimes(2);
            t.Play(() => {
                roomListComponent.GetChild("refreshMask").visible      = false;
                roomListComponent.GetChild("refreshTextField").visible = false;
            });
            rooms = RoomManager.SearchRoom(rooms);
            roomList.itemRenderer = RenderListItem;
            roomList.numItems     = rooms.Count;
        });
    }