コード例 #1
0
        // This is called for each window that your tool is active in. Put the functionality of your tool here.
        public override void OnToolGUI(EditorWindow window)
        {
            EditorGUI.BeginChangeCheck();

            Vector3 position = Tools.handlePosition;

            using (new Handles.DrawingScope())
            {
                float handleSize = HandleUtility.GetHandleSize(position);

                Handles.color = Handles.xAxisColor;
                position      = Handles.Slider(position, Vector3.right);

                Handles.color = Handles.zAxisColor;
                position      = Handles.Slider(position, Vector3.forward);

                Handles.color = Handles.yAxisColor;
                position      = Handles.Slider2D(position + new Vector3(1, 0, 1) * handleSize * slide2DSize, Vector3.up, Vector3.right, Vector3.forward, handleSize * slide2DSize, Handles.RectangleHandleCap, 0);
            }

            if (EditorGUI.EndChangeCheck())
            {
                Vector3 delta = Snapping.Snap(position - Tools.handlePosition, EditorSnapSettings.move);

                Undo.RecordObjects(Selection.transforms, "Move Platform");

                foreach (var transform in Selection.transforms)
                {
                    transform.position += delta;
                }
            }
        }
コード例 #2
0
        protected override void OnEnable()
        {
            base.OnEnable();

            var mainTemplate = EditorGUIUtility.Load(k_GridSettingsWindowUxmlPath) as VisualTreeAsset;

            mainTemplate.CloneTree(rootVisualElement);

            rootVisualElement.Q <TextElement>("PaneTitle").text = L10n.Tr("Grid Visual");
            rootVisualElement.Q <Button>("PaneOption").clicked += PaneOptionMenu;

            m_GridPlane = rootVisualElement.Q <ButtonStripField>("GridPlane");

            foreach (var axis in m_Axes)
            {
                m_GridPlane.AddButton(axis.ToString());
            }

            m_GridPlane.label = L10n.Tr("Grid Plane");
            m_GridPlane.RegisterValueChangedCallback((evt) =>
            {
                m_SceneView.sceneViewGrids.gridAxis = m_Axes[evt.newValue];
                SceneView.RepaintAll();
            });

            m_GridOpacity       = rootVisualElement.Q <Slider>("Opacity");
            m_GridOpacity.label = L10n.Tr("Opacity");

            m_GridOpacity.RegisterValueChangedCallback(evt =>
            {
                m_SceneView.sceneViewGrids.gridOpacity = evt.newValue;
                SceneView.RepaintAll();
            });

            var toHandle = rootVisualElement.Q <Button>("ToHandle");

            toHandle.text     = L10n.Tr("To Handle");
            toHandle.clicked += () =>
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.SetAllGridsPivot(Snapping.Snap(Tools.handlePosition, GridSettings.size));
                }
                SceneView.RepaintAll();
            };

            var toOrigin = rootVisualElement.Q <Button>("ToOrigin");

            toOrigin.text     = L10n.Tr("To Origin");
            toOrigin.clicked += () =>
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.ResetPivot(SceneViewGrid.GridRenderAxis.All);
                }
                SceneView.RepaintAll();
            };
        }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (!health.IsAlive())
        {
            if (currentEvolution == lastEvolution)
            {
                StartCoroutine(OnDeath());
            }

            else
            {
                switch (currentEvolution)
                {
                case TowerEvolutions.Evolution1:
                    StartCoroutine(EvolveTower(TowerEvolutions.Evolution2));
                    break;

                case TowerEvolutions.Evolution2:
                    StartCoroutine(EvolveTower(TowerEvolutions.Evolution3));
                    break;
                }
            }
        }
        else
        {
            Transform target = CheckTarget();
            if (target)
            {
                Vector2 direction = target.position - transform.position;
                targetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
                targetAngle = Snapping.Snap(targetAngle, 45f);
                targetX     = Mathf.Cos(targetAngle * Mathf.Deg2Rad);
                targetY     = Mathf.Sin(targetAngle * Mathf.Deg2Rad);
                if (timerActive)
                {
                    shootTimer -= Time.deltaTime;
                }
                if (shootTimer < 0)
                {
                    shootTimer = 0;
                }
                Shoot();
            }
        }
    }
