Created
March 14, 2015 09:15
-
-
Save yowasou/1b52383f26d7076017e9 to your computer and use it in GitHub Desktop.
MMD4Mecaniumで読み込んできたモデルに、カメラ位置用の空ゲームオブジェクトを追加する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
using System.Collections.Generic; | |
public class CreateCameraPos : EditorWindow | |
{ | |
public class CameraPos | |
{ | |
public string BoneNameJP; | |
public string Name; | |
public bool LikeSearch; | |
public Vector3 FirstPos = new Vector3(0, 0, 0); | |
public CameraPos(string _boneNameJP,bool _likeSearch,string _name,float x,float y,float z) | |
{ | |
BoneNameJP = _boneNameJP; | |
Name = _name; | |
LikeSearch = _likeSearch; | |
FirstPos = new Vector3(x, y, z); | |
} | |
} | |
public class CameraPosis : List<CameraPos> | |
{ | |
public CameraPos Search(string boneName) | |
{ | |
foreach (CameraPos cp in this) | |
{ | |
if (cp.LikeSearch && boneName.IndexOf(cp.BoneNameJP) > -1) | |
{ | |
return cp; | |
} | |
else if (!cp.LikeSearch && boneName == cp.BoneNameJP) | |
{ | |
return cp; | |
} | |
} | |
return null; | |
} | |
public void DestroyCameras() | |
{ | |
foreach (CameraPos cp in this) | |
{ | |
GameObject go = GameObject.Find(cp.Name); | |
if (go != null) | |
{ | |
DestroyImmediate(go); | |
} | |
} | |
} | |
} | |
public CameraPosis cameras; | |
[SerializeField] | |
GameObject mmd4MecaniumModel = null; | |
void OnGUI() | |
{ | |
Init(); | |
EditorGUILayout.Space(); | |
GUILayout.Label("カメラを作成するモデルを選択してください"); | |
mmd4MecaniumModel = (GameObject)EditorGUILayout.ObjectField(mmd4MecaniumModel, typeof(GameObject)); | |
if (GUILayout.Button("Process")) | |
{ | |
if (mmd4MecaniumModel == null) | |
{ | |
Debug.Log("モデルを指定してさい"); | |
} | |
else | |
{ | |
Process(); | |
this.Close(); | |
} | |
} | |
} | |
private void Process() | |
{ | |
MMD4MecanimModel model = mmd4MecaniumModel.GetComponent<MMD4MecanimModel>(); | |
MMD4MecanimData.ModelData modelData = MMD4MecanimData.BuildModelData(model.modelFile); | |
cameras.DestroyCameras(); | |
foreach (MMD4MecanimData.BoneData bone in modelData.boneDataList) | |
{ | |
CameraPos cp = cameras.Search(bone.nameJp); | |
if (cp != null) | |
{ | |
GameObject skl = GameObject.Find(bone.skeletonName); | |
GameObject obj = new GameObject(); | |
obj.name = cp.Name; | |
obj.transform.parent = skl.transform; | |
obj.transform.localPosition = cp.FirstPos; | |
} | |
} | |
} | |
[MenuItem("Window/CreateCameraPOS")] | |
static void OpenPopup() | |
{ | |
CreateCameraPos window = (CreateCameraPos)(EditorWindow.GetWindow(typeof(CreateCameraPos))); | |
Vector2 popupSize = new Vector2(300, 140); | |
window.minSize = popupSize; | |
window.maxSize = popupSize; | |
window.title = "Select MMD4Mecanium Model"; | |
window.ShowPopup(); | |
} | |
public virtual void Init() | |
{ | |
cameras = new CameraPosis(); | |
cameras.Add(new CameraPos("頭", false, "CameraPOS_HEAD", 0, 0, 1f)); | |
cameras.Add(new CameraPos("上半身", false, "CameraPOS_HESO", 0, 0, 1f)); | |
cameras.Add(new CameraPos("上半身2", false, "CameraPOS_MUNE", 0, 0, 1f)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment