Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Razsiel/1718_Game_Engineering in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
YoupKuiper committed Apr 19, 2018
2 parents c651bc7 + bcc373c commit c2fc40e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Assets/Prefabs/CameraContainer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1047995824625588}
m_LocalRotation: {x: 0.23911765, y: 0.3696438, z: -0.09904577, w: 0.89239913}
m_LocalPosition: {x: 0, y: 1, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4096140716981568}
Expand Down Expand Up @@ -185,7 +185,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.6691177, g: 0.6691177, b: 0.6691177, a: 0}
m_Color: {r: 0, g: 0.5034485, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
Expand Down
12 changes: 6 additions & 6 deletions Assets/Prefabs/UI/CommandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ public enum ReadyButtonState

public override void Awake() {
EventManager.InitializeUi += Initialize;
_gameManager = GameManager.GetInstance();
_commandLibrary = _gameManager.CommandLibrary;

Assert.IsNotNull(_commandLibrary);
_gameManager.PlayersInitialized += /*(_player _playerInitialized)*/ () =>

EventManager.PlayersInitialized += /*(_player _playerInitialized)*/ () =>
{
this._player = _gameManager.Players.GetLocalPlayer().Player;
this._player = GameManager.GetInstance().Players.GetLocalPlayer().Player;
print("_player shoudl be filled");
Assert.IsNotNull(_player);

Expand All @@ -59,6 +56,9 @@ public override void Awake() {

public void Initialize()
{
_gameManager = GameManager.GetInstance();
_commandLibrary = _gameManager.CommandLibrary;

//Initialize the ready button and add listener
ReadyButton.GetComponent<Button>().onClick.AddListener(OnReadyButtonClicked);
ReadyButton.GetComponent<Image>().sprite = _gameManager.PrefabContainer.PlayButton;
Expand Down
13 changes: 12 additions & 1 deletion Assets/Prefabs/UI/LevelUI.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -3816,7 +3816,18 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 114502085048644212}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 114752909775571130}
m_MethodName: OnClickContinue
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &114812676876597114
Expand Down
8 changes: 3 additions & 5 deletions Assets/Prefabs/UI/SequenceBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SequenceBar : MonoBehaviour
private void Awake()
{
EventManager.InitializeUi += Initialize;
EventManager.PlayersInitialized += () => {
Player = GameManager.GetInstance().Players.GetLocalPlayer().Player;
};
}

private void Initialize()
Expand Down Expand Up @@ -57,11 +60,6 @@ private void Initialize()

slot.transform.SetParent(gameObject.transform, false);
}

var manager = GameManager.GetInstance();
manager.PlayersInitialized += () => {
Player = manager.Players.GetLocalPlayer().Player;
};
}

public void UnShowDropInPoint(int slotIndex)
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class EventManager
public static UnityAction InitializeAudio;
public static UnityAction InitializeMonologue;

public static UnityAction PlayersInitialized;
public static UnityAction<Player> PlayerInitialized;

public static UnityAction EnableUserInput;
public static UnityAction DisableUserInput;
public static UnityAction<List<BaseCommand>> SequenceChanged;
Expand Down Expand Up @@ -143,4 +146,15 @@ public static void SetPlayerColour()
{
OnSetPlayerColour?.Invoke();
}

public static void OnPlayersInitialized()
{
PlayersInitialized?.Invoke();
}

public static void OnPlayerInitialized(Player player)
{
PlayerInitialized?.Invoke(player);
}

}
6 changes: 3 additions & 3 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GameManager : MonoBehaviour {

public UnityAction<Player> PlayerInitialized;

public UnityAction PlayersInitialized;
// public UnityAction PlayersInitialized;
//public UnityAction

#endregion
Expand Down Expand Up @@ -128,13 +128,13 @@ private void CreatePlayers(List<TGEPlayer> players) {
players[i].PlayerObject = playerObject;
players[i].Player = playerComponent;
//PlayerInitialized(playerComponent);
PlayerInitialized?.Invoke(playerComponent);
EventManager.OnPlayerInitialized(playerComponent);

// if (IsMultiPlayer && players[i].photonPlayer.IsMasterClient)
// playerComponent.gameObject.GetComponent<MeshRenderer>().material.color = Color.blue;
// layerInitialized(playerComponent);
}
PlayersInitialized?.Invoke();
EventManager.OnPlayersInitialized();
EventManager.OnSetPlayerColour();
}