コード例 #4
0
    void Update()
    {
        if (!health.IsAlive())
        {
            StartCoroutine(OnDeath()); return;
        }



        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
        mousePos   = cam.ScreenToWorldPoint(Input.mousePosition);
        Vector2 characterDirection = mousePos - body.position;

        relativeAngle  = Mathf.Atan2(characterDirection.y, characterDirection.x) * Mathf.Rad2Deg;
        relativeAngle  = Snapping.Snap(relativeAngle, 45f);
        relativeMouseX = Mathf.Cos(relativeAngle * Mathf.Deg2Rad);
        relativeMouseY = Mathf.Sin(relativeAngle * Mathf.Deg2Rad);



        if ((relativeMouseX > 0) && !isFacingRight)
        {
            Flip();
        }
        else if ((relativeMouseX < 0) && isFacingRight)
        {
            Flip();
        }

        if (timerActive)
        {
            shootTimer -= Time.deltaTime;
        }
        if (shootTimer < 0)
        {
            shootTimer = 0;
        }
        if (Input.GetButtonDown("Fire1") && !EventSystem.current.IsPointerOverGameObject())
        {
            Shoot();
        }
    }
コード例 #5
0
#pragma warning disable 618
        public static Vector3 Do(
            int id,
            Vector3 handlePos,
            Vector3 offset,
            Vector3 handleDir,
            Vector3 slideDir1,
            Vector3 slideDir2,
            float handleSize,
            Handles.DrawCapFunction drawFunc,
            Vector2 snap,
            bool drawHelper)
#pragma warning restore 618
        {
            bool orgGuiChanged = GUI.changed;

            GUI.changed = false;

            Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper);

            if (GUI.changed)
            {
                handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y;

                if (EditorSnapSettings.gridSnapActive)
                {
                    var normal = Vector3.Cross(slideDir1, slideDir2);

                    if (Snapping.IsCardinalDirection(normal))
                    {
                        var worldSpace = Handles.matrix.MultiplyPoint(handlePos);
                        worldSpace = Snapping.Snap(worldSpace, GridSettings.size, (SnapAxis) ~new SnapAxisFilter(normal));
                        handlePos  = Handles.inverseMatrix.MultiplyPoint(worldSpace);
                    }
                }
            }

            GUI.changed |= orgGuiChanged;
            return(handlePos);
        }
コード例 #6
0
        void DoGridVisualSettings()
        {
            Vector3 grid   = GridSettings.size;
            bool    linked = gridValueLinked;

            EditorGUI.BeginChangeCheck();
            grid = EditorGUILayout.LinkedVector3Field(Contents.gridSize, grid, ref linked);
            if (EditorGUI.EndChangeCheck())
            {
                gridValueLinked   = linked;
                GridSettings.size = grid;
                SceneView.RepaintAll();
            }

            EditorGUI.BeginChangeCheck();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(Contents.movePivot);
            if (GUILayout.Button("Handle"))
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.SetAllGridsPivot(Snapping.Snap(Tools.handlePosition, GridSettings.size));
                }
            }
            if (GUILayout.Button("Reset"))
            {
                foreach (var view in SceneView.sceneViews)
                {
                    ((SceneView)view).sceneViewGrids.ResetPivot(SceneViewGrid.GridRenderAxis.All);
                }
            }
            GUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
        }
コード例 #7
0
 void GridSizeChanged(Vector3 size)
 {
     SetPivot(GridRenderAxis.X, Snapping.Snap(GetPivot(GridRenderAxis.X), GridSettings.size));
     SetPivot(GridRenderAxis.Y, Snapping.Snap(GetPivot(GridRenderAxis.Y), GridSettings.size));
     SetPivot(GridRenderAxis.Z, Snapping.Snap(GetPivot(GridRenderAxis.Z), GridSettings.size));
 }
