Пример #1
0
        public void SetPart(int partId)
        {
//            if(null ==  SingletonManager.Get<WeaponPartsConfigManager>())
//            {
//#if !UnitTest
//                Logger.Error("weapon parts config manager is null !");
//#endif
//                return;
//            }
            if (partId < 1)
            {
#if !UnitTest
                Logger.WarnFormat("illegal weapon parts id {0}", partId);
#endif
                return;
            }
            var config = SingletonManager.Get <WeaponPartsConfigManager>().GetConfigById(partId);
            if (null == config)
            {
                return;
            }
            var partType = (EWeaponPartType)config.Type;
            if (!_weaponPartDic.ContainsKey(partType))
            {
#if !UnitTest
                Logger.ErrorFormat("weapon part type {0} doesn't exist in weaponpartdic ", partType);
#endif
                return;
            }

            var asset    = SingletonManager.Get <WeaponPartsConfigManager>().GetAsset(partId);
            var location = WeaponTypeConvertUtil.GetLocationByPartType((EWeaponPartType)config.Type);
            var item     = _weaponPartDic[partType];
            item.Id    = partId;
            item.Asset = asset;
            RefreshAssets();
        }
Пример #2
0
        private void RefreshAssets()
        {
#if !UnitTest
            if (Logger.IsDebugEnabled)
            {
                Logger.DebugFormat("RefreshAssets cur {0} last {1}", _weapon.Asset, _lastWeapon.Asset);
            }
#endif
            if (_weapon.Id != _lastWeapon.Id)
            {
                if (HasLastWeapon())
                {
                    _weaponModelLoadController.Unload(_lastWeapon.Asset);
                }
                _weaponModelLoadController.LoadWeapon(_weapon.Asset);
            }

            foreach (var partPair in _weaponPartDic)
            {
                var lastPart = _lastWeaponPartDic[partPair.Key];
                if (partPair.Value.Id != lastPart.Id)
                {
                    _weaponModelLoadController.Unload(_lastWeaponPartDic[partPair.Key].Asset);
                    if (partPair.Value.Id > 0)
                    {
                        var location = WeaponTypeConvertUtil.GetLocationByPartType(partPair.Key);
                        _weaponModelLoadController.LoadPart(_weaponPartDic[partPair.Key].Asset, location);
                    }
                }
            }

            _weapon.CopyTo(_lastWeapon);
            foreach (var partPair in _weaponPartDic)
            {
                partPair.Value.CopyTo(_lastWeaponPartDic[partPair.Key]);
            }
        }