|
1 | | -using System.Collections; |
2 | | -using System.Collections.Generic; |
3 | | -using UnityEngine; |
4 | | -using UnityEditor; |
| 1 | +using UnityEditor; |
5 | 2 | using UnityEditor.Animations; |
| 3 | +using UnityEngine; |
6 | 4 |
|
7 | 5 | namespace CVVTuber |
8 | 6 | { |
9 | 7 | public class CVVTuberExampleMenuItem : MonoBehaviour |
10 | 8 | { |
11 | | - [MenuItem ("Tools/CVVTuberExample/Setup CVVTuberExample", false, 1)] |
12 | | - public static void SetCVVTuberSettings () |
| 9 | + [MenuItem("Tools/CVVTuberExample/Setup CVVTuberExample", false, 1)] |
| 10 | + public static void SetCVVTuberSettings() |
13 | 11 | { |
14 | | - GameObject cVVTuberModel = GameObject.Find ("CVVTuberModel"); |
15 | | - if (cVVTuberModel != null) { |
| 12 | + GameObject cVVTuberModel = GameObject.Find("CVVTuberModel"); |
| 13 | + if (cVVTuberModel != null) |
| 14 | + { |
16 | 15 | //Undo.RecordObject(cVVTuberModel.transform.localEulerAngles, "Change cVVTuberModel.transform.localEulerAngles"); |
17 | 16 | //cVVTuberModel.transform.localEulerAngles = new Vector3 (0, 180, 0); |
18 | 17 |
|
19 | | - Animator animator = cVVTuberModel.GetComponent<Animator> (); |
| 18 | + bool allComplete = true; |
| 19 | + |
| 20 | + Animator animator = cVVTuberModel.GetComponent<Animator>(); |
20 | 21 |
|
21 | 22 | AnimatorController animCon = animator.runtimeAnimatorController as AnimatorController; |
22 | | - Undo.RecordObject (animCon, "Set true to layer.ikPass"); |
23 | | - var layers = animCon.layers; |
24 | | - foreach (var layer in layers) { |
25 | | - if (layer.stateMachine.name == "Base Layer") { |
26 | | - layer.iKPass = true; |
| 23 | + if (animCon != null) |
| 24 | + { |
| 25 | + Undo.RecordObject(animCon, "Set true to layer.ikPass"); |
| 26 | + var layers = animCon.layers; |
| 27 | + bool success = false; |
| 28 | + foreach (var layer in layers) |
| 29 | + { |
| 30 | + if (layer.stateMachine.name == "Base Layer") |
| 31 | + { |
| 32 | + layer.iKPass = true; |
| 33 | + success = true; |
| 34 | + } |
| 35 | + } |
| 36 | + EditorUtility.SetDirty(animCon); |
| 37 | + |
| 38 | + if (success) |
| 39 | + { |
| 40 | + Debug.Log("Set true to layer.ikPass"); |
| 41 | + } |
| 42 | + else |
| 43 | + { |
| 44 | + Debug.LogError("success == false"); |
| 45 | + allComplete = false; |
27 | 46 | } |
28 | 47 | } |
29 | | - EditorUtility.SetDirty (animCon); |
| 48 | + else |
| 49 | + { |
| 50 | + Debug.LogError("animCon == null"); |
| 51 | + allComplete = false; |
| 52 | + } |
30 | 53 |
|
31 | | - HeadLookAtIKController headLookAtIKController = FindObjectOfType<HeadLookAtIKController> (); |
32 | | - if (headLookAtIKController != null) { |
33 | | - Undo.RecordObject (headLookAtIKController, "Set animator to headLookAtIKController.target"); |
| 54 | + HeadLookAtIKController headLookAtIKController = FindObjectOfType<HeadLookAtIKController>(); |
| 55 | + if (headLookAtIKController != null) |
| 56 | + { |
| 57 | + Undo.RecordObject(headLookAtIKController, "Set animator to headLookAtIKController.target"); |
34 | 58 | headLookAtIKController.target = animator; |
35 | 59 |
|
36 | | - var lookAtLoot = GameObject.Find ("LookAtRoot").transform; |
37 | | - if (lookAtLoot != null) { |
| 60 | + var lookAtLoot = GameObject.Find("LookAtRoot").transform; |
| 61 | + if (lookAtLoot != null) |
| 62 | + { |
38 | 63 | headLookAtIKController.lookAtRoot = lookAtLoot; |
39 | | - var lookAtTarget = lookAtLoot.transform.Find ("LookAtTarget").transform; |
40 | | - if (lookAtTarget != null) { |
| 64 | + var lookAtTarget = lookAtLoot.transform.Find("LookAtTarget").transform; |
| 65 | + if (lookAtTarget != null) |
| 66 | + { |
41 | 67 | headLookAtIKController.lookAtTarget = lookAtTarget; |
42 | 68 | } |
43 | 69 | } |
| 70 | + EditorUtility.SetDirty(headLookAtIKController); |
44 | 71 |
|
45 | | - EditorUtility.SetDirty (headLookAtIKController); |
| 72 | + if (headLookAtIKController.lookAtRoot != null && headLookAtIKController.lookAtTarget != null) |
| 73 | + { |
| 74 | + Debug.Log("Set animator to headLookAtIKController.target"); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + Debug.LogError("headLookAtIKController.lookAtRoot == null || headLookAtIKController.lookAtTarget == null"); |
| 79 | + allComplete = false; |
| 80 | + } |
| 81 | + } |
| 82 | + else |
| 83 | + { |
| 84 | + Debug.LogError("headLookAtIKController == null"); |
| 85 | + allComplete = false; |
46 | 86 | } |
47 | 87 |
|
48 | | - HeadRotationController headRotationController = FindObjectOfType<HeadRotationController> (); |
49 | | - Undo.RecordObject (headRotationController, "Set head.transform to headRotationController.target"); |
50 | | - if (headRotationController != null) { |
51 | | - headRotationController.target = cVVTuberModel.transform.Find ("Character001/hips/spine/chest/upper_chest/neck/head").transform; |
| 88 | + HeadRotationController headRotationController = FindObjectOfType<HeadRotationController>(); |
| 89 | + Undo.RecordObject(headRotationController, "Set head.transform to headRotationController.target"); |
| 90 | + if (headRotationController != null) |
| 91 | + { |
| 92 | + headRotationController.target = cVVTuberModel.transform.Find("Character001/hips/spine/chest/upper_chest/neck/head").transform; |
| 93 | + EditorUtility.SetDirty(headRotationController); |
52 | 94 |
|
53 | | - EditorUtility.SetDirty (headRotationController); |
| 95 | + if (headRotationController.target != null) |
| 96 | + { |
| 97 | + Debug.Log("Set head.transform to headRotationController.target"); |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + Debug.LogError("headRotationController.target == null"); |
| 102 | + allComplete = false; |
| 103 | + } |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + Debug.LogError("headRotationController == null"); |
| 108 | + allComplete = false; |
54 | 109 | } |
55 | 110 |
|
56 | | - FaceBlendShapeController faceBlendShapeController = FindObjectOfType<FaceBlendShapeController> (); |
57 | | - if (faceBlendShapeController != null) { |
58 | | - Undo.RecordObject (faceBlendShapeController, "Set SkinnedMeshRenderer to faceBlendShapeController.FACE_DEF"); |
59 | | - faceBlendShapeController.FACE_DEF = cVVTuberModel.transform.Find ("FACE_DEF").GetComponent<SkinnedMeshRenderer> (); |
| 111 | + FaceBlendShapeController faceBlendShapeController = FindObjectOfType<FaceBlendShapeController>(); |
| 112 | + if (faceBlendShapeController != null) |
| 113 | + { |
| 114 | + Undo.RecordObject(faceBlendShapeController, "Set SkinnedMeshRenderer to faceBlendShapeController.FACE_DEF"); |
| 115 | + faceBlendShapeController.FACE_DEF = cVVTuberModel.transform.Find("FACE_DEF").GetComponent<SkinnedMeshRenderer>(); |
| 116 | + EditorUtility.SetDirty(faceBlendShapeController); |
60 | 117 |
|
61 | | - EditorUtility.SetDirty (faceBlendShapeController); |
| 118 | + if (faceBlendShapeController.FACE_DEF != null) |
| 119 | + { |
| 120 | + Debug.Log("Set SkinnedMeshRenderer to faceBlendShapeController.FACE_DEF"); |
| 121 | + } |
| 122 | + else |
| 123 | + { |
| 124 | + Debug.LogError("faceBlendShapeController.FACE_DEF == null"); |
| 125 | + allComplete = false; |
| 126 | + } |
| 127 | + } |
| 128 | + else |
| 129 | + { |
| 130 | + Debug.LogError("faceBlendShapeController == null"); |
| 131 | + allComplete = false; |
62 | 132 | } |
63 | 133 |
|
64 | | - } else { |
65 | | - Debug.LogError ("There is no \"CVVTuberModel\" prefab in the scene. Please add \"CVVTuberModel\" prefab to the scene."); |
| 134 | + if (allComplete) |
| 135 | + Debug.Log("CVVTuberExample setup is all complete!"); |
| 136 | + |
| 137 | + } |
| 138 | + else |
| 139 | + { |
| 140 | + Debug.LogError("There is no \"CVVTuberModel\" prefab in the scene. Please add \"CVVTuberModel\" prefab to the scene."); |
66 | 141 | } |
67 | 142 | } |
68 | 143 | } |
|
0 commit comments