예제 #1
0
    public DebugLayout ScrollSingleSelection <T>(
        IReactiveCollection <T> collection, ICellRW <T> selected, Func <T, string> toString, float takeRelativeLayoutSize = 1)
    {
        var currentSelected = InstantiateInLayout(factory.titlePrefab).GetComponentInChildren <Text>();

        currentSelected.SetTextContent(selected.Select(v => $"current: {toString(v)}"));
        var scroll = InstantiateInLayout(factory.scrollPrefab, new DebugLayoutOptions {
            flexibleSpace = takeRelativeLayoutSize
        });

        Rui.PresentInScrollWithLayout(collection, scroll, show: (s, button) =>
        {
            button.Show(toString(s), selected.Select(v => object.ReferenceEquals(v, s)), button.connectionSink);
            button.button.ClickStream().Subscribe(() => selected.value = s);
        }, prefab: PrefabRef.ToPrefabRef(factory.buttonPrefab), layout: Rui.LinearLayout(forceMainSize: 80));
        return(this);
    }
예제 #2
0
    public DebugLayout ScrollSingleSelection(
        IReactiveCollection <string> collection, ICellRW <string> selected, float takeRelativeLayoutSize = 1)
    {
        var currentSelected = InstantiateInLayout(factory.titlePrefab).GetComponentInChildren <Text>();

        currentSelected.SetTextContent(selected.Select(v => $"current: {v}"));
        var scroll = InstantiateInLayout(factory.scrollPrefab, new DebugLayoutOptions {
            flexibleSpace = takeRelativeLayoutSize
        });

        Rui.PresentInScrollWithLayout(collection, scroll, PrefabRef.ToPrefabRef(factory.buttonPrefab), (s, button) =>
        {
            button.Show(s, selected.Select(v => v == s), button.connectionSink);
            button.addConnection = button.button.ClickStream().Subscribe(() => selected.value = s);
        }, layout: Rui.LinearLayout(forceMainSize: 80));

        return(this);
    }
예제 #3
0
        public void Show(IReactiveCollection <Planet> planets, IReactiveCollection <RocketInstance> rockets, ICell <int> playerPlanetId)
        {
            // Present function is a very powerful tool
            // It allows to show any dynamic collection it can:
            //     * Automate loading and destruction
            //     * Automate object pooling
            //     * Show UI data with different layouts
            //     * Show UI data in scroll views with reusable cells (when only visible elements are loaded)
            //     * some other usefull features ...
            // Here is the simplest case of Present
            planets.Present(
                root,
                prefabSelector: data => Resources.Load <PlanetView>(data.config.name),
                show: (data, view) => view.Show(data, playerPlanetId.value == data.id),
                delegates: ExplosionOnDeath <PlanetView>(GameResources.instance.planetDeathFx)
                );

            rockets.Present(
                root,
                prefabSelector: data => PrefabRef <RocketView> .ByName("Missile" + data.config.name),
                show: (data, view) => view.Show(data),
                delegates: ExplosionOnDeath <RocketView>(GameResources.instance.rocketExplosionFx)
                );
        }