public void OnSceneGUI()
        {
            // paint prefabs on mouse drag. don't do anything if no mode is selected, otherwise e.g. movement in scene view wouldn't work with alt key pressed
            if (brushComponent.DrawBrush(editorTarget.mode, editorTarget.brushSettings, out BrushMode brushMode, out RaycastHit raycastHit))
            {
                bool applyPhysics = false;

                switch (interactionType.enumValueIndex)
                {
                case (int)InteractionSettings.InteractionType.AntiGravity:
                    antiGravityModule.OnSceneGUI(brushMode, raycastHit, out applyPhysics);
                    break;

                case (int)InteractionSettings.InteractionType.Magnet:
                    magnetModule.OnSceneGUI(brushMode, raycastHit, out applyPhysics);
                    break;

                case (int)InteractionSettings.InteractionType.ChangeScale:
                    changeScaleModule.OnSceneGUI(brushMode, raycastHit, out applyPhysics);
                    break;

                case (int)InteractionSettings.InteractionType.SetScale:
                    setScaleModule.OnSceneGUI(brushMode, raycastHit, out applyPhysics);
                    break;

                default:
                    throw new System.Exception("Not implemented interaction index: " + interactionType.enumValueIndex);
                }

                if (applyPhysics)
                {
                    needsPhysicsApplied = true;
                }
            }

            // TODO: change text
            // info for the scene gui; used to be dynamic and showing number of prefabs (currently is static until refactoring is done)
            string[] guiInfo = new string[] { "Add prefabs: shift + drag mouse\nRemove prefabs: shift + ctrl + drag mouse\nBrush size: ctrl + mousewheel, Brush rotation: ctrl + shift + mousewheel" };
            brushComponent.Layout(guiInfo);

            // auto physics
            bool applyAutoPhysics = needsPhysicsApplied && editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None && Event.current.type == EventType.MouseUp;

            if (applyAutoPhysics)
            {
                AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, editorTarget.container, editorTarget.spawnSettings.autoSimulationType);
            }
        }
Esempio n. 2
0
        private void SpawnPrefabsAlongSpline()
        {
            // see PerformEditorAction
            {
                editorTarget.splineModule.PlaceObjects();

                editorTarget.splineSettings.dirty = false;

                // Set the editor spline dirty, so that the changed settings (e.g.control points got dragged in the scene) get updated.
                // Ensure the control points get saved when they are changed in the scene if we wouldn't do that, they'd only be change when something changes in the inspector
                EditorUtility.SetDirty(editor.target);
            }

            // used for later
            bool needsPhysicsApplied = true;

            // auto physics
            bool applyAutoPhysics = needsPhysicsApplied && editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None;

            if (applyAutoPhysics)
            {
                AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, editorTarget.container, editorTarget.spawnSettings.autoSimulationType);
            }
        }
Esempio n. 3
0
 private void StartSimulation()
 {
     Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container);
     AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, containerChildren, SpawnSettings.AutoSimulationType.Continuous);
 }
        public void OnSceneGUI()
        {
            // paint prefabs on mouse drag. don't do anything if no mode is selected, otherwise e.g. movement in scene view wouldn't work with alt key pressed
            if (brushComponent.DrawBrush(editorTarget.brushSettings, out BrushMode brushMode, out RaycastHit raycastHit))
            {
                switch (brushMode)
                {
                case BrushMode.ShiftDrag:

                    AddPrefabs(raycastHit);

                    needsPhysicsApplied = true;

                    // consume event
                    Event.current.Use();
                    break;

                case BrushMode.ShiftCtrlDrag:

                    RemovePrefabs(raycastHit);

                    // consume event
                    Event.current.Use();
                    break;
                }
            }

            if (IsFluent())
            {
                if (!brushDistribution.HasPreviewPrefab())
                {
                    brushDistribution.CreatePreviewPrefab();
                }

                // alt + mousewheel = modify height of preview prefab in transform up direction
                if (Event.current.modifiers == EventModifiers.Alt)
                {
                    if (Event.current.isScrollWheel)
                    {
                        PrefabSettings previewPrefabSettings = brushDistribution.GetPreviewPrefabSettings();

                        // the delta value will be modified (reduced) in the offset calculation; it might be too much as it is
                        previewPrefabSettings.brushOffsetUp += Event.current.delta.y;

                        Event.current.Use();
                    }
                }

                brushDistribution.UpdatePreviewPrefab(raycastHit.point, raycastHit.normal);
            }

            // info for the scene gui; used to be dynamic and showing number of prefabs (currently is static until refactoring is done)
            string[] guiInfo = new string[] {
                "Add prefabs: shift + drag mouse"
                + "\nRemove prefabs: shift + ctrl + drag mouse" +
                "\nBrush size: ctrl + mousewheel, Brush rotation: ctrl + shift + mousewheel"
            };

            brushComponent.Layout(guiInfo);

            // auto physics
            bool applyAutoPhysics = needsPhysicsApplied &&
                                    autoPhysicsCollection.Count > 0 &&
                                    editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None &&
                                    Event.current.type == EventType.MouseUp;

            if (applyAutoPhysics)
            {
                AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, autoPhysicsCollection, editorTarget.spawnSettings.autoSimulationType);

                autoPhysicsCollection.Clear();
            }
        }
Esempio n. 5
0
        public void OnSceneGUI()
        {
            // paint prefabs on mouse drag. don't do anything if no mode is selected, otherwise e.g. movement in scene view wouldn't work with alt key pressed
            if (brushComponent.DrawBrush(editorTarget.brushSettings, out BrushMode brushMode, out RaycastHit raycastHit))
            {
                if (editorTarget.interactionSettings.interactionType == InteractionSettings.InteractionType.AntiGravity)
                {
                    switch (brushMode)
                    {
                    case BrushMode.ShiftPressed:

                        AntiGravity(raycastHit);

                        needsPhysicsApplied = true;

                        // don't consume event; mustn't be consumed during layout or repaint
                        //Event.current.Use();
                        break;
                    }
                }

                if (editorTarget.interactionSettings.interactionType == InteractionSettings.InteractionType.Magnet)
                {
                    switch (brushMode)
                    {
                    case BrushMode.ShiftPressed:

                        Attract(raycastHit);

                        needsPhysicsApplied = true;

                        // don't consume event; mustn't be consumed during layout or repaint
                        //Event.current.Use();
                        break;

                    case BrushMode.ShiftCtrlPressed:

                        Repell(raycastHit);

                        needsPhysicsApplied = true;

                        // don't consume event; mustn't be consumed during layout or repaint
                        //Event.current.Use();
                        break;
                    }
                }
            }

            // TODO: change text
            // info for the scene gui; used to be dynamic and showing number of prefabs (currently is static until refactoring is done)
            string[] guiInfo = new string[] { "Add prefabs: shift + drag mouse\nRemove prefabs: shift + ctrl + drag mouse\nBrush size: ctrl + mousewheel, Brush rotation: ctrl + shift + mousewheel" };
            brushComponent.Layout(guiInfo);

            // auto physics
            bool applyAutoPhysics = needsPhysicsApplied && editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None && Event.current.type == EventType.MouseUp;

            if (applyAutoPhysics)
            {
                AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, editorTarget.container, editorTarget.spawnSettings.autoSimulationType);
            }
        }