Пример #1
0
    private float AddBox(Brain b, int level, float prev_center, Color32 color)
    {
        var top_padding = 10;
        var spacing     = 150;
        //  var button = _panel.AddControl<BrainButton>();
        BrainButton button          = _panel.AddPrefab(ListItem) as BrainButton; // as UserListItem;
        dfLabel     NameLabel       = button.Find("Brain Name Label").GetComponent <dfLabel>();
        dfLabel     GenerationLabel = button.Find("Generation Label").GetComponent <dfLabel>();
        dfLabel     FitnessLabel    = button.Find("Fitness Label").GetComponent <dfLabel>();
        BrainButton branchButton    = button.Find("Branch Button").GetComponent <BrainButton>();

        NameLabel.Text       = b.Name;
        GenerationLabel.Text = "Generation: " + b.Generation;
        FitnessLabel.Text    = "Fitness: " + b.BestFitness;
        button.Brain         = b;
        button.Click        += button_Click;
        button.IsNewBrain    = b.IsNewBrain;
        button.DragStart    += button_DragStart;
        //button.BackgroundSprite = "BLANK_TEXTURE";
        button.NormalBackgroundColor = color;
        //button.HoverSprite = "listitem-hover";
        //button.PressedSprite = "listitem-selected";

        //button.Width = 150;
        //button.Height = 80;

        var center_spacing = _panel.Width / (LevelCount[level]);
        var center         = center_spacing * CurrentCount[level] - center_spacing / 2;

        CurrentCount[level] += 1;

        button.RelativePosition = new Vector3(center - button.Width / 2, top_padding + level * spacing);

        var plus = branchButton;


        plus.Brain = b;

        plus.Click += new_button_Click;

        if (level > 0)
        {
            var line = _panel.AddControl <dfSprite>();

            line.SpriteName = "vslider-track-normal";
            line.Width      = 12;
            //line.Height = spacing - button.Height;
            float B = spacing - button.Height;
            line.Height = HypotenuseLength(prev_center, center, B) + 20;
            Vector3 rot   = Vector3.forward;
            float   angle = Angle(B, center - prev_center);
            print("Angle: " + angle);
            line.transform.Rotate(rot, angle);
            float padding = 0;
            if (angle < 0)
            {
                padding = -5;
            }
            if (angle > 0)
            {
                padding = 5;
            }
            line.RelativePosition = new Vector3(prev_center, top_padding + level * spacing - B + padding - 2);
            line.ZOrder           = 0;
        }

        return(center);
    }