コード例 #8
0
ファイル: GraphView.cs プロジェクト: pshtif/Dash
        void ProcessLeftClick(Event p_event, Rect p_rect)
        {
            if (p_event.button != 0)
            {
                return;
            }

            if (p_event.type == EventType.MouseDown)
            {
                GUI.FocusControl("");
            }

            // Select
            if (p_event.type == EventType.MouseDown && !p_event.alt && Graph != null && !p_event.control)
            {
                DashEditorWindow.SetDirty(true);

                NodeBase hitNode      = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));
                int      hitNodeIndex = Graph.Nodes.IndexOf(hitNode);

                if (!SelectionManager.IsSelected(hitNodeIndex) && (!p_event.shift || hitNodeIndex == 0))
                {
                    SelectionManager.ClearSelection();
                }

                if (hitNodeIndex >= 0)
                {
                    AddSelectedNode(hitNodeIndex);

                    dragging = DraggingType.NODE_DRAG;
                }
                else
                {
                    GraphBox box = Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                    if (box != null)
                    {
                        DashEditorCore.selectedBox = box;
                        DashEditorCore.selectedBox.StartDrag();
                        dragging = DraggingType.BOX_DRAG;
                    }
                    else
                    {
                        box = Graph.HitsBoxResize(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                        if (box != null)
                        {
                            DashEditorCore.selectedBox = box;
                            DashEditorCore.selectedBox.StartResize();
                            dragging = DraggingType.BOX_RESIZE;
                        }
                        else
                        {
                            dragging = DraggingType.SELECTION;
                            DashEditorCore.selectedBox = null;
                            Graph.connectingNode       = null;
                            selectedRegion             = new Rect(p_event.mousePosition.x, p_event.mousePosition.y, 0, 0);
                        }
                    }
                }
            }

            // Dragging
            if (p_event.type == EventType.MouseDrag)
            {
                switch (dragging)
                {
                case DraggingType.NODE_DRAG:
                    Vector2 delta = p_event.alt ? Snapping.Snap(p_event.delta, new Vector2(10, 10)): p_event.delta;
                    SelectionManager.DragSelectedNodes(delta, Graph);
                    break;

                case DraggingType.BOX_DRAG:
                    DashEditorCore.selectedBox.Drag(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom));
                    break;

                case DraggingType.BOX_RESIZE:
                    DashEditorCore.selectedBox.Resize(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom));
                    break;

                case DraggingType.SELECTION:
                    selectedRegion.width  += p_event.delta.x;
                    selectedRegion.height += p_event.delta.y;
                    Rect fixedRect = FixRect(selectedRegion);
                    SelectionManager.SelectingNodes(Graph.Nodes.FindAll(n => n.IsInsideRect(fixedRect)).Select(n => n.Index).ToList());
                    break;
                }

                DashEditorWindow.SetDirty(true);
            }

            if (p_event.type == EventType.MouseUp)
            {
                if (dragging == DraggingType.SELECTION)
                {
                    SelectionManager.SelectingToSelected();
                }

                if (dragging == DraggingType.NODE_DRAG || dragging == DraggingType.BOX_DRAG || dragging == DraggingType.BOX_RESIZE)
                {
                    DashEditorCore.SetDirty();
                }

                dragging       = DraggingType.NONE;
                selectedRegion = Rect.zero;
                DashEditorWindow.SetDirty(true);
            }
        }
コード例 #9
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 offset, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.CapFunction capFunction, float snap)
        {
            Event evt       = Event.current;
            var   eventType = evt.GetTypeForControl(id);

            switch (eventType)
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (capFunction != null)
                {
                    capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, eventType);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + offset, size * .2f));
                }
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartPosition        = position;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    float dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection);

                    dist = Handles.SnapValue(dist, snap);

                    Vector3 worldDirection = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 worldPosition  = Handles.matrix.MultiplyPoint(s_StartPosition) + worldDirection * dist;

                    if (EditorSnapSettings.gridSnapActive)
                    {
                        worldPosition = Snapping.Snap(worldPosition, GridSettings.size, (SnapAxis) new SnapAxisFilter(worldDirection));
                    }

                    position = Handles.inverseMatrix.MultiplyPoint(worldPosition);

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, EventType.Repaint);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }
            return(position);
        }
