Joystick Pack を Floating で利用すると、1回目の操作のときだけタップしたところにコントローラーが表示されないバグがありました。その修正方法です。
対応方法
Joystock.cs の ScreenPointToAnchorePosition メソッドに以下3-6行目のコードを追加します。
protected Vector2 ScreenPointToAnchoredPosition(Vector2 screenPosition)
{
3 if (cam == null && canvas.renderMode == RenderMode.ScreenSpaceCamera)
4 {
5 cam = canvas.worldCamera;
6 }
Vector2 localPoint = Vector2.zero;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(baseRect, screenPosition, cam, out localPoint))
{
Vector2 pivotOffset = baseRect.pivot * baseRect.sizeDelta;
return localPoint - (background.anchorMax * baseRect.sizeDelta) + pivotOffset;
}
return Vector2.zero;
}
補足
上記対応しないと cam に canvas.worldCamera が設定されないまま位置計算されて、canvas の scale が考慮されていないに位置に Joystick が表示されます。2回目以降は、FlotingJoystick.cs の OnPointerDown -> base.OnPointerDown(eventData) -> Joystick.cs の OnDrag の中で cam が設定されるので問題にならず、タップした位置にコントローラーが表示されます。
所感
こういう特定の条件下において1回目以降は正常に動くパターンみたいなのはAssetとしても対応が難しいものだなと思いまました。