Skip to content

Instantly share code, notes, and snippets.

@TORISOUP
Created January 12, 2019 08:40
Show Gist options
  • Save TORISOUP/3d0ca0314f0fae17daad96b3968d8e88 to your computer and use it in GitHub Desktop.
Save TORISOUP/3d0ca0314f0fae17daad96b3968d8e88 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
namespace BirdStrike.Vista.UI.TitleScene.Model
{
public class MainMenuManager : MonoBehaviour
{
private Subject<ActionCommand[]> _commandSubject = new Subject<ActionCommand[]>();
public IObservable<ActionCommand[]> CommandSubject => _commandSubject;
private readonly Stack<ActionCommand[]> _commandStack = new Stack<ActionCommand[]>();
void Start()
{
RegisterCommand(_ => new[]
{
new ActionCommand("設定", () => Debug.Log("A")),
new ActionCommand("設定2", () =>
{
RegisterCommand(prev => new[]
{
new ActionCommand("もどる", () => RegisterCommand(__ => prev)),
});
}),
});
}
private void RegisterCommand(Func<ActionCommand[], ActionCommand[]> commands)
{
var p = _commandStack.Count > 0 ? _commandStack.Pop() : new ActionCommand[0];
var c = commands(p);
_commandStack.Push(c);
_commandSubject.OnNext(c);
}
}
public struct ActionCommand
{
public ActionCommand(string name, Action command)
{
Name = name;
Command = command;
}
public string Name { get; }
public Action Command { get; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment