Esempio n. 1
0
        public static DUnit Create(Entity domain, DUnitInfo unitInfo)
        {
            DUnit tower = DUnitFactory.Create(domain, unitInfo.UnitId);

            // 位置信息
            tower.Position = new Vector3(unitInfo.PX, unitInfo.PY, unitInfo.PZ);
            tower.Rotation = new Quaternion(unitInfo.RX, unitInfo.RY, unitInfo.RZ, unitInfo.RW);
            // 类型信息
            tower.AddComponent <UnitTypeComponent, UnitType>(UnitType.UnitTower);
            // 配置信息
            tower.AddComponent <UTowerConfigComponent, int>(unitInfo.ConfigId);
            // 运算者
            tower.AddComponent <OperationerComponent, long>(unitInfo.OperationerId);
            // 阵营信息
            tower.AddComponent <CampComponent, long, CampType>(unitInfo.GamerId, (CampType)unitInfo.Camp);
            // 数值信息
            TowerHelper.InitTowerNumberic(tower);
            // 血量恢复
            NumericComponent numeric = tower.GetComponent <NumericComponent>();

            tower.AddComponent <HPRegainComponent, int>(numeric.GetAsInt(NumericType.HPRegain));

            // 触发创建完成事件
            Game.EventSystem.Publish(new AppEventType.AfterTowerCreate()
            {
                Unit = tower
            }).Coroutine();

            return(tower);
        }
Esempio n. 2
0
        public override void Update(HPRegainComponent self)
        {
            if (self.BeStart)
            {
                // 按秒恢复
                long disTime = TimeHelper.ClientNow() - self.StartMilliseconds;
                if (disTime > 1000)
                {
                    DUnit            tower = self.GetParent <DUnit>();
                    NumericComponent nm    = tower.GetComponent <NumericComponent>();
                    int hpMax = nm.GetAsInt(NumericType.MaxHp);
                    int hp    = nm.GetAsInt(NumericType.Hp);
                    // 到最大值,不再恢复
                    if (hp >= hpMax)
                    {
                        return;
                    }

                    // 确认恢复值
                    int hpRegain = ((int)disTime / 1000) * self.HpRegain;
                    if (hp + hpRegain > hpMax)
                    {
                        hpRegain = hpMax - hp;
                    }

                    // 设置增量值
                    int hpAdd = nm.GetAsInt(NumericType.HpAdd) + hpRegain;
                    NumericAction.SetUnitNumericAction(tower, NumericType.HpAdd, hpAdd);

                    // 矫正剩余时间
                    int extTime = (int)disTime % 1000;
                    self.StartMilliseconds = TimeHelper.ClientNow() - extTime;
                }
                return;
            }
        }
Esempio n. 3
0
        public static void RefreshUI(this InfoComponent self)
        {
            Unit             parent = self.GetParent <Unit>();
            NumericComponent nc     = parent.GetComponent <NumericComponent>();

            if (nc == null)
            {
                Log.Info("RefreshHP " + parent.Id + " 上没有添加 NumericComponent组件");
                return;
            }
            self.Num.text = nc.GetAsInt(NumericType.Hp).ToString();
            float fCurrentHpPercent = nc.GetAsFloat(NumericType.Hp) / nc.GetAsFloat(NumericType.MaxHp);

            self.HpBg.fillAmount = fCurrentHpPercent;
        }