Skip to content

Commit

Permalink
Mostly Done
Browse files Browse the repository at this point in the history
I merged dev into PA_Tweaks, but I haven't merged "down" to dev yet.
Most conflicts should be resolved. Here's a recap of what's been done on
this branch.
- 3 rewind types selectable from TimeManager script
- Fixed clone color code
- Snapping camera to earliest clone
- TimeManager script requires a reference to the camera assigned to the
player
- Everything is hardcoded to display 0 (if needed could put a field
eventually that allows us to set this at will)
- Warp bubble
- not applied to main character yet, will do this ASAP but right now I
got other stuff to do
- there is a lifetime field in TimeManager and WarpBubble script, set
those two fields to the same value if it's not done already (should be
20 I think). Will hardcode something once we settle on a value
- The warp effect is a prefab whose state is modified by the engine's
clock, so it should look/behave as expected when doing stuff "out of
time". It's not super pretty but the implementation is robust and if we
want to improve we could swap it with something else, as long as it is
consistent with the actual interface
- Pressure plate
- All bugs related to pressure plates should be fixed
- Clones will toggle off pressure plate when warping out
- Plates will no longer trigger when disabling the LayerCollisions
- Added a bool check for robustness
As mentioned in #programmers, the lerp for the camera isn't done yet, it
will require some reworking of the engine to make it look nice
  • Loading branch information
PierreALeger committed Mar 14, 2017
1 parent 461e285 commit de003cb
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 159 deletions.
27 changes: 13 additions & 14 deletions Assets/PATimeRefactor/Assets/Prefabs/PressurePlate.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ GameObject:
- component: {fileID: 4858338949452850}
- component: {fileID: 33562989641879620}
- component: {fileID: 23545392253009734}
m_Layer: 21
- component: {fileID: 136578784881225250}
- component: {fileID: 114696680226765280}
m_Layer: 24
m_Name: Cylinder
m_TagString: Untagged
m_TagString: PressurePlateCollider
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
Expand All @@ -36,11 +38,9 @@ GameObject:
serializedVersion: 5
m_Component:
- component: {fileID: 4094971283816024}
- component: {fileID: 136116629899047188}
- component: {fileID: 114614349883559164}
m_Layer: 21
m_Layer: 24
m_Name: PressurePlate
m_TagString: Untagged
m_TagString: PressurePlateCollider
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
Expand All @@ -52,7 +52,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1649229833953150}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 5.21, y: 0.7, z: -20.02}
m_LocalScale: {x: 2, y: 1, z: 2}
m_Children:
- {fileID: 4858338949452850}
Expand Down Expand Up @@ -110,27 +110,26 @@ MeshFilter:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1036937098942168}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &114614349883559164
--- !u!114 &114696680226765280
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1649229833953150}
m_GameObject: {fileID: 1036937098942168}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1731d4eb5ab5db643aa6adfe9ccd22cb, type: 3}
m_Name:
m_EditorClassIdentifier:
mesh: {fileID: 1036937098942168}
active: {fileID: 2100000, guid: d126514c63e26c648b26342075574ffc, type: 2}
inactive: {fileID: 2100000, guid: 6d5cae7598648574fa97b3d331407a30, type: 2}
active: {fileID: 2100000, guid: 3756c7ca466ec3a4681fa05534341942, type: 2}
inactive: {fileID: 2100000, guid: 8e99a5ec37ac45441a88343e99837c54, type: 2}
target: {fileID: 0}
--- !u!136 &136116629899047188
--- !u!136 &136578784881225250
CapsuleCollider:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1649229833953150}
m_GameObject: {fileID: 1036937098942168}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
Expand Down
16 changes: 11 additions & 5 deletions Assets/PATimeRefactor/Assets/Prefabs/TimeManager.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 56ee9fea925a71a4aa590cd5774dd7da, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RewindMode: 2
playerLayer: Player
cloneLayer: Clone
doorLayer: Door DELETEME
aiLayer: Puppy AI
m_RewindMode: 0
m_SnapCameraToClone: 1
m_PlayerCamera: {fileID: 0}
m_WarpInPrefab: {fileID: 1233483338614074, guid: 70076f1ff7aa7d94dab217b667f7cb13,
type: 2}
m_WarpBubbleLife: 20
m_PlayerLayer: Player
m_CloneLayer: Clone
m_DoorLayer: Door DELETEME
m_AILayer: Puppy AI
m_PlateLayer: PressurePlateCollider
m_CloneColorCodes:
- {r: 1, g: 0, b: 0, a: 0}
- {r: 0, g: 0, b: 1, a: 0}
Expand Down
22 changes: 22 additions & 0 deletions Assets/PATimeRefactor/Assets/Scripts/CloneTimeAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class CloneTimeAttachment : MonoBehaviour
[HideInInspector]
public GameObject timeManagerObject;

