123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using MyRoomCustom;
- using UnityEngine;
- using UnityEngine.Rendering;
- public class BgMgr : MonoBehaviour
- {
- public GameObject Parent
- {
- get
- {
- return this.m_goParent;
- }
- }
- public GameObject BgObject
- {
- get
- {
- return this.m_goBg;
- }
- }
- private void Awake()
- {
- this.m_goParent = UTY.GetChildObject(base.gameObject, "BG", false);
- NDebug.Assert(this.m_goParent != null, "__GameMain__/BG が見つかりません");
- }
- public void OnDestroy()
- {
- foreach (KeyValuePair<string, BgMgr.AssetBundleObj> keyValuePair in this.asset_bundle_dic)
- {
- keyValuePair.Value.ab.Unload(true);
- }
- this.asset_bundle_dic.Clear();
- }
- public void ChangeBg(string f_strPrefubName)
- {
- if (!string.IsNullOrEmpty(f_strPrefubName) && 0 <= f_strPrefubName.IndexOf("?"))
- {
- f_strPrefubName = ScriptManager.ReplacePersonal(GameMain.Instance.CharacterMgr.GetMaid(0), f_strPrefubName);
- }
- base.StopCoroutine("CoWaitMovePrefabToChara");
- this.SetPos(Vector3.zero);
- this.SetRot(Vector3.zero);
- this.DelPrefabFromBgAll();
- if (this.m_goBg != null)
- {
- UnityEngine.Object.Destroy(this.m_goBg);
- DeskManager.OnChangeBG(string.Empty, null);
- this.m_goBg = null;
- this.SaveOvrDDPos(true);
- }
- this.m_strBGName = string.Empty;
- if (!string.IsNullOrEmpty(f_strPrefubName))
- {
- UnityEngine.Object @object = this.CreateAssetBundle(f_strPrefubName);
- if (@object == null)
- {
- @object = Resources.Load("BG/" + f_strPrefubName);
- if (@object == null)
- {
- @object = Resources.Load("BG/2_0/" + f_strPrefubName);
- }
- }
- if (@object != null)
- {
- this.m_strBGName = f_strPrefubName;
- this.m_goBg = (UnityEngine.Object.Instantiate(@object) as GameObject);
- MeshRenderer[] componentsInChildren = this.m_goBg.GetComponentsInChildren<MeshRenderer>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- if (componentsInChildren[i] != null && componentsInChildren[i].gameObject.name.ToLower().IndexOf("castshadow") < 0)
- {
- componentsInChildren[i].shadowCastingMode = ShadowCastingMode.Off;
- }
- }
- this.m_goBg.transform.SetParent(this.m_goParent.transform, false);
- if (GameMain.Instance.VRMode && Application.isPlaying && this.AddHitToBg(f_strPrefubName + "_hit") == null && this.AddPrefabToBg(f_strPrefubName + "_Hit", f_strPrefubName + "_Hit", null, Vector3.zero, Vector3.zero) == null)
- {
- this.AddPrefabToBg(f_strPrefubName + "_hit", f_strPrefubName + "_hit", null, Vector3.zero, Vector3.zero);
- }
- this.ShowOvrDD(false);
- DeskManager.OnChangeBG(f_strPrefubName.ToLower(), this.m_goBg);
- }
- else
- {
- Debug.LogError("BGプレハブが見つかりませんでした。BG/" + f_strPrefubName);
- }
- }
- Resources.UnloadUnusedAssets();
- }
- public void ChangeBgMyRoom(string guid)
- {
- base.StopCoroutine("CoWaitMovePrefabToChara");
- this.SetPos(Vector3.zero);
- this.SetRot(Vector3.zero);
- this.DelPrefabFromBgAll();
- if (this.m_goBg != null)
- {
- UnityEngine.Object.Destroy(this.m_goBg);
- DeskManager.OnChangeBG(string.Empty, null);
- this.m_goBg = null;
- this.SaveOvrDDPos(true);
- }
- this.m_strBGName = string.Empty;
- if (!string.IsNullOrEmpty(guid) && CreativeRoomManager.IsExistSaveData(guid))
- {
- this.m_strBGName = "マイルーム:" + guid;
- this.m_goBg = CreativeRoomManager.InstantiateRoom(guid);
- MeshRenderer[] componentsInChildren = this.m_goBg.GetComponentsInChildren<MeshRenderer>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- if (componentsInChildren[i] != null && componentsInChildren[i].gameObject.name.ToLower().IndexOf("castshadow") < 0)
- {
- componentsInChildren[i].shadowCastingMode = ShadowCastingMode.Off;
- }
- }
- this.m_goBg.transform.SetParent(this.m_goParent.transform, false);
- DeskManager.OnChangeBG(this.m_strBGName.ToLower(), this.m_goBg);
- }
- Resources.UnloadUnusedAssets();
- }
- public GameObject CreateAssetBundle(string name)
- {
- if (string.IsNullOrEmpty(name))
- {
- return null;
- }
- name = name.ToLower();
- bool flag = false;
- string text = string.Empty;
- AFileSystemBase afileSystemBase = null;
- if (GameUty.BgFiles.ContainsKey(name + ".asset_bg"))
- {
- flag = true;
- text = name + ".asset_bg";
- afileSystemBase = GameUty.BgFiles[name + ".asset_bg"];
- }
- UnityEngine.Object @object = null;
- if (flag && !string.IsNullOrEmpty(text))
- {
- if (!this.asset_bundle_dic.ContainsKey(text))
- {
- using (AFileBase afileBase = afileSystemBase.FileOpen(text))
- {
- byte[] binary = afileBase.ReadAll();
- AssetBundle assetBundle = AssetBundle.LoadFromMemory(binary);
- BgMgr.AssetBundleObj value = default(BgMgr.AssetBundleObj);
- if (assetBundle.mainAsset != null)
- {
- value.obj = assetBundle.mainAsset;
- }
- else
- {
- value.obj = assetBundle.LoadAllAssets<GameObject>()[0];
- }
- value.ab = assetBundle;
- this.asset_bundle_dic.Add(text, value);
- @object = value.obj;
- string f_strFileName = name + ".asset_bg_shader";
- AFileSystemBase afileSystemBase2 = null;
- if (GameUty.FileSystem.IsExistentFile(f_strFileName))
- {
- afileSystemBase2 = GameUty.FileSystem;
- }
- else if (GameUty.FileSystemOld.IsExistentFile(f_strFileName))
- {
- afileSystemBase2 = GameUty.FileSystemOld;
- }
- if (afileSystemBase2 != null)
- {
- byte[] array = null;
- using (AFileBase afileBase2 = afileSystemBase2.FileOpen(f_strFileName))
- {
- array = afileBase2.ReadAll();
- }
- if (array != null)
- {
- this.LoadAssetBgShaderData(@object as GameObject, array);
- }
- }
- }
- }
- else
- {
- @object = this.asset_bundle_dic[text].obj;
- }
- }
- return (!(@object == null)) ? (@object as GameObject) : null;
- }
- private void LoadAssetBgShaderData(GameObject bgObject, byte[] binary)
- {
- if (binary == null || binary.Length <= 0)
- {
- return;
- }
- using (MemoryStream memoryStream = new MemoryStream(binary))
- {
- using (BinaryReader binaryReader = new BinaryReader(memoryStream))
- {
- int num = binaryReader.ReadInt32();
- List<Shader> list = new List<Shader>();
- Dictionary<string, List<int>> dictionary = new Dictionary<string, List<int>>();
- int num2 = (int)binaryReader.ReadInt16();
- for (int i = 0; i < num2; i++)
- {
- string text = binaryReader.ReadString();
- Shader shader = Shader.Find(text);
- if (shader == null)
- {
- Debug.LogError("shader名[" + text + "]からshaderを特定できませんでした");
- }
- else
- {
- list.Add(shader);
- }
- }
- num2 = (int)binaryReader.ReadInt16();
- for (int j = 0; j < num2; j++)
- {
- string key = binaryReader.ReadString();
- List<int> list2 = new List<int>();
- int num3 = (int)binaryReader.ReadInt16();
- for (int k = 0; k < num3; k++)
- {
- list2.Add(binaryReader.ReadInt32());
- }
- dictionary.Add(key, list2);
- }
- Renderer[] componentsInChildren = bgObject.GetComponentsInChildren<Renderer>(true);
- foreach (Renderer renderer in componentsInChildren)
- {
- List<int> list3 = dictionary[renderer.gameObject.name];
- int num4 = 0;
- foreach (Material material in renderer.sharedMaterials)
- {
- if (!(material == null))
- {
- int index = list3[num4];
- material.shader = list[index];
- num4++;
- }
- }
- }
- }
- }
- }
- public void SetPos(Vector3 f_vWorldPos)
- {
- this.m_goParent.transform.position = f_vWorldPos;
- }
- public void SetRot(Vector3 f_vWorldRot)
- {
- this.m_goParent.transform.rotation = Quaternion.Euler(f_vWorldRot);
- }
- public void DeleteBg()
- {
- this.ChangeBg(null);
- }
- public string GetBGName()
- {
- return this.m_strBGName;
- }
- public GameObject AddHitToBg(string f_strSrc)
- {
- UnityEngine.Object @object = Resources.Load("BG_Hit/" + f_strSrc);
- if (@object == null)
- {
- @object = this.CreateAssetBundle(f_strSrc);
- }
- if (@object == null)
- {
- return null;
- }
- GameObject gameObject = UnityEngine.Object.Instantiate(@object) as GameObject;
- gameObject.name = f_strSrc;
- if (this.m_goBg != null)
- {
- gameObject.transform.SetParent(this.m_goBg.transform, false);
- }
- else
- {
- gameObject.transform.SetParent(this.m_goParent.transform, false);
- }
- return gameObject;
- }
- public GameObject AddPrefabToBg(string f_strSrc, string f_strName, string f_strDest, Vector3 f_vPos, Vector3 f_vRot)
- {
- GameObject gameObject = null;
- Func<string, string, GameObject> func = delegate(string src, string name)
- {
- GameObject gameObject3 = null;
- if (!this.m_dicAttachObj.TryGetValue(name, out gameObject3))
- {
- UnityEngine.Object @object = Resources.Load("Prefab/" + src);
- if (@object == null)
- {
- @object = this.CreateAssetBundle(src);
- }
- if (@object == null)
- {
- return null;
- }
- gameObject3 = (UnityEngine.Object.Instantiate(@object) as GameObject);
- gameObject3.name = name;
- this.m_dicAttachObj.Add(name, gameObject3);
- }
- return gameObject3;
- };
- if (Product.isEnglish && !Product.isPublic)
- {
- gameObject = func(f_strSrc + "_en", f_strName);
- }
- if (gameObject == null)
- {
- gameObject = func(f_strSrc, f_strName);
- if (gameObject == null)
- {
- Debug.Log("指定のプレハブが見つかりませんでした。[" + f_strSrc + "]");
- return null;
- }
- }
- GameObject gameObject2;
- if (this.m_goBg != null)
- {
- if (!string.IsNullOrEmpty(f_strDest))
- {
- gameObject2 = UTY.GetChildObject(this.m_goBg, f_strDest, false);
- }
- else
- {
- gameObject2 = this.m_goBg;
- }
- }
- else
- {
- gameObject2 = this.m_goParent;
- }
- gameObject.transform.SetParent(gameObject2.transform, false);
- gameObject.transform.localPosition = f_vPos;
- gameObject.transform.localRotation = Quaternion.Euler(f_vRot);
- return gameObject;
- }
- public GameObject AddAssetsBundleToBg(string f_strSrc, string f_strName, string f_strDest, Vector3 f_vPos, Vector3 f_vRot)
- {
- GameObject gameObject = null;
- if (!this.m_dicAttachObj.TryGetValue(f_strName, out gameObject))
- {
- UnityEngine.Object @object = this.CreateAssetBundle(f_strSrc);
- if (@object == null)
- {
- Debug.Log("指定のAssetsBundle見つかりませんでした。[" + f_strSrc + "]");
- return null;
- }
- gameObject = (UnityEngine.Object.Instantiate(@object) as GameObject);
- gameObject.name = f_strName;
- this.m_dicAttachObj.Add(f_strName, gameObject);
- }
- GameObject gameObject2;
- if (this.m_goBg != null)
- {
- if (!string.IsNullOrEmpty(f_strDest))
- {
- gameObject2 = UTY.GetChildObject(this.m_goBg, f_strDest, false);
- }
- else
- {
- gameObject2 = this.m_goBg;
- }
- }
- else
- {
- gameObject2 = this.m_goParent;
- }
- gameObject.transform.SetParent(gameObject2.transform, false);
- gameObject.transform.localPosition = f_vPos;
- gameObject.transform.localRotation = Quaternion.Euler(f_vRot);
- return gameObject;
- }
- public void PrefabAnimatorSetParam<T>(string f_strName, string f_strParam, T f_value) where T : IConvertible
- {
- GameObject gameObject = null;
- if (this.m_dicAttachObj.TryGetValue(f_strName, out gameObject))
- {
- Animator component = gameObject.GetComponent<Animator>();
- if (component != null)
- {
- if (f_value.GetType() == typeof(int))
- {
- component.SetInteger(f_strParam, f_value.ToInt32(null));
- }
- else if (f_value.GetType() == typeof(float))
- {
- component.SetFloat(f_strParam, (float)f_value.ToDouble(null));
- }
- else if (f_value.GetType() == typeof(bool))
- {
- component.SetBool(f_strParam, f_value.ToBoolean(null));
- }
- }
- }
- else
- {
- Debug.LogWarning("プレハブが見つかりません。" + f_strName);
- }
- }
- public void PrefabAnimatorTrigger(string f_strName, string f_strParam, bool f_bReset)
- {
- GameObject gameObject = null;
- if (this.m_dicAttachObj.TryGetValue(f_strName, out gameObject))
- {
- Animator component = gameObject.GetComponent<Animator>();
- if (component != null)
- {
- if (f_bReset)
- {
- component.ResetTrigger(f_strParam);
- }
- else
- {
- component.SetTrigger(f_strParam);
- }
- }
- }
- else
- {
- Debug.LogWarning("プレハブが見つかりません。" + f_strName);
- }
- }
- public void MovePrefabToChara(string f_strPrefabName, Maid f_maid, string f_strDestBone, Vector3 f_vOffsPos, Vector3 f_vOffsRot, float f_fTime)
- {
- BgMgr.MovePfefab value = new BgMgr.MovePfefab(f_strPrefabName, f_maid, f_strDestBone, f_vOffsPos, f_vOffsRot, f_fTime);
- base.StartCoroutine("CoWaitMovePrefabToChara", value);
- }
- private IEnumerator CoWaitMovePrefabToChara(BgMgr.MovePfefab f_mp)
- {
- float fNowTime = 0f;
- if (f_mp.maid == null || f_mp.maid.body0 == null)
- {
- yield break;
- }
- GameObject objTarget = null;
- Transform trTarget = CMT.SearchObjName(f_mp.maid.body0.m_trBones, f_mp.strDestBone, true);
- if (trTarget != null)
- {
- this.m_dicAttachObj.TryGetValue(f_mp.strPrefabName, out objTarget);
- }
- if (objTarget == null)
- {
- yield break;
- }
- while (!(trTarget == null))
- {
- objTarget.transform.position = trTarget.position + f_mp.vOffsPos;
- yield return null;
- if ((fNowTime += Time.deltaTime) > f_mp.fTime)
- {
- yield break;
- }
- }
- yield break;
- }
- public GameObject GetPrefabFromBg(string f_strName)
- {
- if (!this.m_dicAttachObj.ContainsKey(f_strName))
- {
- return null;
- }
- return this.m_dicAttachObj[f_strName];
- }
- public void DelPrefabFromBg(string f_strName)
- {
- GameObject obj = null;
- if (this.m_dicAttachObj.TryGetValue(f_strName, out obj))
- {
- this.m_dicAttachObj.Remove(f_strName);
- UnityEngine.Object.Destroy(obj);
- }
- }
- public void DelPrefabFromBgAll()
- {
- base.StopCoroutine("CoWaitMovePrefabToChara");
- foreach (KeyValuePair<string, GameObject> keyValuePair in this.m_dicAttachObj)
- {
- if (keyValuePair.Value != null)
- {
- UnityEngine.Object.DestroyImmediate(keyValuePair.Value);
- }
- }
- this.m_dicAttachObj.Clear();
- }
- public void OnConnectedToServer()
- {
- this.SetPos(Vector3.zero);
- this.SetRot(Vector3.zero);
- }
- public void OnSaveDD()
- {
- this.SaveOvrDDPos(true);
- }
- private void ShowOvrDD(bool f_bShowForce)
- {
- if (this.m_goParent == null)
- {
- return;
- }
- string text = this.GetBGName();
- if (string.IsNullOrEmpty(text))
- {
- text = "__NoBG";
- }
- if (!GameMain.Instance.CMSystem.SConfig.OvrDDtoBG)
- {
- text = "__NoDDtoBG";
- }
- if (!f_bShowForce)
- {
- CMSystem.TransDD transDD;
- if (!GameMain.Instance.CMSystem.OvrDDBG.TryGetValue(text, out transDD))
- {
- if (this.desktop_screen_ != null)
- {
- UnityEngine.Object.DestroyImmediate(this.desktop_screen_);
- this.desktop_screen_ = null;
- }
- return;
- }
- if (!transDD.m_bShow)
- {
- if (this.desktop_screen_ != null)
- {
- UnityEngine.Object.DestroyImmediate(this.desktop_screen_);
- this.desktop_screen_ = null;
- }
- return;
- }
- }
- if (this.desktop_screen_ == null)
- {
- UnityEngine.Object @object = Resources.Load("Prefab/DesktopScreen");
- if (@object != null)
- {
- this.desktop_screen_ = (UnityEngine.Object.Instantiate(@object) as GameObject);
- }
- }
- if (this.desktop_screen_ != null)
- {
- this.desktop_screen_.transform.SetParent(this.m_goParent.transform);
- this.desktop_screen_.transform.localPosition = new Vector3(0f, 2f, 1f);
- this.desktop_screen_.transform.localRotation = Quaternion.identity;
- this.desktop_screen_.transform.localScale = Vector3.one;
- CMSystem.TransDD transDD2;
- if (GameMain.Instance.CMSystem.OvrDDBG.TryGetValue(text, out transDD2))
- {
- this.desktop_screen_.transform.localPosition = transDD2.m_vPos;
- this.desktop_screen_.transform.localRotation = transDD2.m_qRot;
- this.desktop_screen_.transform.localScale = transDD2.m_vScale;
- }
- }
- }
- private void SaveOvrDDPos(bool f_bShowing)
- {
- if (this.desktop_screen_ == null)
- {
- return;
- }
- string text = this.GetBGName();
- if (string.IsNullOrEmpty(text))
- {
- text = "__NoBG";
- }
- if (!GameMain.Instance.CMSystem.SConfig.OvrDDtoBG)
- {
- text = "__NoDDtoBG";
- }
- CMSystem.TransDD transDD = null;
- if (!GameMain.Instance.CMSystem.OvrDDBG.TryGetValue(text, out transDD))
- {
- transDD = new CMSystem.TransDD();
- GameMain.Instance.CMSystem.OvrDDBG.Add(text, transDD);
- }
- transDD.m_vPos = this.desktop_screen_.transform.localPosition;
- transDD.m_qRot = this.desktop_screen_.transform.localRotation;
- transDD.m_vScale = this.desktop_screen_.transform.localScale;
- transDD.m_bShow = f_bShowing;
- }
- public void Update()
- {
- if (Input.GetKeyDown(KeyCode.F10) && NInput.GetKey(KeyCode.LeftShift))
- {
- this.SetShowDesktopScreen(!this.isShowDesktopScreen);
- }
- else if (Input.GetKey(KeyCode.F11) && NInput.GetKey(KeyCode.LeftShift))
- {
- if (this.desktop_screen_ != null)
- {
- this.desktop_screen_.transform.localScale += new Vector3(0.1f, 0.1f, 0.1f) * Time.deltaTime;
- }
- }
- else if (Input.GetKey(KeyCode.F12) && NInput.GetKey(KeyCode.LeftShift) && this.desktop_screen_ != null)
- {
- this.desktop_screen_.transform.localScale += new Vector3(0.1f, 0.1f, 0.1f) * -Time.deltaTime;
- }
- }
- public bool isShowDesktopScreen
- {
- get
- {
- return this.desktop_screen_ != null;
- }
- }
- public void SetShowDesktopScreen(bool isShow)
- {
- if (isShow)
- {
- if (this.desktop_screen_ == null)
- {
- this.ShowOvrDD(true);
- }
- }
- else if (this.desktop_screen_ != null)
- {
- this.SaveOvrDDPos(false);
- UnityEngine.Object.DestroyImmediate(this.desktop_screen_);
- this.desktop_screen_ = null;
- }
- }
- public GameObject current_bg_object
- {
- get
- {
- return this.m_goBg;
- }
- }
- public GameObject bg_parent_object
- {
- get
- {
- return this.m_goParent;
- }
- }
- private GameObject m_goParent;
- private GameObject m_goBg;
- private Dictionary<string, BgMgr.AssetBundleObj> asset_bundle_dic = new Dictionary<string, BgMgr.AssetBundleObj>();
- private string m_strBGName = string.Empty;
- private Dictionary<string, GameObject> m_dicAttachObj = new Dictionary<string, GameObject>();
- private GameObject desktop_screen_;
- private struct AssetBundleObj
- {
- public AssetBundle ab;
- public UnityEngine.Object obj;
- }
- private class MovePfefab
- {
- public MovePfefab(string f_strPrefabName, Maid f_maid, string f_strDestBone, Vector3 f_vOffsPos, Vector3 f_vOffsRot, float f_fTime)
- {
- this.strPrefabName = f_strPrefabName;
- this.maid = f_maid;
- this.strDestBone = f_strDestBone;
- this.vOffsPos = f_vOffsPos;
- this.vOffsRot = f_vOffsRot;
- this.fTime = f_fTime;
- }
- public string strPrefabName;
- public Maid maid;
- public string strDestBone;
- public Vector3 vOffsPos;
- public Vector3 vOffsRot;
- public float fTime;
- }
- }
|