Skip to content

Instantly share code, notes, and snippets.

@NVentimiglia
Last active August 25, 2016 06:03
Show Gist options
  • Save NVentimiglia/e6851fb212efaad7b484b2f116e97635 to your computer and use it in GitHub Desktop.
Save NVentimiglia/e6851fb212efaad7b484b2f116e97635 to your computer and use it in GitHub Desktop.
interface IAuth
{
void Login();
}
public class LeoAuthController : IAuth
{
void Login();
}
public class MockAuthController : IAuth
{
void Login();
}
public class Main
#if UNITY
: MonoBehaviour
#endif
{
//Singleton ?
Injection container;
void Awake()
{
//lazy
container = new Injection();
container.RegisterSingleton<Injection>(container);
container.RegisterSingleton<IAuth, LeoAuthController>();
container.RegisterSingleton<IViewService, MyViewService>();
container.RegisterSingleton<GameController>();
#if !UNITY
Start();
#endif
}
void Start()
{
//A
container.Get<GameController>().Start();
}
}
#region WTF
public class GameController // Scene Controller
{
[Inject]
protected IViewService ViewService;
// Handles Game Events, States, Pausing, Ect
void Start()
{
var view = ViewService.Create<MainViewModel>();
view.Init();
}
public void ShowLogin()
{
ViewService.Create<AuthView>().Init();
}
}
#endregion
public class MainViewModel
{
[Inject]
protected GameController Controller;
[Inject]
protected IViewService ViewService;
//Handles UI Click
public void ShowLogin()
{
//A
Controller.ShowLogin();
//B
var view = ViewService.Create<AuthView>();
view.Init(); // show it
}
}
public class AuthViewModel
{
[Inject]
protected IAuth Auth;
//UI click
pubic void Back()
{
ViewService.Create<MainViewModel>();
}
}
interface IViewService
{
TViewModel Create<TViewModel>();
}
public class ViewService : IViewService
{
[Inject]
IInjection container;
[Inject]
IAssetService assetService;
[Depricated("DO NOT USE")]
pubic TViewModel Create<TViewModel>(TViewModel model)
{
var view = //Get Prefab
Binder(model, view);
container.Inject(model);
return model;
}
/// <summary>
/// Use this one
/// </summary>
/// <returns></returns>
pubic TViewModel Create<TViewModel>()
{
var model = new TViewModel();
var view = assetService.GetView<TViewModel>();
Binder(model, view);
container.Inject(model);
return model;
}
pubic void Destroy<TViewModel>()
{
//clean up view
}
}
public interface IAssetService
{
//Download stuff
//get stuff
}
public class FriendsViewModel
{
public ObservableCollection<FriendData> Friends;
void Awake()
{
// Get data from service / controller
Friends = Service.GetFriends();
// Optional, more complex view model.... Good for combinding multiple data models
Friends = Service.GetFriends().Select(o=> new FriendsViewModel(o));
}
void OnClick(FriendData data)
{
//Show Popup
}
}
// Injection
// Register Instance (Mono)
// Register Singleton (Same instance every time)
// Register Transient (New instance each time)
// Register Scoped (Transient with IDisposable constraint)
// Unregister
// InjectInto Using Annotation
// Get
// Print
// new() constraint on viewmodels and injected service
// Infrastructure
*DataResponse (ErrorCode, Payload, ErrorMessage)
*DataBinding (Magic)
*Injection (Magic)
*Protobuff Serialization (Media Filter)
//Main
BindingConfig
//Framework
*Start work on these
*IViewService (Navigation, Popup, Display) ???? Popup Stack ???
*IAssetService (PNG, AssetBundles, Prefabs, Audio)
IRestService (Back end comm)
INetworkService (SmartFox, Pusher)
*IStorage (DataStore, Database, Local cache)
*IAudioService
*IConfigService
*ILocalizationService (English, Spanish, Portuguese, French, German )
IPurchaseService
IAdsService
IErrorService (Error Reporting)
ILogService (Debug, Info, Trace)
IAnalyticsService
*IInputService (Touch, mouse) ???
!GameConsole (Done !)
IPushNoticeService
ILeaderboardService
//Game
*IDictionaryService
*IWordValidationService
*ITileService
*IBoardService
IPowerupService ???
?IInventoryService (User Data, duh)
IFriendsService
IGiftingService
IAIService
IGameService (Gameplay loop, gameplay events)
IEffectService (Pool)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment