using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEngine.UI;
|
|
using System.IO;
|
|
|
|
public class BatchModify
|
|
{
|
|
//要处理的目录
|
|
private static string modify_path = "D:/_mrzj/develop/code/u3d/Assets/LuaFramework/AssetBundleRes/scene/terrain/map";
|
|
|
|
|
|
static bool isChange = false;
|
|
|
|
[MenuItem("MixTool/BatchModifyPrefab")]
|
|
static void BatchModifyPrefab()
|
|
{
|
|
string[] cacheLog = { "已经处理的按钮记录:" };
|
|
string[] curPrefabs = { "", "", "" };
|
|
int startIndex = 0;
|
|
string[] files = Directory.GetFiles(modify_path, "*.prefab", SearchOption.AllDirectories);
|
|
EditorApplication.update = delegate ()
|
|
{
|
|
string filePath = GetRelativeAssetsPath(files[startIndex]);
|
|
GameObject _prefab = AssetDatabase.LoadAssetAtPath(filePath, typeof(GameObject)) as GameObject;
|
|
if (_prefab == null)
|
|
{
|
|
Debug.Log("该路径不能正常加载预制体 = >>> " + filePath);
|
|
return;
|
|
}
|
|
GameObject find_obj = PrefabUtility.InstantiatePrefab(_prefab) as GameObject;
|
|
if (find_obj == null)
|
|
{
|
|
Debug.Log("该路径不实例化预制体 = >>> " + filePath);
|
|
return;
|
|
}
|
|
isChange = false;
|
|
bool isCancel = EditorUtility.DisplayCancelableProgressBar(string.Format("资源处理中({0}/{1})", startIndex, files.Length), find_obj.name, (float)startIndex / (float)files.Length);
|
|
|
|
CloseLightData(find_obj);
|
|
//这里是修改带Text的RecTransform大小
|
|
// ChangeTransformDeltaSize(find_obj.transform);
|
|
|
|
|
|
if (isChange)
|
|
{
|
|
PrefabUtility.ReplacePrefab(find_obj, _prefab, ReplacePrefabOptions.Default);
|
|
cacheLog[0] = CacheLog(cacheLog[0], "已经处理" + find_obj.gameObject.name, curPrefabs[0], find_obj.gameObject.name);
|
|
}
|
|
MonoBehaviour.DestroyImmediate(find_obj);
|
|
startIndex++;
|
|
|
|
if (isCancel || startIndex >= files.Length)
|
|
{
|
|
AssetDatabase.Refresh();
|
|
AssetDatabase.SaveAssets();
|
|
EditorUtility.ClearProgressBar();
|
|
EditorApplication.update = null;
|
|
startIndex = 0;
|
|
Debug.Log("处理完成");
|
|
foreach (var item in cacheLog)
|
|
{
|
|
Debug.Log(item);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
static private string CacheLog(string cacheLog, string log, string lastPrefab, string curPrefab)
|
|
{
|
|
string str = "";
|
|
if (lastPrefab != curPrefab)
|
|
{
|
|
str = "\n\n[" + curPrefab + "]\n" + log;
|
|
}
|
|
else
|
|
str = "\n" + log;
|
|
str = cacheLog + str;
|
|
return str;
|
|
}
|
|
|
|
static private string GetRelativeAssetsPath(string path)
|
|
{
|
|
return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
|
|
}
|
|
|
|
static private void ChangeTransformDeltaSize(Transform transform)
|
|
{
|
|
Text tx = transform.GetComponent<Text>();
|
|
if (tx != null)
|
|
{
|
|
RectTransform rt = transform.GetComponent<RectTransform>();
|
|
if (rt != null)
|
|
{
|
|
if (rt.sizeDelta.y > 20 && rt.sizeDelta.y < 30)
|
|
{
|
|
rt.sizeDelta = new Vector2(rt.sizeDelta.x, 30);
|
|
isChange = true;
|
|
Debug.Log("==>" + transform.name + " delta y = " + rt.sizeDelta);
|
|
}
|
|
}
|
|
}
|
|
|
|
int child_num = transform.childCount;
|
|
if (child_num > 0)
|
|
{
|
|
for(int i = 0; i< child_num; ++i)
|
|
{
|
|
Transform temp_tf = transform.GetChild(i);
|
|
if (temp_tf != null)
|
|
{
|
|
ChangeTransformDeltaSize(temp_tf);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static private void CloseLightData(GameObject go)
|
|
{
|
|
MeshRenderer img2 = go.GetComponent<MeshRenderer>();
|
|
if (img2 != null)
|
|
{
|
|
img2.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
|
|
isChange = true;
|
|
// if (img2.receiveShadows || img2.lightProbeUsage != UnityEngine.Rendering.LightProbeUsage.Off || img2.reflectionProbeUsage != UnityEngine.Rendering.ReflectionProbeUsage.Off || img2.shadowCastingMode != UnityEngine.Rendering.ShadowCastingMode.Off || img2.motionVectorGenerationMode != MotionVectorGenerationMode.ForceNoMotion)
|
|
// {
|
|
// img2.receiveShadows = false;
|
|
// img2.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;
|
|
// img2.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
|
|
// img2.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
|
|
// img2.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
|
|
// isChange = true;
|
|
// }
|
|
}
|
|
}
|
|
}
|