Advertisement
Guest User

Untitled

a guest
Jul 8th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. public override void AppendVisualElement(VisualElement ret)
  2. {      
  3.         VisualElement dmgOut = ret.Query<VisualElement>("applyStats");
  4.  
  5.         ListView damageList = new ListView();
  6.  
  7.         Func<VisualElement> makeItem = () =>
  8.         {
  9.             //Debug.Log("Make ");
  10.             var box = new VisualElement();
  11.             box.style.flexDirection = FlexDirection.Row;
  12.             box.style.flexGrow = 1f;
  13.             box.style.flexShrink = 0f;
  14.             box.style.flexBasis = 0f;
  15.             box.Add(new Label());
  16.             box.Add(new Button());
  17.             box.Add(new EnumField());
  18.             return box;
  19.         };
  20.  
  21.         Action<VisualElement, int> bindItem = (e, i) =>
  22.         {
  23.             Debug.Log("Bind for: " + i + " formula count: " + damageOut[i].formula.Count);
  24.             (e.ElementAt(0) as Label).text = i.ToString();
  25.             Button removeBtn = e.ElementAt(1) as Button;
  26.             //int thisIndex = i;
  27.             Action click = () =>
  28.             {
  29.                 //Debug.Log("RemoveAt! " + i);
  30.                 damageOut.RemoveAt(i);
  31.                 damageList.Refresh();
  32.                 //Debug.Log(removeBtn..clicked.GetInvocationList().Length);
  33.                 //removeBtn.clicked.
  34.             };
  35.             removeBtn.clicked -= click;
  36.             removeBtn.clicked += click;
  37.             removeBtn.text = "-";
  38.         };
  39.  
  40.         damageList.itemsSource = damageOut;
  41.         damageList.itemHeight = 100;
  42.         damageList.makeItem = makeItem;
  43.         damageList.bindItem = bindItem;
  44.  
  45.         damageList.style.flexDirection = FlexDirection.Column;
  46.         damageList.style.minHeight = 200;
  47.         damageList.selectionType = SelectionType.Multiple;
  48.         damageList.style.flexGrow = 1f;
  49.         damageList.style.flexShrink = 0f;
  50.         damageList.style.flexBasis = 0f;
  51.  
  52.         ret.style.flexGrow = 1f;
  53.         dmgOut.style.height = new StyleLength(220);//ret.style.height.value.value + damagePropField.style.height.value.value);
  54.  
  55.         //dmgOut.contentRect = new Rect(Vector2.zero, new Vector2(100, 100));
  56.         dmgOut.Add(damageList);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement