Skip to content

Commit

Permalink
Merge pull request #33 from hackerspace-ntnu/feature/player-model-exc…
Browse files Browse the repository at this point in the history
…lusion

Feature/player model exclusion
  • Loading branch information
toberge committed Nov 15, 2022
2 parents 7645321 + 40664d1 commit 36a141e
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 23 deletions.
Binary file added Assets/Models/Player.fbx
Binary file not shown.
111 changes: 111 additions & 0 deletions Assets/Models/Player.fbx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 121 additions & 10 deletions Assets/Prefabs/Input/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 71015680234268071}
- component: {fileID: 71015680234268070}
- component: {fileID: 71015680234268065}
- component: {fileID: 865509316470258782}
- component: {fileID: 9672907109803670}
Expand All @@ -34,18 +33,12 @@ Transform:
m_LocalPosition: {x: 20.1, y: 1.05, z: -15.06}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 6766120154461720422}
- {fileID: 6507685450046118291}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &71015680234268070
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 71015680234268067}
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &71015680234268065
MeshRenderer:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -163,3 +156,121 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b92c430e6e288cc42a9a091e7fefacaf, type: 3}
m_Name:
m_EditorClassIdentifier:
chips: 0
meshBase: {fileID: 6245866794775287260}
--- !u!1 &8105111567943840941
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6507685450046118291}
m_Layer: 0
m_Name: CameraOffset
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6507685450046118291
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8105111567943840941}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.27, z: 0.4}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 71015680234268071}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &6515775260878448781
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 2
m_TransformParent: {fileID: 71015680234268071}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalScale.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalScale.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalScale.z
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalPosition.y
value: -1
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalRotation.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
propertyPath: m_Name
value: Mesh
objectReference: {fileID: 0}
m_RemovedComponents: []
m_AddedGameObjects: []
m_SourcePrefab: {fileID: 100100000, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
--- !u!1 &6245866794775287260 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
m_PrefabInstance: {fileID: 6515775260878448781}
m_PrefabAsset: {fileID: 0}
--- !u!4 &6766120154461720422 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 36f325ef5d4a87f68bc3e576bea07712, type: 3}
m_PrefabInstance: {fileID: 6515775260878448781}
m_PrefabAsset: {fileID: 0}
13 changes: 8 additions & 5 deletions Assets/Scripts/Gamestate/PlayerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class PlayerFactory : MonoBehaviour

private PlayerInputManagerController playerInputManagerController;


private void Awake()
{
playerInputManagerController = PlayerInputManagerController.Singleton;
Expand Down Expand Up @@ -46,15 +45,19 @@ private void InstantiatePlayer(PlayerInput playerInput)
{
// Spawn player at spawnPoint's position with spawnPoint's rotation
GameObject player = Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
// Set recieved playerInput (and most importantly it's camera) at player's position with player's rotation
playerInput.transform.position = player.transform.position;
playerInput.transform.rotation = player.transform.rotation;
Transform cameraOffset = player.transform.Find("CameraOffset");
// Make playerInput child of player it's attached to
playerInput.transform.parent = player.transform;
// Set recieved playerInput (and most importantly its camera) at an offset from player's position
playerInput.transform.localPosition = cameraOffset.localPosition;
playerInput.transform.rotation = player.transform.rotation;
// Enable Camera
playerInput.GetComponent<Camera>().enabled = true;
// Update player's movement script with which playerInput it should attach listeners to
player.GetComponent<PlayerMovement>().SetPlayerInput(playerInput.GetComponent<FPSInputManager>());
player.GetComponent<PlayerManager>().SetPlayerInput(playerInput.GetComponent<FPSInputManager>());
var playerManager = player.GetComponent<PlayerManager>();
playerManager.SetPlayerInput(playerInput.GetComponent<FPSInputManager>());
// Set unique layer for player
playerManager.SetLayer(playerInput.playerIndex);
}
}
32 changes: 32 additions & 0 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[RequireComponent(typeof(PlayerMovement))]
public class PlayerManager : MonoBehaviour
{
// Layers 12 through 15 are gun layers.
private static int allGunsMask = (1 << 12) | (1 << 13) | (1 << 14) | (1 << 15);

// TODO add context when shooty system is done
public delegate void HitEvent(PlayerManager killer, PlayerManager victim);

Expand All @@ -14,17 +18,45 @@ public class PlayerManager : MonoBehaviour

private FPSInputManager fpsInput;

[SerializeField]
private GameObject meshBase;

/// <summary>
/// Function for setting a playerInput and adding movement related listeners to it.
/// </summary>
/// <param name="player"></param>
public void SetPlayerInput(FPSInputManager player)
{
fpsInput = player;
GetComponent<PlayerMovement>().SetPlayerInput(fpsInput);
// TODO Don't commit sudoku.
fpsInput.onFire += (ctx) => onDeath?.Invoke(this, this);
}

public void SetLayer(int playerIndex)
{
int playerLayer = LayerMask.NameToLayer("Player " + playerIndex);

// Set layers for the camera to ignore (the other players' gun layers, and this layer)
// Bitwise negation of this player's model layer and all gun layers that do not belong to this player
// Gun layers are 4 above their respective player layers.
var mask = ((1 << 16) - 1) ^ ((1 << playerLayer) | ((1 << (playerLayer + 4)) ^ allGunsMask));
fpsInput.GetComponent<Camera>().cullingMask = mask;

// Set correct layer on self, mesh and gun (TODO)
gameObject.layer = playerLayer;
SetLayerOnSubtree(meshBase, playerLayer);
}

private void SetLayerOnSubtree(GameObject node, int layer)
{
node.layer = layer;
foreach (Transform child in node.transform)
{
SetLayerOnSubtree(child.gameObject, layer);
}
}

new public string ToString()
{
return "Player " + fpsInput.playerInput.playerIndex;
Expand Down
16 changes: 8 additions & 8 deletions ProjectSettings/TagManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ TagManager:
- UI
-
-
-
-
-
-
-
-
-
-
- Player 0
- Player 1
- Player 2
- Player 3
- Gun 0
- Gun 1
- Gun 2
- Gun 3
-
-
-
Expand Down

0 comments on commit 36a141e

Please sign in to comment.