예제 #1
0
        void Start()
        {
            Debug.Log("Main:Start()");

            AppConfig.Init();

            GameObject.DontDestroyOnLoad(this.gameObject);

            if (IsNeedPrintConcole)
            {
                if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.Android)
                {
                    this.gameObject.AddComponent <LogHandler>();
                }
            }

            this.gameObject.AddComponent <ThreadManager>();//for download or extract assets
            this.gameObject.AddComponent <ResourceManager>();
            this.gameObject.AddComponent <NetworkManager>();
            this.gameObject.AddComponent <XLuaManager>();
            this.gameObject.AddComponent <TestManager>();
            UnityMMO.NetMsgDispatcher.GetInstance().Init();
            ResMgr.GetInstance().Init();
            Debug.Log("loading view active in main");
            var loadingViewTrans = GameObject.Find("UICanvas/Top/LoadingView");

            loadingViewTrans.gameObject.SetActive(true);
            loadingView = loadingViewTrans.GetComponent <LoadingView>();
            JumpToState(State.CheckExtractResource);
        }
예제 #2
0
    //往外拿
    public void GetObj(string name, UnityAction <GameObject> callBack)
    {
        //查看对应的是否有这个list以及里面有没有物体
        if (poolDic.ContainsKey(name) && poolDic[name].poolList.Count > 0)
        {
            GameObject obj = poolDic[name].GetObj();
            //先调用自己应该完成的接口
            obj.GetComponent <IReusable>().OnSpawn();

            //再掉传进来的委托
            callBack(obj);
        }
        else//没有的话就实例化一个拿出去
        {
            //异步加载
            ResMgr.GetInstance().LoadAsync <GameObject>(name, (o) =>
            {
                o.name = name;//把对象名改成和池子名字一样
                //先调用自己应该完成的接口
                o.GetComponent <IReusable>().OnSpawn();
                //再调用传进来的委托
                callBack(o);
            });
        }
    }
예제 #3
0
    public bool OnShow(Transform parent)
    {
        if (m_LoadStaticObj == null)
        {
            //TODO:obj pool
            // XLuaFramework.ResourceManager.GetInstance().LoadPrefabGameObjectWithAction(m_ResPath, delegate(UnityEngine.Object obj){
            GameObject obj = ResMgr.GetInstance().GetSceneRes(m_ResID);
            if (obj == null)
            {
                return(false);
            }
            m_LoadStaticObj = obj as GameObject;
            // Debug.Log("LoadScene obj "+(obj!=null).ToString() +" m_LoadStaticObj : "+(m_LoadStaticObj!=null).ToString());
            m_LoadStaticObj.transform.SetParent(parent);
            m_LoadStaticObj.transform.position    = m_Position;
            m_LoadStaticObj.transform.eulerAngles = m_Rotation;
            m_LoadStaticObj.transform.localScale  = m_Size;

            Renderer renderer = m_LoadStaticObj.GetComponent <Renderer>();
            renderer.lightmapIndex       = m_LightmapIndex;
            renderer.lightmapScaleOffset = m_LightmapScaleOffset;
            // });
            return(true);
        }
        return(false);
    }
예제 #4
0
    public void Init()
    {
        Debug.Log("GameDataMgr.init");
        Debug.Log("PlayerInfo_url:" + PlayerInfo_url);

        string info = ResMgr.GetInstance().Load <TextAsset>("Files/ItemInfo").text;

        Debug.Log(info);
        Items items = JsonUtility.FromJson <Items>(info);

        Debug.Log(items.info.Count);
        for (int i = 0; i < items.info.Count; i++)
        {
            itemInfos.Add(items.info[i].id, items.info[i]);
        }

        //初始化角色
        if (File.Exists(PlayerInfo_url))
        {
            //读取记录
            byte[] bytes = File.ReadAllBytes(PlayerInfo_url);
            string json  = Encoding.UTF8.GetString(bytes);
            playerInfo = JsonUtility.FromJson <Player>(json);
            Debug.Log(" 读取记录" + playerInfo.name);
        }
        else
        {
            //新建记录并保存
            playerInfo = new Player();
            SavePlayerInfo();
        }
    }
예제 #5
0
    protected override void OnUpdate()
    {
        var requestArray = Group.GetComponentDataArray <NameboardSpawnRequest>();
        var entityArray  = Group.GetEntityArray();

        var spawnRequests = new NameboardSpawnRequest[requestArray.Length];

        for (var i = 0; i < requestArray.Length; i++)
        {
            spawnRequests[i] = requestArray[i];
            PostUpdateCommands.DestroyEntity(entityArray[i]);
        }

        for (var i = 0; i < spawnRequests.Length; i++)
        {
            var request = spawnRequests[i];
            GameObjectEntity nameboardGOE = m_world.Spawn <GameObjectEntity>(ResMgr.GetInstance().GetPrefab("Nameboard"));
            nameboardGOE.transform.SetParent(nameboardCanvas);
            var    nameboardBehav = nameboardGOE.GetComponent <Nameboard>();
            var    uid            = EntityManager.GetComponentData <UID>(request.Owner);
            string name           = SceneMgr.Instance.GetNameByUID(uid.Value);
            nameboardBehav.Name = name;
            var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(request.Owner);
            nameboardBehav.CurColorStyle = isMainRole ? Nameboard.ColorStyle.Green : Nameboard.ColorStyle.Red;
            if (EntityManager.HasComponent <NameboardData>(request.Owner))
            {
                var nameboardData = EntityManager.GetComponentData <NameboardData>(request.Owner);
                nameboardData.UIEntity   = nameboardGOE.Entity;
                nameboardData.UIResState = NameboardData.ResState.Loaded;
                EntityManager.SetComponentData(request.Owner, nameboardData);
            }
        }
    }
예제 #6
0
    void Init()
    {
        Player p = GameDataMgr.GetInstance().GetPlayerInfo();

        for (int i = 0; i < p.items.Count; i++)
        {
            ItemCell temp = ResMgr.GetInstance().Load <GameObject>("UI/ItemCell").GetComponent <ItemCell>();

            temp.transform.SetParent(content);

            temp.transform.localScale = Vector3.one;
            temp.Init(p.items[i]);
        }
        for (int i = 0; i < p.equips.Count; i++)
        {
            ItemCell temp = ResMgr.GetInstance().Load <GameObject>("UI/ItemCell").GetComponent <ItemCell>();
            temp.transform.SetParent(content);
            temp.transform.localScale = Vector3.one;
            temp.Init(p.equips[i]);
        }
        for (int i = 0; i < p.gems.Count; i++)
        {
            ItemCell temp = ResMgr.GetInstance().Load <GameObject>("UI/ItemCell").GetComponent <ItemCell>();
            temp.transform.SetParent(content);
            temp.transform.localScale = Vector3.one;
            temp.Init(p.gems[i]);
        }
    }
예제 #7
0
 public static void SmoothChangeMusicAudio(string name, float volume, float fadeInTime)
 {
     ResMgr.GetInstance().LoadAsync <AudioClip>("Sound/" + name, (clip) =>
     {
         current.StartCoroutine(SmoothChange(current.musicSource, clip, volume, fadeInTime));
     });
 }
예제 #8
0
    public void ShowPanel(string name, Ui_Type type)
    {
        ResMgr.GetInstance().LoadAsync <GameObject>(name, (obj) =>
        {
            GameObject fatherGo = bot;
            switch (type)
            {
            case Ui_Type.mid:
                fatherGo = mid;
                break;

            case Ui_Type.top:
                fatherGo = top;
                break;

            case Ui_Type.system:
                fatherGo = system;
                break;

            default:
                break;
            }
            obj.transform.SetParent(fatherGo.transform);

            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;
            (obj.transform as RectTransform).offsetMax = Vector2.zero;
            (obj.transform as RectTransform).offsetMin = Vector2.zero;

            UiDic.Add(name, obj.GetComponent <BasePanel>());
        });
    }
예제 #9
0
파일: ItemCell.cs 프로젝트: yiyuwuyan/WuXia
    public void Init(ItemInfo i)
    {
        //Debug.Log("the id:"+i.id);
        //Debug.Log("the icon:"+ GameDataMgr.GetInstance().GetItemInfo(i.id).icon);
        GetControl <Image>("item").sprite = ResMgr.GetInstance().Load <Sprite>("icon/" + GameDataMgr.GetInstance().GetItemInfo(i.id).icon);
        GetControl <Text>("itemNum").text = "数量:" + i.nums;
        item = GameDataMgr.GetInstance().GetItemInfo(i.id);

        EventTrigger trigger = gameObject.AddComponent <EventTrigger>();

        #region PointerEnter
        //UnityAction<BaseEventData> enter = new UnityAction<BaseEventData>(PointerEnter);
        //EventTrigger.Entry myenter = new EventTrigger.Entry();
        //myenter.eventID = EventTriggerType.PointerEnter;
        //myenter.callback.AddListener(enter);
        //trigger.triggers.Add(myenter);
        #endregion
        #region PointerExit

        EventTrigger.Entry myexit = new EventTrigger.Entry();
        myexit.eventID = EventTriggerType.PointerExit;
        myexit.callback.AddListener(PointerExit);
        trigger.triggers.Add(myexit);
        #endregion
        #region NewPointEnter
        EventTrigger.Entry newEnter = new EventTrigger.Entry();
        newEnter.eventID = EventTriggerType.PointerEnter;
        newEnter.callback.AddListener(PointerEnter);
        trigger.triggers.Add(newEnter);
        #endregion
    }
예제 #10
0
파일: PoolMgr.cs 프로젝트: yiyuwuyan/WuXia
 /// <summary>
 /// 获取 池中的 obj (transform)
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public void GetObj(string key, UnityAction <GameObject> callback)
 {
     if (pool.ContainsKey(key) && pool[key].pool.Count > 0)
     {
         if (callback != null)
         {
             callback(pool[key].GetObj().gameObject);
         }
         else
         {
             pool[key].GetObj();
         }
     }
     else
     {
         //obj = GameObject.Instantiate(Resources.Load(key)) as GameObject;
         //obj.gameObject.name = key;
         ResMgr.GetInstance().LoadAsync <GameObject>(key, (o) => {
             o.name = key;
             if (callback != null)
             {
                 callback(o);
             }
         });
     }
 }
예제 #11
0
 // Called each frame while the state is set to Play
 public override void PrepareFrame(Playable playable, FrameData info)
 {
     if (Defenders == null || Defenders.Count <= 0 || leftShowCount <= 0)
     {
         return;
     }
     for (int i = 0; i < Defenders.Count; i++)
     {
         var defender = Defenders[i];
         // Debug.Log("defender uid : "+defender.uid+" damage:"+defender.damage+" hp:"+defender.cur_hp+" damagetype:"+defender.flag);
         var defenderEntity = SceneMgr.Instance.GetSceneObject(defender.uid);
         if (EntityMgr.HasComponent <LocomotionState>(defenderEntity))
         {
             //进入受击状态
             var locomotionState = EntityMgr.GetComponentData <LocomotionState>(defenderEntity);
             locomotionState.LocoState = LocomotionState.State.BeHit;
             locomotionState.StartTime = Time.time;
             EntityMgr.SetComponentData <LocomotionState>(defenderEntity, locomotionState);
             //显示战斗飘字
             var          defenderTrans = EntityMgr.GetComponentObject <Transform>(defenderEntity);
             var          flyWordObj    = ResMgr.GetInstance().SpawnGameObject("FightFlyWord");
             FightFlyWord flyWord       = flyWordObj.GetComponent <FightFlyWord>();
             flyWord.SetData(defender.damage, defender.flag);
             var pos = defenderTrans.position;
             pos += Vector3.up * 1;
             flyWord.transform.position = pos;
             flyWord.StartFly();
         }
     }
     leftShowCount--;
 }
예제 #12
0
    /// <summary>
    /// 根据道具信息初始化 格子信息
    /// </summary>
    public void InitInfo(ItemInfo info)
    {
        this._itemInfo = info;
        if (info == null)
        {
            imgIcon.gameObject.SetActive(false);
            return;
        }
        GetControl <Image>("imgIcon").gameObject.SetActive(true);
        //根据道具信息,更新格子对象
        print("得到了id" + info.id + "  " + info.num);
        Item itemData = GameDataMgr.GetInstance().GetItemInfo(info.id);

        //使用我们的道具表中的数据
        GetControl <Image>("imgIcon").sprite = ResMgr.GetInstance().Load <Sprite>("Icon/" + itemData.icon);
        if (type == E_Item_Type.Bag)
        {
            //数量
            GetControl <Text>("txtNum").text = info.num.ToString();
        }
        //只要装备才可以进行拖动
        if (itemData.type == (int)E_Bag_Type.Equip)
        {
            OpenDragEvent();
        }
    }
