@@ -38,120 +38,82 @@ private void Update()
3838
3939 try
4040 {
41- if ( ctrlComp == null )
41+ var compData = default ( ovrAvatarComponent ) ;
42+ var ctrlCompData = default ( ovrAvatarControllerComponent ) ;
43+ var handCompData = default ( ovrAvatarHandComponent ) ;
44+
45+ if ( TryGetCtrlComponent ( owner . sdkAvatar , ref ctrlCompData , ref compData ) )
4246 {
43- var ctrlCompData = default ( ovrAvatarControllerComponent ) ;
44- var ctrlCompDataBase = default ( ovrAvatarComponent ) ;
45- if ( TryGetCtrlComponent ( owner . sdkAvatar , ref ctrlCompDataBase , ref ctrlCompData ) )
47+ if ( ctrlComp == null )
4648 {
47- var goParent = new GameObject ( ctrlCompDataBase . name ) ;
49+ var goParent = new GameObject ( compData . name ) ;
4850 goParent . transform . SetParent ( transform , false ) ;
4951 ctrlComp = AddAvatarCtrlComp ( goParent ) ;
5052
51- for ( uint i = 0 , imax = ctrlCompDataBase . renderPartCount ; i < imax ; ++ i )
53+ for ( uint i = 0 , imax = compData . renderPartCount ; i < imax ; ++ i )
5254 {
53- var goPart = new GameObject ( ctrlCompDataBase . name + "_renderPart_" + ( int ) i ) ;
55+ var goPart = new GameObject ( compData . name + "_renderPart_" + ( int ) i ) ;
5456 goPart . transform . SetParent ( goParent . transform , false ) ;
55- IntPtr renderPart = OvrAvatar . GetRenderPart ( ctrlCompDataBase , i ) ;
57+ IntPtr renderPart = OvrAvatar . GetRenderPart ( compData , i ) ;
5658 ovrAvatarRenderPartType type = CAPI . ovrAvatarRenderPart_GetType ( renderPart ) ;
57- var ovrRenderPart = AddAvatarRenderComp ( goPart , type , renderPart , ctrlCompDataBase , true ) ;
59+ var ovrRenderPart = AddAvatarRenderComp ( goPart , type , renderPart , compData , true ) ;
5860 if ( ovrRenderPart != null )
5961 {
6062 ctrlComp . RenderParts . Add ( ovrRenderPart ) ;
6163 }
6264 }
6365 }
6466
65- PrintHierarchy ( ctrlComp . transform , 0 ) ;
67+ UpdateAvatarCtrlComp ( ctrlComp , ref ctrlCompData , ref compData ) ;
6668 }
6769
68- UpdateAvatarCtrlComp ( ctrlComp ) ;
69-
70- if ( handComp == null )
70+ if ( TryGetHandComponent ( owner . sdkAvatar , ref handCompData , ref compData ) )
7171 {
72- var handCompDataBase = default ( ovrAvatarComponent ) ;
73- var handCompData = default ( ovrAvatarHandComponent ) ;
74- if ( TryGetHandComponent ( owner . sdkAvatar , ref handCompDataBase , ref handCompData ) )
72+ if ( handComp == null )
7573 {
76- var goParent = new GameObject ( handCompDataBase . name ) ;
74+ var goParent = new GameObject ( compData . name ) ;
7775 goParent . transform . SetParent ( transform , false ) ;
7876 handComp = AddAvatarHandComp ( goParent ) ;
7977
80- for ( uint i = 0 , imax = handCompDataBase . renderPartCount ; i < imax ; ++ i )
78+ for ( uint i = 0 , imax = compData . renderPartCount ; i < imax ; ++ i )
8179 {
82- var goPart = new GameObject ( handCompDataBase . name + "_renderPart_" + ( int ) i ) ;
80+ var goPart = new GameObject ( compData . name + "_renderPart_" + ( int ) i ) ;
8381 goPart . transform . SetParent ( goParent . transform , false ) ;
84- IntPtr renderPart = OvrAvatar . GetRenderPart ( handCompDataBase , i ) ;
82+ IntPtr renderPart = OvrAvatar . GetRenderPart ( compData , i ) ;
8583 ovrAvatarRenderPartType type = CAPI . ovrAvatarRenderPart_GetType ( renderPart ) ;
86- var ovrRenderPart = AddAvatarRenderComp ( goPart , type , renderPart , handCompDataBase , false ) ;
84+ var ovrRenderPart = AddAvatarRenderComp ( goPart , type , renderPart , compData , false ) ;
8785 if ( ovrRenderPart != null )
8886 {
8987 handComp . RenderParts . Add ( ovrRenderPart ) ;
9088 }
9189 }
9290 }
9391
94- PrintHierarchy ( handComp . transform , 0 ) ;
92+ UpdateAvatarHandComp ( handComp , ref handCompData , ref compData ) ;
9593 }
96-
97- UpdateAvatarHandComp ( handComp ) ;
9894 }
9995 catch ( Exception e )
10096 {
10197 Debug . Log ( "lawwong CompUpdate " + ( isLeft ? "L" : "R" ) + " " + e . Message + " -- " + e . StackTrace ) ;
10298 }
10399 }
104100
105- private void PrintHierarchy ( Transform t , int indent )
106- {
107- var indentStr = string . Empty ;
108- for ( int i = indent ; i > 0 ; -- i ) { indentStr += " " ; }
109- Debug . Log ( "lawwongPH " + indentStr + "Trans: " + t . name + " " + ( t . gameObject . activeInHierarchy ? "O" : "X" ) ) ;
110- indentStr += " " ;
111- var comps = Utility . ListPool < Component > . Get ( ) ;
112- try
113- {
114- t . GetComponents ( comps ) ;
115- for ( int i = 0 , imax = comps . Count ; i < imax ; ++ i )
116- {
117- var compType = comps [ i ] . GetType ( ) ;
118- if ( comps [ i ] is MonoBehaviour )
119- {
120- Debug . Log ( "lawwongPH " + indentStr + "Comps: " + compType . Name + " " + ( ( ( MonoBehaviour ) comps [ i ] ) . enabled ? "O" : "X" ) ) ;
121- }
122- else if ( compType != typeof ( Transform ) )
123- {
124- Debug . Log ( "lawwongPH " + indentStr + "Comps: " + compType . Name ) ;
125- }
126- }
127- }
128- finally
129- {
130- Utility . ListPool < Component > . Release ( comps ) ;
131- comps = null ;
132- }
133- for ( int i = 0 , imax = t . childCount ; i < imax ; ++ i )
134- {
135- PrintHierarchy ( t . GetChild ( i ) , indent + 1 ) ;
136- }
137- }
138-
139- private bool TryGetCtrlComponent ( IntPtr avatar , ref ovrAvatarComponent compDataBase , ref ovrAvatarControllerComponent compData )
101+ private bool TryGetCtrlComponent ( IntPtr avatar , ref ovrAvatarControllerComponent ctrlCompData , ref ovrAvatarComponent compData )
140102 {
141103#if VIU_OCULUSVR_20_0_OR_NEWER
142104 if ( isLeft )
143105 {
144- if ( CAPI . ovrAvatarPose_GetLeftControllerComponent ( avatar , ref compData ) )
106+ if ( CAPI . ovrAvatarPose_GetLeftControllerComponent ( avatar , ref ctrlCompData ) )
145107 {
146- CAPI . ovrAvatarComponent_Get ( compData . renderComponent , true , ref compDataBase ) ;
108+ CAPI . ovrAvatarComponent_Get ( ctrlCompData . renderComponent , true , ref compData ) ;
147109 return true ;
148110 }
149111 }
150112 else
151113 {
152- if ( CAPI . ovrAvatarPose_GetRightControllerComponent ( avatar , ref compData ) )
114+ if ( CAPI . ovrAvatarPose_GetRightControllerComponent ( avatar , ref ctrlCompData ) )
153115 {
154- CAPI . ovrAvatarComponent_Get ( compData . renderComponent , true , ref compDataBase ) ;
116+ CAPI . ovrAvatarComponent_Get ( ctrlCompData . renderComponent , true , ref compData ) ;
155117 return true ;
156118 }
157119 }
@@ -162,30 +124,30 @@ private bool TryGetCtrlComponent(IntPtr avatar, ref ovrAvatarComponent compDataB
162124 CAPI . ovrAvatarPose_GetRightControllerComponent ( owner . sdkAvatar ) ;
163125 if ( compDataRef . HasValue )
164126 {
165- compData = compDataRef . Value ;
166- compDataBase = ( ovrAvatarComponent ) Marshal . PtrToStructure ( compData . renderComponent , typeof ( ovrAvatarComponent ) ) ;
127+ ctrlCompData = compDataRef . Value ;
128+ compData = ( ovrAvatarComponent ) Marshal . PtrToStructure ( ctrlCompData . renderComponent , typeof ( ovrAvatarComponent ) ) ;
167129 return true ;
168130 }
169131 return false ;
170132#endif
171133 }
172134
173- private bool TryGetHandComponent ( IntPtr avatar , ref ovrAvatarComponent compDataBase , ref ovrAvatarHandComponent compData )
135+ private bool TryGetHandComponent ( IntPtr avatar , ref ovrAvatarHandComponent handCompData , ref ovrAvatarComponent compData )
174136 {
175137#if VIU_OCULUSVR_20_0_OR_NEWER
176138 if ( isLeft )
177139 {
178- if ( CAPI . ovrAvatarPose_GetLeftHandComponent ( avatar , ref compData ) )
140+ if ( CAPI . ovrAvatarPose_GetLeftHandComponent ( avatar , ref handCompData ) )
179141 {
180- CAPI . ovrAvatarComponent_Get ( compData . renderComponent , true , ref compDataBase ) ;
142+ CAPI . ovrAvatarComponent_Get ( handCompData . renderComponent , true , ref compData ) ;
181143 return true ;
182144 }
183145 }
184146 else
185147 {
186- if ( CAPI . ovrAvatarPose_GetRightHandComponent ( avatar , ref compData ) )
148+ if ( CAPI . ovrAvatarPose_GetRightHandComponent ( avatar , ref handCompData ) )
187149 {
188- CAPI . ovrAvatarComponent_Get ( compData . renderComponent , true , ref compDataBase ) ;
150+ CAPI . ovrAvatarComponent_Get ( handCompData . renderComponent , true , ref compData ) ;
189151 return true ;
190152 }
191153 }
@@ -196,8 +158,8 @@ private bool TryGetHandComponent(IntPtr avatar, ref ovrAvatarComponent compDataB
196158 CAPI . ovrAvatarPose_GetRightHandComponent ( owner . sdkAvatar ) ;
197159 if ( compDataRef . HasValue )
198160 {
199- compData = compDataRef . Value ;
200- compDataBase = ( ovrAvatarComponent ) Marshal . PtrToStructure ( compData . renderComponent , typeof ( ovrAvatarComponent ) ) ;
161+ handCompData = compDataRef . Value ;
162+ compData = ( ovrAvatarComponent ) Marshal . PtrToStructure ( handCompData . renderComponent , typeof ( ovrAvatarComponent ) ) ;
201163 return true ;
202164 }
203165 return false ;
@@ -207,9 +169,8 @@ private bool TryGetHandComponent(IntPtr avatar, ref ovrAvatarComponent compDataB
207169 private OvrAvatarComponent AddAvatarCtrlComp ( GameObject go )
208170 {
209171#if VIU_OCULUSVR_20_0_OR_NEWER
210- var comp = go . AddComponent < OvrAvatarTouchController > ( ) ;
172+ var comp = go . AddComponent < OvrAvatarComponent > ( ) ;
211173 comp . SetOvrAvatarOwner ( owner . ovrAvatar ) ;
212- comp . isLeftHand = isLeft ;
213174 return comp ;
214175#else
215176 go . AddComponent < OvrAvatarTouchController > ( ) ;
@@ -220,40 +181,39 @@ private OvrAvatarComponent AddAvatarCtrlComp(GameObject go)
220181 private OvrAvatarComponent AddAvatarHandComp ( GameObject go )
221182 {
222183#if VIU_OCULUSVR_20_0_OR_NEWER
223- var comp = go . AddComponent < OvrAvatarHand > ( ) ;
184+ var comp = go . AddComponent < OvrAvatarComponent > ( ) ;
224185 comp . SetOvrAvatarOwner ( owner . ovrAvatar ) ;
225- comp . isLeftHand = isLeft ;
226186 return comp ;
227187#else
228188 go . AddComponent < OvrAvatarHand > ( ) ;
229189 return go . AddComponent < OvrAvatarComponent > ( ) ;
230190#endif
231191 }
232192
233- private void UpdateAvatarCtrlComp ( OvrAvatarComponent comp )
193+ private void UpdateAvatarCtrlComp ( OvrAvatarComponent comp , ref ovrAvatarControllerComponent ctrlCompData , ref ovrAvatarComponent compData )
234194 {
195+ var recoverPos = comp . transform . localPosition ;
196+ var recoverRot = comp . transform . localRotation ;
235197#if VIU_OCULUSVR_20_0_OR_NEWER
198+ comp . UpdateAvatar ( ctrlCompData . renderComponent ) ;
236199#else
237- var compDataBase = default ( ovrAvatarComponent ) ;
238- var compData = default ( ovrAvatarControllerComponent ) ;
239- if ( TryGetCtrlComponent ( owner . sdkAvatar , ref compDataBase , ref compData ) )
240- {
241- comp . UpdateAvatar ( compDataBase , owner . ovrAvatar ) ;
242- }
200+ comp . UpdateAvatar ( compData , owner . ovrAvatar ) ;
243201#endif
202+ comp . transform . localPosition = recoverPos ;
203+ comp . transform . localRotation = recoverRot ;
244204 }
245205
246- private void UpdateAvatarHandComp ( OvrAvatarComponent comp )
206+ private void UpdateAvatarHandComp ( OvrAvatarComponent comp , ref ovrAvatarHandComponent handCompData , ref ovrAvatarComponent compData )
247207 {
208+ var recoverPos = comp . transform . localPosition ;
209+ var recoverRot = comp . transform . localRotation ;
248210#if VIU_OCULUSVR_20_0_OR_NEWER
211+ comp . UpdateAvatar ( handCompData . renderComponent ) ;
249212#else
250- var compDataBase = default ( ovrAvatarComponent ) ;
251- var compData = default ( ovrAvatarHandComponent ) ;
252- if ( TryGetHandComponent ( owner . sdkAvatar , ref compDataBase , ref compData ) )
253- {
254- comp . UpdateAvatar ( compDataBase , owner . ovrAvatar ) ;
255- }
213+ comp . UpdateAvatar ( compData , owner . ovrAvatar ) ;
256214#endif
215+ comp . transform . localPosition = recoverPos ;
216+ comp . transform . localRotation = recoverRot ;
257217 }
258218
259219 private OvrAvatarRenderComponent AddAvatarRenderComp ( GameObject go , ovrAvatarRenderPartType type , IntPtr renderPart , ovrAvatarComponent compData , bool isController )
@@ -279,7 +239,6 @@ private OvrAvatarRenderComponent AddAvatarRenderComp(GameObject go, ovrAvatarRen
279239 var wasActive = go . activeSelf ;
280240 typeof ( OvrAvatarSkinnedMeshRenderPBSComponent ) . GetMethod ( "Initialize" , flags ) . Invoke ( renderer , new object [ ]
281241 { rendererData , null , 0 , 0 } ) ;
282- Debug . Log ( "lawwong AddAvatarRenderComp " + go . name + " " + ( wasActive ? "O" : "X" ) + " >> " + ( go . activeSelf ? "O" : "X" ) ) ;
283242 return renderer ;
284243 }
285244 case ovrAvatarRenderPartType . SkinnedMeshRenderPBS_V2:
0 commit comments