private PressurePlate m_PressurePlate;

public TimeManager manager { get; set; }
public int m_TimelineID { get; set; }

Expand All @@ -35,6 +37,7 @@ private void Awake()
{
m_Transform = GetComponent<Transform>();
m_Agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
m_PressurePlate = null;
}

// Late to make sure that any disabling script has time to run
Expand All @@ -55,7 +58,26 @@ private void OnTriggerEnter(Collider other)
{
manager.handleParadox(m_TimelineID);
}
if (other.tag == "PressurePlateCollider")
{
m_PressurePlate = other.gameObject.GetComponentInParent<PressurePlate>();
}

}

private void OnTriggerExit(Collider other)
{
if (other.tag == "PressurePlateCollider")
{
m_PressurePlate = null;
}
}

public void pressureOff()
{
if (m_PressurePlate != null)
{
m_PressurePlate.forceExit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class PuppyCharacterController : MonoBehaviour {
public bool m_IsLatched { get; set; }
public bool m_IsHome { get; set; }

private PlayerTimeAttachment m_PlayerTimeAttachment;
private PlayerUserController m_PlayerUserController;
private Vector3 m_HomePosition;

private bool m_HaltPathing;
Expand All @@ -57,7 +57,7 @@ private void Start()
{
m_Agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
m_Character = GetComponent<PuppyMovement>();
m_PlayerTimeAttachment = m_Player.GetComponent<PlayerTimeAttachment>();
m_PlayerUserController = m_Player.GetComponent<PlayerUserController>();
m_HomePosition = m_Home.GetComponent<Transform>().position;
m_Target = m_HomePosition;
m_Agent.updateRotation = true;
Expand Down Expand Up @@ -95,7 +95,7 @@ private void OnTriggerEnter(Collider other)

if (other.tag == "Player")
{
m_PlayerTimeAttachment.m_HasPuppy = true;
m_PlayerUserController.m_HasPuppy = true;
}
m_IsLatched = true;
m_IsHome = false;
Expand All @@ -107,7 +107,7 @@ private void OnTriggerEnter(Collider other)
m_IsHome = true;
m_IsLatched = false;
m_Target = m_HomePosition;
m_PlayerTimeAttachment.m_HasPuppy = false;
m_PlayerUserController.m_HasPuppy = false;
}
}

Expand Down
77 changes: 42 additions & 35 deletions Assets/PATimeRefactor/Assets/Scripts/TimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public enum GameState

public GameState m_GameState { get; private set; }

public string playerLayer;
public string cloneLayer;
public string doorLayer;
public string aiLayer;
public string m_PlayerLayer;
public string m_CloneLayer;
public string m_DoorLayer;
public string m_AILayer;
public string m_PlateLayer;

public bool m_WaitingForPlayer { get; set; }

Expand Down Expand Up @@ -156,8 +157,12 @@ private void create(bool rewinding = false)
haltClones();
}
}
public void trashClone()
public void trashClone(bool onOpen = false)
{
if (!onOpen && m_CloneTimeAttachment != null)
{
m_CloneTimeAttachment.pressureOff();
}
Destroy(m_CloneInstance);
m_CloneTimeAttachment = null;
m_CloneController = null;
Expand All @@ -181,7 +186,7 @@ public void close(int end)
public void open(int index)
{
m_End = -1;
trashClone();
trashClone(true);
trashBubble();
m_TimelineIndex = index;
}
Expand Down Expand Up @@ -274,15 +279,15 @@ public void runClones(bool rewinding = false)
{
if (m_WarpInInstance == null)
{
m_WarpInInstance = Instantiate(m_WarpInPrefab, m_MasterArrayRef[m_TimelineIndex].m_DogPosition + new Vector3(0.0f, 1.0f, 0.0f), m_MasterArrayRef[m_TimelineIndex].m_DogRotation);
m_WarpInInstance = Instantiate(m_WarpInPrefab, m_MasterArrayRef[m_Start].m_DogPosition + new Vector3(0.0f, 1.0f, 0.0f), m_MasterArrayRef[m_Start].m_DogRotation);
}
m_WarpInInstance.GetComponent<WarpBubble>().m_CurrentIndex = m_TimelineIndex - m_Start;
}
else if (m_TimelineIndex >= m_End && m_TimelineIndex <= m_End + m_WarpBubbleLife)
{
if (m_WarpInInstance == null)
{
m_WarpInInstance = Instantiate(m_WarpInPrefab, m_MasterArrayRef[m_TimelineIndex].m_DogPosition + new Vector3(0.0f, 1.0f, 0.0f), m_MasterArrayRef[m_TimelineIndex].m_DogRotation);
m_WarpInInstance = Instantiate(m_WarpInPrefab, m_MasterArrayRef[m_End].m_DogPosition + new Vector3(0.0f, 1.0f, 0.0f), m_MasterArrayRef[m_End].m_DogRotation);
}
m_WarpInInstance.GetComponent<WarpBubble>().m_CurrentIndex = m_TimelineIndex - m_End;
}
Expand Down Expand Up @@ -340,7 +345,7 @@ void Start()
m_CurrentCamera = 0;

// Disable collisions between clones
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(cloneLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_CloneLayer), true);
}