예제 #13
0
 //往外拿东西
 public void GetObj(string name, UnityAction <GameObject> callback)
 {
     if (poolDic.ContainsKey(name) && poolDic[name].poolList.Count > 0)//有dictionary,dic中有东西,第二个参数代表后面的gameobject
     {
         //通过委托返回给外部,让外部进行使用
         callback(poolDic[name].GetObj());
         //obj = poolDic[name].GetObj();
         //poolDic[name].RemoveAt(0);//把第一个移除掉,拿出去
     }
     else
     {
         //缓存池中没有该物体,我们去目录中加载
         //外面传一个预设体的路径和名字,内部加载它
         ResMgr.GetInstance().LoadAsync <GameObject>(name, (o) =>
         {
             o.name = name;
             callback(o);
         }
                                                     );
         //obj = GameObject.Instantiate(Resources.Load<GameObject>(name));
         //obj.name = name;//把对象名字改成和池子名字一样,push的时候不用一个一个push
     }
     //激活
     //obj.SetActive(true);
     //断开缓存池物体与poolobj的父子关系
     //obj.transform.parent = null;
     // return obj;
 }
예제 #14
0
 public bool OnShow(Transform parent)
 {
     if (m_LoadStaticObj == null)
     {
         GameObject obj = ResMgr.GetInstance().GetSceneRes(m_ResID);
         if (obj == null)
         {
             return(false);
         }
         m_LoadStaticObj = obj as GameObject;
         // Debug.Log("LoadScene obj "+(obj!=null).ToString() +" m_LoadStaticObj : "+(m_LoadStaticObj!=null).ToString());
         m_LoadStaticObj.transform.SetParent(parent);
         m_LoadStaticObj.transform.position    = m_Position;
         m_LoadStaticObj.transform.eulerAngles = m_Rotation;
         m_LoadStaticObj.transform.localScale  = m_Size;
         if (m_LightmapIndex != -1)
         {
             Renderer renderer = m_LoadStaticObj.GetComponent <Renderer>();
             renderer.lightmapIndex       = m_LightmapIndex;
             renderer.lightmapScaleOffset = m_LightmapScaleOffset;
         }
         return(true);
     }
     return(false);
 }
 public void Init()
 {
     if (sceneUIPerfab != null)
     {
         GameObject sceneUIObj = GameObject.Find(sceneUIPerfab.name);
         if (sceneUIObj)
         {
             GameObject.Destroy(sceneUIObj);
         }
         ResMgr.GetInstance().loadAsync <GameObject>("UI/" + sceneUIPerfab.name, (o) =>
         {
             if (o != null)
             {
                 o.SetActive(true);
                 Canvas cav           = o.GetComponent <Canvas>();
                 cav.worldCamera      = Camera.main;
                 cav.sortingLayerName = "InputUI";
                 cav.sortingOrder     = 10;
                 cav.planeDistance    = 1;
                 cav = null;
                 InitUI(o);
             }
         });
     }
     isScene    = false;
     isTempTime = false;
     AddListener();
 }
예제 #16
0
    private Dictionary <int, Item> itemInfos = new Dictionary <int, Item>();//建一个字典 把list的内容移到字典中
    /// <summary>
    /// 初始化数据
    /// </summary>
    public void Init()
    {
        //加载Resources文件夹下的json 获取它的内容
        string info = ResMgr.GetInstance().Load <TextAsset>("Json/ItemInfo").text;//同步加载

        Debug.Log(info);
        //根据json文件内容 解析成对赢得数据结构 并存储起来
        Items items = JsonUtility.FromJson <Items>(info);

        Debug.Log(items.info.Count);

        for (int i = 0; i < items.info.Count; ++i)
        {
            itemInfos.Add(items.info[i].id, items.info[i]);//把list中的内容放入到字典中
        }

        //初始化 角色信息
        if (File.Exists(PlayerInfo_Url))
        {
            //取这个文件的信息
            byte[] bytes = File.ReadAllBytes(PlayerInfo_Url);//保存字节数组
            //字节数组转成string
            string json = Encoding.UTF8.GetString(bytes);
            //把字符串转换成玩家数据结构
            playerInfo = JsonUtility.FromJson <Player>(json);

            Debug.Log(playerInfo.name);
        }
        else
        {
            //没有玩家数据时 初始化一个默认数据
            playerInfo = new Player();
            SavePlayerInfo();
        }
    }
