Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whaison/7484263459e71279f7e09feb520f8698 to your computer and use it in GitHub Desktop.
Save whaison/7484263459e71279f7e09feb520f8698 to your computer and use it in GitHub Desktop.
ModelAnimationSplitterWithAnimeControllerTrigger.cs
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using UnityEditor.Animations;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Linq;
using System;
using Object = UnityEngine.Object;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
/// <summary>
/// Model animation spliter.
/// by Koki Ibukuro @asus4 >Noboru Otsuka
/// </summary>
public class ModelAnimationSplitterWithAnimeControllerTrigger : EditorWindow {
public TextAsset csvAsset;
public TextAsset csvOffsetUVAsset;
public GameObject modelAsset;
string modelAssetPath;
string CharaName;
string AnimationNameStr;
string AnimationClipEventNameStr;
string CharaDir;
string CharaDirName;
int build_colWidthleft;
int build_colWidthright;
int build_rowHeight;
float buildYLeft;
float buildYRight;
float buildY;
float buildY_event;
bool build_baseLayer_start;
bool build_left_start;
bool build_right_start;
bool build_left_now;
bool build_right_now;
int build_count;
string sd_num_charaname;
string sd_num;
string sd_only_num;
bool bool_effect_fix;
string fix_anim_09_attack_event_anim_path;
string fix_anim_10_skill_event_anim_path;
AnimationClip fix_anim_09_attack_event_anim_ref;
AnimationClip fix_anim_10_skill_event_anim_ref;
UnityEditor.Animations.AnimatorController AnimatorControllerRef;
AnimatorStateMachine BaseLayerStateMachine;
AnimatorStateMachine EventLayerStateMachine;
private List<UnityEditor.Animations.AnimatorState> BaseLayerStateList = new List<UnityEditor.Animations.AnimatorState>();
private List<UnityEditor.Animations.AnimatorState> EventLayerStateList = new List<UnityEditor.Animations.AnimatorState>();
List<AnimationClip> CharaAnimationClipListRef;
List<AnimationClip> eventAnimationClipList= new List<AnimationClip>();
ModelImporterClipAnimation[] clipAnimations;
GameObject Panel_VerticalLayout;
private int selGridInt = 0;
private string[] selCaptions = new string[] {
"non-Add",
"Add-offsetUV",
};
string AddOffsetUVorNon;
void OnGUI ()
{
GUILayout.Label ("CSV to Split Animtion V2.1.6", EditorStyles.boldLabel);
GUILayout.Space (10f);
csvAsset = EditorGUILayout.ObjectField ("frame.txt", csvAsset, typeof(TextAsset), false) as TextAsset;
if (csvAsset == null) {
GUILayout.Label ("Set CSV Data. Extension need .txt");
}
GUILayout.Space (10f);
modelAsset = EditorGUILayout.ObjectField ("3D Model", modelAsset, typeof(GameObject), false) as GameObject;
if (modelAsset == null) {
GUILayout.Label ("Set FBX or other 3D model object.");
}
GUILayout.Space (10f);
/*
selGridInt = GUILayout.SelectionGrid(selGridInt, selCaptions, 2, "Toggle");
AddOffsetUVorNon= selCaptions [selGridInt];
if (AddOffsetUVorNon == "Add-offsetUV") {
csvOffsetUVAsset = EditorGUILayout.ObjectField ("offset.txt", csvOffsetUVAsset, typeof(TextAsset), false) as TextAsset;
if (csvOffsetUVAsset == null) {
GUILayout.Label ("Set csv offsetUV Asset Data. Extension need .txt");
}
}
*/
/// <summary>
GUILayout.Space (20f);
if (GUILayout.Button ("Split with CSV", GUILayout.Width (140f))) {
SplitWithCsv ();
}
/// </summary>
}
void build_Reset()
{
modelAssetPath="";
CharaName="";
AnimationNameStr="";
AnimationClipEventNameStr="";
CharaDir="";
build_colWidthleft = 250;
build_colWidthright = 200;
build_rowHeight=50;
buildYLeft=0;
buildYRight=0;
buildY=0;
buildY_event = 0;
build_baseLayer_start=false;
build_left_start=false;
build_right_start=false;
build_left_now=false;
build_right_now=false;
build_count=1;
ParseClipCount = 0;
bool_effect_fix = false;
#pragma warning disable 0219
string fix_anim_09_attack_event_anim_path = "";
fix_anim_09_attack_event_anim_path = "";
string fix_anim_10_skill_event_anim_path = "";
fix_anim_10_skill_event_anim_path = "";
AnimationClip fix_anim_09_attack_event_anim_ref = null;
AnimationClip fix_anim_10_skill_event_anim_ref = null;
BaseLayerStateList = new List<UnityEditor.Animations.AnimatorState>();
}
string csvOffsetUV;
List<float> offsetV_time_List ;
List<float> offsetV_value_List ;
List<float> offsetU_time_List ;
List<float> offsetU_value_List ;
void ParceOffsetCSV (string csv)
{
// split to lines
string[] lines = csv.Split ('\n');
//Debug.Log("[]lines = "+ []lines);
char[] trims = {'\r', ' '};
Debug.Log("trims = "+trims);
//List<string> lines = new List<string> ();
offsetV_time_List = new List<float>();
offsetV_value_List = new List<float>();
offsetU_time_List = new List<float>();
offsetU_value_List = new List<float>();
Debug.Log("lines.Length; = "+lines.Length);
for (int i=0; i<lines.Length; i++)
{
string linestr = lines [i].Trim (trims);
//ModelImporterClipAnimation clip = ParseClip (s);
Debug.Log ("OffsetUVのラインは ="+linestr);
string[] lineArr = linestr.Split (',');
//Debug.Log("[] arr = "+[] arr);
Debug.Log("lineArr.Length = "+lineArr.Length);
string[] lineArr0 = lineArr[0].Split ('_');
for (int j=1; j<lineArr.Length; j++)
{
float lineArrFloat = 0;
/*
if(float.TryParse(lineArr [j], out lineArrFloat)){
//正常の時
//bに結果の123.45が入っている
}else{
//エラー時:文字列が少数で無い時
//bには常に0が入っている
}
*/
if (lineArr [j] != "") {
try {
lineArrFloat = float.Parse (lineArr [j]);
} catch (System.FormatException formaterr) {
Debug.Log ("エラーの文字列=" + lineArr [j] + "エラー内容" + formaterr);
}
if (lineArr0 [0] == "offsetV") {
if (lineArr0 [1] == "time") {
offsetV_time_List.Add (lineArrFloat);
}
if (lineArr0 [1] == "value") {
offsetV_value_List.Add (lineArrFloat);
}
}
if (lineArr0 [0] == "offsetU") {
if (lineArr0 [1] == "time") {
offsetU_time_List.Add (lineArrFloat);
}
if (lineArr0 [1] == "value") {
offsetU_value_List.Add (lineArrFloat);
}
}
}
}
}
if (lines.Length == 0) {
Debug.Log ("offsetCSVのラインは lines.Length= 0 個ありました");
//return null;
} else {
Debug.Log ("offsetCSVのラインは lines.Length= " +lines.Length+ " 個ありました");
}
}
public string modelDirStr;
public void SplitWithCsv ()
{
/////////////////////////////////////
build_Reset ();
///////////////////////////////////////
if (Assert (csvAsset != null, "Need to set CSV Text") || Assert (modelAsset != null, "Need to set 3D Model")) {
return;
}
string csv = csvAsset.text;
Debug.Log ("csvAsset=" + csvAsset);
Debug.Log ("modelAsset=" + modelAsset);
/**/
/////////////////////////////////////////////////////////////////////////////
///
///
///
AddOffsetUVorNon= selCaptions [selGridInt];
if(AddOffsetUVorNon=="Add-offsetUV"){
string csvOffsetUV = csvOffsetUVAsset.text;
ParceOffsetCSV(csvOffsetUV);
}
///
///
modelDirStr = AssetDatabase.GetAssetPath (modelAsset);
Debug.Log ("000 SplitWithCsv --- modelDirStr=" + modelDirStr);
string[] modelDirArr;
modelDirArr=modelDirStr.Split("/"[0]);
string buildDir = modelDirArr[0];
for(int i = 1; i < modelDirArr.Length-1; i++)
{
buildDir = buildDir +"/"+ modelDirArr [i];
}
CharaDir = buildDir;
Debug.Log ("CharaDir="+CharaDir);
CharaName = modelDirArr [modelDirArr.Length-1];
Debug.Log ("CharaName="+CharaName);
CharaDirName = modelDirArr [modelDirArr.Length - 2];
Debug.Log ("------------------------------------------------------CharaDirName="+CharaDirName);
string[] CharaNamaArr;
CharaNamaArr=CharaName.Split("_"[0]);
sd_num_charaname = CharaNamaArr [0] + "_" + CharaNamaArr [1] + "_" + CharaNamaArr [2];
try{
if(CharaNamaArr [3]!=null){
sd_num_charaname=sd_num_charaname+"_"+CharaNamaArr [3];
}
}catch{
}
sd_num = CharaNamaArr [0] + "_" + CharaNamaArr [1];
sd_only_num=CharaNamaArr [1];
///////////////////////////////////////////////////////////////////////////////
//bool_effect_fix
//CharaDir
/*
string EditedAnimation_fix_path=CharaDir+"/EditedAnimation_fix";
Debug.Log ("EditedAnimation_fix_path= "+EditedAnimation_fix_path);
if (File.Exists (EditedAnimation_fix_path+"/anim_09_attack_event.anim")) {
Debug.Log ("すでにFiXしたエフェクト用アニメーションが見つかりました!" + EditedAnimation_fix_path);
fix_anim_09_attack_event_anim_path = EditedAnimation_fix_path + "/anim_09_attack_event.anim";
fix_anim_10_skill_event_anim_path = EditedAnimation_fix_path + "/anim_10_skill_event.anim";
fix_anim_09_attack_event_anim_ref = AssetDatabase.LoadAssetAtPath (fix_anim_09_attack_event_anim_path,typeof(AnimationClip)) as AnimationClip;
fix_anim_10_skill_event_anim_ref = AssetDatabase.LoadAssetAtPath (fix_anim_10_skill_event_anim_path,typeof(AnimationClip)) as AnimationClip;
Debug.Log ("#########fix_anim_09_attack_event_anim_ref="+fix_anim_09_attack_event_anim_ref);
Debug.Log ("##########fix_anim_10_skill_event_anim_ref="+fix_anim_10_skill_event_anim_ref);
bool_effect_fix = true;
}
EditedAnimation_fix_path=CharaDir+"/EditedAnimation_fix";
Debug.Log ("EditedAnimation_fix_path= "+EditedAnimation_fix_path);
if (File.Exists (EditedAnimation_fix_path+"/anim_09_attack_event_fix.anim")) {
Debug.Log ("すでにFiXしたエフェクト用アニメーションが見つかりました!" + EditedAnimation_fix_path);
fix_anim_09_attack_event_anim_path = EditedAnimation_fix_path + "/anim_09_attack_event_fix.anim";
fix_anim_10_skill_event_anim_path = EditedAnimation_fix_path + "/anim_10_skill_event_fix.anim";
fix_anim_09_attack_event_anim_ref = AssetDatabase.LoadAssetAtPath (fix_anim_09_attack_event_anim_path,typeof(AnimationClip)) as AnimationClip;
fix_anim_10_skill_event_anim_ref = AssetDatabase.LoadAssetAtPath (fix_anim_10_skill_event_anim_path,typeof(AnimationClip)) as AnimationClip;
Debug.Log ("#########fix_anim_09_attack_event_anim_ref="+fix_anim_09_attack_event_anim_ref);
Debug.Log ("##########fix_anim_10_skill_event_anim_ref="+fix_anim_10_skill_event_anim_ref);
bool_effect_fix = true;
}
if(bool_effect_fix == false){
Debug.Log ("エフェクト用アニメーションないので作ります。" + EditedAnimation_fix_path);
}
*/
////////////////////////////////////////////////////////////////////////////////
string ACpath;
ACpath=CharaDir+"/"+CharaDirName+"_controller.controller";
UnityEditor.Animations.AnimatorController controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(ACpath);
AnimatorControllerRef = controller;
AnimatorControllerRef.RemoveLayer(0);
AnimatorControllerRef.AddLayer("BaseLayer");
BaseLayerStateMachine = AnimatorControllerRef.layers [0].stateMachine;
BaseLayerStateMachine.exitPosition = new Vector3 (0,-150,0);
BaseLayerStateMachine.entryPosition = new Vector3 (0,-100,0);
BaseLayerStateMachine.anyStatePosition = new Vector3 (0,100,0);
AnimatorControllerRef.layers [0].stateMachine.AddStateMachineBehaviour<UniRx.Triggers.ObservableStateMachineTrigger> ();
//ObservableStateMachineTrigger
//////////////////////////////////////////////////////////////////////////////////////////////////
//string[] clipNameArr= AnimationNameStr.Split("_"[0]);
//string StateName=clipNameArr[clipNameArr.Length-1];
///
//AnimatorControllerRef.AddParameter(StateName,UnityEngine.AnimatorControllerParameterType.Trigger);
//AnimatorControllerRef.AddParameter("State",UnityEngine.AnimatorControllerParameterType.Int);
/////////////////////////////////////////////////////////////////////////////////////////////////
/*
AnimatorControllerRef.AddLayer("EventLayer");
EventLayerStateMachine = AnimatorControllerRef.layers [1].stateMachine;
EventLayerStateMachine.exitPosition = new Vector3 (0,-150,0);
EventLayerStateMachine.entryPosition = new Vector3 (0,-100,0);
EventLayerStateMachine.anyStatePosition = new Vector3 (0,100,0);
EventLayerStateMachine.AddState ("Default State", new Vector3 (-250, -100,0));
*/
//////////////////////
//build_Reset ();
/////////////////////
////////////////////////////////////////////////////////////////////////////////
//ModelImporterClipAnimation[] clipAnimations = ParceCSV (csv);
clipAnimations = ParceCSV (csv);
Debug.Log ("SplitWithCsv () clipAnimations= "+clipAnimations);
//AnimationClip AnimationClipRef;
//CreateAnimationClip(CharaDirName);
UnityEditor.Animations.AnimatorState state001= BaseLayerStateMachine.AddState(CharaNamaArr [2],new Vector3(0,buildY,0));
Debug.Log ("BaseLayerStateList= "+BaseLayerStateList);
//state001.motion = AnimationClipRef;
//UnityEditor.Animations.AnimatorState state002 = EventLayerStateMachine.AddState(CharaNamaArr [2],new Vector3(0,buildY,0));
//state002.motion = AnimationClipRef;
/*
if (Assert (clipAnimations != null, "can't parse CSV to Animation")) {
Debug.Log (csv);
return;
}
*/
//ModelImpotersetting();
Loadfile ();
}
float keyframe_reduction_rotation;
float keyframe_reduction_position;
float keyframe_reduction_scale;
public void Loadfile()
{
try
{
string UnityLocalTextPass = "Tools/Motion/Editor/KeyframeReductionList/keyframeReduction_list.txt";
string filepass;
string HD_path = Application.dataPath + "/" + UnityLocalTextPass;
filepass = HD_path;
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(filepass))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Debug.Log(line);
string[] line_Arr=line.Split(","[0]);
if(sd_only_num==line_Arr[0]){
Debug.Log("見つかった line_Arr[0]="+line_Arr[0]+"おなまえは"+line_Arr[4]+" 手動更新?"+line_Arr[5]);
keyframe_reduction_rotation=float.Parse(line_Arr[1]);
keyframe_reduction_position=float.Parse(line_Arr[2]);
keyframe_reduction_scale=float.Parse(line_Arr[3]);
}
//int CharaId=int.Parse(line_Arr[0]);
//effectInfomation.chara_id=int.Parse(line_Arr[1]);
//effectInfomation.asset_name=line_Arr[2];
//effectInfomation.asset_path=line_Arr[3];
//effectInfomation.guid=line_Arr[4];
}
}
}
catch (System.Exception e)
{
Debug.Log ("System.Exception e="+e);
// Let the user know what went wrong.
//Console.WriteLine("The file could not be read:");
//Console.WriteLine(e.Message);
}
ModelImpotersetting();
}
void ModelImpotersetting(){
string path = AssetDatabase.GetAssetPath (modelAsset);
modelAssetPath = path;
ModelImporter importer = AssetImporter.GetAtPath (path) as ModelImporter;
if (Assert (importer != null, "set 3D model, like FBX,etc..")) {
return;
}
//importer.splitAnimations = true; // obsolute in Unity4
importer.clipAnimations = clipAnimations;
//アニメーションのついたFBXをUnityに持ってきた時に発生するアニメーションの誤差.
//Maya等からUnityにアニメーションのついたFBXをインポートした場合、デフォルトではKeyframe Reduction(冗長なアニメーションが削除) される。.
//そのせいで若干誤差が出てその誤差が気になる場合がある。.
importer.animationRotationError = keyframe_reduction_rotation;
importer.animationPositionError = keyframe_reduction_position;
importer.animationScaleError = keyframe_reduction_scale;
AssetDatabase.ImportAsset (path);
AssetDatabase.Refresh ();
//DisplayDialog ("Success", "finish split!");
FbxSeachAndStateMotionSettiong ();
//EditedAnimationStateMotionSetting ();
CreateFbxToPrefab_v2 ();
MaskTransformAllTrue ();
//ウィンドウ閉じる
Close ();
DisplayDialog ("Success", "finish split! And AnimatorController State.Motion Attach clips!");
/*
if (bool_effect_fix == true) {
string AnimationEvent_normal_path=CharaDir+"/AnimationEvent";
string EditedAnimation_normal_path=CharaDir+"/EditedAnimation";
AssetDatabase.DeleteAsset (AnimationEvent_normal_path);
AssetDatabase.DeleteAsset (EditedAnimation_normal_path);
AssetDatabase.Refresh ();
}
*/
}
void MaskTransformAllTrue(){
//ModelImporter modelImporter = (ModelImporter) setImporter.GetAtPath(AssetDatabase.GetAssetPath(TargetObject));
string path = AssetDatabase.GetAssetPath (modelAsset);
//FBXFindAllPropatiesAndWrite.FBXMetaFileReadAndWrite (path+".meta");
FixMask.FBXFixMaskAtPath (path);
/*
modelAssetPath = path;
ModelImporter modelImporter = AssetImporter.GetAtPath (path) as ModelImporter;
SerializedObjectWriterTypeViewerModelMotionMaskTransform2 (modelImporter);
*/
/*
SerializedObject so = new SerializedObject(modelImporter);
SerializedProperty clips = so.FindProperty ("clipAnimations");
for (int i = 0; i < modelImporter.clipAnimations.Length; i++)
{
//SerializedProperty transformMask = so.FindProperty ("transformMask");
SerializedObject clip= clips.GetArrayElementAtIndex (i).serializedObject;
SerializedProperty events = clip.FindProperty("events");
SerializedProperty transformMask = clip.FindProperty("transformMask");//good
//var transformMask = clips.GetArrayElementAtIndex (i).FindPropertyRelative ("transformMask");
//m_MaskSource.
// as AvatarMask;
//var ev = clips.GetArrayElementAtIndex(i).FindPropertyRelative("events");
//AnimationEvent[] array = new AnimationEvent[ev.arraySize];
//SerializedProperty serializedProperty = sp.FindPropertyRelative("events");
//avatarMask.transformCount;
//transformMask transformMasks = clips.GetArrayElementAtIndex(i).FindPropertyRelative("transformMask");
int transformCount =transformMask.FindPropertyRelative ("transformCount").intValue;
Debug.Log ("MaskTransformAllTrue transformCount= "+transformCount);
//for (int t = 0; t < transformCount; t++)
//{
// Debug.Log ("m_MaskSource.GetTransformPath("+i+")"+ m_MaskSource.GetTransformPath(i));
// m_MaskSource.SetTransformActive (i, true);
// }
}
*/
}
public static void SerializedObjectWriterTypeViewerModelMotionMaskTransform2 (ModelImporter modelImporter)
{
var so = new SerializedObject (modelImporter);
var pop = so.GetIterator ();
while (pop.NextVisible (true)) {
if (pop.propertyType.ToString () == "Integer") {
Debug.Log ("Type: " + pop.propertyType + " Path: " + pop.propertyPath + " IntegerValue: " + pop.intValue);
} else if (pop.propertyType.ToString () == "Boolean") {
Debug.Log ("Type: " + pop.propertyType + " Path: " + pop.propertyPath + " BooleanValue: " + pop.boolValue);
} else if (pop.propertyType.ToString () == "Float") {
Debug.Log ("Type: " + pop.propertyType + " Path: " + pop.propertyPath + " FloatValue: " + pop.floatValue);
} else {
Debug.Log ("Other Type: " + pop.propertyType + " Path: " + pop.propertyPath );
}
if (pop.propertyPath.IndexOf ("bodyMask.Array.data") != -1)
{
//Debug.Log ("############### bodyMask見つけたよ####################");
}
//"transformMask"
if (pop.propertyPath.IndexOf ("transformMask") != -1)
{
Debug.Log ("############### transformMask見つけたよ ################# Type: " + pop.propertyType + " Path: " + pop.propertyPath );
}
}
}
public static void SerializedObjectWriterTypeViewer(GameObject gameObjectRef,PassObject Obj)
{
Component[] allComponent;
allComponent = gameObjectRef.GetComponents<Component>();
bool bool_UVModule=false;
bool bool_frameOverTime=false;
foreach(Component go in allComponent)
{
SerializedObject m_Object = new SerializedObject(go);
////////////////////////////////////
m_Object.Update ();
////////////////////////////////////
//SerializedObject psSerial = new SerializedObject (newPS);
Debug.Log ("--------"+ go.GetType() +"-------");
SerializedProperty obj = m_Object.GetIterator();
foreach(SerializedProperty property in obj)
{
if(property.name=="transformMask"){
Debug.Log("//#######transformMask を見つけました#############transformMask="+bool_UVModule);
Debug.Log(property.name + " : " + property.propertyType);
}
/*
if (bool_UVModule == true) {
Debug.Log(property.name + " : " + property.propertyType);
try {
if (property.name == "enabled") {
Debug.Log ("//#######UVModule のプロパティセッティング#############property.boolValue="+property.boolValue);
//Debug.Log("//##### 01 ##UVModule enabled property.boolValue~"+property.boolValue.ToString()+"#############");
}
} catch (System.Exception e) {
Debug.Log ("----enabled----" + e + "-------");
}
try {
if (property.name == "scalar") {
property.floatValue = float.Parse(Obj.frameOverTime);
Debug.Log ("----scalar property.floatValue=----" + property.floatValue + "-------");
bool_frameOverTime = false;
}
} catch (System.Exception e2) {
Debug.Log ("----scalar----" + e2 + "-------");
}
try{
if (property.name == "minMaxState") {
property.intValue = int.Parse(Obj.minMaxState);
Debug.Log ("----minMaxState property.intValue=----" + property.intValue + "-------");
}
}catch(System.Exception e21)
{
Debug.Log ("----scalar----" + e21 + "-------");
}
try {
if (property.name == "tilesX") {
property.intValue = int.Parse(Obj.tilesX);
Debug.Log ("----tilesX property.floatValue=----" + property.intValue + "-------");
}
} catch (System.Exception e3) {
Debug.Log ("----tilesX----" + e3 + "-------");
}
}//if(bool_UVModule==true)
*/
}//foreach(SerializedProperty property in obj)
///////////////////////////////////////////////
m_Object.ApplyModifiedProperties ();//保存
//////////////////////////////////////////////
}//foreach(Component go in allComponent)
}//public static void SerializedObjectWriter(GameObject gameObjectRef,PassObject Obj)
void FbxSeachAndStateMotionSettiong(){
//fbxファイルからAnimationClipを取得する
//http://qiita.com/fujimisakari/items/dfcc1230cd135cf134a1
//CharaAnimationClipListRef=GetAnimationClipInFbx (modelAsset.name);
//BaseLayerStateList ["+animNum+ "- 1]
for(int i = 0; i < BaseLayerStateList.Count-1; i++){
Debug.Log (" BaseLayerStateList["+i+"]= "+BaseLayerStateList[i]);
if (BaseLayerStateList [i] != null)
{
//string[] clipNameArr = BaseLayerStateList [i].name.Split ("_" [0]);
Debug.Log ("########FbxSeachAndStateMotionSettiong#######################BaseLayerStateList[i].name= " + BaseLayerStateList[i].name);
}
}
Object[] all = AssetDatabase.LoadAllAssetsAtPath(modelAssetPath);
//foreach (var item in all)
for(int i = 0; i < all.Length-1; i++)
{
var clip = all[i] as AnimationClip;
if (clip != null)
{
Debug.Log ("clip item.name= : " + clip.name);
string animationName = clip.name;
string[] arr = animationName.Split ('_');
string clipEndName = arr [arr.Length - 1];
//string[] arr=BaseLayerStateList[i].name.Split("_"[0]);
Debug.Log("##########FbxSeachAndStateMotionSettiong####################clipEndName= "+arr[arr.Length-1]);
if (clipEndName != "Take 001") {
for (int j = 0; j < BaseLayerStateList.Count - 1; j++) {
//Debug.Log (" BaseLayerStateList["+i+"]= "+BaseLayerStateList[i]);
//string[] stateNameArr=BaseLayerStateList[j].name.Split("_"[0]);
if (BaseLayerStateList [j] != null) {
string stateEndName = BaseLayerStateList [j].name;
//Debug.Log ("#################################################################BaseLayerStateList[" + j + "].name= " + BaseLayerStateList [j].name);
if (clipEndName == BaseLayerStateList [j].name) {
Debug.Log ("######FbxSeachAndStateMotionSettiong#################clipEndName= " + clipEndName + " とstateEndName= " + stateEndName + " みつかったよ");
BaseLayerStateList [j].motion = clip as UnityEngine.Motion;
Debug.Log ("######FbxSeachAndStateMotionSettiong#################BaseLayerStateList [j].motion= " + BaseLayerStateList [j].motion+ " とBaseLayerStateList [j].motion.name= " + BaseLayerStateList [j].motion.name + " セットされたよ");
}
}
}
/*
if (arr[0]=="motion") {
int animNum=int.Parse (arr[2]);//motion_[CardID]_000の番号
Debug.Log ("clip.name= "+clip.name+" をanimator Controller にセットします。");
Debug.Log ("BaseLayerStateList ["+animNum+ "- 1].name"+BaseLayerStateList [animNum - 1].name);
BaseLayerStateList [animNum - 1].motion = clip as UnityEngine.Motion;
Debug.Log ("BaseLayerStateList ["+animNum+ "- 1].name"+BaseLayerStateList [animNum - 1].name);
Debug.Log ("BaseLayerStateList ["+animNum+ "- 1].motion"+BaseLayerStateList [animNum - 1].motion);
}
*/
}
}
}
AssetDatabase.Refresh();
}
GameObject fbxPrefabRef;
//string sd_num_charaname;
void CreateFbxToPrefab_v2 ()
{
var go = Selection.activeGameObject;
go = modelAsset;
Debug.Log ("CreateFbxToPrefab_v2 -- go=" + go);
//Mesh m1 = go.GetComponent<MeshFilter>().mesh;//update line1
//AssetDatabase.CreateAsset(m1, "Assets/savedMesh/" + go.name +"_M" + ".asset"); // update line2
string modelDirStr = AssetDatabase.GetAssetPath (go);
Debug.Log ("CreateFbxToPrefab_v2 -- modelDirStr=" + modelDirStr);
Debug.Log ("CreateFbxToPrefab_v2 -- modelAsset=" + modelAsset);
string[] modelDirArr;
modelDirArr=modelDirStr.Split("/"[0]);
string buildDir = modelDirArr[0];
for(int i = 1; i < modelDirArr.Length-1; i++)
{
buildDir = buildDir +"/"+ modelDirArr [i];
}
string CharaDir = buildDir;
Debug.Log ("CreateFbxToPrefab_v2 --CharaDir="+CharaDir);
string CharaName = modelDirArr [modelDirArr.Length-1];
Debug.Log ("CreateFbxToPrefab_v2 --CharaName="+CharaName);
GameObject modelAssetIns = GameObject.Instantiate (modelAsset);
var prefab = PrefabUtility.CreateEmptyPrefab(CharaDir +"/"+ sd_num+ "_fbx_motion_prefab.prefab");
fbxPrefabRef = PrefabUtility.ReplacePrefab (modelAssetIns, prefab, ReplacePrefabOptions.ConnectToPrefab);
//プレハブを交換する場合、ソースはインスタンスである必要があります。あなたがソースとして使用しているプレハブはプレハブ資産です。
//UnityEditor.PrefabUtility:ReplacePrefab(ゲームオブジェクト、オブジェクト、ReplacePrefabオプション)
GameObject.DestroyImmediate(modelAssetIns);
AssetDatabase.Refresh();
////////////////////////////
//fbxPrefabRef = prefab as GameObject;
Debug.Log ("CreateFbxToPrefab_v2 ------ fbxPrefabRef= "+fbxPrefabRef);
///////////////////////////
string path = AssetDatabase.GetAssetPath (fbxPrefabRef);
AssetDatabase.ImportAsset (path);
FbxPefabSetting ();
ButtonMakeing ();
}
SkinnedMeshRenderer SkinnedMeshRendererRef;
Material FbxPrefabMeshMaterialRef;
GameObject FbxPrefabMeshRef;
Texture2D FbxPrefabTexture2D;
Texture FbxPrefabTexture;
public Shader shader1MobileDiffuse;
void FbxPefabSetting(){
//fbx_prefab_ref.GetComponent<Animator>().runtimeAnimatorController=
Debug.Log ("CreateFbxToPrefab FbxPefabSetting------fbxPrefabRef= " + fbxPrefabRef);
Animator animator = fbxPrefabRef.GetComponent<Animator>();
Debug.Log ("------fbxPrefabRef animator= " + animator);
Debug.Log ("------fbxPrefabRef animator.runtimeAnimatorController= "+animator.runtimeAnimatorController);
Debug.Log ("------AnimatorControllerRef= "+AnimatorControllerRef);
animator.runtimeAnimatorController = (RuntimeAnimatorController)AnimatorControllerRef as RuntimeAnimatorController;
//animator.runtimeAnimatorController = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load ("path/to/controller_file"));
fbxPrefabRef.transform.localPosition = new Vector3 (0,0,0);
fbxPrefabRef.transform.localRotation = Quaternion.Euler (new Vector3 (0, 0, 0));
fbxPrefabRef.transform.localScale = new Vector3 (1.0f, 1.0f, 0.1f);
//fbxPrefabRef.AddComponent<IdleMotionChangerTrigger> ();
fbxPrefabRef.AddComponent<MotionEventHandler> ();
//UnitDataBox unitDataBox=fbxPrefabRef.AddComponent<UnitDataBox> ();
string UnitDataScriptableAssetPass = CharaDir + "/" + sd_num + "_asset.asset";
Debug.Log ("---------UnitDataScriptableAssetPass="+UnitDataScriptableAssetPass);
//UnitData UnitDataScriptableAsset = AssetDatabase.LoadAssetAtPath(UnitDataScriptableAssetPass, typeof(UnitData)) as UnitData;
//unitDataBox.unitData = UnitDataScriptableAsset;
//fbxPrefabRefに子供いたら
int countp1 = 0;
//bool nameOKbool = false;
foreach (Transform child in fbxPrefabRef.transform) {
Debug.Log ("Child[" + countp1 + "]:" + child.name);
string[] CharaNamaArr;
CharaNamaArr=child.name.Split("_"[0]);
/*
if (CharaNamaArr [0] == "m2dtoolkit") {
nameOKbool = true;
} else {
if (nameOKbool == false) {
}
}
*/
//if ( child.name.ToLower().IndexOf("mesh")!=-1)
if(child.gameObject.GetComponent<SkinnedMeshRenderer> ()!=null)
{
FbxPrefabMeshRef=child.gameObject;
Debug.Log ("SkinnedMeshRendererのついている-------メッシュが見つかりました。!!!!!FbxPrefabMeshRef="+FbxPrefabMeshRef.name);
if (FbxPrefabMeshRef.name == "m2dtoolkit_test_045_finish_del_ok_end_do_combine_katamen_mat_tga_tex_uv_:MeshShape") {
} else {
string errorMassage = "Mayaでメッシュの名前を \n m2dtoolkit_test_045_finish_del_ok_end_do_combine_katamen_mat_tga_tex_uv_:MeshShape \n に変更してください。";
//EditorUtility.DisplayDialog ("メッシュの名前が不正です!!", errorMassage, "ok");
}
}else
{
if (FbxPrefabMeshRef == null)
{
Debug.Log ("-------メッシュが見つかりませんでした");
}
}
countp1++;
}
//SkinnedMeshRendererRef=FbxPrefabMeshRef.GetComponent<SkinnedMeshRenderer> ();
//FbxPrefabMeshMaterialRef=SkinnedMeshRendererRef.materials [0];
//FbxPrefabMeshMaterialRef = SkinnedMeshRendererRef.sharedMaterial;
//FbxPrefabMeshMaterialRef.name =CharaDirName + "_mat.mat";
//Debug.Log ("---------FbxPrefabMeshMaterialRef.name=" + FbxPrefabMeshMaterialRef.name);
//Debug.Log ("---------FbxPrefabMeshMaterialRef.name="+FbxPrefabMeshMaterialRef.name);
//shader1MobileDiffuse = Shader.Find( "Mobile/Diffuse" );
//shader3TransparentVegetationGradation = AssetDatabase.LoadAssetAtPath("/Assets/SD_Chara/shader/"+ "Transparent VegetationGradation.shader", typeof(Shader)) as Shader;
//shader2TransparentVegetation.
//Debug.Log("FbxPrefabMeshMaterialRef.shader="+FbxPrefabMeshMaterialRef.shader);
//FbxPrefabMeshMaterialRef.shader = shader1MobileDiffuse;// FbxPrefabMeshMaterialRef.shader;
//Texture2D FbxPrefabTexture2D = AssetDatabase.LoadAssetAtPath(CharaDir +"/"+ sd_num_charaname+ "_png.png", Texture2D) as Texture2D;
//string TexturePass = CharaDir + "/" + sd_num + "_jpg.jpg";
//Debug.Log ("---------TexturePass="+TexturePass);
//Texture FbxPrefabTexture = AssetDatabase.LoadAssetAtPath(TexturePass, typeof(Texture)) as Texture;
//FbxPrefabTexture2D.
//FbxPrefabMeshMaterialRef.SetTexture("_MainTex",FbxPrefabTexture);
}
void ButtonMakeing()
{
Debug.Log ("########ButtonMakeing####################################################################");
Debug.Log ("########ButtonMakeing####################################################################");
Debug.Log ("########ButtonMakeing####################################################################");
Panel_VerticalLayout = GameObject.Find ("Panel_VerticalLayout").gameObject;
//Panel_VerticalLayout
GameObject Button_prefab= AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Tools/Motion/Editor/Prefab/Button_AAA.prefab") as GameObject;
//
Object[] all = AssetDatabase.LoadAllAssetsAtPath(modelAssetPath);
//foreach (var item in all)
for(int i = 0; i < all.Length-1; i++)
{
var clip = all[i] as AnimationClip;
if (clip != null)
{
Debug.Log ("clip item.name= : " + clip.name);
string animationName = clip.name;
string[] arr = animationName.Split ('_');
string clipEndName=arr[arr.Length-1];
/*
string clipEndName = arr [3];
try{
if(arr[4]!=null)
{
clipEndName=clipEndName+"_"+arr[4];
}
}catch{
}
*/
//string[] arr=BaseLayerStateList[i].name.Split("_"[0]);
Debug.Log("##########FbxSeachAndStateMotionSettiong####################clipEndName= "+clipEndName);
if (clipEndName != "Take 001") {
for (int j = 0; j < BaseLayerStateList.Count; j++) {
//Debug.Log (" BaseLayerStateList["+i+"]= "+BaseLayerStateList[i]);
//string[] stateNameArr=BaseLayerStateList[j].name.Split("_"[0]);
if (BaseLayerStateList [j] != null) {
string stateEndName = BaseLayerStateList [j].name;
Debug.Log ("#################################################################BaseLayerStateList[" + j + "].name= " + BaseLayerStateList [j].name);
if (clipEndName == BaseLayerStateList [j].name) {
Debug.Log ("######FbxSeachAndStateMotionSettiong#################clipEndName= " + clipEndName + " とstateEndName= " + stateEndName + " みつかったよ");
//BaseLayerStateList [j].motion = clip as UnityEngine.Motion;
GameObject Button_Ins = GameObject.Instantiate (Button_prefab);
Button_Ins.transform.SetParent (Panel_VerticalLayout.transform);
//UnityEngine.UI.Button Button_name=new UnityEngine.UI.Button();
Button_Ins.name="Button_name";
RectTransform Button_Ins_RectTransform =Button_Ins.GetComponent<RectTransform>();
//Button_name
Button_Ins_RectTransform.localScale = new Vector3(1.0f,1.0f,1.0f);//SetParentのあとじゃないと効かない
Button_Ins.name=clipEndName;
Button_Ins.transform.FindChild ("Text").GetComponent<Text> ().text = clipEndName;
//CardIDかWeponIDか調べる。
//string[] clipNameArr=clip.name.Split("_"[0]);
int coundetionNum=3;
if(arr[1].IndexOf("C")>-1){
Debug.Log("カードモーション");
coundetionNum = 3;
}else if(arr[1].IndexOf("W")>-1){
Debug.Log("ウェポンモーション");
coundetionNum = 3;
}
int goInt = int.Parse(arr[coundetionNum]);
Button_Ins.transform.GetComponent<TapSwichMotionScript> ().goInt = goInt;
}
}
}
/*
if (arr[0]=="motion") {
int animNum=int.Parse (arr[2]);//motion_[CardID]_000の番号
Debug.Log ("clip.name= "+clip.name+" をanimator Controller にセットします。");
Debug.Log ("BaseLayerStateList ["+animNum+ "- 1].name"+BaseLayerStateList [animNum - 1].name);
BaseLayerStateList [animNum - 1].motion = clip as UnityEngine.Motion;
Debug.Log ("BaseLayerStateList ["+animNum+ "- 1].name"+BaseLayerStateList [animNum - 1].name);
Debug.Log ("BaseLayerStateList ["+animNum+ "- 1].motion"+BaseLayerStateList [animNum - 1].motion);
}
*/
}
}
}
}
bool Assert (bool b, string error)
{
if (!b) {
DisplayDialog ("Warning", error);
return true;
} else {
return false;
}
}
void DisplayDialog (string title, string message)
{
Debug.LogWarning (message);
EditorUtility.DisplayDialog (title, message, "OK");
}
ModelImporterClipAnimation[] ParceCSV (string csv)
{
// split to lines
string[] lines = csv.Split ('\n');
//Debug.Log("[]lines = "+ []lines);
char[] trims = {'\r', ' '};
Debug.Log("trims = "+trims);
List<ModelImporterClipAnimation> clips = new List<ModelImporterClipAnimation> ();
Debug.Log("lines.Length; = "+lines.Length);
for (int i=0; i<lines.Length; i++)
{
string s = lines [i].Trim (trims);
Debug.Log ("ParseClip(s= "+s+")");
bool ParseBool = true;
if (s.IndexOf("Tstance") != -1) {
ParseBool = false;
Debug.Log("てぃーすたんすやらないよー");
}
if (s.IndexOf("TposeEnd") != -1) {
ParseBool = true;
Debug.Log("てぃーポーズもやるー");
}
if (s=="") {
ParseBool = false;
Debug.Log("なんにもないのもやらないよー");
}
if (ParseBool == true) {
Debug.Log ("==========================ParseClip(s= "+s+") ===============================するよー");
ModelImporterClipAnimation clip = ParseClip (s);
Debug.Log ("ParseClip(c) の戻り値=clip= " + clip);
if (clip != null) {
Debug.Log ("clipsにAdd する clip= " + clip);
clips.Add (clip);
Debug.Log ("=====================clips の長さはclips.Count= " + clips.Count + "");
}
}
}
if (clips.Count == 0) {
Debug.Log ("CSVのクリップスは clips.Count= 0 個ありました");
return null;
} else {
Debug.Log ("CSVのクリップスは clips.Count= " + clips.Count + " 個ありました");
build_count = 0;
}
return clips.ToArray();
}
int ParseClipCount=0;
ModelImporterClipAnimation ParseClip (string line)
{
string[] arr = line.Split (',');
//Debug.Log("[] arr = "+[] arr);
Debug.Log("arr.Length = "+arr.Length);
if (arr.Length < 4) {
return null;
} else {
Debug.Log ("CSV行の長さは必要なだけあります。");
}
ModelImporterClipAnimation clip = new ModelImporterClipAnimation ();
//clip.maskType (ClipAnimationMaskType.CreateFromThisModel);
/*
AvatarMask avatarMask = new AvatarMask ();
int avatarTransCount= avatarMask.transformCount;
for (int i = 0; i < avatarTransCount; i++)
{
//avatarMask.GetTransformActive (i);
avatarMask.SetTransformActive (i, true);
}
*/
//try{
//clip.maskSource (avatarMask);
//}catch(){
//}
// name
string name = arr [0];
if (!string.IsNullOrEmpty (name)) {
clip.name = name;
Debug.Log ("clip.name =" + clip.name);
AnimationNameStr = clip.name;
} else {
return null;
}
// first
try {
//clip.firstFrame = int.Parse (arr [1]); // change to float in unity4
clip.firstFrame = float.Parse (arr [1]);
Debug.Log ("clip.firstFrame =" + clip.firstFrame);
} catch {
//
return null;
}
// last
try {
//clip.lastFrame = int.Parse (arr [2]); // change to float in unity4
//clip.lastFrame = float.Parse (arr [2]-1);//ループモーションマイナス1削除
clip.lastFrame = float.Parse (arr [2]);
Debug.Log ("clip.lastFrame =" + clip.lastFrame);
}catch {
//
return null;
Debug.Log("clip.lastFrameがないよ!!!!!!!!!!!!!!!!!!!!!!");
}
//try {
///////////////////////////////////////////
///
///
///
//CardIDかWeponIDか調べる。
string StateWay="left";
string[] clipNameArr=clip.name.Split("_"[0]);
int coundetionNum=3;
if(clipNameArr[1].IndexOf("C")>-1){
Debug.Log("カードモーション");
coundetionNum = 3;
StateWay = "right";
}else if(clipNameArr[1].IndexOf("W")>-1){
Debug.Log("ウェポンモーション");
coundetionNum = 3;
StateWay = "left";
}
int clipCounditionInt = int.Parse(clipNameArr[coundetionNum]);
string StateName=clipNameArr[clipNameArr.Length-1];
if (StateWay == "left") {
AnimatorControllerRef.AddParameter(StateName,UnityEngine.AnimatorControllerParameterType.Trigger);
UnityEditor.Animations.AnimatorState state001 = BaseLayerStateMachine.AddState(StateName,new Vector3(-build_colWidthleft,buildYLeft,0));
UnityEditor.Animations.AnimatorStateTransition state001Transition = BaseLayerStateMachine.AddAnyStateTransition(state001);
state001Transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, StateName);
//state001Transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals,clipCounditionInt, "State");
if(AnimationNameStr=="anim_01_wait"){
state001.writeDefaultValues=true;
Debug.Log("-----------------anim_01_wait のとき state001.writeDefaultValues= "+state001.writeDefaultValues);
}
BaseLayerStateList.Add(state001);
Debug.Log("#################################################################BaseLayerStateList.Count= "+BaseLayerStateList.Count);
//state001.motion=clip. as UnityEngine.Motion;
buildYLeft=buildYLeft+build_rowHeight*1.0f;
build_count++;
}
if (StateWay == "right") {
Debug.Log("------build_right_now="+build_right_now+" ここはtrueでadd---buildY = "+buildY+"----build_count="+build_count+"---AnimationNameStr="+AnimationNameStr+"-add---");
AnimatorControllerRef.AddParameter(StateName,UnityEngine.AnimatorControllerParameterType.Trigger);
UnityEditor.Animations.AnimatorState state002 = BaseLayerStateMachine.AddState(StateName,new Vector3(build_colWidthright,buildYRight,0));
UnityEditor.Animations.AnimatorStateTransition state002Transition = BaseLayerStateMachine.AddAnyStateTransition(state002);
state002Transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, StateName);
//state002Transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.Equals,clipCounditionInt, "State");
BaseLayerStateList.Add(state002);
Debug.Log("######################################################################BaseLayerStateList.Count= "+BaseLayerStateList.Count);
buildYRight=buildYRight+build_rowHeight*1.0f;
build_count++;
}
//} catch {
//return null;
// Debug.Log("Animatorにならべるところがなんかおかしいよ");
//}
try {
//clip.lastFrame = int.Parse (arr [2]); // change to float in unity4
bool myLoopTimebool=false;
if(clipNameArr[clipNameArr.Length-1].IndexOf("Walk")>-1){
Debug.Log("Walkモーション");
myLoopTimebool=true;
}else if(clipNameArr[clipNameArr.Length-1]=="Idle"){
Debug.Log("Idleモーション");
myLoopTimebool=true;
}else if(clipNameArr[clipNameArr.Length-1].IndexOf("Loop")>-1){
Debug.Log("Loopモーション");
myLoopTimebool=true;
}else if(clipNameArr[clipNameArr.Length-1]=="Run"){
Debug.Log("Runモーション");
myLoopTimebool=true;
}
/*
switch (AnimationNameStr)
{
case "anim_01_Idle":
myLoopTimebool=true;
break;
case "anim_02_Charge":
myLoopTimebool=true;
break;
case "anim_03_TranceIn":
myLoopTimebool=false;
break;
case "anim_04_TranceTurn":
myLoopTimebool=false;
break;
case "anim_05_TranceOut":
myLoopTimebool=false;
break;
case "anim_06_Walk":
myLoopTimebool=true;
break;
case "anim_07_Attack":
myLoopTimebool=false;
break;
case "anim_08_UnionIdle":
myLoopTimebool=true;
break;
case "anim_09_UnionAttack":
myLoopTimebool=false;
break;
case "anim_10_WeaponOut":
myLoopTimebool=false;
break;
case "anim_11_WeaponIn":
myLoopTimebool=false;
break;
default:
myLoopTimebool=false;
break;
}
*/
clip.loopTime=myLoopTimebool;
Debug.Log ("clip.loopTime =" + clip.loopTime);
} catch {
//return null;
}
/////////////////////////////Effect
///
///
List<AnimationEvent> animEventsList1 = new List<AnimationEvent>();
try {
////////////////////////
/// ////////////////////////////
string eventStr1 = arr [3];
// アニメーションイベントの作成
AnimationEvent animEvent1 = new AnimationEvent();
//AnimationEvent[] animEvents;
// 関数名をセット
animEvent1.functionName =eventStr1;
AnimationClipEventNameStr=animEvent1.functionName;
// Int型のパラメーターを格納
animEvent1.intParameter = 0;
//animEvent.time=arr [4];
//animEvent.objectReferenceParameter=objEffect_0_start as UnityEngine.Object ;
// 設定した時間にイベントを送信
animEvent1.time = float.Parse (arr [4]);
// アニメーションイベントの追加
//clip.AddEvent(animEvent);
if(arr [3+1]!=null){
Debug.Log("while loop arr["+3+"+1]="+arr [3+1]+" があるので実行");
//////////////////////////////////////
//AnimationClipRef;
//CreateAnimationClip(AnimationNameStr+"_event");
//Crate();
///////////////////////////////////////
//animEvent1.objectReferenceParameter=ScriptableObjectRef as UnityEngine.Object ;
// アニメーションイベントの追加
//clip.AddEvent(animEvent);
animEventsList1.Add(animEvent1);
}
//animEventsList1.Add(animEvent1);
} catch {
//return null;
}
try {
////////////////////////
/// ////////////////////////////
string eventStr2= arr [5];
// アニメーションイベントの作成
AnimationEvent animEvent2 = new AnimationEvent();
//AnimationEvent[] animEvents;
// 関数名をセット
animEvent2.functionName =eventStr2;
AnimationClipEventNameStr=animEvent2.functionName;
// Int型のパラメーターを格納
animEvent2.intParameter = 0;
//animEvent.time=arr [4];
//animEvent.objectReferenceParameter=objEffect_0_start as UnityEngine.Object ;
// 設定した時間にイベントを送信
animEvent2.time = float.Parse (arr [6]);
// アニメーションイベントの追加eventAnimationClipList
//clip.AddEvent(animEvent);
if(arr [5+1]!=null){
Debug.Log("while loop arr["+5+"+1]="+arr [5+1]+" があるので実行");
//////////////////////////////////////
//Crate();
///////////////////////////////////////
//animEvent2.objectReferenceParameter=ScriptableObjectRef as UnityEngine.Object ;
// アニメーションイベントの追加
//clip.AddEvent(animEvent);
animEventsList1.Add(animEvent2);
}
//animEventsList1.Add(animEvent2);
} catch {
//return null;
}
try{
//for(int i = 7; i < arr.Length; i+2)
//{
int i=7;
while(i < arr.Length)
{
//Debug.Log ("I've washed a cup!");
Debug.Log("--------while loop i="+i+"----------------------");
/// ////////////////////////////
string eventStr3= arr [i];
Debug.Log("while loop eventStr3="+eventStr3);
// アニメーションイベントの作成
AnimationEvent animEvent3 = new AnimationEvent();
//AnimationEvent[] animEvents;
// 関数名をセット
animEvent3.functionName =eventStr3;
AnimationClipEventNameStr=animEvent3.functionName;
// Int型のパラメーターを格納
animEvent3.intParameter = 0;
//animEvent.time=arr [4];
// 設定した時間にイベントを送信
animEvent3.time = float.Parse (arr [i+1]);
Debug.Log("while loop animEvent3.time="+animEvent3.time);
if(arr [i+1]!=null){
Debug.Log("while loop arr["+i+"+1]="+arr [i+1]+" があるので実行");
//////////////////////////////////////
//Crate();
///////////////////////////////////////
//animEvent3.objectReferenceParameter=ScriptableObjectRef as UnityEngine.Object ;
// アニメーションイベントの追加
//clip.AddEvent(animEvent);
animEventsList1.Add(animEvent3);
}
Debug.Log("--------while loop i="+i+"----------------------end");
i=i+2;
Debug.Log("--------while loop i="+i+"--------------------next");
}
} catch {
//return null;
}
try{
////----------------------------------------------------------------
if(offsetU_time_List[0]!=null){
for (int i=0; i<offsetU_time_List.Count; i++) {
float offsetUtime=offsetU_time_List[i];
float offsetUvalue=offsetU_value_List[i];
Debug.Log("------firstframe:"+clip.firstFrame+"より大きくてlastFrame:"+clip.lastFrame+"より小さい=offsetUtime"+offsetUtime+" -----------------");
if(offsetUtime>=clip.firstFrame){
//firstframeより大きくて
if(offsetUtime<=clip.lastFrame){
//lastFrameより小さい
Debug.Log("------firstframe:"+clip.firstFrame+"より大きくてlastFrame:"+clip.lastFrame+"より小さい=offsetUtime"+offsetUtime+" ------みっけ-----------");
//AnimationClipRef;
/// ////////////////////////////
string eventStr4= "OnAnimEventTrigger";
Debug.Log("while loop eventStr4="+eventStr4);
// アニメーションイベントの作成
AnimationEvent animEvent4 = new AnimationEvent();
//AnimationEvent[] animEvents;
// 関数名をセット
animEvent4.functionName =eventStr4;
AnimationClipEventNameStr=animEvent4.functionName;
// Int型のパラメーターを格納
animEvent4.intParameter = 0;
//animEvent.time=arr [4];
// 設定した時間にイベントを送信
float timeSa=clip.lastFrame-clip.firstFrame;
float oneframe=timeSa/100.0f;
animEvent4.time = oneframe*i+1;
Debug.Log("while loop animEvent4.time="+animEvent4.time);
//if(arr [i+1]!=null){
Debug.Log("while loop arr["+i+"+1]="+arr [i+1]+" があるので実行");
//////////////////////////////////////
//Crate();
///////////////////////////////////////
//ScriptableObjectRef.offsetU=offsetUvalue*-1.0F;
//animEvent4.objectReferenceParameter=ScriptableObjectRef as UnityEngine.Object ;
// アニメーションイベントの追加
//clip.AddEvent(animEvent);
Debug.Log("-----------animEventsList1.Count = "+animEventsList1.Count);
animEventsList1.Add(animEvent4);
Debug.Log("-----------animEventsList1.Count = "+animEventsList1.Count+" 増えた?");
//}
}
}
}
}
if(offsetV_time_List[0]!=null){
for (int i=0; i<offsetV_time_List.Count; i++) {
float offsetVtime=offsetV_time_List[i];
float offsetVvalue=offsetV_value_List[i];
Debug.Log("------firstframe:"+clip.firstFrame+"より大きくてlastFrame:"+clip.lastFrame+"より小さい=offsetVtime"+offsetVtime+" -----------------");
if(offsetVtime>=clip.firstFrame){
//firstframeより大きくて
if(offsetVtime<=clip.lastFrame){
//lastFrameより小さい
Debug.Log("------firstframe:"+clip.firstFrame+"より大きくてlastFrame:"+clip.lastFrame+"より小さい=offsetVtime"+offsetVtime+" -------みっけ----------");
//AnimationClipRef;
/// ////////////////////////////
string eventStr4= "OnAnimEventTrigger";
Debug.Log("while loop eventStr4="+eventStr4);
// アニメーションイベントの作成
AnimationEvent animEvent4 = new AnimationEvent();
//AnimationEvent[] animEvents;
// 関数名をセット
animEvent4.functionName =eventStr4;
AnimationClipEventNameStr=animEvent4.functionName;
// Int型のパラメーターを格納
animEvent4.intParameter = 0;
//animEvent.time=arr [4];
float timeSa=clip.lastFrame-clip.firstFrame;
float oneframe=timeSa/100.0f;
animEvent4.time = oneframe*i+1;
Debug.Log("while loop animEvent4.time="+animEvent4.time);
//if(arr [i+1]!=null){
Debug.Log("イベント があるので実行");
//////////////////////////////////////
//Crate();
///////////////////////////////////////
//ScriptableObjectRef.offsetV=offsetVvalue*-1.0F;
//animEvent4.objectReferenceParameter=ScriptableObjectRef as UnityEngine.Object ;
// アニメーションイベントの追加
//clip.AddEvent(animEvent);
Debug.Log("-----------animEventsList1.Count = "+animEventsList1.Count);
animEventsList1.Add(animEvent4);
Debug.Log("-----------animEventsList1.Count = "+animEventsList1.Count+" 増えた?");
//}
}
}
}
}
///--------------------------------------------------------------------
}catch{
}
Debug.Log("-----------animEventsList1.Count = "+animEventsList1.Count+" -------------最後イベントいくつ?");
if(animEventsList1.Count!=0){
AnimationEvent[] animationEventArr1 = animEventsList1.ToArray();
//clip.events = animationEventArr1;
//AnimationClipRef.frameRate = 24;
//AnimationClipRef.
//AnimationClipRef.events= animationEventArr1;
//AnimationUtility.SetAnimationEvents(AnimationClipRef, animationEventArr1);
//clip.maskType (ClipAnimationMaskType.CreateFromThisModel);
//clip.maskSource(A)
clip.events=animationEventArr1;
//eventAnimationClipList.Add (AnimationClipRef);
//public static void SetAnimationEvents(AnimationClip clip, AnimationEvent[] events);
//Debug.Log ("clip.events =" + clip.events);
//Debug.Log ("AnimationClipRef.events =" + AnimationClipRef.events);
///////////////////////////////////////////////////////////////////////////
if (buildY_event == 0) {
buildY_event = buildY;
} else {
buildY_event = buildY_event + build_rowHeight;
}
//UnityEditor.Animations.AnimatorState state003 = EventLayerStateMachine.AddState(clip.name,new Vector3(-build_colWidthleft,buildY_event,0));
//UnityEditor.Animations.AnimatorStateTransition state003Transition = EventLayerStateMachine.AddAnyStateTransition(state003);
//state003Transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, AnimationNameStr);
//EventLayerStateList.Add(state003);
if (buildY_event == 0) {
}
/// ///////////////////////////////////////////////////////////////////////
}
/*
// wrapmode
try {
clip.wrapMode = (WrapMode) System.Enum.Parse(typeof(WrapMode), arr [3]);
} catch {
return null;
}
if (clip.wrapMode == WrapMode.Loop || clip.wrapMode == WrapMode.PingPong) {
clip.loop = true;
}
*/
Debug.Log ("################################################ParseClip############################################################Count=" + ParseClipCount+" 回目");
ParseClipCount = ParseClipCount + 1;
Debug.Log ("################################################ParseClipの返し値=clip=" + clip);
return clip;
}
/// <summary>
/// CreateScriptableObjectPrefub
/// </summary>
///
string[] labels = {"Data", "ScriptableObject"};
string getSavePath (string filename,string folderName,string filetype)
{
Debug.Log("------- getSavePath ----- filename="+filename);
//string objectName = selectedObject.name;
//string objectName = selectedObject.name;
string objectName = filename;
//string objectName = selectedObject.name+"_AnimationClipEventData";
if (filetype == ".asset") {
//objectName = selectedObject.name+"_"+AnimationNameStr+"_"+AnimationClipEventNameStr;
}
if (filetype == ".anim") {
//objectName =AnimationNameStr+"_event";
}
//Debug.Log("------- getSavePath ----- objectName="+objectName);
//string dirPath = Path.GetDirectoryName (AssetDatabase.GetAssetPath (selectedObject));
////////////
string dirPath = CharaDir;
//string dirPath = CharaDir+"/AnimationClipEventData";
//////////
Debug.Log ("------ getSavePath -----dirPath="+dirPath);
//string path = string.Format ("{0}/{1}.asset", dirPath, objectName);
//string path = dirPath+"/"+objectName+".asset";
string path = dirPath+"/"+objectName+filetype;
//string AnimationEventDir = dirPath + "/AnimationEvent";
string MakeDir = dirPath +"/"+ folderName;
if (AssetDatabase.IsValidFolder (MakeDir)) {
Debug.Log (MakeDir + " ありました!");
} else {
Debug.Log (MakeDir+" ないのでつくりますです!");
string guid = AssetDatabase.CreateFolder(dirPath, folderName);
string newFolderPath = AssetDatabase.GUIDToAssetPath(guid);
Debug.Log (newFolderPath+" = newFolderPath 作りました!");
Debug.Log (MakeDir+" = MakeDir 作りました!");
}
//path= MakeDir+"/"+objectName+".asset";
path= MakeDir+"/"+objectName+filetype;
if (File.Exists (path)) {
for (int i = 1;; i++) {
//path = string.Format ("{0}/{1}({2}).asset", dirPath, objectName, i);
path=MakeDir+"/"+objectName+"_"+i+filetype;
if (!File.Exists (path))
break;
}
}
Debug.Log("------ getSavePath --------- path="+path);
return path;
}
////////////////////////////////////////////////////////////////////////////////
#region Static
/// <summary>
/// Open the tool window
/// </summary>
[MenuItem("Tools/Motion/Animation Split And Make AnimeController Trigger")]
static public void OpenWindow ()
{
EditorWindow.GetWindow<ModelAnimationSplitterWithAnimeControllerTrigger> (true, "Model Animation Splitter With AnimeControllerTrigger", true);
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment