using System; using System.Collections; using System.Collections.Generic; using MaidStatus; using UnityEngine; public class VRTouchButtonCtrl : MonoBehaviour { public void Init(GameObject goPresetButtonPanel, Maid maid) { this.m_goPresetButtonPanel = goPresetButtonPanel; this.m_maid = maid; this.m_goItemPresetsViewer = UTY.GetChildObject(this.m_goPresetButtonPanel, "ItemPresetsViewer", false); this.m_listPresetBtn = new Dictionary(); this.m_listItemPresetBtn = new Dictionary(); IEnumerator enumerator = Enum.GetValues(typeof(VRTouchButtonCtrl.LeftButtons)).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; this.initBtnList("LeftButtons", ((VRTouchButtonCtrl.LeftButtons)obj).ToString()); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.m_goParentItemBtn = UTY.GetChildObject(this.m_goItemPresetsViewer, "Scroll View/Grid", false); UIButton component = UTY.GetChildObject(this.m_goPresetButtonPanel, "PresetButtons/LeftButtons/BG", false).GetComponent(); this.activeColor = new Color(component.defaultColor.r, component.defaultColor.g, component.defaultColor.b, 1f); this.inActiveColor = component.defaultColor; this.m_sbScrollBar = UTY.GetChildObject(this.m_goItemPresetsViewer, "Scroll Bar", false).GetComponent(); this.m_goItemScrollView = UTY.GetChildObject(this.m_goPresetButtonPanel, "ItemPresetsViewer/Scroll View", false); this.m_pItemScrollViewPanel = this.m_goItemScrollView.GetComponent(); GameObject childObject = UTY.GetChildObject(this.m_goPresetButtonPanel, "ItemPresetsViewer/BG", false); this.m_spScrollViewBG = childObject.GetComponent(); this.m_maxScrollViewWidth = (int)this.m_pItemScrollViewPanel.baseClipRegion.z; this.m_scrollViewSize = new Vector4(0f, 0f, (float)this.m_maxScrollViewWidth, (float)((int)this.m_pItemScrollViewPanel.baseClipRegion.w)); this.m_scrollViewSoftnessX = (int)this.m_pItemScrollViewPanel.clipSoftness.x; this.m_nguiContentWidth = GameObject.Find("UI Root").GetComponent().manualWidth; this.m_ajustedNguiContentWidth = this.m_nguiContentWidth - 650; GameObject childObject2 = UTY.GetChildObject(this.m_goPresetButtonPanel, "PresetButtons", false); float x = UTY.GetChildObject(childObject2, "LeftButtons/Pose", false).transform.position.x; float x2 = UTY.GetChildObject(childObject2, "LeftButtons/Clothes", false).transform.position.x; float x3 = UTY.GetChildObject(childObject2, "LeftButtons/BG", false).transform.position.x; this.dicBtnPosX = new Dictionary { { "Pose", x }, { "Clothes", x2 }, { "BG", x3 } }; this.m_goItemSpriteBtn = (Resources.Load("SceneEdit/PresetButton/Prefabs/ItemSpritePresetButton") as GameObject); this.m_goItemTxtrBtn = (Resources.Load("SceneEdit/PresetButton/Prefabs/ItemTxtrPresetButton") as GameObject); this.m_spItemIcon = this.m_goItemSpriteBtn.GetComponent(); if (this.m_goSceneVRTouch == null) { this.m_goSceneVRTouch = GameObject.Find("_SceneVRTouch_"); } this.m_sceneVRTouch = this.m_goSceneVRTouch.GetComponent(); this.m_goItemPresetsViewer.SetActive(false); } public void CreateItemPresetsViewer(string type, string clickBtnName, string prevActiveBtnName) { if (!string.IsNullOrEmpty(this.last_draw_type_)) { if (this.last_draw_type_ == PresetButtonMgr.ItemTypes.Pose.ToString()) { this.backup_pose_scroll_pos_ = this.m_sbScrollBar.value; } else if (this.last_draw_type_ == PresetButtonMgr.ItemTypes.BG.ToString()) { this.backup_bg_scroll_pos_ = this.m_sbScrollBar.value; } } this.m_dicItem = new Dictionary(); if (type == "PresetButtons" && clickBtnName == PresetButtonMgr.ItemTypes.Pose.ToString()) { this.m_dicItem = this.LoadItemData(clickBtnName); } else if (type == "PresetButtons" && clickBtnName == PresetButtonMgr.ItemTypes.Clothes.ToString()) { this.m_dicItem = this.LoadClothesData(); } else if (!(type == "PresetButtons") || !(clickBtnName == PresetButtonMgr.ItemTypes.PriSave.ToString())) { if (!(type == "PresetButtons") || !(clickBtnName == PresetButtonMgr.ItemTypes.Voice.ToString())) { if (type == "PresetButtons" && clickBtnName == PresetButtonMgr.ItemTypes.BG.ToString()) { this.m_dicItem = this.LoadItemData(clickBtnName); } } } this.last_draw_type_ = clickBtnName; List list = new List(); foreach (KeyValuePair keyValuePair in this.m_dicItem) { if (keyValuePair.Key.StartsWith(clickBtnName)) { list.Add(keyValuePair.Value); } } if (list.Count == 0 && clickBtnName != "View") { Debug.LogError(string.Format("アイテムビューワに表示するアイテムが存在しません。押下されたボタン={0}", clickBtnName)); return; } this.LoadItemBtn(list, clickBtnName); this.initItemBtnList(list); this.AdjustItemPresets(type, clickBtnName, prevActiveBtnName); if (type == "PresetButtons" && clickBtnName == PresetButtonMgr.ItemTypes.Pose.ToString()) { this.m_sbScrollBar.value = this.backup_pose_scroll_pos_; } else if (type == "PresetButtons" && clickBtnName == PresetButtonMgr.ItemTypes.BG.ToString()) { this.m_sbScrollBar.value = this.backup_bg_scroll_pos_; } } private void initBtnList(string btnType, string btnName) { string text = null; bool flag = false; VRTouchButtonCtrl.PresetButton presetButton = new VRTouchButtonCtrl.PresetButton(); if (btnType == "LeftButtons" || btnType == "RightButtons") { text = "PresetButtons/" + btnType + "/" + btnName; flag = true; } else if (btnType == "itemPresetButtons") { text = "ItemPresetsViewer/Scroll View/Grid/" + btnName; flag = false; } UIButton component = UTY.GetChildObject(this.m_goPresetButtonPanel, text, false).GetComponent(); GameObject childObject = UTY.GetChildObject(this.m_goPresetButtonPanel, text + "/SelectCursor", false); childObject.SetActive(false); if (flag && btnName != "View") { GameObject childObject2 = UTY.GetChildObject(this.m_goPresetButtonPanel, text + "/WindowArrow", false); childObject2.SetActive(false); presetButton.m_goWindowArrow = childObject2; } presetButton.m_btnButton = component; presetButton.m_name = btnName; presetButton.m_goSelectCursor = childObject; if (btnType == "LeftButtons" || btnType == "RightButtons") { this.m_listPresetBtn.Add(presetButton.m_name, presetButton); } else if (btnType == "itemPresetButtons") { this.m_listItemPresetBtn[presetButton.m_name] = presetButton; } } private void LoadItemBtn(List listItemPreset, string clickBtnName) { if (clickBtnName == PresetButtonMgr.ItemTypes.Pose.ToString() || clickBtnName == PresetButtonMgr.ItemTypes.Voice.ToString() || clickBtnName == PresetButtonMgr.ItemTypes.BG.ToString()) { this.m_goItemBtn = this.m_goItemTxtrBtn; } else if (clickBtnName == PresetButtonMgr.ItemTypes.Clothes.ToString() || clickBtnName == PresetButtonMgr.ItemTypes.PriSave.ToString()) { this.m_goItemBtn = this.m_goItemSpriteBtn; } IEnumerator enumerator = this.m_goParentItemBtn.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; UnityEngine.Object.Destroy(transform.gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.m_goParentItemBtn.transform.DetachChildren(); this.m_listItemPresetBtn.Clear(); foreach (VRTouchButtonCtrl.ItemPreset itemPreset in listItemPreset) { GameObject gameObject = UnityEngine.Object.Instantiate(this.m_goItemBtn); switch (itemPreset.m_itemType) { case PresetButtonMgr.ItemTypes.Pose: case PresetButtonMgr.ItemTypes.Voice: case PresetButtonMgr.ItemTypes.BG: { UITexture component = gameObject.GetComponent(); component.mainTexture = itemPreset.m_txtItemIcon; this.m_currentItemIconWidth = component.width; break; } case PresetButtonMgr.ItemTypes.Clothes: case PresetButtonMgr.ItemTypes.PriSave: { UISprite component2 = gameObject.GetComponent(); string b = null; if (itemPreset.m_atlasName != b) { component2.atlas = Resources.Load(itemPreset.m_atlasName); b = itemPreset.m_atlasName; } component2.spriteName = itemPreset.m_spriteName; this.m_currentItemIconWidth = component2.width; break; } } gameObject.transform.name = itemPreset.m_name; gameObject.transform.parent = this.m_goParentItemBtn.transform; gameObject.transform.localScale = Vector3.one; gameObject.transform.localPosition = Vector3.zero; gameObject.transform.rotation = Quaternion.identity; switch (itemPreset.m_itemType) { case PresetButtonMgr.ItemTypes.Pose: { UIButton component3 = gameObject.GetComponent(); EventDelegate.Add(component3.onClick, new EventDelegate.Callback(this.ClickPose)); break; } case PresetButtonMgr.ItemTypes.Clothes: { UIButton component3 = gameObject.GetComponent(); EventDelegate.Add(component3.onClick, new EventDelegate.Callback(this.ClickClothes)); break; } case PresetButtonMgr.ItemTypes.PriSave: { UIButton component3 = gameObject.GetComponent(); EventDelegate.Add(component3.onClick, new EventDelegate.Callback(this.PresetSave)); break; } case PresetButtonMgr.ItemTypes.Voice: { UIButton component3 = gameObject.GetComponent(); EventDelegate.Add(component3.onClick, new EventDelegate.Callback(this.ClickVoice)); break; } case PresetButtonMgr.ItemTypes.BG: { UIButton component3 = gameObject.GetComponent(); EventDelegate.Add(component3.onClick, new EventDelegate.Callback(this.ClickBG)); break; } } } } private void initItemBtnList(List listItemPreset) { foreach (VRTouchButtonCtrl.ItemPreset itemPreset in listItemPreset) { this.initBtnList("itemPresetButtons", itemPreset.m_name); } } public void AdjustItemPresets(string type, string clickBtnName, string prevActiveBtnName) { VRTouchButtonCtrl.PresetButton btn = new VRTouchButtonCtrl.PresetButton(); VRTouchButtonCtrl.PresetButton btn2 = new VRTouchButtonCtrl.PresetButton(); if (type == "PresetButtons") { btn = this.m_listPresetBtn[clickBtnName]; if (prevActiveBtnName != null) { btn2 = this.m_listPresetBtn[prevActiveBtnName]; } } else if (type == "ItemPresetsViewer") { btn = this.m_listItemPresetBtn[clickBtnName]; if (prevActiveBtnName != null) { btn2 = this.m_listItemPresetBtn[prevActiveBtnName]; } } this.SetActiveBtn(btn, true); if (prevActiveBtnName != null) { this.SetActiveBtn(btn2, false); } if (type == "PresetButtons") { this.AdjustScrollViewWidth(); this.m_goItemPresetsViewer.transform.position = new Vector2(this.dicBtnPosX[clickBtnName], this.m_goItemPresetsViewer.transform.position.y); float num = -this.m_goItemPresetsViewer.transform.localPosition.x + (float)(this.m_spScrollViewBG.width / 2) - (float)(this.m_nguiContentWidth / 2); if (num > 0f) { this.m_goItemPresetsViewer.transform.localPosition = new Vector2(this.m_goItemPresetsViewer.transform.localPosition.x + num, this.m_goItemPresetsViewer.transform.localPosition.y); } this.m_goItemPresetsViewer.SetActive(true); this.m_goParentItemBtn.GetComponent().Reposition(); this.AdjustScrollViewItemPos(); if (this.m_scrollViewWidthOver) { this.m_sbScrollBar.value = 0f; } } } private void AdjustScrollViewItemPos() { UIScrollView component = this.m_goItemScrollView.GetComponent(); component.ResetPosition(); } public void SetDefaultScrollBarPos() { this.m_sbScrollBar.value = 0f; } private void AdjustScrollViewWidth() { this.m_scrollViewWidthOver = false; int num = (this.m_currentItemIconWidth + this.itemIconOffsetX) * this.m_listItemPresetBtn.Count + this.m_scrollViewSoftnessX; if (num > this.m_maxScrollViewWidth) { num = this.m_maxScrollViewWidth; this.m_scrollViewWidthOver = true; } this.m_scrollViewSize.z = (float)num; this.m_pItemScrollViewPanel.baseClipRegion = this.m_scrollViewSize; int num2 = this.m_currentItemIconWidth * 3; int num3 = num2 + num; if (num3 > this.m_ajustedNguiContentWidth) { num3 = this.m_ajustedNguiContentWidth; } this.m_spScrollViewBG.width = num3; UIGrid component = this.m_goParentItemBtn.GetComponent(); component.cellWidth = (float)(this.m_currentItemIconWidth + this.itemIconOffsetX); } private void SetActiveBtn(VRTouchButtonCtrl.PresetButton btn, bool active) { if (Enum.IsDefined(typeof(PresetButtonMgr.ItemTypes), btn.m_name)) { btn.m_goSelectCursor.SetActive(active); if (btn.m_goWindowArrow != null) { btn.m_goWindowArrow.SetActive(active); } if (active) { btn.m_btnButton.defaultColor = this.activeColor; } else { btn.m_btnButton.defaultColor = this.inActiveColor; } } } public void SetActiveBtn(string btnName, bool active) { VRTouchButtonCtrl.PresetButton btn = this.m_listPresetBtn[btnName]; this.SetActiveBtn(btn, active); } private Dictionary LoadClothesData() { Dictionary dictionary = new Dictionary(); VRTouchButtonCtrl.ItemPreset itemPreset = new VRTouchButtonCtrl.ItemPreset(); itemPreset.m_name = VRTouchButtonCtrl.ClothesButton.Clothes_Dress.ToString(); itemPreset.m_atlasName = "SceneEdit/Preset/Atlas/AtlasPreset"; itemPreset.m_spriteName = "cm3d2_edit_clothesicon_dress"; itemPreset.m_spItemIcon = this.m_spItemIcon; itemPreset.m_itemType = PresetButtonMgr.ItemTypes.Clothes; dictionary.Add(itemPreset.m_name, itemPreset); itemPreset = new VRTouchButtonCtrl.ItemPreset(); itemPreset.m_name = VRTouchButtonCtrl.ClothesButton.Clothes_Lingerie.ToString(); itemPreset.m_atlasName = "SceneEdit/Preset/Atlas/AtlasPreset"; itemPreset.m_spriteName = "cm3d2_edit_clothesicon_lingerie"; itemPreset.m_spItemIcon = this.m_spItemIcon; itemPreset.m_itemType = PresetButtonMgr.ItemTypes.Clothes; dictionary.Add(itemPreset.m_name, itemPreset); itemPreset = new VRTouchButtonCtrl.ItemPreset(); itemPreset.m_name = VRTouchButtonCtrl.ClothesButton.Clothes_Nude.ToString(); itemPreset.m_atlasName = "SceneEdit/Preset/Atlas/AtlasPreset"; itemPreset.m_spriteName = "cm3d2_edit_clothesicon_nude"; itemPreset.m_spItemIcon = this.m_spItemIcon; itemPreset.m_itemType = PresetButtonMgr.ItemTypes.Clothes; dictionary.Add(itemPreset.m_name, itemPreset); return dictionary; } private Dictionary LoadItemData(string clickBtnName) { Dictionary dictionary = new Dictionary(); Personal.Data personal = this.m_maid.status.personal; SceneEdit.PVBInfo[] array = null; if (clickBtnName == PresetButtonMgr.ItemTypes.Pose.ToString()) { array = this.m_sceneVRTouch.m_listPose.ToArray(); } else if (!(clickBtnName == PresetButtonMgr.ItemTypes.Voice.ToString())) { if (clickBtnName == PresetButtonMgr.ItemTypes.BG.ToString()) { array = this.m_sceneVRTouch.m_listBg.ToArray(); } } int num = 0; foreach (SceneEdit.PVBInfo pvbinfo in array) { VRTouchButtonCtrl.ItemPreset itemPreset = new VRTouchButtonCtrl.ItemPreset(); itemPreset.m_name = clickBtnName + "_" + num; itemPreset.m_itemType = (PresetButtonMgr.ItemTypes)Enum.Parse(typeof(PresetButtonMgr.ItemTypes), clickBtnName); itemPreset.m_pvbInfo = pvbinfo; itemPreset.m_txtItemIcon = pvbinfo.texIcon; dictionary.Add(itemPreset.m_name, itemPreset); num++; } return dictionary; } private void PresetSave() { string name = UIButton.current.name; PresetMgr.Filter filter = PresetMgr.Filter.None; if (name == VRTouchButtonCtrl.PriSaveButton.PriSave_WearAndBody.ToString()) { Debug.Log("「服/体」が押下されました"); GameMain.Instance.CharacterMgr.PresetSave(this.m_maid, CharacterMgr.PresetType.All); filter = PresetMgr.Filter.All; } else if (name == VRTouchButtonCtrl.PriSaveButton.PriSave_Wear.ToString()) { Debug.Log("「服」が押下されました"); GameMain.Instance.CharacterMgr.PresetSave(this.m_maid, CharacterMgr.PresetType.Wear); filter = PresetMgr.Filter.Wear; } else if (name == VRTouchButtonCtrl.PriSaveButton.PriSave_Body.ToString()) { Debug.Log("「体」が押下されました"); GameMain.Instance.CharacterMgr.PresetSave(this.m_maid, CharacterMgr.PresetType.Body); filter = PresetMgr.Filter.Body; } else { Debug.LogError(string.Format("不適切なボタンが押下されました。ボタン名={0}", name)); } if (this.isActivePresetPanel()) { float scrollBarValue = BaseMgr.Instance.GetScrollBarValue(); BaseMgr.Instance.UpdatePresetList(); Debug.Log("Call UpdatePresetList"); if (PresetMgr.m_currentActiveFilterBtnName != PresetMgr.Filter.None) { BaseMgr.Instance.UpdateFilterPreset(PresetMgr.m_currentActiveFilterBtnName); Debug.Log("Call UpdateFilterPreset"); if (PresetMgr.m_currentActiveFilterBtnName != PresetMgr.Filter.NotFilter && PresetMgr.m_currentActiveFilterBtnName != filter) { BaseMgr.Instance.SetScrollBar(scrollBarValue); } } } } private bool isActivePresetPanel() { GameObject gameObject = GameObject.Find("/UI Root"); GameObject gameObject2 = gameObject.transform.Find("PresetPanel").gameObject; return gameObject2.activeSelf; } private void ClickClothes() { string name = UIButton.current.name; this.ClickClothesByButtonName(name); } public void ClickClothesByButtonName(string clickBtnName) { if (clickBtnName == "Clothes_Nude") { this.m_sceneVRTouch.ClothesState(SceneEditInfo.ClothesState.Nude); } else if (clickBtnName == "Clothes_Dress") { this.m_sceneVRTouch.ClothesState(SceneEditInfo.ClothesState.Wear); } else if (clickBtnName == "Clothes_Lingerie") { this.m_sceneVRTouch.ClothesState(SceneEditInfo.ClothesState.Underwear); } Debug.Log(string.Format("{0}が押下(実行)されました。", clickBtnName)); } private void ClickBG() { string name = UIButton.current.name; VRTouchButtonCtrl.ItemPreset itemPreset; if (this.m_dicItem.TryGetValue(name, out itemPreset)) { this.m_sceneVRTouch.Bg(itemPreset.m_pvbInfo); Debug.Log(string.Format("{0}が押下されました。", name)); } else { Debug.LogError(string.Format("不適切なボタンが押下されました。ボタン名={0}", name)); } } private void ClickVoice() { string name = UIButton.current.name; VRTouchButtonCtrl.ItemPreset itemPreset; if (this.m_dicItem.TryGetValue(name, out itemPreset)) { Debug.Log(string.Format("{0}が押下されました。", name)); } else { Debug.LogError(string.Format("不適切なボタンが押下されました。ボタン名={0}", name)); } } private void ClickPose() { string name = UIButton.current.name; VRTouchButtonCtrl.ItemPreset itemPreset; if (this.m_dicItem.TryGetValue(name, out itemPreset)) { this.m_sceneVRTouch.Pose(itemPreset.m_pvbInfo); Debug.Log(string.Format("{0}が押下されました。", name)); } else { Debug.LogError(string.Format("不適切なボタンが押下されました。ボタン名={0}", name)); } } public GameObject m_goSceneVRTouch; [SerializeField] private int itemIconOffsetX = 15; private Maid m_maid; private SceneVRTouch m_sceneVRTouch; private Dictionary m_listPresetBtn; private Dictionary m_listItemPresetBtn; private Dictionary m_dicItem; private GameObject m_goPresetButtonPanel; private GameObject m_goItemBtn; private GameObject m_goItemPresetsViewer; private GameObject m_goItemScrollView; private GameObject m_goParentItemBtn; private UISprite m_spItemIcon; private UISprite m_spScrollViewBG; private UIPanel m_pItemScrollViewPanel; private UIScrollBar m_sbScrollBar; private bool m_scrollViewWidthOver; private GameObject m_goItemSpriteBtn; private GameObject m_goItemTxtrBtn; private Color activeColor; private Color inActiveColor; private int m_currentItemIconWidth; private Vector4 m_scrollViewSize; private int m_maxScrollViewWidth; private int m_scrollViewSoftnessX; private int m_ajustedNguiContentWidth; private int m_nguiContentWidth; private Dictionary dicBtnPosX; private const string ITEM_SPRITE_PRESET_BUTTON_PATH = "SceneEdit/PresetButton/Prefabs/ItemSpritePresetButton"; private const string ITEM_TXTR_PRESET_BUTTON_PATH = "SceneEdit/PresetButton/Prefabs/ItemTxtrPresetButton"; private const string ATLAS_PRESET = "SceneEdit/Preset/Atlas/AtlasPreset"; private const string PRISAVE_CLOTHES_BODY_SPRITE_NAME = "cm3d2_edit_priset_buttom_clothes_body"; private const string PRISAVE_CLOTHES_SPRITE_NAME = "cm3d2_edit_priset_buttom_clothes"; private const string PRISAVE_BODY_SPRITE_NAME = "cm3d2_edit_preset_buttom_body"; private const string CLOTHES_NUDE_SPRITE_NAME = "cm3d2_edit_clothesicon_nude"; private const string CLOTHES_DRESS_SPRITE_NAME = "cm3d2_edit_clothesicon_dress"; private const string CLOTHES_LINGERIE_SPRITE_NAME = "cm3d2_edit_clothesicon_lingerie"; private const int RIGHT_OFFSET = 650; private string last_draw_type_; private float backup_pose_scroll_pos_; private float backup_bg_scroll_pos_; private enum LeftButtons { Pose, Clothes, BG } private enum PriSaveButton { PriSave_Wear, PriSave_Body, PriSave_WearAndBody } private enum ClothesButton { Clothes_Nude, Clothes_Dress, Clothes_Lingerie } private class ItemPreset { public string m_name { get; set; } public PresetButtonMgr.ItemTypes m_itemType { get; set; } public string m_atlasName { get; set; } public string m_spriteName { get; set; } public UISprite m_spItemIcon { get; set; } public SceneEdit.PVBInfo m_pvbInfo { get; set; } public Texture2D m_txtItemIcon { get; set; } } private class PresetButton { public string m_name { get; set; } public UIButton m_btnButton { get; set; } public GameObject m_goSelectCursor { get; set; } public GameObject m_goWindowArrow { get; set; } } }