예제 #17
0
    /// <summary>
    /// 显示面板
    /// </summary>
    /// <typeparam name="T">面板脚本类型</typeparam>
    /// <param name="panelName">面板名</param>
    /// <param name="layer">显示在哪一层</param>
    /// <param name="callBack">当面板预设体创建成功后 你想做的事</param>
    public void ShowPanel <T>(string panelName, E_UI_Layer layer = E_UI_Layer.Mid, UnityAction <T> callBack = null) where T : BasePanel
    {
        if (panelDic.ContainsKey(panelName))
        {
            panelDic[panelName].ShowMe();
            // 处理面板创建完成后的逻辑
            if (callBack != null)
            {
                callBack(panelDic[panelName] as T);
            }
            //避免面板重复加载 如果存在该面板 即直接显示 调用回调函数后  直接return 不再处理后面的异步加载逻辑
            return;
        }

        ResMgr.GetInstance().LoadAsync <GameObject>("UI/" + panelName, (obj) =>
        {
            //把他作为 Canvas的子对象
            //并且 要设置它的相对位置
            //找到父对象 你到底显示在哪一层
            Transform father = bot;
            switch (layer)
            {
            case E_UI_Layer.Mid:
                father = mid;
                break;

            case E_UI_Layer.Top:
                father = top;
                break;

            case E_UI_Layer.System:
                father = system;
                break;
            }
            //设置父对象  设置相对位置和大小
            obj.transform.SetParent(father);

            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;

            (obj.transform as RectTransform).offsetMax = Vector2.zero;
            (obj.transform as RectTransform).offsetMin = Vector2.zero;

            //得到预设体身上的面板脚本
            T panel = obj.GetComponent <T>();
            // 处理面板创建完成后的逻辑
            if (callBack != null)
            {
                callBack(panel);
            }

            panel.ShowMe();

            //把面板存起来
            panelDic.Add(panelName, panel);
        });
    }
예제 #18
0
 public void OnHide()
 {
     if (m_LoadStaticObj)
     {
         // Object.Destroy(m_LoadStaticObj);
         ResMgr.GetInstance().UnuseSceneObject(m_ResID, m_LoadStaticObj);
         m_LoadStaticObj = null;
     }
 }
예제 #19
0
    /// <summary>
    /// /显示面板
    /// </summary>
    /// <typeparam name="T">面板类型</typeparam>
    /// <param name="panelName">面板名</param>
    /// <param name="layer">显示的层级</param>
    /// <param name="callback">当面板预设体创建成功后,你想做的事情</param>
    public void ShowPanel <T>(string panelName, E_UI_Layer layer, UnityAction <T> callback = null) where T : BasePanel
    {
        if (PanelDic.ContainsKey(panelName))   //已经有面板存着了
        //处理面板创建完成后的逻辑
        {
            if (callback != null)
            {
                callback(PanelDic[panelName] as T);
            }
            return; //避免面板重复加载,如果存在该面板,即直接显示,调用回调函数后 直接return ,不再处理
        }

        ResMgr.GetInstance().LoadAsync <GameObject>("UI/" + panelName, (obj) => {
            //把它作为canvas的子对象
            //设置它的相对位置
            //找到父对象,到底显示哪一层
            Transform father = bot;
            switch (layer)
            {
            case E_UI_Layer.Bot:
                father = bot;
                break;

            case E_UI_Layer.Mid:
                father = mid;
                break;

            case E_UI_Layer.Top:
                father = top;
                break;

            case E_UI_Layer.System:
                father = system;
                break;
            }
            //设置父对象 设置相对位置和大小
            obj.transform.SetParent(father);

            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;

            (obj.transform as RectTransform).offsetMax = Vector2.zero;
            (obj.transform as RectTransform).offsetMin = Vector2.zero;

            //得到预设体身上的面板脚本
            T panel = obj.GetComponent <T>();
            //处理面板创建完成后的逻辑
            if (callback != null)
            {
                callback(panel);
            }

            panel.ShowMe();//展示面板之后干的事情,基类的虚函数
            //把面板存起来
            PanelDic.Add(panelName, panel);
        });
    }
예제 #20
0
    /// <summary>
    /// 页签切换的函数
    /// </summary>
    /// <param name="type"></param>
    public void ChangeType(E_Bag_Type type)
    {
        //默认值是道具列表信息
        List <ItemInfo> tempInfo = GameDataMgr.GetInstance().playerInfo.items;

        switch (type)
        {
        case E_Bag_Type.Equip:
            tempInfo = GameDataMgr.GetInstance().playerInfo.equips;
            break;

        case E_Bag_Type.Gem:
            tempInfo = GameDataMgr.GetInstance().playerInfo.gems;
            break;
        }
        //更新前先删除之前的格子
        for (int i = 0; i < list.Count; i++)
        {
            Destroy(list[i].gameObject);
        }
        list.Clear();
        temp_items.Clear();

        int      totalNum  = 0;
        ItemInfo item_info = new ItemInfo();

        for (int i = 0; i < tempInfo.Count; i++)
        {
            if (temp_items.ContainsKey(tempInfo[i].id))
            {
                totalNum += tempInfo[i].num;
                temp_items[tempInfo[i].id] = new ItemInfo()
                {
                    id = tempInfo[i].id, num = totalNum
                };
            }
            else
            {
                totalNum = tempInfo[i].num;
                temp_items.Add(tempInfo[i].id, new ItemInfo()
                {
                    id = tempInfo[i].id, num = totalNum
                });
            }
        }
        //更新现在的数据
        //动态创建 ItemCell 预设体 并且将它存放到list里面
        foreach (var item in temp_items)
        {
            ItemCell cell = ResMgr.GetInstance().Load <GameObject>("UI/ItemCell").GetComponent <ItemCell>();
            cell.transform.parent     = content;
            cell.transform.localScale = Vector3.one;
            cell.InitInfo(temp_items[item.Key]);
            list.Add(cell);
        }
    }
예제 #21
0
    /// <summary>
    /// 显示面板
    /// </summary>
    /// <typeparam name="T">面板脚本类型</typeparam>
    /// <param name="panelName"></param>
    /// <param name="layer"></param>
    /// <param name="callBack">创建成功后处理的逻辑</param>
    public void ShowPanel <T>(string panelName, E_UI_Layer layer = E_UI_Layer.Mid, UnityAction <T> callBack = null) where T : BasePanel
    {
        ResMgr.GetInstance().LoadAsync <GameObject>("UI/" + panelName, (obj) =>
        {
            if (panelDic.ContainsKey(panelName))// 如果已经创建了一次 就直接调用它后面的逻辑
            {
                panelDic[panelName].ShowMe();
                if (callBack != null)
                {
                    callBack(panelDic[panelName] as T);
                }
                //避免面板重复加载
                return;
            }

            //把它放在Canvas下面
            //设置它的相对位置

            //找到父对象 到底显示在哪一层
            Transform father = bot;
            switch (layer)
            {
            case E_UI_Layer.Mid:
                father = mid;
                break;

            case E_UI_Layer.Top:
                father = top;
                break;

            case E_UI_Layer.System:
                father = system;
                break;

            default:
                break;
            }
            //设置父对象
            obj.transform.SetParent(father);
            //设置相对位置和大小
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;
            (obj.transform as RectTransform).offsetMax = Vector2.zero;
            (obj.transform as RectTransform).offsetMin = Vector2.zero;
            //得到预设体身上的面板脚本
            T panel = obj.GetComponent <T>();
            panel.ShowMe();
            //处理面板创建后的逻辑
            if (callBack != null)
            {
                callBack(panel);
            }
            //把面板存起来
            panelDic.Add(panelName, panel);
        });
    }