コード例 #10
0
ファイル: Slider1D.cs プロジェクト: xxpniu/UnityCsReference
        internal static Vector3 Do(int id, Vector3 position, Vector3 offset, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.CapFunction capFunction, float snap)
        {
            Event evt       = Event.current;
            var   eventType = evt.GetTypeForControl(id);

            switch (eventType)
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (capFunction != null)
                {
                    capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, eventType);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + offset, size * .2f));
                }
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    GUIUtility.hotControl = id;        // Grab mouse focus
                    s_StartMousePosition  = evt.mousePosition;
                    s_ConstraintOrigin    = Handles.matrix.MultiplyPoint3x4(position);
                    s_StartPosition       = position;
                    s_ConstraintDirection = Handles.matrix.MultiplyVector(slideDirection);
                    s_HandleOffset        = HandleUtility.CalcPositionOnConstraint(Camera.current, evt.mousePosition, s_ConstraintOrigin, s_ConstraintDirection, out Vector3 point)
                            ? s_ConstraintOrigin - point
                            : Vector3.zero;
                    evt.Use();
                    s_StartHandleSize = HandleUtility.GetHandleSize(point);
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    // First try to calculate the translation by casting a mouse ray against a world position plane
                    // oriented towards the camera. This gives more accurate results than doing the line translation
                    // in 2D space, but is more prone towards skewing extreme values when the ray is near parallel
                    // to the plane. To address this, CalcPositionOnConstraint will fail if the mouse ray is close
                    // to parallel (see HandleUtility.k_MinRayConstraintDot) and fall back to 2D based movement.
                    if (HandleUtility.CalcPositionOnConstraint(Camera.current, evt.mousePosition, s_ConstraintOrigin, s_ConstraintDirection, out Vector3 worldPosition))
                    {
                        var handleOffset = s_HandleOffset * (HandleUtility.GetHandleSize(worldPosition) / s_StartHandleSize);
                        worldPosition += handleOffset;

                        if (EditorSnapSettings.incrementalSnapActive)
                        {
                            Vector3 dir  = worldPosition - s_ConstraintOrigin;
                            float   dist = Handles.SnapValue(dir.magnitude, snap) * Mathf.Sign(Vector3.Dot(s_ConstraintDirection, dir));
                            worldPosition = s_ConstraintOrigin + s_ConstraintDirection.normalized * dist;
                        }
                        else if (EditorSnapSettings.gridSnapActive)
                        {
                            worldPosition = Snapping.Snap(worldPosition, GridSettings.size, (SnapAxis) new SnapAxisFilter(s_ConstraintDirection));
                        }

                        position             = Handles.inverseMatrix.MultiplyPoint(worldPosition);
                        s_StartPosition      = position;
                        s_StartMousePosition = evt.mousePosition;
                    }
                    else
                    {
                        // Unlike HandleUtility.CalcPositionOnConstraint, CalcLineTranslation _does_ multiply constraint
                        // origin and direction by Handles.matrix, so make sure to pass in unmodified vectors here
                        float dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, evt.mousePosition, s_StartPosition, slideDirection);
                        dist          = Handles.SnapValue(dist, snap);
                        worldPosition = Handles.matrix.MultiplyPoint(s_StartPosition) + s_ConstraintDirection * dist;
                        if (EditorSnapSettings.gridSnapActive)
                        {
                            worldPosition = Snapping.Snap(worldPosition, GridSettings.size, (SnapAxis) new SnapAxisFilter(s_ConstraintDirection));
                        }
                        position = Handles.inverseMatrix.MultiplyPoint(worldPosition);
                    }

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, EventType.Repaint);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }
            return(position);
        }