2024-08-13 20:02:59 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using MagicaCloth2;
|
2024-09-25 16:48:35 +08:00
|
|
|
|
using SRF;
|
2024-08-13 20:02:59 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-10-09 18:03:44 +08:00
|
|
|
|
using System.Linq;
|
2024-08-13 20:02:59 +08:00
|
|
|
|
using UnityEditor;
|
2024-10-09 18:03:44 +08:00
|
|
|
|
using UnityEditor.Experimental;
|
2024-08-13 20:02:59 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
|
|
|
|
public class ModifyPrefab : EditorWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
private GameObject[] objs;
|
|
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
[MenuItem("Test/tools/<2F><EFBFBD> prefab")]
|
|
|
|
|
|
public static void ShowWindow() { GetWindow<ModifyPrefab>("<22><EFBFBD> Prefab"); }
|
2024-08-13 20:02:59 +08:00
|
|
|
|
public void CreateGUI()
|
|
|
|
|
|
{
|
2024-11-04 13:41:33 +08:00
|
|
|
|
Button btn1 = new() { name = "button1", text = "<22><EFBFBD> wind zone" };
|
2024-08-13 20:02:59 +08:00
|
|
|
|
rootVisualElement.Add(btn1);
|
|
|
|
|
|
btn1.RegisterCallback<ClickEvent>(ModifyPlayers);
|
|
|
|
|
|
|
|
|
|
|
|
Button btn3 = new() { name = "button3", text = "get autoGen character" };
|
|
|
|
|
|
rootVisualElement.Add(btn3);
|
|
|
|
|
|
btn3.RegisterCallback<ClickEvent>(GetObjs);
|
|
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
Button btn2 = new() { name = "button2", text = "<22><EFBFBD> auto gen prefab" };
|
2024-08-13 20:02:59 +08:00
|
|
|
|
rootVisualElement.Add(btn2);
|
|
|
|
|
|
btn2.RegisterCallback<ClickEvent>(ModifyAutoGen);
|
2024-08-14 12:47:34 +08:00
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
Button btn4 = new() { name = "button4", text = "<22><EFBFBD> <20><>ɫ scale" };
|
2024-08-14 12:47:34 +08:00
|
|
|
|
rootVisualElement.Add(btn4);
|
|
|
|
|
|
btn4.RegisterCallback<ClickEvent>(ModifyScale);
|
2024-09-25 14:51:09 +08:00
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
Button btn5 = new() { name = "button5", text = "<22>Ƴ<EFBFBD>pos<6F>ؼ<EFBFBD>֡" };
|
2024-09-25 14:51:09 +08:00
|
|
|
|
rootVisualElement.Add(btn5);
|
2024-10-09 18:03:44 +08:00
|
|
|
|
btn5.RegisterCallback<ClickEvent>(AnimOptimize);
|
2024-09-25 16:48:35 +08:00
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
Button btn6 = new() { name = "button6", text = "<22><EFBFBD><DEB8><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>" };
|
2024-09-25 16:48:35 +08:00
|
|
|
|
rootVisualElement.Add(btn6);
|
|
|
|
|
|
btn6.RegisterCallback<ClickEvent>(ModifyBattery);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ModifyBattery(ClickEvent evt)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject[] objectArray = Selection.gameObjects;
|
|
|
|
|
|
foreach (GameObject obj in objectArray)
|
|
|
|
|
|
{
|
2024-11-04 13:41:33 +08:00
|
|
|
|
// <20><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><DEB8><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>Ҫ Ctrl+S <20>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-25 16:48:35 +08:00
|
|
|
|
var ins = obj.transform.GetChild(0);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ins.Find("R_Root/").ResetLocal();
|
|
|
|
|
|
Debug.Log($"{ins.name}:{ins.Find("R_Root/").name}");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
ins.Find("R_root/").ResetLocal();
|
|
|
|
|
|
Debug.Log($"{ins.name}:{ins.Find("R_root/").name}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-13 20:02:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-14 12:47:34 +08:00
|
|
|
|
void ModifyScale(ClickEvent evt)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject[] objectArray = Selection.gameObjects;
|
2024-09-25 14:51:09 +08:00
|
|
|
|
foreach (GameObject obj in objectArray)
|
2024-08-14 12:47:34 +08:00
|
|
|
|
{
|
2024-11-04 13:41:33 +08:00
|
|
|
|
// <20><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><DEB8><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>Ҫ Ctrl+S <20>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>
|
2024-08-14 12:47:34 +08:00
|
|
|
|
obj.transform.GetChild(0).localScale = new Vector3(1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-13 20:02:59 +08:00
|
|
|
|
void ModifyPlayers(ClickEvent evt)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject[] objectArray = Selection.gameObjects;
|
|
|
|
|
|
ModifyWind(objectArray);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GetObjs(ClickEvent ent)
|
|
|
|
|
|
{
|
2024-11-04 13:41:33 +08:00
|
|
|
|
string[] subFloders = AssetDatabase.GetSubFolders("Assets/Art_Out/AutoGen/Characters");
|
2024-08-13 20:02:59 +08:00
|
|
|
|
string[] guids = AssetDatabase.FindAssets("character_A", subFloders);
|
|
|
|
|
|
List<GameObject> list = new List<GameObject>();
|
|
|
|
|
|
foreach (string guid in guids)
|
|
|
|
|
|
{
|
|
|
|
|
|
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
|
|
|
|
GameObject obj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
|
|
|
|
|
list.Add(obj);
|
|
|
|
|
|
Debug.Log(obj.name);
|
|
|
|
|
|
}
|
|
|
|
|
|
objs = list.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
void ModifyAutoGen(ClickEvent ent)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
ModifyWind(objs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ModifyWind(GameObject[] objectArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (GameObject obj in objectArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
//instantiate asset.
|
|
|
|
|
|
GameObject prefab = (GameObject)PrefabUtility.InstantiatePrefab(obj);
|
|
|
|
|
|
//delete old wind zone
|
|
|
|
|
|
if (prefab.transform.Find("Magica Wind Zone") is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyImmediate(prefab.transform.Find("Magica Wind Zone").gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (prefab.transform.GetChild(0).Find("Magica Wind Zone") is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyImmediate(prefab.transform.GetChild(0).Find("Magica Wind Zone").gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
// create new wind zone
|
|
|
|
|
|
GameObject wind = new("Magica Wind Zone");
|
|
|
|
|
|
wind.transform.SetParent(prefab.transform);
|
|
|
|
|
|
var component = wind.AddComponent<MagicaWindZone>();
|
|
|
|
|
|
component.directionAngleX = 180;// set direction
|
|
|
|
|
|
component.main = 3;
|
|
|
|
|
|
// save
|
|
|
|
|
|
string path = AssetDatabase.GetAssetPath(obj);
|
|
|
|
|
|
|
|
|
|
|
|
PrefabUtility.SaveAsPrefabAssetAndConnect(prefab, path, InteractionMode.AutomatedAction);
|
|
|
|
|
|
UniTask.Delay(10);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-25 14:51:09 +08:00
|
|
|
|
|
2024-10-09 18:03:44 +08:00
|
|
|
|
public void AnimOptimize(ClickEvent evt)
|
2024-09-25 14:51:09 +08:00
|
|
|
|
{
|
|
|
|
|
|
var obj = Selection.activeGameObject;
|
|
|
|
|
|
var path = AssetDatabase.GetAssetPath(obj);
|
|
|
|
|
|
AnimationClip clip = AssetDatabase.LoadAssetAtPath<AnimationClip>(path);
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log(clip.name);
|
|
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
// ɾ<><C9BE>POS<4F><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
2024-09-25 14:51:09 +08:00
|
|
|
|
EditorCurveBinding[] curveBingdings = AnimationUtility.GetCurveBindings(clip);
|
|
|
|
|
|
foreach (var curveBingding in curveBingdings)
|
|
|
|
|
|
{
|
|
|
|
|
|
string name = curveBingding.propertyName.ToLower();
|
2024-10-09 18:03:44 +08:00
|
|
|
|
string bonePath = curveBingding.path;
|
2024-11-04 13:41:33 +08:00
|
|
|
|
// ɾ<><C9BE>POS<4F><53>Ҫ<EFBFBD>ų<EFBFBD><C5B3><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>
|
2024-10-09 18:03:44 +08:00
|
|
|
|
string[] fliter = new string[]{
|
|
|
|
|
|
"Root/Bip001",
|
|
|
|
|
|
"Root/Bip001/Bip001 Spine/Bip001 Spine1/Bip001 R Clavicle/Bip001 R UpperArm/Bip001 R Forearm/Bip001 R Hand/Grip_point01",
|
|
|
|
|
|
"Root/Bip001/Bip001 Spine/Bip001 Spine1/Bip001 L Clavicle/Bip001 L UpperArm/Bip001 L Forearm/Bip001 L Hand/Grip_point02"};
|
2024-09-25 14:51:09 +08:00
|
|
|
|
// Debug.Log(bone);
|
2024-10-09 18:03:44 +08:00
|
|
|
|
if (name.Contains("position") && !fliter.Any(a => a == bonePath))
|
2024-09-25 14:51:09 +08:00
|
|
|
|
{
|
|
|
|
|
|
AnimationUtility.SetEditorCurve(clip, curveBingding, null); // Set to null to remove the curve.
|
|
|
|
|
|
}
|
|
|
|
|
|
if (name.Contains("scale"))
|
|
|
|
|
|
{
|
|
|
|
|
|
AnimationUtility.SetEditorCurve(clip, curveBingding, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-09 18:03:44 +08:00
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
// <20><><EFBFBD>㾫<EFBFBD><E3BEAB>ѹ<EFBFBD><D1B9>
|
2024-10-09 18:03:44 +08:00
|
|
|
|
AnimationClipCurveData[] curves = null;
|
|
|
|
|
|
curves = AnimationUtility.GetAllCurves(clip);
|
|
|
|
|
|
Keyframe key;
|
|
|
|
|
|
Keyframe[] keyFrames;
|
|
|
|
|
|
for (int ii = 0; ii < curves.Length; ++ii)
|
|
|
|
|
|
{
|
|
|
|
|
|
AnimationClipCurveData curveDate = curves[ii];
|
|
|
|
|
|
if (curveDate.curve == null || curveDate.curve.keys == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
keyFrames = curveDate.curve.keys;
|
|
|
|
|
|
for (int i = 0; i < keyFrames.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
key = keyFrames[i];
|
|
|
|
|
|
key.value = float.Parse(key.value.ToString("f3"));
|
|
|
|
|
|
key.inTangent = float.Parse(key.inTangent.ToString("f3"));
|
|
|
|
|
|
key.outTangent = float.Parse(key.outTangent.ToString("f3"));
|
|
|
|
|
|
keyFrames[i] = key;
|
|
|
|
|
|
}
|
|
|
|
|
|
curveDate.curve.keys = keyFrames;
|
|
|
|
|
|
clip.SetCurve(curveDate.path, curveDate.type, curveDate.propertyName, curveDate.curve);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-04 13:41:33 +08:00
|
|
|
|
// <20><>ȡanim<69>ļ<EFBFBD>
|
2024-10-09 18:03:44 +08:00
|
|
|
|
AnimationClip newClip = new AnimationClip();
|
|
|
|
|
|
EditorUtility.CopySerialized(clip, newClip);
|
|
|
|
|
|
string newAnimPath = "";
|
|
|
|
|
|
AssetDatabase.CreateAsset(newClip, newAnimPath);
|
2024-09-25 14:51:09 +08:00
|
|
|
|
}
|
2024-08-13 20:02:59 +08:00
|
|
|
|
}
|