Expand Down
47 changes: 24 additions & 23 deletions Assets/Scripts/Photon/RoomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,45 +193,46 @@ private void SendStopExecution()
this.photonView.RPC(nameof(StopExecution), PhotonTargets.All);
}

private int amountOfSequenceRan = 0;

[PunRPC]
public void StartExecution(PhotonMessageInfo info)
{
EventManager.ExecutionStarted?.Invoke();
int playersSequenceRan = 0;
EventManager.ExecutionStarted?.Invoke();

foreach (TGEPlayer p in gameManager.Players)
{
p.Player.StartExecution();
p.Player.OnPlayerSequenceRan += () =>
{
playersSequenceRan++;
if (playersSequenceRan > 1)
if (!gameManager.LevelData.HasReachedAllGoals())
{
EventManager.OnLevelReset(gameManager.LevelData,
gameManager.Players.Select(x => x.Player).ToList());

foreach (var player in gameManager.Players)
{
player.Player.IsReady = false;
}
}
else
{
EventManager.OnAllLevelGoalsReached();
}
p.Player.OnPlayerSequenceRan += (Player player) => PlayerSequenceRan(player);
}
}

};
private void PlayerSequenceRan(Player p)
{
amountOfSequenceRan++;
if(amountOfSequenceRan > 1)
{
if(!gameManager.LevelData.HasReachedAllGoals())
{
//EventManager.OnLevelReset(gameManager.LevelData,
// gameManager.Players.Select(x => x.Player).ToList());
}
else
{
EventManager.OnAllLevelGoalsReached();
}
amountOfSequenceRan = 0;
}

p.OnPlayerSequenceRan -= PlayerSequenceRan;
}

[PunRPC]
public void StopExecution(PhotonMessageInfo info)
{
foreach(TGEPlayer p in gameManager.Players)
{
p.Player.StopAllCoroutines();
p.Player.IsReady = false;
p.Player.StopAllCoroutines();
EventManager.OnLevelReset(gameManager.LevelData,
gameManager.Players.Select(x => x.Player).ToList());
}
Expand Down
26 changes: 13 additions & 13 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Player : MonoBehaviour
public UnityAction OnPlayerReady;
public UnityAction OnPlayerUnReady;
public UnityAction StopSequence;
public UnityAction OnPlayerSequenceRan;
public UnityAction<Player> OnPlayerSequenceRan;
public UnityAction OnPlayerStop;
public UnityAction OnPlayerUnready;
private Coroutine coroutine;
Expand All @@ -41,12 +41,16 @@ void Start()
_gameManager = GameManager.GetInstance();
_sequence = new List<BaseCommand>();

if (GameManager.GetInstance().Players.GetLocalPlayer().Player == this)
OnPlayerSequenceRan += () =>
{
this.IsReady = false;
};
//if (GameManager.GetInstance().Players.GetLocalPlayer().Player == this)
// OnPlayerSequenceRan += () =>
// {
// this.IsReady = false;
// };

EventManager.LevelReset += (leveldata, players) =>
{
this.IsReady = false;
};
/*
_sequence = new List<BaseCommand>
{
Expand All @@ -64,10 +68,7 @@ void Start()

//StartCoroutine(WaitForInput());
}

// Update is called once per frame
void Update() { }


//Press Spacebar to run sequence
IEnumerator WaitForInput()
{
Expand All @@ -93,7 +94,7 @@ public void UpdateSequence(List<CommandEnum> commands)

public void StartExecution()
{
StartCoroutine(ExecuteCommands());
this.coroutine = StartCoroutine(ExecuteCommands());
}

public void ReadyButtonClicked()
Expand Down Expand Up @@ -144,8 +145,7 @@ IEnumerator ExecuteCommands()

yield return new WaitForSeconds(delay);
}
OnPlayerSequenceRan?.Invoke();
OnPlayerSequenceRan = null;
OnPlayerSequenceRan?.Invoke(this);
}

public void AddOrInsertCommandAt(BaseCommand command, int index)
Expand Down

0 comments on commit c2fc40e

Please sign in to comment.