コード例 #1
0
    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
        _instance   = this;
        CanvasRoot  = transform;
        graphic     = CanvasRoot.GetComponent <GraphicRaycaster>();
        canvas      = CanvasRoot.GetComponent <Canvas>();
        uicamera    = CanvasRoot.Find("Camera").GetComponent <Camera>();
        canvasRect  = CanvasRoot.GetComponent <RectTransform>();
        loading     = CanvasRoot.Find("Loading").gameObject;
        loading_cur = loading.transform.Find("loading_cur").GetComponent <Image>();
        loading_txt = loading.transform.Find("loading_txt").GetComponent <Text>();

        notice     = this.transform.Find("Notice").gameObject;
        notice_pop = notice.GetComponent <PopTextMgr>();
        //JsonMgr.GetSingleton();

#if UNITY_EDITOR
        if (EnableDebugUILine)
        {
            this.gameObject.AddComponent <DebugUILine>();
        }
#endif

        //调整分辨率
        float designAspect = designWidth / designHeight;
        float aspect       = Screen.width / Screen.height;
        this.GetComponent <CanvasScaler>().matchWidthOrHeight = (aspect > designAspect ? 1 : 0);
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        Image CurHpPro = this.Unit.IsEnemy ? this.Hp_enemy_pro : this.Hp_self_pro;

        if (Unit != null)
        {
            Vector3 followPoint = OUT_SCREEN;
            //if (!Unit.IsDead)
            {
                Vector2 targetScreenPosition = Camera.main.WorldToScreenPoint(new Vector3(Unit.CurPos.x, Unit.HorseId != 0 ? 3.7f : 2.6f, Unit.CurPos.y));
                if (!RectTransformUtility.ScreenPointToWorldPointInRectangle(Info_obj, targetScreenPosition, CanvasView.Instance.uicamera, out followPoint))
                {
                    Debug.LogErrorFormat("计算位置失败:{0}", Unit.UID);
                }
            }
            Info_obj.position = followPoint;

            //更新Hp
            float newFillAmount = this.Unit.CurHP / (float)this.Unit.MaxHP;
            CurHpPro.fillAmount = newFillAmount;

            //HP_FADE
            if (Hp_group.alpha > 0)
            {
                if (Time.time > startFade)
                {
                    Hp_group.alpha = Mathf.Max(0, Hp_group.alpha - FADE_SPEED * Time.deltaTime);
                }
            }
        }

        float fill_dis = CurHpPro.fillAmount - Follow_pro.fillAmount;

        if (fill_dis >= 0)
        {
            Follow_pro.fillAmount = CurHpPro.fillAmount;
        }
        else
        {
            float fill_delta = FOLLOW_SPEED * Time.deltaTime;
            if (fill_delta >= -fill_dis)
            {
                Follow_pro.fillAmount = CurHpPro.fillAmount;
            }
            else
            {
                Follow_pro.fillAmount -= fill_delta;
            }
        }

        //处理冒字
        if (Time.time - _lastPopTime >= POP_GAP && _popObjs.Count > 0)
        {
            PopObj     obj = _popObjs.Dequeue();
            PopTextMgr mgr = obj.Dir == PopTextDir.Up ? this.PopText : (obj.Dir == PopTextDir.LEFT ? this.PopTextLeft : this.PopTextRight);
            mgr.AddInfo(obj.info, obj.style);
            _lastPopTime = Time.time;
        }
    }
コード例 #3
0
 // Use this for initialization
 void Start()
 {
     Info_obj       = this.transform.GetComponent <RectTransform>();
     Hp_group       = this.transform.Find("hp_group").GetComponent <CanvasGroup>();
     Hp_self_pro    = this.transform.Find("hp_group/hp_self_pro").GetComponent <Image>();
     Hp_enemy_pro   = this.transform.Find("hp_group/hp_enemy_pro").GetComponent <Image>();
     Follow_pro     = this.transform.Find("hp_group/follow_pro").GetComponent <Image>();
     PopText        = this.transform.Find("PopText").GetComponent <PopTextMgr>();
     PopTextLeft    = this.transform.Find("PopTextLeft").GetComponent <PopTextMgr>();
     PopTextRight   = this.transform.Find("PopTextRight").GetComponent <PopTextMgr>();
     Hp_group.alpha = 0;
 }