예제 #22
0
 public static void AmbientAudio(string name, float volume = 0.5f, bool isLoop = false)
 {
     ResMgr.GetInstance().LoadAsync <AudioClip>("Sound/" + name, (clip) =>
     {
         current.ambientSource.loop   = isLoop;
         current.ambientSource.volume = volume;
         current.ambientSource.clip   = clip;
         current.ambientSource.Play();
     });
 }
예제 #23
0
    public void ShowPanel <T>(string panelName,
                              E_UI_Layer layer         = E_UI_Layer.Top,
                              UnityAction <T> callback = null) where T : BasePanel
    {
        //已经显示了此面板
        Debug.Log(panelName);
        if (panelDic.ContainsKey(panelName))
        {
            //Debug.Log(1111);
            //调用重写方法,具体内容自己添加
            panelDic[panelName].ShowMe();
            if (callback != null)
            {
                callback(panelDic[panelName] as T);
            }
            return;
        }
        ResMgr.GetInstance().LoadAsync <GameObject>("UI/" + panelName, (obj) => {
            //把它作为Canvas的子对象
            //并且设置它的相对位置
            //找到父对象
            Transform father = bot;
            switch (layer)
            {
            case E_UI_Layer.Mit:
                father = mid;
                break;

            case E_UI_Layer.Top:
                father = top;
                break;
            }
            //设置父对象
            obj.transform.SetParent(father);

            //设置相对位置和大小
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;

            (obj.transform as RectTransform).offsetMax = Vector2.zero;
            (obj.transform as RectTransform).offsetMin = Vector2.zero;

            //得到预设体身上的脚本(继承自BasePanel)
            T panel = obj.GetComponent <T>();
            panel.ShowMe();
            //执行外面想要做的事情
            if (callback != null)
            {
                callback(panel);
            }

            //在字典中添加此面板
            panelDic.Add(panelName, panel);
        });
    }
예제 #24
0
파일: UIBase.cs 프로젝트: pdool/zhugong
 protected virtual void OnInitSkin()
 {
     if (!string.IsNullOrEmpty(mainSkinPath))
     {
         _skin = ResMgr.GetInstance().CreateGameObject(mainSkinPath, false);
     }
     _skin.transform.parent           = this.transform;
     _skin.transform.localEulerAngles = Vector3.zero;
     _skin.transform.localPosition    = Vector3.zero;
     _skin.transform.localScale       = Vector3.one;
 }
예제 #25
0
    //显示面板
    //面板名  面板层级 面板回调函数
    public void ShowPanel <T>(string panelName, UILayer layer = UILayer.Mid, UnityAction <T> callBack = null) where T : BasePanel
    {
        if (panelDic.ContainsKey(panelName))
        {
            panelDic[panelName].ShowThis();
            if (callBack != null)
            {
                callBack(panelDic[panelName] as T);
            }
        }

        ResMgr.GetInstance().LoadAsync <GameObject>("UI/" + panelName, (obj) =>
        {
            //加载完后需要做的事
            //找到父对象显示层级
            Transform father = bot;
            switch (layer)
            {
            case UILayer.Bot:
                father = bot;
                break;

            case UILayer.Mid:
                father = mid;
                break;

            case UILayer.System:
                father = system;
                break;

            case UILayer.Top:
                father = top;
                break;
            }
            //设置相对位置大小 和父对象
            obj.transform.SetParent(father);

            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;
            (obj.transform as RectTransform).offsetMax = Vector2.zero;

            //得到预设体的面板脚本
            T panel = obj.GetComponent <T>();
            //处理面板创建后的逻辑
            if (callBack != null)
            {
                callBack(panel);
            }

            panel.ShowThis();
            panelDic.Add(panelName, panel);
        });
    }
예제 #26
0
파일: Test.cs 프로젝트: HNGZY/Astar_Test
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         PoolMgr.GetInstance().GetObj("Cube", (o) => { o.transform.position = new Vector3(2, 2, 2); o.AddComponent <PoolPush>(); });
     }
     if (Input.GetMouseButtonDown(1))
     {
         ResMgr.GetInstance().LoadAsync <GameObject>("Cube", o => { o.name = "张鹏笨蛋"; });
         ResMgr.GetInstance().Load <GameObject>("Cube").gameObject.name = "王鹏笨蛋";
     }
 }
