Ejemplo n.º 1
0
        private HPBar CreateHPBar(ActorType at)
        {
            string prefabpath = string.Empty;

            switch (at)
            {
            case ActorType.AT_LOCAL_PLAYER:
            case ActorType.AT_REMOTE_PLAYER:
            case ActorType.AT_PVP_PLAYER:
                prefabpath = HPBarPlayerPrefab;
                break;

            case ActorType.AT_MONSTER:
                prefabpath = HPBarMonsterPrefab;
                break;

            case ActorType.AT_BOSS:
                prefabpath = HPBarBossPrefab;
                break;

            case ActorType.AT_NPC:
                prefabpath = HPBarNPCPrefab;
                break;

            case ActorType.AT_PET:
                prefabpath = HPBarPetPrefab;
                break;

            default:
                return(null);
            }

            GameObject prefab = (GameObject)CoreEntry.gResLoader.Load(prefabpath, typeof(GameObject));

            if (prefab == null)
            {
                return(null);
            }

            GameObject    obj = GameObject.Instantiate(prefab) as GameObject;
            RectTransform rt  = obj.GetComponent <RectTransform>();
            HPBar         ret = obj.GetComponent <HPBar>();

            obj.SetActive(true);
            rt.SetParent(HPBarRoot);
            rt.anchoredPosition3D = Vector3.zero;
            rt.localScale         = Vector3.one;
            ret.BarType           = at;
            if (ret.BarType == ActorType.AT_BOSS)
            {
                rt.anchoredPosition = new Vector2(40, 260);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 移除血条。
        /// </summary>
        /// <param name="bar">血条对象。</param>
        public void RemoveHPBar(HPBar bar)
        {
            if (bar == null)
            {
                return;
            }

            Stack <HPBar> cache;

            if (!m_CacheHPBar.TryGetValue(bar.BarType, out cache))
            {
                cache = new Stack <HPBar>();
                m_CacheHPBar.Add(bar.BarType, cache);
            }

            bar.gameObject.SetActive(false);
            cache.Push(bar);
        }
Ejemplo n.º 3
0
        public HPBar GetHPBar(ActorType at)
        {
            Stack <HPBar> cache;

            if (!m_CacheHPBar.TryGetValue(at, out cache))
            {
                cache = new Stack <HPBar>();
                m_CacheHPBar.Add(at, cache);
            }

            if (cache.Count > 0)
            {
                HPBar bar = cache.Pop();
                bar.gameObject.SetActive(true);
                return(bar);
            }

            return(CreateHPBar(at));
        }