Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving multiple controllers at once
#1
Hi, is it possible to move all selected controllers at once? If you need the controllers to be at a specific distance from each other but still need to move them back and forth to test and adjust for each new object you add, it will become almost unmanageable as the controllers grows in number. Having to adjust the position manually for each one, every time you make a change is becoming a huge problem while editing and I don't want to think about how it will be once the spline is full of controllers.
Reply
#2
You can create a script that will have as parameters a position slider and an inter-controllers distance. You set it up, and then just tweak the position slider. The script will take care of moving all the selected controllers accordingly. Curvy's API is great to allow you to make your own editor tools on top of Curvy's functionalities.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
You're not talking to someone who can code. I've spent today trying to figure out just how to make a script do something when I select things, let alone actually interact with Curvy............ Cry
Reply
#4
I am right now without a PC, so I can't write you some code to help, but here are usefull links:
https://docs.unity3d.com/ScriptReference/Selection-gameObjects.html
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
On Curvy's side, take a look at:
SplineController.Position
SplineController.PositionMode

Other than coding, I don't see how you can achieve what you asked for.
I hope this helped
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
No PC? Are you in hell? Big Grin

No seriously though, sorry, but that didn't help. When I try to do something new I want to do it properly so it looks nice, is useful and that I learn as much as possible.

This is what I want to achieve:

  1. I want the script to run only when I have 2 or more splinecontrollers selected. I've been trying figure out how to get an int from Selection.stuff.., but no luck. I can't figure out how to check how many of the selected objects have the correct component. I don't even know if it is the correct approach, is there a way do a check if you are editing multiple items of the correct type (component)?
  2. Once 1 is fixed I want, if it's even possible, to override how splinecontrollers move multiple objects now. I want, when you move the position slider during multi selection, to offset each controller by input value from the slider, instead of moving all to the same spot.
  3. If 2 is not possible, I want a new slider to appear under the position slider that does point 2. Or if you can't modify other scripts at all I want the slider to appear next to the Curvy icons in the scene view.
  4. When all this is done I need a check so all controllers stop moving when one hits the end of spline so the offsets doesn't get messed up, but this will probably be easy.
Right now I don't even know if I have setup the script correctly, so right now I'll appreciate all help.

Code:
using UnityEngine;
using UnityEditor;
using FluffyUnderware.Curvy.Controllers;

namespace FluffyUnderware.CurvyEditor.Controllers
{
   public class MoveMultipleControllers : EditorWindow
        {
       public void OnSelectionChange()
       {
           


       }
   }
}
Reply
#6
Yep, in hell until Wednesday. Then I will be in purgatory (installing everything on my new pc) for some time.

  1. I have no environnement to test in, but here is my guess of the code you need:
    Code:
    var selectedControllers =Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c=> c != null).ToList();
    if(selectedControllers.Count > 1)
    {
    //your stuff
    }
  2. As far as I know you can't tell Unity to do special operations when updating a value from multiple selected objects in the inspector
  3. I think the easiest is to just create a new script with a position slider, and when the values is modified (see OnValidate above) execute you code that will get all the selected controllers and modify their positions accordingly
  4. You can simple convert the value of the position slider I spoke about in point 3 from the 0;1 range to another range, before assigning the value to the controllers, to make sure that all controllers stay in their valide range
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
Quote:Yep, in hell until Wednesday. Then I will be in purgatory (installing everything on my new pc) for some time.
Oh man, I had to change to win10 last year and it was so much trouble setting up everything to not annoy you, plus of course Unity started fussing too. So I hope it goes better for you and everything goes smooth. Tongue 


Quote:var selectedControllers =Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c=> c != null).ToList();
See this shit here, I tried so many variations of Selection. like adding .length or GetComponent or GetFiltered and even trying to save that to an array and count that, but nothing worked together in a way that was useful. I also read lots of posts and articles and none even suggested how to get anything close to what you posted. How are you even supposed look it up? Huh 

Well, I will fiddle around with this now and see what I can come up with. Thanks.
Reply
#8
(01-19-2020, 04:07 PM)Lupp_ Wrote: I had to change to win10 last year and it was so much trouble setting up everything to not annoy you, plus of course Unity started fussing too. So I hope it goes better for you and everything goes smooth. Tongue 

