123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SceneEditWindow
- {
- [AddComponentMenu("SceneEditWindow/CustomPartsWindow")]
- public class CustomPartsWindow : BasePhotoWindow
- {
- public override string windowName
- {
- get
- {
- return "CustomPartsWindow";
- }
- }
- public override void Start()
- {
- base.Start();
- this.subWindowVisibleCheckBox.check = false;
- this.subWindowVisibleCheckBox.onClick.Add(new Action<WFCheckBox>(this.OnClickOpenSubWindow));
- this.checkBoxCustomEnabled.onClick.Add(new Action<WFCheckBox>(this.OnClickCustomEnabled));
- this.subWindowVisibleCheckBox.visible = false;
- this.enabledMpns = new HashSet<MPN>();
- foreach (string value in this.customEnabledMpnNames)
- {
- MPN item = MPN.null_mpn;
- try
- {
- item = (MPN)Enum.Parse(typeof(MPN), value);
- }
- catch (Exception e)
- {
- NDebug.AssertParseError("MPN", e);
- }
- this.enabledMpns.Add(item);
- }
- this.partsIndexTabPanel.UpdateChildren();
- foreach (UIWFTabButton uiwftabButton in this.partsIndexTabPanel.button_list)
- {
- EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnSelectIndexButton));
- }
- this.visibleTabPanel.UpdateChildren();
- foreach (UIWFTabButton uiwftabButton2 in this.visibleTabPanel.button_list)
- {
- EventDelegate.Add(uiwftabButton2.onSelect, new EventDelegate.Callback(this.OnSelectVisibleButton));
- }
- this.visibleTabPanel.Select(this.visibleTabPanel.button_list[0]);
- this.scaleSlider.onChangeValue.Clear();
- this.scaleSlider.onChangeValue.Add(new Action<float>(this.onChangeScaleSlider));
- this.UpdateChildren();
- }
- public void Initizalize(Maid maid)
- {
- if (maid == null || maid.body0 == null || maid.body0.m_Bones == null)
- {
- NDebug.Assert("メイドのボディ読み込みが終了していないのにInitizalizeが呼ばれています", false);
- return;
- }
- this.subWindowVisibleCheckBox.check = false;
- this.maid = maid;
- this.animation = maid.body0.m_Bones.GetComponent<Animation>();
- this.visible = false;
- }
- private void OnDestroy()
- {
- GameObject worldTransformAxisParent = PhotoWindowManager.GetWorldTransformAxisParent();
- if (worldTransformAxisParent != null)
- {
- UnityEngine.Object.DestroyImmediate(worldTransformAxisParent);
- }
- }
- public void DestroySelectCustomParts()
- {
- if (this.selectCustomParts == null)
- {
- return;
- }
- foreach (CustomParts customParts in this.selectCustomParts)
- {
- customParts.Destroy();
- }
- this.selectCustomParts = null;
- }
- public bool SetItem(SceneEdit.SMenuItem menuItem)
- {
- this.reseaveLoadMenuItem = null;
- if (menuItem == null || menuItem.m_boDelOnly || !this.enabledMpns.Contains(menuItem.m_mpn))
- {
- return false;
- }
- this.reseaveLoadMenuItem = menuItem;
- return true;
- }
- public void ResetPoint(MPN mpn)
- {
- List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(mpn);
- for (int i = 0; i < attachPointListFromMPN.Count; i++)
- {
- CustomParts customParts = new CustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value);
- customParts.enabled = false;
- }
- }
- public void ResetAllPoint()
- {
- foreach (MPN mpn in this.enabledMpns)
- {
- this.ResetPoint(mpn);
- }
- }
- public new void Update()
- {
- if (this.reseaveLoadMenuItem != null && !GameMain.Instance.CharacterMgr.IsBusy())
- {
- this.CreateItemData(this.reseaveLoadMenuItem);
- this.reseaveLoadMenuItem = null;
- }
- if (this.selectCustomParts == null || this.selectCustomParts.Length == 0 || !this.editMode)
- {
- return;
- }
- foreach (CustomParts customParts in this.selectCustomParts)
- {
- if (customParts.enabled)
- {
- Transform transform = customParts.indirectObject.transform;
- customParts.SetTransformData(transform, true);
- }
- }
- }
- public void UpdateUI()
- {
- if (this.selectCustomParts != null)
- {
- foreach (CustomParts customParts in this.selectCustomParts)
- {
- customParts.tranformAxis.Visible = false;
- customParts.gizmoRender.Visible = false;
- }
- }
- if (!this.editMode)
- {
- return;
- }
- CustomParts customParts2 = this.selectCustomParts[this.selectCustomPartsIndex];
- this.checkBoxCustomEnabled.check = customParts2.enabled;
- Vector3 position;
- Quaternion rotation;
- Vector3 localScale;
- customParts2.GetTransformData(out position, out rotation, out localScale, true);
- customParts2.indirectObject.transform.position = position;
- customParts2.indirectObject.transform.rotation = rotation;
- customParts2.indirectObject.transform.localScale = localScale;
- customParts2.tranformAxis.Visible = (customParts2.enabled && this.axisVisibleButton.isSelected);
- customParts2.gizmoRender.Visible = (customParts2.enabled && this.rotateVisibleButton.isSelected);
- this.scaleSlider.value = customParts2.scale.x;
- this.editToolObject.SetActive(customParts2.enabled);
- }
- public void ViewMode(bool enabled)
- {
- if (this.selectCustomParts == null || this.selectCustomParts.Length == 0 || !this.editMode)
- {
- return;
- }
- if (this.selectCustomParts != null)
- {
- foreach (CustomParts customParts in this.selectCustomParts)
- {
- customParts.tranformAxis.Visible = false;
- customParts.gizmoRender.Visible = false;
- }
- }
- if (enabled)
- {
- return;
- }
- this.UpdateUI();
- }
- public void OnExecItemPrev(SceneEdit.SMenuItem menuItem)
- {
- this.isBackupDatas = null;
- if (this.reseaveLoadMenuItem != null && !GameMain.Instance.CharacterMgr.IsBusy())
- {
- this.CreateItemData(this.reseaveLoadMenuItem);
- this.reseaveLoadMenuItem = null;
- }
- this.DestroySelectCustomParts();
- if (menuItem.m_mpn == MPN.hairf || menuItem.m_mpn == MPN.hairt)
- {
- MPN f_mpn = (menuItem.m_mpn != MPN.hairf) ? MPN.acckamisub : MPN.acckami;
- List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(f_mpn);
- for (int i = 0; i < attachPointListFromMPN.Count; i++)
- {
- new BaseCustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value)
- {
- enabled = false
- }.Reset();
- }
- this.visible = false;
- }
- else if (this.enabledMpns.Contains(menuItem.m_mpn))
- {
- MaidProp prop = this.maid.GetProp(menuItem.m_mpn);
- int nFileNameRID = prop.nFileNameRID;
- bool flag = menuItem.m_nMenuFileRID == nFileNameRID;
- if (menuItem.m_nMenuFileRID != nFileNameRID && !menuItem.m_boDelOnly)
- {
- List<SceneEdit.SMenuItem> list = null;
- if (menuItem.m_bGroupLeader)
- {
- list = menuItem.m_listMember;
- }
- else if (menuItem.m_leaderMenu != null)
- {
- list = menuItem.m_leaderMenu.m_listMember;
- }
- if (list != null)
- {
- foreach (SceneEdit.SMenuItem smenuItem in list)
- {
- if (smenuItem.m_nMenuFileRID == nFileNameRID)
- {
- flag = true;
- break;
- }
- }
- }
- }
- List<CustomParts> list2 = new List<CustomParts>();
- List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN2 = this.maid.body0.GetAttachPointListFromMPN(menuItem.m_mpn);
- for (int j = 0; j < attachPointListFromMPN2.Count; j++)
- {
- list2.Add(new CustomParts(this.maid, attachPointListFromMPN2[j].Key, attachPointListFromMPN2[j].Value));
- }
- if (flag)
- {
- this.isBackupDatas = new bool[list2.Count];
- for (int k = 0; k < list2.Count; k++)
- {
- CustomParts customParts = list2[k];
- this.isBackupDatas[k] = customParts.enabled;
- if (customParts.enabled)
- {
- customParts.SaveBackup();
- }
- }
- }
- foreach (CustomParts customParts2 in list2)
- {
- customParts2.Reset();
- customParts2.enabled = false;
- }
- }
- else
- {
- this.visible = false;
- }
- }
- public void CreateItemData(SceneEdit.SMenuItem menu)
- {
- this.DestroySelectCustomParts();
- this.selectCustomPartsIndex = 0;
- List<KeyValuePair<TBody.SlotID, string>> attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(menu.m_mpn);
- if (attachPointListFromMPN.Count != 0)
- {
- if (Product.isPublic)
- {
- foreach (TBodySkin tbodySkin in this.maid.body0.goSlot)
- {
- if (tbodySkin.m_ParentMPN == menu.m_mpn)
- {
- tbodySkin.Update();
- }
- }
- attachPointListFromMPN = this.maid.body0.GetAttachPointListFromMPN(menu.m_mpn);
- this.selectCustomParts = new CustomParts[attachPointListFromMPN.Count];
- }
- this.selectCustomParts = new CustomParts[attachPointListFromMPN.Count];
- }
- for (int i = 0; i < attachPointListFromMPN.Count; i++)
- {
- CustomParts customParts = new CustomParts(this.maid, attachPointListFromMPN[i].Key, attachPointListFromMPN[i].Value);
- customParts.indirectObject = GameObject.Find(menu.m_nMenuFileRID.ToString() + "_" + i.ToString());
- if (customParts.indirectObject == null)
- {
- customParts.indirectObject = new GameObject();
- customParts.indirectObject.name = menu.m_nMenuFileRID.ToString();
- }
- if (this.isBackupDatas != null && this.isBackupDatas.Length == attachPointListFromMPN.Count && this.isBackupDatas[i])
- {
- customParts.enabled = true;
- customParts.LoadBackup();
- }
- Vector3 position;
- Quaternion rotation;
- Vector3 localScale;
- customParts.GetTransformData(out position, out rotation, out localScale, true);
- customParts.indirectObject.transform.position = position;
- customParts.indirectObject.transform.rotation = rotation;
- customParts.indirectObject.transform.localScale = localScale;
- customParts.menuItem = menu;
- customParts.tranformAxis = PhotoWindowManager.CreateWorldTransformAxis(customParts.indirectObject, false, true);
- customParts.tranformAxis.Visible = false;
- customParts.tranformAxis.ScaleMinMax = new Vector2(this.scaleSlider.MinNum, this.scaleSlider.MaxNum);
- customParts.gizmoRender = PhotoWindowManager.CreateWorldTransformRotate(customParts.indirectObject, false);
- customParts.gizmoRender.offsetScale = 0.4f;
- customParts.gizmoRender.Visible = false;
- this.checkBoxCustomEnabled.check = customParts.enabled;
- this.selectCustomParts[i] = customParts;
- }
- this.isBackupDatas = null;
- }
- public void OnSelectIndexButton()
- {
- if (!UIWFSelectButton.current.isSelected)
- {
- return;
- }
- this.selectCustomPartsIndex = 0;
- UILabel componentInChildren = UIWFSelectButton.current.transform.parent.GetComponentInChildren<UILabel>(true);
- if (componentInChildren == null)
- {
- this.selectCustomPartsIndex = 0;
- }
- else
- {
- this.selectCustomPartsIndex = int.Parse(componentInChildren.text) - 1;
- }
- this.UpdateUI();
- }
- public void OnSelectVisibleButton()
- {
- this.UpdateUI();
- }
- public void onChangeScaleSlider(float value)
- {
- if (!this.editMode || this.selectCustomParts == null || this.selectCustomParts.Length == 0)
- {
- return;
- }
- CustomParts customParts = this.selectCustomParts[this.selectCustomPartsIndex];
- customParts.indirectObject.transform.localScale = new Vector3(value, value, value);
- }
- protected void OnClickOpenSubWindow(WFCheckBox checkBox)
- {
- if (GameMain.Instance.CharacterMgr.IsBusy() || this.selectCustomParts == null || this.selectCustomParts.Length <= 0)
- {
- this.editMode = false;
- return;
- }
- this.editMode = checkBox.check;
- this.partsIndexTabPanel.Select(this.partsIndexTabPanel.button_list[this.selectCustomPartsIndex]);
- for (int i = 0; i < this.partsIndexTabPanel.transform.childCount; i++)
- {
- this.partsIndexTabPanel.transform.GetChild(i).gameObject.SetActive(i < this.selectCustomParts.Length);
- }
- this.OnClickCustomEnabled(this.checkBoxCustomEnabled);
- }
- protected void OnClickCustomEnabled(WFCheckBox checkBox)
- {
- if (!this.editMode)
- {
- return;
- }
- CustomParts customParts = this.selectCustomParts[this.selectCustomPartsIndex];
- customParts.enabled = checkBox.check;
- this.UpdateUI();
- }
- public bool playMaidAnimation
- {
- get
- {
- return !(this.animation == null) && !this.maid.GetLockHeadAndEye();
- }
- set
- {
- if (this.playMaidAnimation == value || this.animation == null)
- {
- return;
- }
- AnimationState animationState = this.animation[this.maid.body0.LastAnimeFN.ToLower()];
- if (animationState == null)
- {
- Debug.LogError(this.maid.body0.LastAnimeFN.ToLower() + "のAnimationStateが見つかりませんでした");
- return;
- }
- animationState.enabled = value;
- this.maid.LockHeadAndEye(!value);
- if (GameMain.Instance.VRMode)
- {
- if (GameMain.Instance.OvrMgr.ovr_obj.left_controller != null && GameMain.Instance.OvrMgr.ovr_obj.left_controller.grip_collider != null)
- {
- GameMain.Instance.OvrMgr.ovr_obj.left_controller.grip_collider.ResetGrip();
- }
- if (GameMain.Instance.OvrMgr.ovr_obj.right_controller != null && GameMain.Instance.OvrMgr.ovr_obj.right_controller.grip_collider != null)
- {
- GameMain.Instance.OvrMgr.ovr_obj.right_controller.grip_collider.ResetGrip();
- }
- MaidColliderCollect component = this.maid.GetComponent<MaidColliderCollect>();
- if (component != null)
- {
- List<CapsuleCollider> collider = component.GetCollider(MaidColliderCollect.ColliderType.Grab);
- foreach (CapsuleCollider capsuleCollider in collider)
- {
- capsuleCollider.gameObject.SetActive(value);
- }
- }
- }
- }
- }
- public override bool visible
- {
- get
- {
- return base.visible;
- }
- set
- {
- base.visible = value;
- this.subWindowVisibleCheckBox.check = value;
- this.OnClickOpenSubWindow(this.subWindowVisibleCheckBox);
- }
- }
- public bool editMode
- {
- get
- {
- return this.subWindowVisibleCheckBox.check;
- }
- set
- {
- if (this.selectCustomParts == null)
- {
- value = false;
- }
- this.subWindowVisibleCheckBox.check = value;
- this.playMaidAnimation = !value;
- if (this.selectCustomParts != null && this.selectCustomParts.Length != 0)
- {
- this.UpdateUI();
- }
- }
- }
- [SerializeField]
- private WFCheckBox subWindowVisibleCheckBox;
- [SerializeField]
- private WFCheckBox checkBoxCustomEnabled;
- [SerializeField]
- private GameObject editToolObject;
- [SerializeField]
- private UIWFTabPanel partsIndexTabPanel;
- [SerializeField]
- private UIWFTabPanel visibleTabPanel;
- [SerializeField]
- private UIWFTabButton axisVisibleButton;
- [SerializeField]
- private UIWFTabButton rotateVisibleButton;
- [SerializeField]
- private PhotoSliderAndInput scaleSlider;
- [SerializeField]
- private string[] customEnabledMpnNames;
- private Maid maid;
- private Animation animation;
- private SceneEdit.SMenuItem reseaveLoadMenuItem;
- private bool[] isBackupDatas;
- private CustomParts[] selectCustomParts;
- private int selectCustomPartsIndex;
- private HashSet<MPN> enabledMpns;
- }
- }
|