public void BakeRender(Water hostWater) { RefAreaRootObjTable.Clear(); ClearBake(hostWater); renderCheck.Clear(); hostWater.allTextureConfig.Clear(); hostWater.WaterRefObjRoot = new GameObject(); hostWater.WaterRefObjRoot.name = "WaterRefObjRoot"; hostWater.WaterRefObjRoot.transform.position = Vector3.zero; hostWater.WaterRefObjRoot.transform.rotation = Quaternion.identity; hostWater.WaterRefObjRoot.transform.localScale = Vector3.one; hostWater.allVisibleRenderList.Clear(); List <MeshRenderer> MeshRendersList = new List <MeshRenderer>(); List <SkinnedMeshRenderer> SkinnedMeshRenderList = new List <SkinnedMeshRenderer>(); MeshRendersList.AddRange(GameObject.FindObjectsOfType <MeshRenderer>()); SkinnedMeshRenderList.AddRange(GameObject.FindObjectsOfType <SkinnedMeshRenderer>()); MeshRenderer waterRender = hostWater.GetComponent <MeshRenderer>(); Collider waterCollider = hostWater.GetComponent <Collider>(); if (waterRender) { if (!waterCollider) { waterCollider = hostWater.gameObject.AddComponent <MeshCollider>(); } if (waterRender.sharedMaterial) { foreach (string spro in WaterTexturesPropertyNames) { if (waterRender.sharedMaterial.HasProperty(spro)) { Texture t = waterRender.sharedMaterial.GetTexture(spro); if (t) { string patch = AssetDatabase.GetAssetPath(t); if (!string.Empty.Equals(patch)) { ResConfigData cof = AssetBundleImporter.MakeTextureAssetBundleFromReference(patch, string.Empty); SceneTextureConfigData cd = new SceneTextureConfigData(); cd.AssetBundleName = cof.AssetBundleName; cd.AssetGUID = cof.AssetGUID; cd.AssetName = cof.AssetName; cd.ShaderKeyWordName = spro; if (null != cof) { hostWater.allTextureConfig.Add(cd); } } } } } } foreach (BoxCollider box in hostWater.WaterRefAeraList) { GameObject go = new GameObject(); go.name = box.gameObject.name; go.transform.SetParent(hostWater.WaterRefObjRoot.transform); go.transform.localPosition = Vector3.zero; go.transform.rotation = Quaternion.identity; go.transform.localScale = Vector3.one; hostWater.WaterRefAeraRootObjList.Add(go); RefAreaRootObjTable.Add(box, go); } BakeRender_MeshRender(MeshRendersList, hostWater, waterRender, waterCollider); BakeRender_SkinnedMeshRender(SkinnedMeshRenderList, hostWater, waterRender, waterCollider); } hostWater.bBaked = true; }
public override void OnInspectorGUI() { bool bDirty = false; pa.m_TextureSize = EditorGUILayout.IntField("贴图大小:", pa.m_TextureSize); pa.m_ClipPlaneOffset = EditorGUILayout.FloatField("物体到水面的距离:", pa.m_ClipPlaneOffset); pa.EdgeBlendStength = EditorGUILayout.Slider("水面边缘柔和:", pa.EdgeBlendStength, 0, 10); if (!Application.isPlaying) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(BakeCullMask, new GUIContent("显示层:")); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } } EditorGUILayout.LabelField("反射数目:" + pa.allVisibleRenderList.Count); BoundsPos = EditorGUILayout.BeginScrollView(BoundsPos); for (int i = 0; i < pa.WaterRefAeraList.Count; i++) { BoxCollider bc = pa.WaterRefAeraList[i]; if (!bc) { pa.WaterRefAeraList.RemoveAt(i); continue; } EditorGUILayout.BeginHorizontal("box"); bc = EditorGUILayout.ObjectField(bc, typeof(BoxCollider), true) as BoxCollider; if (GUILayout.Button("删除")) { GameObject.DestroyImmediate(bc.gameObject); pa.WaterRefAeraList.RemoveAt(i); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); if (GUILayout.Button("增加反射区域")) { GameObject go = new GameObject(); go.name = "WaterRefArea--" + pa.WaterRefAeraList.Count; go.transform.localScale = Vector3.one * 5.0f; go.transform.SetParent(pa.transform); Vector3 dir = EditorCamera.GetRotation() * Vector3.forward; go.transform.localRotation = Quaternion.identity; go.transform.position = EditorCamera.GetPosition() + dir * 10; go.layer = Water.WaterObjLayer; BoxCollider box = go.AddComponent <BoxCollider>(); box.isTrigger = true; pa.WaterRefAeraList.Add(box); Selection.activeGameObject = go; } if (GUILayout.Button("Bake")) { AssetBundleImporter.BeginPrefabAssetImport(); BakeRender(pa); AssetBundleImporter.EndPrefabAssetImport(); bDirty = true; } if (GUILayout.Button("Clear")) { ClearBake(pa); bDirty = true; } if (GUILayout.Button("Init")) { Water.Init(); } bDirty |= GUI.changed; if (bDirty) { EditorUtility.SetDirty(pa); } }
public void LoadFiles(UFileData data, string currentPath, int depth = 0) { GUIContent content = GetGUIContent(currentPath); if (content != null) { data.depth = depth; data.content = content; string patch1 = currentPath.Replace("\\", "/"); data.assetPath = patch1; if (patch1.Contains('.')) { ResConfigData config = AssetBundleImporter.MakeTextureAssetBundleFromReference(patch1, string.Empty); if (null == config) { Debug.LogError("找不资源的,资源路径:" + patch1); } data.configData = config; } } //当前路径下所有文件信息 foreach (var path in Directory.GetFiles(currentPath)) { content = GetGUIContent(path); if (content != null) { UFileData child = new UFileData(); child.depth = depth + 1; child.content = content; string patch1 = path.Replace("\\", "/"); child.assetPath = patch1; if (patch1.Contains('.')) { ResConfigData config = AssetBundleImporter.MakeTextureAssetBundleFromReference(patch1, string.Empty); if (null == config) { Debug.LogError("找不资源的,资源路径:" + patch1); } child.configData = config; } data.childs.Add(child); } } //WillTodo:排序这里无法判断没ID的图片,先不用 //data.childs.Sort((x, y) => //{ // UFileData XData = x as UFileData; // UFileData YData = y as UFileData; // int idX = Convert.ToInt32(XData.assetPath.Substring(XData.assetPath.LastIndexOf('_') + 1, XData.assetPath.LastIndexOf('.') - XData.assetPath.LastIndexOf('_') - 1)); // int idY = Convert.ToInt32(YData.assetPath.Substring(YData.assetPath.LastIndexOf('_') + 1, YData.assetPath.LastIndexOf('.') - YData.assetPath.LastIndexOf('_') - 1)); // return idX.CompareTo(idY); //}); foreach (var path in Directory.GetDirectories(currentPath)) { UFileData childDir = new UFileData(); data.childs.Add(childDir); LoadFiles(childDir, path, depth + 1); } }