166 lines
6.5 KiB
C#
166 lines
6.5 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Art.temp.Editor.AnimationTools;
|
|
using Art.temp.Editor.PrefabTool;
|
|
using cfg.WeaponCfg;
|
|
using Framework;
|
|
using SaadKhawaja.InstantScreenshot;
|
|
using UnityEditor;
|
|
using UnityEditor.UIElements;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Art.temp.Editor.ScreenShotTool
|
|
{
|
|
public class ScreenShotTool : EditorWindow
|
|
{
|
|
[MenuItem("Test/Animation 工具/Screen Shot Tool")]
|
|
public static void ShowWindow()
|
|
{
|
|
var win = GetWindow<ScreenShotTool>("screen shot Tool");
|
|
win.minSize = new Vector2(400, 400);
|
|
}
|
|
|
|
ObjectField animField;
|
|
TextField widthField;
|
|
TextField heightField;
|
|
|
|
public void CreateGUI()
|
|
{
|
|
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Art/temp/Editor/CommonUSSFile.uss");
|
|
rootVisualElement.styleSheets.Add(styleSheet);
|
|
|
|
// settings
|
|
Label labelSetting = new() { text = "图片尺寸" };
|
|
rootVisualElement.Add(labelSetting);
|
|
widthField = new TextField("width") { value = "2048" };
|
|
heightField = new TextField("height") { value = "2048" };
|
|
rootVisualElement.Add(widthField);
|
|
rootVisualElement.Add(heightField);
|
|
Label label0 = new() { text = "------------------------------------------------------" };
|
|
rootVisualElement.Add(label0);
|
|
|
|
Button btn1 = new() { text = "截取player" };
|
|
btn1.RegisterCallback<ClickEvent>(ShotDisplayPlayer);
|
|
Button btn2 = new() { text = "截取载具" };
|
|
btn2.RegisterCallback<ClickEvent>(ShotDisplayVehicle);
|
|
Button btn3 = new() { text = "截取 MonsterClass.xlsx 中所有的 enemy" };
|
|
btn3.RegisterCallback<ClickEvent>(ShotMonster);
|
|
|
|
animField = new ObjectField("动作");
|
|
rootVisualElement.Add(animField);
|
|
rootVisualElement.Add(btn1);
|
|
|
|
Label label1 = new() { text = "------------------------------------------------------" };
|
|
rootVisualElement.Add(label1);
|
|
|
|
rootVisualElement.Add(btn2);
|
|
|
|
Label label2 = new() { text = "------------------------------------------------------" };
|
|
rootVisualElement.Add(label2);
|
|
|
|
rootVisualElement.Add(btn3);
|
|
}
|
|
|
|
private void ShotDisplayPlayer(ClickEvent evt)
|
|
{
|
|
GameObject[] goes = Selection.gameObjects;
|
|
if (animField.value == null)
|
|
{
|
|
Debug.LogWarning("请设置动作 clip 文件,注意不是 Fbx");
|
|
return;
|
|
}
|
|
|
|
if (goes.Length == 0)
|
|
{
|
|
Debug.LogWarning("请选择要截取的角色 prefab");
|
|
return;
|
|
}
|
|
|
|
foreach (GameObject go in goes)
|
|
{
|
|
GameObject prefab = (GameObject)PrefabUtility.InstantiatePrefab(go);
|
|
Transform instance = prefab.transform.GetChild(0);
|
|
|
|
// 重绘面部
|
|
AnimHelper.SetFaceMaterial(instance.gameObject);
|
|
|
|
// set anim
|
|
if (animField.value is AnimationClip clip)
|
|
{
|
|
AnimationMode.StartAnimationMode();
|
|
AnimationMode.SampleAnimationClip(instance.gameObject, clip, 0f);
|
|
//
|
|
const string folder = "D:/screenshot_player";
|
|
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
|
InstantScreenshot.TakeScreenshot(
|
|
folder,
|
|
$"{instance.name}.png",
|
|
Camera.main, int.Parse(widthField.value), int.Parse(heightField.value), 1, true);
|
|
|
|
AnimationMode.StopAnimationMode();
|
|
DestroyImmediate(prefab);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("需要指定动作。");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShotDisplayVehicle(ClickEvent evt)
|
|
{
|
|
GameObject[] goes = Selection.gameObjects;
|
|
if (goes.Length == 0)
|
|
{
|
|
Debug.LogWarning("选择要截取的载具 prefab");
|
|
return;
|
|
}
|
|
|
|
foreach (GameObject go in goes)
|
|
{
|
|
GameObject prefab = (GameObject)PrefabUtility.InstantiatePrefab(go);
|
|
const string folder = "D:/screenshot_vehicle";
|
|
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
|
InstantScreenshot.TakeScreenshot(
|
|
folder,
|
|
$"{prefab.name}.png",
|
|
Camera.main, int.Parse(widthField.value), int.Parse(heightField.value), 1, true);
|
|
DestroyImmediate(prefab);
|
|
}
|
|
}
|
|
|
|
private void ShotMonster(ClickEvent evt)
|
|
{
|
|
var dataMonster = EditorTableManager.instance.tables.MonsterClass.DataList;
|
|
List<DataWeapon> dataWeapon = EditorTableManager.instance.tables.WeaponConfig.DataList;
|
|
const string folder = "D:/screenshot_monster/{0}";
|
|
foreach (string g in new string[] { "g01", "g02", "g03", "g04", "g05", "g06", "g08", "g11" })
|
|
{
|
|
string path = string.Format(folder, g);
|
|
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
|
}
|
|
|
|
foreach (var data in dataMonster)
|
|
{
|
|
string nameId = data.NameId;
|
|
int weaponId = data.WeaponId;
|
|
string group = dataWeapon.SingleOrDefault(weapon => weapon.ID == weaponId)?.GroupName;
|
|
Debug.Log($"id:{nameId} weaponId:{weaponId} groupName:{group}");
|
|
|
|
CharacterAssetInfo monster = CharacterFactory.CreateEmeny(nameId);
|
|
string animPath = $"Assets/Art/Animations/compressedShow/compressed_ani_{group}_s_standready001.anim";
|
|
AnimationClip clip = AssetDatabase.LoadAssetAtPath<AnimationClip>(animPath);
|
|
monster.ShotShow(weaponId, clip);
|
|
InstantScreenshot.TakeScreenshot(
|
|
string.Format(folder, group),
|
|
$"{monster.objInstance.name}_{group}.png",
|
|
Camera.main, int.Parse(widthField.value), int.Parse(heightField.value), 1, true);
|
|
|
|
AnimationMode.StopAnimationMode();
|
|
DestroyImmediate(monster.objInstance);
|
|
}
|
|
}
|
|
}
|
|
} |