예제 #27
0
    protected override void OnUpdate()
    {
        var requestArray  = Group.ToComponentDataArray <NameboardSpawnRequest>(Allocator.TempJob);
        var entityArray   = Group.ToEntityArray(Allocator.TempJob);
        var spawnRequests = new NameboardSpawnRequest[requestArray.Length];

        for (var i = 0; i < requestArray.Length; i++)
        {
            spawnRequests[i] = requestArray[i];
            PostUpdateCommands.DestroyEntity(entityArray[i]);
        }

        for (var i = 0; i < spawnRequests.Length; i++)
        {
            var request = spawnRequests[i];
            if (!EntityManager.Exists(request.Owner))
            {
                continue;
            }
            GameObjectEntity nameboardGOE = m_world.Spawn <GameObjectEntity>(ResMgr.GetInstance().GetPrefab("Nameboard"));
            nameboardGOE.transform.SetParent(nameboardCanvas);
            nameboardGOE.transform.localScale = new Vector3(-1, 1, 1);
            var    nameboardBehav = nameboardGOE.GetComponent <Nameboard>();
            var    uid            = EntityManager.GetComponentData <UID>(request.Owner);
            string name           = SceneMgr.Instance.GetNameByUID(uid.Value);
            nameboardBehav.Name = name;
            var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(request.Owner);
            Debug.Log("name : " + name + " isMainRole:" + isMainRole);
            nameboardBehav.CurColorStyle = isMainRole ? Nameboard.ColorStyle.Green : Nameboard.ColorStyle.Red;
            if (EntityManager.HasComponent <NameboardData>(request.Owner))
            {
                var nameboardData = EntityManager.GetComponentData <NameboardData>(request.Owner);
                nameboardData.UIEntity   = nameboardGOE.Entity;
                nameboardData.UIResState = NameboardData.ResState.Loaded;
                EntityManager.SetComponentData(request.Owner, nameboardData);
            }
            bool hasHPData = EntityManager.HasComponent <HealthStateData>(request.Owner);
            // Debug.Log("has Hp data "+hasHPData);
            if (hasHPData)
            {
                var hpData = EntityManager.GetComponentData <HealthStateData>(request.Owner);
                nameboardBehav.MaxHp = hpData.MaxHp;
                nameboardBehav.CurHp = hpData.CurHp;
                // nameboardBehav.UpdateBloodBar(hpData.CurHp, hpData.MaxHp);
            }

            var sceneObjType = EntityManager.GetComponentData <SceneObjectTypeData>(request.Owner);
            nameboardBehav.SetBloodVisible(sceneObjType.Value == SceneObjectType.Role || sceneObjType.Value == SceneObjectType.Monster);
        }
        requestArray.Dispose();
        entityArray.Dispose();
    }
예제 #28
0
    public void InitInfo(ItemInfo info)
    {
        Item itemData = GameDataMgr.GetInstance().GetItemInfo(info.id);

        //使用我们的道具表中的数据
        GetControl <Image>("imageIcon").sprite = ResMgr.GetInstance().Load <Sprite>("Icon/" + itemData.icon);
        //数量
        GetControl <Text>("txtNum").text = "数量: " + info.num.ToString();

        GetControl <Text>("txtName").text = itemData.name;

        GetControl <Text>("txtTips").text = itemData.tips;
    }
예제 #29
0
 public void InitAPool(string name, string path)
 {
     if (PoolDic.ContainsKey(name))
     {
         return;
     }
     ResMgr.GetInstance().LoadAsync <GameObject>(path, (obj) =>
     {
         obj.name = name;
         obj.SetActive(false);
         PoolDic.Add(name, new PoolData(path, obj, transform));
     });
 }
예제 #30
0
    Transform system; //画布
    public UIManager()
    {
        GameObject obj = ResMgr.GetInstance().Load <GameObject>("UI/Canvas").gameObject;

        bot    = obj.transform.Find("bot");
        mid    = obj.transform.Find("mid");
        top    = obj.transform.Find("top");
        system = obj.transform.Find("system");
        GameObject.DontDestroyOnLoad(obj);


        obj = ResMgr.GetInstance().Load <GameObject>("UI/EventSystem").gameObject;
        GameObject.DontDestroyOnLoad(obj);
    }