static void AddMethodToLookup(System.Type type, SceneViewTool obj, string methodName, EventType eventType)
 {
     if (!methods.ContainsKey (eventType))
         methods.Add (eventType, new List<MethodRef> ());
     var method = type.GetMethod (methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     if (method != null)
         methods[eventType].Add (new MethodRef (obj, method));
 }
    static void AddMethodToLookup(System.Type type, SceneViewTool obj, string methodName, EventType eventType)
    {
        if (!methods.ContainsKey(eventType))
        {
            methods.Add(eventType, new List <MethodRef> ());
        }
        var method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

        if (method != null)
        {
            methods[eventType].Add(new MethodRef(obj, method));
        }
    }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        protected internal override void PreInput()
        {
            SceneObject[] selectedSceneObjects = Selection.SceneObjects;

            if (selectedSceneObjects.Length == 0)
            {
                if (activeHandle != null)
                {
                    activeHandle.Destroy();
                    activeHandle = null;
                }
            }
            else
            {
                if (activeHandleType != EditorApplication.ActiveSceneTool || activeHandle == null)
                {
                    if (activeHandle != null)
                    {
                        activeHandle.Destroy();
                        activeHandle = null;
                    }

                    switch (EditorApplication.ActiveSceneTool)
                    {
                    case SceneViewTool.Move:
                        activeHandle = new MoveHandle();
                        break;

                    case SceneViewTool.Rotate:
                        activeHandle = new RotateHandle();
                        break;

                    case SceneViewTool.Scale:
                        activeHandle = new ScaleHandle();
                        break;
                    }

                    activeHandleType = EditorApplication.ActiveSceneTool;
                }
            }

            if (activeHandle != null)
            {
                // In case the object moved programmatically, make the handle reflect its current transform
                UpdateActiveHandleTransform(selectedSceneObjects);

                activeHandle.PreInput();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Triggered when one of the scene tool buttons is clicked, changing the active scene handle.
 /// </summary>
 /// <param name="tool">Clicked scene tool to activate.</param>
 private void OnSceneToolButtonClicked(SceneViewTool tool)
 {
     EditorApplication.ActiveSceneTool = tool;
     editorSettingsHash = EditorSettings.Hash;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Triggered when one of the scene tool buttons is clicked, changing the active scene handle.
 /// </summary>
 /// <param name="tool">Clicked scene tool to activate.</param>
 private void OnSceneToolButtonClicked(SceneViewTool tool)
 {
     EditorApplication.ActiveSceneTool = tool;
     editorSettingsHash = EditorSettings.Hash;
 }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        protected internal override void PreInput()
        {
            SceneObject[] selectedSceneObjects = Selection.SceneObjects;

            if (selectedSceneObjects.Length == 0)
            {
                if (activeHandle != null)
                {
                    activeHandle.Destroy();
                    activeHandle = null;
                }
            }
            else
            {
                if (activeHandleType != EditorApplication.ActiveSceneTool || activeHandle == null)
                {
                    if (activeHandle != null)
                    {
                        activeHandle.Destroy();
                        activeHandle = null;
                    }

                    switch (EditorApplication.ActiveSceneTool)
                    {
                    case SceneViewTool.Move:
                        activeHandle = new MoveHandle();
                        break;

                    case SceneViewTool.Rotate:
                        activeHandle = new RotateHandle();
                        break;

                    case SceneViewTool.Scale:
                        activeHandle = new ScaleHandle();
                        break;
                    }

                    activeHandleType = EditorApplication.ActiveSceneTool;
                }
            }

            if (activeHandle != null)
            {
                Quaternion rotation;
                if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
                {
                    rotation = Quaternion.Identity;
                }
                else
                {
                    rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection
                }
                Vector3 position;
                if (EditorApplication.ActivePivotMode == HandlePivotMode.Pivot)
                {
                    position = selectedSceneObjects[0].Position; // Just take pivot from the first one, no averaging
                }
                else
                {
                    List <SceneObject> flatenedHierarchy = new List <SceneObject>();
                    foreach (var so in selectedSceneObjects)
                    {
                        flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so));
                    }

                    position = EditorUtility.CalculateCenter(flatenedHierarchy.ToArray());
                }

                activeHandle.Position = position;
                activeHandle.Rotation = rotation;

                activeHandle.PreInput();
            }
        }
 public MethodRef(SceneViewTool instance, MethodInfo method)
 {
     this.instance = instance;
     this.method   = method;
 }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        protected internal override void PreInput()
        {
            SceneObject[] selectedSceneObjects = Selection.SceneObjects;

            if (selectedSceneObjects.Length == 0)
            {
                if (activeHandle != null)
                {
                    activeHandle.Destroy();
                    activeHandle = null;
                }
            }
            else
            {
                if (activeHandleType != EditorApplication.ActiveSceneTool || activeHandle == null)
                {
                    if (activeHandle != null)
                    {
                        activeHandle.Destroy();
                        activeHandle = null;
                    }

                    switch (EditorApplication.ActiveSceneTool)
                    {
                        case SceneViewTool.Move:
                            activeHandle = new MoveHandle();
                            break;
                        case SceneViewTool.Rotate:
                            activeHandle = new RotateHandle();
                            break;
                        case SceneViewTool.Scale:
                            activeHandle = new ScaleHandle();
                            break;
                    }

                    activeHandleType = EditorApplication.ActiveSceneTool;
                }
            }

            if (activeHandle != null)
            {
                Quaternion rotation;
                if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
                    rotation = Quaternion.Identity;
                else
                    rotation = selectedSceneObjects[0].Rotation; // We don't average rotation in case of multi-selection

                Vector3 position;
                if (EditorApplication.ActivePivotMode == HandlePivotMode.Pivot)
                    position = selectedSceneObjects[0].Position; // Just take pivot from the first one, no averaging
                else
                {
                    List<SceneObject> flatenedHierarchy = new List<SceneObject>();
                    foreach (var so in selectedSceneObjects)
                        flatenedHierarchy.AddRange(EditorUtility.FlattenHierarchy(so));

                    AABox selectionBounds = EditorUtility.CalculateBounds(flatenedHierarchy.ToArray());
                    position = selectionBounds.Center;
                }

                activeHandle.Position = position;
                activeHandle.Rotation = rotation;

                activeHandle.PreInput();
            }
        }
 public MethodRef(SceneViewTool instance, MethodInfo method)
 {
     this.instance = instance;
     this.method = method;
 }