1- using UnityEditor ;
2- using UnityEditor . Animations ;
3- using UnityEngine ;
4-
5- namespace CVVTuber
6- {
7- public class CVVTuberExampleMenuItem : MonoBehaviour
8- {
9- [ MenuItem ( "Tools/CVVTuberExample/Setup CVVTuberExample" , false , 1 ) ]
10- public static void SetCVVTuberSettings ( )
11- {
12- GameObject cVVTuberModel = GameObject . Find ( "CVVTuberModel" ) ;
13- if ( cVVTuberModel != null )
14- {
15- //Undo.RecordObject(cVVTuberModel.transform.localEulerAngles, "Change cVVTuberModel.transform.localEulerAngles");
16- //cVVTuberModel.transform.localEulerAngles = new Vector3 (0, 180, 0);
17-
18- bool allComplete = true ;
19-
20- Animator animator = cVVTuberModel . GetComponent < Animator > ( ) ;
21-
22- AnimatorController animCon = animator . runtimeAnimatorController as AnimatorController ;
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 ;
46- }
47- }
48- else
49- {
50- Debug . LogError ( "animCon == null" ) ;
51- allComplete = false ;
52- }
53-
54- HeadLookAtIKController headLookAtIKController = FindObjectOfType < HeadLookAtIKController > ( ) ;
55- if ( headLookAtIKController != null )
56- {
57- Undo . RecordObject ( headLookAtIKController , "Set animator to headLookAtIKController.target" ) ;
58- headLookAtIKController . target = animator ;
59-
60- var lookAtLoot = GameObject . Find ( "LookAtRoot" ) . transform ;
61- if ( lookAtLoot != null )
62- {
63- headLookAtIKController . lookAtRoot = lookAtLoot ;
64- var lookAtTarget = lookAtLoot . transform . Find ( "LookAtTarget" ) . transform ;
65- if ( lookAtTarget != null )
66- {
67- headLookAtIKController . lookAtTarget = lookAtTarget ;
68- }
69- }
70- EditorUtility . SetDirty ( headLookAtIKController ) ;
71-
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 ;
86- }
87-
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 ) ;
94-
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 ;
109- }
110-
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 ) ;
117-
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 ;
132- }
133-
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." ) ;
141- }
142- }
143- }
1+ using UnityEditor ;
2+ using UnityEditor . Animations ;
3+ using UnityEngine ;
4+
5+ namespace CVVTuber
6+ {
7+ public class CVVTuberExampleMenuItem : MonoBehaviour
8+ {
9+ [ MenuItem ( "Tools/CVVTuberExample/Setup CVVTuberExample" , false , 1 ) ]
10+ public static void SetCVVTuberSettings ( )
11+ {
12+ GameObject cVVTuberModel = GameObject . Find ( "CVVTuberModel" ) ;
13+ if ( cVVTuberModel != null )
14+ {
15+ //Undo.RecordObject(cVVTuberModel.transform.localEulerAngles, "Change cVVTuberModel.transform.localEulerAngles");
16+ //cVVTuberModel.transform.localEulerAngles = new Vector3 (0, 180, 0);
17+
18+ bool allComplete = true ;
19+
20+ Animator animator = cVVTuberModel . GetComponent < Animator > ( ) ;
21+
22+ AnimatorController animCon = animator . runtimeAnimatorController as AnimatorController ;
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 ;
46+ }
47+ }
48+ else
49+ {
50+ Debug . LogError ( "animCon == null" ) ;
51+ allComplete = false ;
52+ }
53+
54+ HeadLookAtIKController headLookAtIKController = FindObjectOfType < HeadLookAtIKController > ( ) ;
55+ if ( headLookAtIKController != null )
56+ {
57+ Undo . RecordObject ( headLookAtIKController , "Set animator to headLookAtIKController.target" ) ;
58+ headLookAtIKController . target = animator ;
59+
60+ var lookAtLoot = GameObject . Find ( "LookAtRoot" ) . transform ;
61+ if ( lookAtLoot != null )
62+ {
63+ headLookAtIKController . lookAtRoot = lookAtLoot ;
64+ var lookAtTarget = lookAtLoot . transform . Find ( "LookAtTarget" ) . transform ;
65+ if ( lookAtTarget != null )
66+ {
67+ headLookAtIKController . lookAtTarget = lookAtTarget ;
68+ }
69+ }
70+ EditorUtility . SetDirty ( headLookAtIKController ) ;
71+
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 ;
86+ }
87+
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 ) ;
94+
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 ;
109+ }
110+
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 ) ;
117+
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 ;
132+ }
133+
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." ) ;
141+ }
142+ }
143+ }
144144}
0 commit comments