-
Notifications
You must be signed in to change notification settings - Fork 446
/
SocialContext.cs
88 lines (75 loc) · 3.04 KB
/
SocialContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright 2013 ThirdMotion, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// SocialContext maps the Context for the social interactivity component.
/// ===========
/// A key thing to notice here is how easily we can swap one service (or model, or whatever)
/// for another that satisfies the same interface.
using System;
using UnityEngine;
using strange.examples.multiplecontexts.main;
using strange.extensions.context.api;
using strange.extensions.context.impl;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.dispatcher.eventdispatcher.impl;
using strange.examples.multiplecontexts.common;
using strange.extensions.command.api;
using strange.extensions.command.impl;
namespace strange.examples.multiplecontexts.social
{
public class SocialContext : MVCSContext
{
public SocialContext (MonoBehaviour view) : base(view)
{
}
public SocialContext (MonoBehaviour view, ContextStartupFlags flags) : base(view, flags)
{
}
protected override void mapBindings()
{
commandBinder.Bind(SocialEvent.FULFILL_CURRENT_USER_REQUEST).To<CreateUserTileCommand>();
commandBinder.Bind (MainEvent.GAME_COMPLETE).InSequence ()
.To<GameCompleteCommand> ()
.To<CreateFriendListCommand> ();
//We can do different things depending on whether or not this is the first context to instantiate
//In this case, when we're operating within a larger context we want to kill the AudioListener
if (this == Context.firstContext)
{
commandBinder.Bind(ContextEvent.START).To<StartCommand>().Once();
}
else
{
commandBinder.Bind(ContextEvent.START)
.To<KillAudioListenerCommand>()
.To<StartCommand>()
.Once();
}
commandBinder.Bind (MainEvent.REMOVE_SOCIAL_CONTEXT).To<RemoveContextCommand>();
//So today we're posting to Facebook. Maybe tomorrow we'll want to use
//GooglePlus, or Twitter, or Pinterest...
injectionBinder.Bind<ISocialService> ().To<FacebookService> ().ToSingleton ();
//injectionBinder.Bind<ISocialService> ().To<GoogleService> ().ToSingleton ();
mediationBinder.Bind<UserTileView>().To<UserTileMediator>();
mediationBinder.Bind<AwardView>().To<AwardViewMediator>();
}
//You can safely ignore this bit. Since changing our default to Signals from Events, this is now necessary in this example.
protected override void addCoreComponents()
{
base.addCoreComponents();
injectionBinder.Unbind<ICommandBinder>(); //Unbind to avoid a conflict!
injectionBinder.Bind<ICommandBinder>().To<EventCommandBinder>().ToSingleton();
}
}
}