// Not sure if this should go in FixedUpdate or Update, Fixed seemed safer and more stable (constant frame rate)
Expand All @@ -363,8 +368,9 @@ void Update()
{
if (m_RestoreControlOnNextFrame)
{
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(playerLayer), false);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(doorLayer), false);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_PlayerLayer), false);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_DoorLayer), false);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_PlateLayer), false);
m_GameState = GameState.NORMAL;
m_RestoreControlOnNextFrame = false;
}
Expand Down Expand Up @@ -456,6 +462,9 @@ void Update()
// Restore control
m_RestoreControlOnNextFrame = true;

// Restore Puppy State
m_PuppyController.restoreState(m_MasterArray[m_MasterPointer]);

// Nudge pointers up
// Place pointers to next position
m_MasterPointer++;
Expand Down Expand Up @@ -581,8 +590,10 @@ public void timeStopToggle(bool stopTime)
m_GameState = GameState.REWIND;

// Disable collisions
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(playerLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(doorLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_PlayerLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_DoorLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_PlateLayer), true);


// Halt AIs
for (int i = 0; i < m_ActiveTimeline; i++)
Expand Down Expand Up @@ -647,7 +658,7 @@ public void masterScrub(int amount, int flipOffset = 0)
if (m_ActiveTimeline != i)
m_Timelines[i].runClones(true);
else
m_Timelines[i].trashClone();
m_Timelines[i].trashClone(true);
}
#endregion

Expand All @@ -672,28 +683,22 @@ public void masterScrub(int amount, int flipOffset = 0)
#endregion

// Special case when rewinding (duct tape used here, more robust solution will follow)
if (m_SnapCameraToClone)
if (m_SnapCameraToClone && m_GameState == GameState.REWIND)
{
if (m_Timelines[m_CurrentCamera].m_TimelineIndex == m_Timelines[m_CurrentCamera].m_Start + 1 && m_CurrentCamera != 0)
// Find the "latest" running timeline
for (int i = m_ActiveTimeline - 1; i >= 0; i--)
{
m_Timelines[m_CurrentCamera].activateCamera(false);
m_CurrentCamera--;
m_Timelines[m_CurrentCamera].activateCamera(true);

}
else if (
m_CurrentCamera != m_ActiveTimeline - 1
&&
(
( m_Timelines[m_CurrentCamera + 1].m_TimelineIndex <= m_Timelines[m_CurrentCamera + 1].m_End - 1)
if (
(m_Timelines[i].m_TimelineIndex <= m_Timelines[i].m_End - 1)
&&
( m_Timelines[m_CurrentCamera + 1].m_TimelineIndex >= m_Timelines[m_CurrentCamera + 1].m_Start + 1)
(m_Timelines[i].m_TimelineIndex >= m_Timelines[i].m_Start + 1)
)
)
{
m_Timelines[m_CurrentCamera].activateCamera(false);
m_CurrentCamera++;
m_Timelines[m_CurrentCamera].activateCamera(true);
{
m_Timelines[m_CurrentCamera].activateCamera(false);
m_CurrentCamera = i;
m_Timelines[m_CurrentCamera].activateCamera(true);
break;
}
}
}
}
Expand All @@ -713,9 +718,11 @@ public void handleParadox(int idToRevert, Transform lastPos = null)
m_GameState = GameState.PARADOX;

// Disable collisions
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(playerLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(cloneLayer), LayerMask.NameToLayer(doorLayer), true);

Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_PlayerLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_DoorLayer), true);
Physics.IgnoreLayerCollision(LayerMask.NameToLayer(m_CloneLayer), LayerMask.NameToLayer(m_PlateLayer), true);


// Fetch revert targert
m_RevertTimeline = idToRevert;

Expand Down
Loading

0 comments on commit de003cb

Please sign in to comment.