예제 #1
0
 void OnDisable()
 {
     ToolManager.activeToolChanged -= ActiveToolDidChange;
     if (_impl != null)
     {
         _impl.Dispose();
         _impl = null;
     }
 }
예제 #2
0
 void ActiveToolDidChange()
 {
     if (ToolManager.IsActiveTool(this))
     {
     }
     else
     {
         if (_impl != null)
         {
             _impl.Dispose();
             _impl = null;
         }
     }
 }
예제 #3
0
        public override void OnToolGUI(EditorWindow window)
        {
            if (_impl == null)
            {
                _impl = new BoneSelector(SceneView.lastActiveSceneView.camera);
            }

            var root = Selection.activeGameObject?.GetComponent <Vrm10Instance>();

            if (root == null)
            {
                return;
            }
            _impl.SetTarget(root.gameObject);
            if (Event.current.type == EventType.Repaint)
            {
                _impl.Draw();
            }

            // bone manipulator
            var  selected = _impl.SelectedBoneInfo;
            bool selector = true;

            if (selected != null)
            {
                EditorGUI.BeginChangeCheck();
                Quaternion rot = Handles.RotationHandle(selected.HeadObject.transform.rotation, selected.HeadObject.transform.position);
                // Debug.Log($"{selected}");
                if (EditorGUI.EndChangeCheck())
                {
                    // UNDO
                    Undo.RecordObject(selected.HeadObject.transform, "bone rotation");

                    // apply
                    selected.HeadObject.transform.rotation = rot;
                    selector = false;
                }
            }

            if (selector)
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    // 回転ギズモがなんもしなかった
                    // selector
                    Vector2 mousePosition = Event.current.mousePosition;
                    Ray     ray           = HandleUtility.GUIPointToWorldRay(mousePosition);
                    Event   e             = Event.current;
                    _impl.IntersectBone(ray);
                }
                else if (Event.current.type == EventType.MouseMove)
                {
                    // hover
                    Vector2 mousePosition = Event.current.mousePosition;
                    Ray     ray           = HandleUtility.GUIPointToWorldRay(mousePosition);
                    Event   e             = Event.current;
                    _impl.IntersectBone(ray, true);
                }
            }

            // disable sceneView select
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        }