カスタマイズ機能セレクター修正

This commit is contained in:
kimura 2022-05-13 10:50:33 +09:00
parent ce05ce22b6
commit 01060c2df0
1 changed files with 9 additions and 6 deletions

View File

@ -25,12 +25,12 @@ namespace MyGame.Scenes.marketing.Scripts
public void Initialize() public void Initialize()
{ {
var content = scrollRect.content; var viewport = scrollRect.viewport;
content.DestroyAllChildrens(); viewport.DestroyAllChildrens();
var categories = (ShopCustomizeCategory[])Enum.GetValues(typeof(ShopCustomizeCategory)); var categories = (ShopCustomizeCategory[])Enum.GetValues(typeof(ShopCustomizeCategory));
foreach (var category in categories) foreach (var category in categories)
{ {
targetDict.Add(category, Instantiate(listPrefab, content)); targetDict.Add(category, Instantiate(listPrefab, viewport));
} }
buttonDict.Add(ShopCustomizeCategory.Category1, signBoardButton); buttonDict.Add(ShopCustomizeCategory.Category1, signBoardButton);
buttonDict.Add(ShopCustomizeCategory.Category2, decoration1Button); buttonDict.Add(ShopCustomizeCategory.Category2, decoration1Button);
@ -39,11 +39,13 @@ namespace MyGame.Scenes.marketing.Scripts
buttonDict.Add(ShopCustomizeCategory.Category5, decoration2Button); buttonDict.Add(ShopCustomizeCategory.Category5, decoration2Button);
// buttonDict.Add(ShopCustomizeCategory.Category6, category6Button); // buttonDict.Add(ShopCustomizeCategory.Category6, category6Button);
initializeCompositeDisposable.Dispose(); initializeCompositeDisposable.Clear();
buttonDict.Select(pair => pair.Value.OnClickObservable.Select(_ => pair.Key)) buttonDict.Select(pair => pair.Value.OnClickObservable.Select(_ => pair.Key))
.Merge() .Merge()
.StartWith(ShopCustomizeCategory.Category1)
.ThrottleFirst(TimeSpan.FromSeconds(.2f)) .ThrottleFirst(TimeSpan.FromSeconds(.2f))
.Subscribe(ChangeCategory).AddTo(initializeCompositeDisposable); .Subscribe(ChangeCategory)
.AddTo(initializeCompositeDisposable);
} }
public ShopCustomizeItem GenerateItem(ShopCustomizeCategory category) public ShopCustomizeItem GenerateItem(ShopCustomizeCategory category)
@ -68,8 +70,9 @@ namespace MyGame.Scenes.marketing.Scripts
foreach (var pair in targetDict) foreach (var pair in targetDict)
{ {
pair.Value.gameObject.SetActive(pair.Key == category); pair.Value.gameObject.SetActive(pair.Key == category);
buttonDict[pair.Key]?.SetActive(pair.Key == category); buttonDict[pair.Key].SetActive(pair.Key == category);
} }
scrollRect.content = targetDict[category] as RectTransform;
} }
} }
} }