Thank you. I will indeed switch from Windows 7 to 10 with this PC. A lot of fun ahead Big Grin

(01-19-2020, 04:07 PM)Lupp_ Wrote: See this shit here, I tried so many variations of Selection. like adding .length or GetComponent or GetFiltered and even trying to save that to an array and count that, but nothing worked together in a way that was useful. I also read lots of posts and articles and none even suggested how to get anything close to what you posted. How are you even supposed look it up? Huh 
I want to say "this comes with experience", but that would not be very helpful Big Grin. So I will say "reading the official doc". Usually I first read official articles, then start testing with simple code. To write that code I will certainly need to read various parts of the API reference. No need to read all of it, but a thorough read of the main classes needed in what I am testing is a good thing. Then of course you will need time, the brain does not assimilate things instantly. It's normal to come back to the same doc multiple times before understanding fully what it explains. Forums are very useful, but should not replace reading the official documentation.

Here is the api reference for the System.Linq namespace, which contains the methods I used. You might want to start with the Enumerable class
https://docs.microsoft.com/fr-fr/dotnet/...mework-4.8
And to learn more about linq
https://docs.microsoft.com/en-us/dotnet/...epts/linq/

Linq queries is quite an advanced subject. Keep in mind that you can always do the same things with longer code using loops and temporary arrays. I use Linq for the ease and speed of writing, and to avoid dumb bugs (less code = less bugs).
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
I guess that you've used win10 before, but if you haven't I would recommend the first thing you do is download Open-shell and 7+ taskbar tweaker. That will take care of the horrible UI and make it actually possible to find stuff. I'm pretty sure win10 was the first OS developed to be user hostile. I also recommend uninstall as much as possible, some things though can only be removed through command prompt. Good luck removing Cortana and other spy crap though.
Also win10 assumes you're retarded and will prevent you from editing system files unless you change both ownership and permissions on files, BUT, if you change owner of the Windows folder it's very possible to brick Windows. I did and it was hell getting it to work again so be careful.
One more tip is to set your internet connection to metered. That's the only way to stop updates to be downloaded automatically.


I've read your tips and apparently learned nothing. Cool I decided I want a popup window to appear when I select a controller, like when you select a camera. So I assumed I had to inherit from EditorWindow and I guess I can't use OnValidate then? So I used OnSelectionChange and pasted some code from examples to see if I can get a window top pup up to start with. But when I select a controller absolutely nothing happens and since I get no errors I don't know why...

Code:
using UnityEngine;
using UnityEditor;
using FluffyUnderware.Curvy.Controllers;
using System.Linq;

namespace FluffyUnderware.CurvyEditor.Controllers
{
   public class MoveMultipleControllers : EditorWindow
   {
       public void OnSelectionChange()
       {
           var selectedControllers = Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c => c != null).ToList();

           if (selectedControllers.Count > 0)
           {
               MoveMultipleControllers window = (MoveMultipleControllers)GetWindow(typeof(MoveMultipleControllers));
               window.Show();
           }
       }
       void OnGUI()
       {
           EditorGUILayout.LabelField("This is an example of EditorWindow.ShowPopup", EditorStyles.wordWrappedLabel);
           GUILayout.Space(70);
           if (GUILayout.Button("Agree!")) this.Close();
       }
   }
}
Reply
#10
Thanks for the tips about windows 10. This will indeed be the first time I install Windows 10 on my computer.

I believe that to get OnSelectionChange executed you have to open the window first, and only then it will executed when the selection is updated. In this link you will find an example of how to open a window
https://docs.unity3d.com/ScriptReference/EditorWindow.OnSelectionChange.html
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Distance travelled across multiple splines jh092 1 7 02-23-2024, 09:44 AM
Last Post: _Aka_
  Best practice for controllers slowing down/speeding up along the spline Curry 1 5 08-06-2023, 09:47 PM
Last Post: _Aka_
  Moving object down or up the spline using gravity velikizlivuk 6 16 07-26-2023, 10:06 PM
Last Post: _Aka_
  Multiple Splines and Generators Performantly for Road System drock 1 6 07-17-2023, 10:31 AM
Last Post: _Aka_

Forum Jump: