private void OnStyleDropdownValueChangedHandler(int index) { //Logger.Log("Change style to value " + value); _curLaserCfg = _styleCfgs[index]; _styleId = _curLaserCfg.styleId; _styleText.text = _curLaserCfg.name; UpdateColorDropdownOptions(); // 如果选择的弹型没有之前选择的颜色,则默认设置为该弹型的第一种颜色 if (!CheckColorAvailable(_styleId, _colorId)) { _colorId = _curLaserCfg.availableColors[0]; _colorDropdown.value = _colorList.IndexOf(_colorId); } else { _colorDropdown.value = _colorList.IndexOf(_colorId); } if (_blendIndex == -1) { _blendIndex = 0; _blendModeDropdown.value = _blendIndex; } UpdateBulletId(); UpdateBulletIdTextAndPreview(); }
private void InitAllShow() { InitStyleDropdownOptions(); if (_curBulletId == 0) { _styleId = -1; _colorId = -1; _blendIndex = -1; UpdateColorDropdownOptions(); StartCoroutine(UpdateDropdownText("undefined", "undefined", "undefined")); } else { _styleId = (_curBulletId % 100000) / 1000; _colorId = (_curBulletId % 1000) / 10; _blendIndex = _curBulletId % 10; _curLaserCfg = DatabaseManager.LaserDatabase.GetLaserStyleCfg(_showType, _styleId); // 更新子弹颜色的下拉框 UpdateColorDropdownOptions(); ColorCfg colorCfg = DatabaseManager.LaserDatabase.GetColorCfgByColorId(_colorId); string blendText = ((eBlendMode)_blendIndex).ToString(); StartCoroutine(UpdateDropdownText(_curLaserCfg.name, colorCfg.colorName, blendText)); } UpdateBulletIdTextAndPreview(); }
private void InitBulletItems() { _itemList = new List <StyleItem>(); _bulletCfgs = DatabaseManager.LaserDatabase.GetLaserStyleCfgsByType(_bulletType); for (int i = 0; i < _bulletCfgs.Count; i++) { LaserStyleCfg cfg = _bulletCfgs[i]; GameObject item = ResourceManager.GetInstance().GetPrefab("Prefabs/Views/EditViews", "LaserStyleItem"); RectTransform itemTf = item.GetComponent <RectTransform>(); itemTf.SetParent(_itemContainerTf, false); // 初始化StyleItem结构 StyleItem styleItem = new StyleItem(); styleItem.styleId = cfg.styleId; styleItem.itemGo = item; styleItem.btn = itemTf.Find("BtnBg").gameObject; styleItem.selectImgGo = itemTf.Find("SelectImg").gameObject; styleItem.selectImgGo.SetActive(false); // 设置子弹图像 Image bulletImg = itemTf.Find("BulletImg").GetComponent <Image>(); bulletImg.sprite = ResourceManager.GetInstance().GetSprite(cfg.packName, cfg.resName); int itemIndex = i; // 添加事件监听 UIEventListener.Get(styleItem.btn).AddClick(() => { OnStyleItemClickHandler(itemIndex); }); _itemList.Add(styleItem); } }
/// <summary> /// 检查对应style的激光是否包含colorId对应的颜色 /// </summary> /// <param name="styleId"></param> /// <param name="colorId"></param> /// <returns></returns> private bool CheckColorAvailable(int styleId, int colorId) { if (_styleId == -1 || _colorId == -1) { return(false); } LaserStyleCfg cfg = DatabaseManager.LaserDatabase.GetLaserStyleCfg(_showType, styleId); if (cfg.type == BulletType.Undefined || cfg.availableColors.IndexOf(colorId) == -1) { return(false); } return(true); }
private void UpdateColorDropdownOptions() { if (_styleId == -1) { return; } _colorDropdown.onValueChanged.RemoveAllListeners(); LaserStyleCfg cfg = DatabaseManager.LaserDatabase.GetLaserStyleCfg(_showType, _styleId); _colorList = cfg.availableColors; List <Dropdown.OptionData> options = new List <Dropdown.OptionData>(); for (int i = 0; i < _colorList.Count; i++) { ColorCfg colorCfg = DatabaseManager.BulletDatabase.GetColorCfgByColorId(_colorList[i]); Dropdown.OptionData optionData = new Dropdown.OptionData(colorCfg.colorName); options.Add(optionData); } _colorDropdown.options = options; _colorDropdown.onValueChanged.AddListener(OnColorDropdownValueChangedHandler); }
public LaserDatabase() { #region Style _styleCfgList = new List <LaserStyleCfg>(); // Laser #region 普通激光 LaserStyleCfg cfg = new LaserStyleCfg { type = BulletType.Laser, typePrefixNum = 2, styleId = 1, name = "Style1", packName = "STGLaserAtlas0", resName = "Laser201010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 尖头激光 cfg = new LaserStyleCfg { type = BulletType.Laser, typePrefixNum = 2, styleId = 2, name = "Style2", packName = "STGLaserAtlas0", resName = "Laser202010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 鳞弹头激光 cfg = new LaserStyleCfg { type = BulletType.Laser, typePrefixNum = 2, styleId = 3, name = "Style3", packName = "STGLaserAtlas0", resName = "Laser203010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 米弹激光 cfg = new LaserStyleCfg { type = BulletType.Laser, typePrefixNum = 2, styleId = 4, name = "Style4", packName = "STGLaserAtlas0", resName = "Laser204010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion // LinearLaser #region 尖头激光 cfg = new LaserStyleCfg { type = BulletType.LinearLaser, typePrefixNum = 3, styleId = 2, name = "Style2", packName = "STGLinearLaserAtlas0", resName = "Laser302010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 鳞弹头激光 cfg = new LaserStyleCfg { type = BulletType.LinearLaser, typePrefixNum = 3, styleId = 3, name = "Style3", packName = "STGLinearLaserAtlas0", resName = "Laser303010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 米弹激光 cfg = new LaserStyleCfg { type = BulletType.LinearLaser, typePrefixNum = 3, styleId = 4, name = "Style4", packName = "STGLinearLaserAtlas0", resName = "Laser304010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 曲线激光贴图 cfg = new LaserStyleCfg { type = BulletType.LinearLaser, typePrefixNum = 3, styleId = 5, name = "Style5", packName = "STGLinearLaserAtlas1", resName = "Laser305010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion // CurveLaser #region 曲线激光贴图 cfg = new LaserStyleCfg { type = BulletType.CurveLaser, typePrefixNum = 4, styleId = 1, name = "Style1", packName = "STGCurveLaserAtlas", resName = "Laser401010", showScale = 1, availableColors = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, }; _styleCfgList.Add(cfg); #endregion #region 闪电激光 cfg = new LaserStyleCfg { type = BulletType.CurveLaser, typePrefixNum = 4, styleId = 10, name = "Style10", packName = "STGCurveLaserAtlas1", resName = "Laser410000", showScale = 1, availableColors = new List <int> { 0 }, }; _styleCfgList.Add(cfg); #endregion #endregion #region color _colorCfgList = new List <ColorCfg>(); #region DeepGray ColorCfg colorCfg = new ColorCfg { colorId = 0, colorName = "DeepGray", packName = "ColorAtlas", resName = "COLOR_DEEP_GRAY", }; _colorCfgList.Add(colorCfg); #endregion #region DeepRed colorCfg = new ColorCfg { colorId = 1, colorName = "DeepRed", packName = "ColorAtlas", resName = "COLOR_DEEP_RED", }; _colorCfgList.Add(colorCfg); #endregion #region Red colorCfg = new ColorCfg { colorId = 2, colorName = "Red", packName = "ColorAtlas", resName = "COLOR_RED", }; _colorCfgList.Add(colorCfg); #endregion #region DeepPurple colorCfg = new ColorCfg { colorId = 3, colorName = "DeepPurple", packName = "ColorAtlas", resName = "COLOR_DEEP_PURPLE", }; _colorCfgList.Add(colorCfg); #endregion #region Purple colorCfg = new ColorCfg { colorId = 4, colorName = "Purple", packName = "ColorAtlas", resName = "COLOR_PURPLE", }; _colorCfgList.Add(colorCfg); #endregion #region DeepBlue colorCfg = new ColorCfg { colorId = 5, colorName = "DeepBlue", packName = "ColorAtlas", resName = "COLOR_DEEP_BLUE", }; _colorCfgList.Add(colorCfg); #endregion #region Blue colorCfg = new ColorCfg { colorId = 6, colorName = "Blue", packName = "ColorAtlas", resName = "COLOR_BLUE", }; _colorCfgList.Add(colorCfg); #endregion #region RoyalBlue colorCfg = new ColorCfg { colorId = 7, colorName = "RoyalBlue", packName = "ColorAtlas", resName = "COLOR_ROYAL_BLUE", }; _colorCfgList.Add(colorCfg); #endregion #region Cyan colorCfg = new ColorCfg { colorId = 8, colorName = "Cyan", packName = "ColorAtlas", resName = "COLOR_DEEP_CYAN", }; _colorCfgList.Add(colorCfg); #endregion #region DeepGreen colorCfg = new ColorCfg { colorId = 9, colorName = "DeepGreen", packName = "ColorAtlas", resName = "COLOR_DEEP_GREEN", }; _colorCfgList.Add(colorCfg); #endregion #region Green colorCfg = new ColorCfg { colorId = 10, colorName = "Green", packName = "ColorAtlas", resName = "COLOR_GREEN", }; _colorCfgList.Add(colorCfg); #endregion #region Chartreuse colorCfg = new ColorCfg { colorId = 11, colorName = "Chartreuse", packName = "ColorAtlas", resName = "COLOR_CHARTREUSE", }; _colorCfgList.Add(colorCfg); #endregion #region Yellow colorCfg = new ColorCfg { colorId = 12, colorName = "Yellow", packName = "ColorAtlas", resName = "COLOR_YELLOW", }; _colorCfgList.Add(colorCfg); #endregion #region GoldenYellow colorCfg = new ColorCfg { colorId = 13, colorName = "GoldenYellow", packName = "ColorAtlas", resName = "COLOR_GOLDEN_YELLOW", }; _colorCfgList.Add(colorCfg); #endregion #region Orange colorCfg = new ColorCfg { colorId = 14, colorName = "Orange", packName = "ColorAtlas", resName = "COLOR_ORANGE", }; _colorCfgList.Add(colorCfg); #endregion #region Gray colorCfg = new ColorCfg { colorId = 15, colorName = "Gray", packName = "ColorAtlas", resName = "COLOR_GRAY", }; _colorCfgList.Add(colorCfg); #endregion #endregion }