- Home /
Tree View List Problems
Hello,
I have 2D fixed joints on my UI buttons as shown below:
I have extra code for the movement and stuff but in essence, each of these is in a 2d "train" using fixed joints. I don't understand though, why isn't Orange being moved down too since it's attached to blue, it's anchor is on blue? Shouldn't it be attached and moving when blue moves? Instead I get the picture below...
I am not sure what you are trying to do. Joints? As in physics joints?
Yes. I am simply trying to make a train of UI so that when the UI position changes, the train pushes the contents downward.
I'm sorry, I have not a single clue on what you are trying to do. A train? Do you mean a tree? But at least I can assure you of one thing, if you are using physics elements in a UI system, you are probably doing something very wrong somewhere
I am just trying to get dropdown lists that move the contents below it down when I press the arrow. There is literally nothing anywhere that shows me how to do this... The ways I was doing it before were the worst... by manually moving down the contents' transforms... and that was so stupid and didn't even work. I just want when I press a dropdown arrow, the contents of the thing display and move the rest of the list down.
Answer by lgarczyn · Oct 08, 2019 at 08:51 PM
So there are a few solutions for this. Basically whatever you are trying to do with physics is a terrible idea and won't work.
You keep using the word train, but I have never heard of the word train to describe a foldable list. This is a tree view, not train.
What you want is that each node of your tree be able to calculate its height, kinda like this:
float GetHeight()
{
if (closed)
return (self_height);
else
{
float height = self_height;
foreach (var child in children)
height += child.GetHeight();
return (height);
}
}
Now you can calculate the position of any element.
But realistically, just use one of the dozen tree view package:
Holy crap all I needed was the term "tree view" and all my problems are solved. I didn't know what to call the dang thing... I have been working on this for two weeks and kept googling "dynamic dropdown list" and "dropdown list that pushes the contents below it down" and there was just no help for that... Finally my suffering can partially end... I originally had hard coded a method to literally just move everything down 30 and then move it back up 30. IT was so bad. Then the desperate attempt to figure it out lead me to fixed joints. I know it was stupid but I literally had no idea how to figure out what I needed to do. Tree view!!!!!!!!!!!!!!!
So... I have been trying to use this code for a bit. What I am trying to do now is to put this script on each button that I have so that they will all display properly. It is throwing errors at me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Heights : $$anonymous$$onoBehaviour
{
public RawImage right;
public RawImage down;
public Vector2 position = new Vector2(0.5f, 0.5f);
public float height;
public float GetHeight()
{
position = gameObject.transform.position;
height = position.y;
if (right.gameObject.activeInHierarchy.Equals(true)) // if the arrow is facing right, don't do anything
{
return height;
}
else
{
foreach (Transform child in transform)
height += child.GetHeight();
return height;
}
}
}
I can't help you unless you give me the errors. Also, please use a Boolean to store the state of the object, ins$$anonymous$$d of getting it's state from the active status.
Answer by muzammilshahiddevhouse · Sep 20, 2021 at 10:26 AM
@maw0041 https://www.youtube.com/watch?v=8uLSGlNQHo0 Bro just follow the link it has expandable menu tutorial.