123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using I2.Loc;
- using UnityEngine;
- using wf;
- public class ObjectCreateWindow : BaseMaidPhotoWindow
- {
- public static string folder_path
- {
- get
- {
- string text = PhotoWindowManager.path_photo_folder + "MyObject";
- if (!Directory.Exists(text))
- {
- Directory.CreateDirectory(text);
- }
- return text;
- }
- }
- public bool visibleTextureSelectWindow
- {
- get
- {
- return this.textureSelectSubtWindow.visible;
- }
- set
- {
- this.textureSelectSubtWindow.visible = value;
- }
- }
- public override void Awake()
- {
- base.Awake();
- EventDelegate.Add(this.selectTextureButton.onClick, new EventDelegate.Callback(this.OnClickSelectTextureButton));
- if (this.typeSelectPopupList != null)
- {
- EventDelegate.Add(this.typeSelectPopupList.onChange, delegate()
- {
- if (this.selectData == this.target_list_[0])
- {
- GameObject parent = GameObject.Find("CustomObjectPrev");
- GameObject gameObject3 = null;
- if (UIPopupList.current.value.IndexOf("プレーン") != -1 && this.selectData.customObject.type != BasePhotoCustomObject.Type.Plane)
- {
- gameObject3 = Utility.CreatePrefab(parent, "ScenePhotoMode/CustomObject/Plane", false);
- }
- else if (UIPopupList.current.value.IndexOf("スフィア") != -1 && this.selectData.customObject.type != BasePhotoCustomObject.Type.Sphere)
- {
- gameObject3 = Utility.CreatePrefab(parent, "ScenePhotoMode/CustomObject/Sphere", false);
- }
- if (gameObject3 != null)
- {
- int key = -1;
- foreach (KeyValuePair<int, BasePhotoCustomObject> keyValuePair in this.buttonDic)
- {
- if (keyValuePair.Value == this.selectData.customObject)
- {
- key = keyValuePair.Key;
- break;
- }
- }
- BasePhotoCustomObject component3 = gameObject3.GetComponent<BasePhotoCustomObject>();
- ObjectCreateWindow.Data value = new ObjectCreateWindow.Data(component3);
- this.target_list_[0] = value;
- this.buttonDic[key] = component3;
- UnityEngine.Object.DestroyImmediate(this.selectData.customObject.gameObject);
- this.selectData = null;
- this.selectData = value;
- this.UpdateObjectEditUI(this.selectData);
- }
- }
- });
- }
- this.editScaleSlider.ResetValue();
- this.editScaleSlider.onChangeValue.Add(delegate(float val)
- {
- if (this.selectData != null)
- {
- this.selectData.customObject.scale = val;
- }
- });
- this.texColorPalette.onChangeValue.Add(delegate(WindowPartsInputColorrPalette colorInputs, Color setColor)
- {
- if (this.selectData != null)
- {
- this.selectData.customObject.textureColor = setColor;
- }
- });
- EventDelegate.Add(this.planeBackDrawPopupList.onChange, delegate()
- {
- if (this.selectData != null && this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
- {
- PhotoCustomObjectPlane.BackRenderingType backRenderingType = PhotoCustomObjectPlane.BackRenderingType.Mirror;
- if (UIPopupList.current.value.IndexOf("反転") == 0)
- {
- backRenderingType = PhotoCustomObjectPlane.BackRenderingType.Flip;
- }
- else if (UIPopupList.current.value.IndexOf("透明") == 0)
- {
- backRenderingType = PhotoCustomObjectPlane.BackRenderingType.None;
- }
- (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType = backRenderingType;
- }
- });
- EventDelegate.Add(this.sphereBackDrawPopupList.onChange, delegate()
- {
- if (this.selectData != null && this.selectData.customObject.type == BasePhotoCustomObject.Type.Sphere)
- {
- PhotoCustomObjectSphere.RenderingType renderingType = PhotoCustomObjectSphere.RenderingType.TwoSides;
- if (UIPopupList.current.value.IndexOf("表面表示") == 0)
- {
- renderingType = PhotoCustomObjectSphere.RenderingType.Front;
- }
- else if (UIPopupList.current.value.IndexOf("裏面表示") == 0)
- {
- renderingType = PhotoCustomObjectSphere.RenderingType.Back;
- }
- (this.selectData.customObject as PhotoCustomObjectSphere).renderingType = renderingType;
- }
- });
- this.camera_move_support_ = base.gameObject.AddComponent<WfCameraMoveSupport>();
- this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.objectListGrid.transform);
- EventDelegate.Add(this.saveButton.onClick, new EventDelegate.Callback(this.OnClickSave));
- EventDelegate.Add(this.textureRestoreButton.onClick, new EventDelegate.Callback(this.OnClickTextureRestore));
- this.CheckPrevVisible.check = false;
- this.CheckPrevVisible.onClick.Add(delegate(WFCheckBox check_box)
- {
- if (this.selectData != null)
- {
- this.selectData.customObject.visible = check_box.check;
- }
- });
- this.textureSelectSubtWindow.GetButtonOnClickEventList(BasePhotoSubWindow.BtnType.End).Add(delegate
- {
- this.visibleTextureSelectWindow = false;
- });
- this.textureSelectSubtWindow.SetButtonEnabled(BasePhotoSubWindow.BtnType.End, true, false);
- GameObject gameObject = GameObject.Find("CustomObjectPrev");
- if (gameObject == null)
- {
- gameObject = new GameObject("CustomObjectPrev");
- }
- gameObject.transform.localPosition = new Vector3(0f, 1.5f, -0.8f);
- GameObject gameObject2 = Utility.CreatePrefab(gameObject, "ScenePhotoMode/CustomObject/Plane", false);
- BasePhotoCustomObject component = gameObject2.GetComponent<BasePhotoCustomObject>();
- this.target_list_.Add(new ObjectCreateWindow.Data(component));
- UIWFTabButton uiwftabButton = this.CreateTabButton(this.objectListGrid.gameObject, component, "新規オブジェクト");
- Localize componentInChildren = uiwftabButton.GetComponentInChildren<Localize>();
- if (componentInChildren != null)
- {
- componentInChildren.SetTerm("ScenePhotoMode/マイオブジェ/新規オブジェクト");
- }
- Action<string, List<string>> action = delegate(string path, List<string> result_list)
- {
- string[] files = Directory.GetFiles(path);
- for (int i = 0; i < files.Length; i++)
- {
- if (Path.GetExtension(files[i]) == ".poj")
- {
- result_list.Add(files[i]);
- }
- }
- };
- List<string> list = new List<string>();
- action(ObjectCreateWindow.folder_path, list);
- foreach (string text in list)
- {
- BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(gameObject, text);
- if (!(basePhotoCustomObject == null))
- {
- this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, text));
- this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, text);
- }
- }
- foreach (ObjectCreateWindow.Data data in this.target_list_)
- {
- data.customObject.visible = false;
- }
- UIWFTabPanel component2 = this.objectListGrid.GetComponent<UIWFTabPanel>();
- component2.UpdateChildren();
- component2.Select(this.objectListGrid.GetChild(0).gameObject.GetComponent<UIWFTabButton>());
- Utility.ResetNGUI(this.objectListGrid);
- Utility.ResetNGUI(this.scroll_view_);
- this.UpdateChildren();
- }
- public override void Start()
- {
- base.Start();
- this.visibleTextureSelectWindow = false;
- }
- private void OnDestroy()
- {
- }
- public void OnClickSelectTextureButton()
- {
- this.visibleTextureSelectWindow = !this.visibleTextureSelectWindow;
- }
- public void OnChangeSelectTexture(string pngPath)
- {
- this.textureExpTextObject.SetActive(false);
- if (!string.IsNullOrEmpty(this.selectData.fullPath) && this.selectData.backupPng == null)
- {
- byte[] imageBinarys = this.selectData.customObject.imageBinarys;
- this.selectData.backupPng = new byte[imageBinarys.Length];
- Array.Copy(imageBinarys, this.selectData.backupPng, imageBinarys.Length);
- this.textureRestoreButton.isEnabled = true;
- }
- this.selectData.customObject.SetTexture(pngPath);
- UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
- Sprite sprite2D = Sprite.Create(this.selectData.customObject.mainTexture, new Rect(0f, 0f, (float)this.selectData.customObject.mainTexture.width, (float)this.selectData.customObject.mainTexture.height), default(Vector2));
- componentInChildren.sprite2D = sprite2D;
- }
- private void UpdateObjectEditUI(ObjectCreateWindow.Data targetData)
- {
- if (targetData == null)
- {
- return;
- }
- if (this.typeSelectPopupList != null)
- {
- this.typeSelectPopupList.value = ((targetData.customObject.type != BasePhotoCustomObject.Type.Plane) ? "スフィア" : "プレーン");
- this.typeSelectPopupList.GetComponent<UIButton>().isEnabled = (targetData == this.target_list_[0]);
- }
- UILabel componentInChildren = this.saveButton.GetComponentInChildren<UILabel>();
- Localize component = componentInChildren.GetComponent<Localize>();
- if (!string.IsNullOrEmpty(targetData.fullPath))
- {
- componentInChildren.text = "更新";
- if (component != null)
- {
- component.SetTerm("ScenePhotoMode/マイオブジェ/更新");
- }
- this.textureExpTextObject.SetActive(false);
- }
- else
- {
- componentInChildren.text = "保存";
- if (component != null)
- {
- component.SetTerm("ScenePhotoMode/マイオブジェ/保存");
- }
- if (targetData.customObject.mainTexture != null)
- {
- this.textureExpTextObject.SetActive(false);
- }
- else
- {
- this.textureExpTextObject.SetActive(true);
- }
- }
- this.textureRestoreButton.gameObject.SetActive(!string.IsNullOrEmpty(targetData.fullPath));
- this.textureRestoreButton.isEnabled = (targetData.backupPng != null);
- foreach (ObjectCreateWindow.Data data in this.target_list_)
- {
- data.customObject.visible = (data == targetData && this.CheckPrevVisible.check);
- }
- BasePhotoCustomObject customObject = targetData.customObject;
- UI2DSprite componentInChildren2 = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
- if (customObject.mainTexture != null)
- {
- Sprite sprite2D = Sprite.Create(customObject.mainTexture, new Rect(0f, 0f, (float)customObject.mainTexture.width, (float)customObject.mainTexture.height), default(Vector2));
- componentInChildren2.sprite2D = sprite2D;
- }
- else
- {
- componentInChildren2.sprite2D = null;
- }
- this.editScaleSlider.value = customObject.scale;
- this.texColorPalette.ColorPalette.SetColor(customObject.textureColor);
- this.texColorPalette.ColorPalette.UIUpdate();
- this.planeUIParent.SetActive(false);
- this.sphereUIParent.SetActive(false);
- if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
- {
- this.planeUIParent.SetActive(true);
- PhotoCustomObjectPlane.BackRenderingType backRenderingType = (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType;
- this.planeBackDrawPopupList.value = ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.Flip) ? ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.None) ? "鏡合わせ" : "透明") : "反転");
- }
- else if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Sphere)
- {
- this.sphereUIParent.SetActive(true);
- PhotoCustomObjectSphere.RenderingType renderingType = (this.selectData.customObject as PhotoCustomObjectSphere).renderingType;
- this.sphereBackDrawPopupList.value = ((renderingType != PhotoCustomObjectSphere.RenderingType.TwoSides) ? ((renderingType != PhotoCustomObjectSphere.RenderingType.Front) ? "裏面表示" : "表面表示") : "両面表示");
- }
- }
- public void OnSelectItem(BasePhotoCustomObject select)
- {
- foreach (ObjectCreateWindow.Data data in this.target_list_)
- {
- if (data.customObject == select)
- {
- this.selectData = data;
- this.UpdateObjectEditUI(this.selectData);
- break;
- }
- }
- }
- public void OnClickTextureRestore()
- {
- if (this.selectData == null || this.selectData.backupPng == null)
- {
- return;
- }
- this.selectData.customObject.SetTexture(this.selectData.backupPng);
- UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
- Sprite sprite2D = Sprite.Create(this.selectData.customObject.mainTexture, new Rect(0f, 0f, (float)this.selectData.customObject.mainTexture.width, (float)this.selectData.customObject.mainTexture.height), default(Vector2));
- componentInChildren.sprite2D = sprite2D;
- this.textureRestoreButton.isEnabled = false;
- this.selectData.backupPng = null;
- }
- public void OnClickSave()
- {
- if (this.selectData == null)
- {
- return;
- }
- if (this.selectData.customObject.mainTexture == null)
- {
- GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/マイオブジェ/ダイアログ/テクスチャが未設定です", null, SystemDialog.TYPE.OK, null, null);
- return;
- }
- if (string.IsNullOrEmpty(this.selectData.fullPath))
- {
- this.savePanel.Open(this.selectData.customObject, delegate(string filePath)
- {
- GameObject parent = GameObject.Find("CustomObjectPrev");
- BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(parent, filePath);
- if (basePhotoCustomObject == null)
- {
- return;
- }
- this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, filePath));
- this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, filePath);
- this.objectListGrid.GetComponent<UIWFTabPanel>().UpdateChildren();
- Utility.ResetNGUI(this.objectListGrid);
- Utility.ResetNGUI(this.scroll_view_);
- this.UpdateChildren();
- ObjectManagerWindow objectManagerWindow2 = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
- objectManagerWindow2.createBgObjectWindow.AddMyObject(filePath);
- });
- }
- else
- {
- if (File.Exists(this.selectData.fullPath))
- {
- File.Delete(this.selectData.fullPath);
- }
- try
- {
- File.WriteAllBytes(this.selectData.fullPath, this.selectData.customObject.Serialize());
- ObjectManagerWindow objectManagerWindow = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
- objectManagerWindow.createBgObjectWindow.UpdateMyObject(this.selectData.fullPath);
- }
- catch
- {
- GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/マイオブジェ/ダイアログ/オブジェクトの保存に失敗しました", null, SystemDialog.TYPE.OK, null, null);
- }
- }
- }
- public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
- {
- }
- public override void OnMaidRemoveEventPrev(Maid maid)
- {
- }
- public void OnClickCameraFocus()
- {
- if (this.select_trans_target_ == null || this.select_trans_target_.obj == null)
- {
- return;
- }
- Vector3 position = this.select_trans_target_.obj.transform.position;
- float distance = 4f;
- Vector2 aroundAngle = new Vector2(-180f, 4.7f);
- this.camera_move_support_.StartCameraPosition(position, distance, aroundAngle);
- }
- private BasePhotoCustomObject CreateLoadCustomObject(GameObject parent, string filePath)
- {
- BasePhotoCustomObject basePhotoCustomObject = BasePhotoCustomObject.InstantiateFromFile(parent, filePath);
- if (basePhotoCustomObject == null)
- {
- return null;
- }
- string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
- basePhotoCustomObject.gameObject.name = fileNameWithoutExtension.GetHashCode().ToString();
- basePhotoCustomObject.visible = false;
- return basePhotoCustomObject;
- }
- private UIWFTabButton CreateTabButton(GameObject parent_obj, BasePhotoCustomObject target, string filePath)
- {
- GameObject gameObject = Utility.CreatePrefab(parent_obj, "ScenePhotoMode/WindowListItem", true);
- gameObject.name = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
- gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
- UIWFTabButton component = gameObject.GetComponent<UIWFTabButton>();
- this.buttonDic.Add(component.GetHashCode(), target);
- EventDelegate.Add(component.onSelect, delegate()
- {
- if (!UIWFSelectButton.current.isSelected)
- {
- return;
- }
- if (this.buttonDic.ContainsKey(UIWFSelectButton.current.GetHashCode()))
- {
- this.OnSelectItem(this.buttonDic[UIWFSelectButton.current.GetHashCode()]);
- }
- });
- return component;
- }
- public override void OnSerializeEvent()
- {
- }
- public override void OnDeserializeEvent()
- {
- }
- public override KeyValuePair<string, Dictionary<string, string>> Serialize()
- {
- KeyValuePair<string, Dictionary<string, string>> result = base.Serialize();
- Dictionary<string, string> value = result.Value;
- result = new KeyValuePair<string, Dictionary<string, string>>(result.Key, value);
- return result;
- }
- public override void Deserialize(Dictionary<string, Dictionary<string, string>> data)
- {
- base.Deserialize(data);
- string key = base.gameObject.name + "title";
- if (!data.ContainsKey(key))
- {
- return;
- }
- this.visibleTextureSelectWindow = false;
- }
- public PhotoModeObjectSave savePanel;
- public UIButton selectTextureButton;
- public GameObject textureExpTextObject;
- public UIButton textureRestoreButton;
- public TextureSelectSubWindow textureSelectSubtWindow;
- public UIGrid objectListGrid;
- public UIPopupList typeSelectPopupList;
- public WFCheckBox CheckPrevVisible;
- public UIButton saveButton;
- public PhotoSliderAndInput editScaleSlider;
- public WindowPartsInputColorrPalette texColorPalette;
- public GameObject planeUIParent;
- public UIPopupList planeBackDrawPopupList;
- public GameObject sphereUIParent;
- public UIPopupList sphereBackDrawPopupList;
- private Dictionary<int, BasePhotoCustomObject> buttonDic = new Dictionary<int, BasePhotoCustomObject>();
- private List<ObjectCreateWindow.Data> target_list_ = new List<ObjectCreateWindow.Data>();
- private ObjectCreateWindow.Data selectData;
- private bool change_bg_;
- private PhotoTransTargetObject select_trans_target_;
- private WfCameraMoveSupport camera_move_support_;
- private UIScrollView scroll_view_;
- private class Data
- {
- public Data(BasePhotoCustomObject obj)
- {
- this.customObject = obj;
- }
- public Data(BasePhotoCustomObject obj, string fullPath)
- {
- this.customObject = obj;
- this.fullPath = fullPath;
- }
- public BasePhotoCustomObject customObject;
- public byte[] backupPng;
- public string fullPath;
- }
- }
|