Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
81d4022
Remove some debug output
marian42 Nov 15, 2018
442846f
Instead of using recursion, save yet to be removed modules in a queue
marian42 Nov 15, 2018
6834a19
Add an option to arrange module prototypes in a grid
marian42 Nov 15, 2018
326c26b
Switch to the package manager version of post-processing
andybak Nov 15, 2018
0c62954
Fix duplicate camera
andybak Nov 15, 2018
7a2edc2
Restore original tunnel probability
andybak Nov 15, 2018
ed7868e
Split MapGenerator into a Map class and a behaviour
marian42 Nov 15, 2018
2a9439e
Split Map into an AbstractMap and an InfiniteMap to allow different s…
marian42 Nov 16, 2018
e01be44
Implement boundary constraints that cover all horizontal directions a…
marian42 Nov 16, 2018
d915b89
Fix NullreferenceException in FollowPlayer
marian42 Nov 16, 2018
da4521a
Update the Simplify Modules feature
marian42 Nov 16, 2018
633603a
Display the number of iterations needed to collapse an area
marian42 Nov 16, 2018
016f850
Store module health in short integers to save memory
marian42 Nov 16, 2018
dc6f079
Fix a memory issue related to dictionary lookups
marian42 Nov 16, 2018
c23bafb
Fix diagonal movement from being 140% faster
shemetz Nov 16, 2018
d91d482
Fix a build compile error
marian42 Nov 16, 2018
ee37951
Replace a foreach loop with a for loop
marian42 Nov 16, 2018
1fbd0cf
Merge pull request #4 from IxxyXR/packagemanager-postprocessing
marian42 Nov 16, 2018
5b03462
Merge remote-tracking branch 'origin/master'
marian42 Nov 16, 2018
c97946b
Merge pull request #5 from itamarcu/patch-1
marian42 Nov 16, 2018
1a7c21d
Merge branch 'mapgenerator-refactor'
marian42 Nov 16, 2018
1d549a4
Tweak post processing settings
marian42 Nov 16, 2018
5a220d9
Add tunnel ceiling colliders
marian42 Nov 16, 2018
9dc349e
Update README.md
marian42 Nov 16, 2018
8e5dbca
Reference the correct layer for the postprocessing volume
marian42 Nov 16, 2018
0d940d9
Allow cancelling map generation in edit mode
marian42 Nov 16, 2018
a92b571
Tweak map classes
marian42 Nov 17, 2018
42de215
Reduce slot memory usage if they are no longer in the history
marian42 Nov 17, 2018
edb4a41
Update gitignore, no longer needs postprocessing folder
marian42 Nov 17, 2018
784796c
Fix a concurrency bug
marian42 Nov 18, 2018
bfc9eef
Use Shannon Entropy to select slots for collapsing
marian42 Nov 18, 2018
5158fe6
Tweak editor GUI
marian42 Nov 18, 2018
4371e82
Tweak skybox and reflections
marian42 Nov 18, 2018
f000d94
Lock cursor to game window
marian42 Nov 18, 2018
bcdd4d9
Mark scene dirty when using the Map UI
marian42 Nov 18, 2018
6b24cf6
Add new blocks
marian42 Nov 19, 2018
b208402
Prevent a NullReferenceExeption when using MapBehaviour, but not Fol…
marian42 Nov 19, 2018
c449a5e
Tweak FlightController
marian42 Nov 19, 2018
f47befc
Add arches
marian42 Nov 27, 2018
89689a9
Determine rotational symmetry of prototypes based on their connectors
marian42 Nov 27, 2018
3903b0c
Add interior blocks
marian42 Nov 29, 2018
16c7ec5
Disable interior blocks as they make the game too slow
marian42 Dec 4, 2018
a4e884a
Measure time when initializing a map in the editor
marian42 Dec 4, 2018
ace5496
Make ModuleSet serializable
marian42 Dec 4, 2018
ee54217
Save all affected slots in the Module class and serialize it
marian42 Dec 4, 2018
92305cf
Only show AreaSelector gizmos when it's selected
marian42 Dec 4, 2018
7c1a70f
Store module data in a ScriptableObject, not in the scene
marian42 Dec 4, 2018
4240fb3
Move all code related to editing module data into the ModuleData class
marian42 Dec 4, 2018
77a3196
Split scene into a game scene and a prototypes scene
marian42 Dec 4, 2018
a6b7207
Implement a faster way to collapse slots based on implied exclusion r…
marian42 Dec 4, 2018
9361bdf
Remove an outdated comment
marian42 Dec 6, 2018
1260e2f
Make backtracking work with the new Collapse method
marian42 Dec 6, 2018
7a3209a
Use ModuleSet to store possible neighbors in a module
marian42 Dec 6, 2018
6be7ac1
Add an option to disable boundary constraints
marian42 Dec 12, 2018
424dba6
Tweak SlotInspector GUI
marian42 Dec 12, 2018
c69aa8f
Remove return value for Slot.AddModules
marian42 Dec 12, 2018
628bebd
Remove the Collapse Fast algorithm since it turned out not to work
marian42 Dec 26, 2018
b6e92ea
Store all prototypes in a single prefab
marian42 Dec 27, 2018
675f5c4
Make Slot.RemoveModules faster
marian42 Dec 27, 2018
4be09f0
Don't store count in ModuleSet
marian42 Dec 27, 2018
8e48355
Calculate entropy faster
marian42 Dec 27, 2018
d37d704
Simplify Slot constructor
marian42 Dec 27, 2018
1689d36
Update progress bar less often
marian42 Dec 27, 2018
4d506be
Merge branch 'wfc-refactor'
marian42 Dec 27, 2018
d7f58da
Add occlusion information to the module prototypes
marian42 Dec 29, 2018
d9eea6e
Add classes to support Occlusion Culling
marian42 Dec 29, 2018
410ecda
Create occlusion data when generating maps and visualize it
marian42 Dec 29, 2018
f451ecf
Cull rooms based on the normal of their doors
marian42 Dec 30, 2018
1e0f37d
Add method to convert worldspace vector to slot position
marian42 Dec 30, 2018
cb048b1
Use camera frustum to check if an outside portal is visible
marian42 Dec 30, 2018
97f3729
Cull outside blocks based on their visibility through portals
marian42 Dec 31, 2018
73bb68d
Fix portal bounds being zero width
marian42 Dec 31, 2018
bd88ff5
Fix some bugs related to detecting portals
marian42 Jan 1, 2019
f17671e
Handle all cases of portal and room visibility correctly
marian42 Jan 1, 2019
f7f84b3
Rename FollowPlayer to GenerateMapNearPlayer and remove far culling
marian42 Jan 1, 2019
1bde668
Use chunks to make occlusion culling faster
marian42 Jan 1, 2019
18cc62b
Improve culling rules to cull more invisible stuff
marian42 Jan 4, 2019
b458e6e
Improve editor visualization of occulsion portals and rooms
marian42 Jan 4, 2019
b67fad4
Save portal visibility as a boolean
marian42 Jan 4, 2019
5601447
Rremove ExteriorBlocks and save renderers directly in chunks
marian42 Jan 4, 2019
f1bff7a
When culling exterior blocks, still render their shadows
marian42 Jan 4, 2019
376e35b
Hide chunks outside that are far from the camera
marian42 Jan 4, 2019
a23c28e
Add method to compute portal corners
marian42 Jan 4, 2019
196ebd4
Don't draw portal gizmos in editor
marian42 Jan 4, 2019
f4a750b
Don't remember portal visibility as it creates wrong results in some …
marian42 Jan 4, 2019
23adbe0
Update scene
marian42 Jan 5, 2019
7220998
Merge branch 'occlusion-culling'
marian42 Jan 6, 2019
d009d28
Fix some build errors
marian42 Jan 6, 2019
b930c76
Fix some meshes for interior blocks
marian42 Jan 10, 2019
36be4df
Update Unity version
marian42 Jan 13, 2019
1e7654e
Fix rooms being incorrectly culled when looking inside -> outside -> …
marian42 Jan 13, 2019
a927d9a
Only follow occlusion portals that face the camera
marian42 Jan 13, 2019
8b6b3fa
Simplify occlusion culling logic
marian42 Jan 13, 2019
8b67bd7
Increase probabilities for interior modules
marian42 Jan 13, 2019
be08b23
Update Readme
marian42 Jan 13, 2019
727b615
Fix initial visibility for rooms
marian42 Jan 14, 2019
c424e6a
Draw bounding box when drawing a portal
marian42 Jan 14, 2019
d9133c4
Increase bounding box size for portals to avoid flickering when stand…
marian42 Jan 14, 2019
d72811b
Use Unity's new Vector3Int class for integer vectors
marian42 Jan 15, 2019
24e1f85
Use built-in vector rounding methods
marian42 Jan 15, 2019
6a938c4
Split occlusion culling class into three smaller classes
marian42 Jan 15, 2019
07f5c38
Remove some methods in the Portal class
marian42 Jan 15, 2019
1792f0f
Remember portal rooms to reduce dictionary lookups
marian42 Jan 15, 2019
d470aff
Remove time measurement for occlusion culling
marian42 Jan 15, 2019
c8b5a57
Fix incorrect range for RangeCulling
marian42 Jan 15, 2019
8f6755c
Make all rooms visible when edit mode
marian42 Jan 15, 2019
9dd6e33
Add an option to disable culling data gizmos
marian42 Jan 19, 2019
7a28bbf
Add a note about the Blender requirement to the readme file
marian42 Mar 1, 2019
aced2cf
Show possible neighbors when editing module prototypes
marian42 May 21, 2019
23b357e
Prevent an exception when adding a new ModulePrototype to a game object
marian42 May 21, 2019
52ee105
Show details about removed modules in the slot inspector
marian42 May 23, 2019
04a2290
Remove the create parameter from the GetSlot method
marian42 May 23, 2019
fe55379
Improve the range limit warning
marian42 May 24, 2019
f4aeb71
Remove Slot.iterationCount
marian42 May 24, 2019
0c764cc
Allow filtering modules in the SlotInspector
marian42 May 24, 2019
8f009af
docs(readme): Fixed typos
kyranet May 29, 2019
278d497
Merge pull request #11 from kyranet/patch-1
marian42 May 29, 2019
499432e
Add more interior blocks
marian42 Jun 6, 2019
0ef0b1c
Prevent an exception when removing a portal that does not exist
marian42 Jan 19, 2019
757d163
Add an undo button to the SlotInspector
marian42 Jun 7, 2019
1f93308
Delete BlockBehaviour
marian42 Jun 9, 2019
2689657
Save module prototypes after adding an exclusion rule using the SlotI…
marian42 Jun 9, 2019
b03008d
Save assets after creating and simplifying module data
marian42 Jun 9, 2019
c65fc9a
Add more exclusion rules for the new interior blocks
marian42 Jun 9, 2019
2c4f5fa
Improve grid snapping for the SlotInspector
marian42 Jun 9, 2019
f2d143d
Use AbstractMap.BLOCK_SIZE in some places where it's hardcoded
marian42 Jul 2, 2019
58ac4b4
Fix a build error
marian42 Jul 22, 2019
ad2d983
Specify the required Blender version in the Readme
marian42 Oct 12, 2019
a40d88e
Change the file format for the blocks from Blender to FBX
marian42 Nov 3, 2019
bbf3538
Update Unity version
marian42 Jul 26, 2019
e012d2a
First version of a tree generator
marian42 Nov 22, 2018
526522e
Generate leaves
marian42 Nov 26, 2018
94eab5d
Add a tree prefab
marian42 Nov 26, 2018
e5560ba
Update Unity
marian42 Nov 4, 2019
02937e4
Rename Tree to TreeGenerator
marian42 Nov 4, 2019
916f919
Add a mechanism to subscribe to map generation events
marian42 Nov 5, 2019
7c880e8
Implement Tree placer
marian42 Nov 5, 2019
3c93ce0
Update tree prefab
marian42 Nov 5, 2019
42997a7
Move tree related assets into a separate folder
marian42 Nov 5, 2019
93d5130
Move the Node class into a separate file
marian42 Nov 7, 2019
0f7b89b
Add minimum branching depth
marian42 Nov 7, 2019
66e91f8
Calculate bark UVs
marian42 Nov 7, 2019
a07005a
Improve stem generation
marian42 Nov 8, 2019
11f55a7
Add an option to disable generation of leaves
marian42 Nov 8, 2019
3a3648b
Create a single tree mesh
marian42 Nov 8, 2019
b1abd13
Fix placement of leaf colliders
marian42 Nov 8, 2019
e4f1092
Prevent twists in the generated tree mesh
marian42 Nov 8, 2019
0b44e51
Fix tree gizmos
marian42 Nov 8, 2019
058e4cf
Improve branch size calculation
marian42 Nov 8, 2019
2d601d0
Allow for more than two branches per node
marian42 Nov 8, 2019
9bd81cb
Reduce the number of raycasts in Node.cs
marian42 Nov 8, 2019
4634a59
Build trees in a coroutine
marian42 Nov 8, 2019
245f9be
Reduce memory allocation in tree mesh generation
marian42 Nov 8, 2019
988f123
Improve leaf mesh generation
marian42 Nov 8, 2019
97ba887
Reduce memory allocation while iterating through
marian42 Nov 8, 2019
87bf52f
Remove unused code
marian42 Nov 8, 2019
1b4357d
Update tree material
marian42 Nov 8, 2019
60cfb00
Only compile gizmo drawing in editor
marian42 Nov 10, 2019
b35d422
Manually select which module prototypes can grow trees
marian42 Nov 10, 2019
7e7a622
Add colliders for walkable areas to prevent trees from growing there
marian42 Nov 10, 2019
8920077
Fix tree generator output when generating trees without leaves
marian42 Nov 10, 2019
7f58ed9
Fix trees intersecting with the environment
marian42 Nov 10, 2019
246cb15
Make tree game objects children of their module game objects
marian42 Nov 10, 2019
54a7d23
Clean up tree generation code
marian42 Nov 10, 2019
767dceb
Create branch colliders
marian42 Nov 10, 2019
4b44bfb
Implement random color choice for leaves
marian42 Nov 10, 2019
6061eb3
Add spring color scheme
marian42 Nov 10, 2019
5b7cfba
Update game scene
marian42 Nov 10, 2019
14f9f79
Add screenshot script
marian42 Aug 9, 2020
91eef18
Update Unity version
marian42 Aug 9, 2020
cf57748
Prevent an exception when the TreePlacer is disabled
marian42 Aug 9, 2020
2ae5eb0
Remove unused properties
marian42 Aug 9, 2020
45e73f6
Fix some corner cases that cause performance issues in TreePlacer
marian42 Aug 9, 2020
3c00fd3
Merge branch 'trees'
marian42 Aug 9, 2020
25b14e3
Remove unused coroutine counter
marian42 Aug 9, 2020
fb3e0dc
Remove unused method
marian42 Aug 9, 2020
b9c740b
Fix a NullReferenceException when placing trees near the edge of the map
marian42 Aug 9, 2020
c8a701c
Remove code to guess connectors
marian42 Aug 11, 2020
a078eb3
Remove an unused enum
marian42 Aug 11, 2020
cc9c85d
Draw occlusion portal debug gizmos only if DrawGizmo is checked
marian42 Aug 11, 2020
3e2a3e4
Fix exceptions getting lost during map generation in the editor if sh…
marian42 Aug 11, 2020
93eca8a
Prevent exceptions in SlotInspector if no MapBehaviour is specified
marian42 Aug 11, 2020
25ae8aa
Fix an exception when displaying the range limit warning outside the …
marian42 Aug 11, 2020
a871b9e
Fix mouse sensitivity being framerate-dependent
marian42 Aug 13, 2020
09cb71d
Display stack traces of exceptions in the world generation thread
marian42 Aug 13, 2020
48a31eb
Remove an unused class
marian42 Aug 14, 2020
bc1d49c
Implement free camera
marian42 Aug 17, 2020
529520f
Fix distance culling being inaccurate if the behaviour is disabled an…
marian42 Aug 17, 2020
e0b9521
Fix a bug in the allocation of the tiling map
marian42 Aug 17, 2020
86f7efa
Don't log if collapsing was successful
marian42 Aug 17, 2020
dc189bd
Don't initialize default column entropy as it has no effect
marian42 Aug 17, 2020
358f9eb
Fix more index errors in TilingMap
marian42 Aug 17, 2020
1a45f55
Make backtracking exponential
marian42 Aug 17, 2020
8e24f78
Implement control mode switcher and put camera control behaviours int…
marian42 Aug 23, 2020
26e3e92
Add an up/down movement axis for the free camera
marian42 Aug 23, 2020
83442d6
Update occlusion culling logic to make it simpler and prevent crashes
marian42 Aug 24, 2020
e8ba72e
Rename RangeCulling to DistanceCulling
marian42 Aug 24, 2020
7c4e291
Disable check for unreachable modules in the release build
marian42 Aug 24, 2020
c9b2131
Create screenshots folder and add it to gitignore
marian42 Aug 24, 2020
b137262
Fix interiors not rendering if occlusion culling is disabled
marian42 Sep 20, 2020
d5bb887
Change CursorLockMode to Locked instead of Confined
TurboWafflz Mar 24, 2021
8750c53
Merge pull request #18 from TurboWafflz/patch-1
marian42 Mar 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sysinfo.txt

*.blend1
*.blend1.meta
Assets/PostProcessing/

Assets/PostProcessing\.meta
Logs/

Screenshots/
33 changes: 18 additions & 15 deletions Assets/Code/AreaSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@
using UnityEditor;

public class AreaSelector : MonoBehaviour {
public MapGenerator MapGenerator;
public MapBehaviour MapBehaviour;

public Vector3i StartPosition {
public Vector3Int StartPosition {
get {
var start = new Vector3i((this.transform.position) / MapGenerator.BlockSize);
if (start.Y >= this.MapGenerator.Height) {
start.Y = this.MapGenerator.Height - 1;
var start = Vector3Int.RoundToInt((this.transform.position) / InfiniteMap.BLOCK_SIZE);
if (start.y >= this.MapBehaviour.Map.Height) {
start.y = this.MapBehaviour.Map.Height - 1;
}
if (start.Y < 0) {
start.Y = 0;
if (start.y < 0) {
start.y = 0;
}
return start;
}
}

public Vector3i Size {
public Vector3Int Size {
get {
var start = this.StartPosition;
var size = new Vector3i(this.transform.localScale / MapGenerator.BlockSize);
if (size.Y + start.Y >= this.MapGenerator.Height) {
size.Y = System.Math.Max(0, this.MapGenerator.Height - start.Y);
var size = Vector3Int.RoundToInt(this.transform.localScale / InfiniteMap.BLOCK_SIZE);
if (size.y + start.y >= this.MapBehaviour.Map.Height) {
size.y = System.Math.Max(0, this.MapBehaviour.Map.Height - start.y);
}
return size;
}
}

#if UNITY_EDITOR
[DrawGizmo(GizmoType.InSelectionHierarchy | GizmoType.NotInSelectionHierarchy)]
[DrawGizmo(GizmoType.Selected)]
static void DrawGizmoForMyScript(AreaSelector areaSelector, GizmoType gizmoType) {
var size = areaSelector.Size.ToVector3() * MapGenerator.BlockSize;
var start = areaSelector.StartPosition.ToVector3() * MapGenerator.BlockSize - new Vector3(1f, 0, 1f) * MapGenerator.BlockSize * 0.5f;
if (areaSelector.MapBehaviour == null || !areaSelector.MapBehaviour.Initialized) {
return;
}
var size = areaSelector.Size.ToVector3() * InfiniteMap.BLOCK_SIZE;
var start = areaSelector.StartPosition.ToVector3() * InfiniteMap.BLOCK_SIZE - new Vector3(1f, 0, 1f) * InfiniteMap.BLOCK_SIZE * 0.5f;
Gizmos.color = Color.red;
Gizmos.DrawWireCube(areaSelector.MapGenerator.transform.position + start + size * 0.5f, size);
Gizmos.DrawWireCube(areaSelector.MapBehaviour.transform.position + start + size * 0.5f, size);
}
#endif
}
8 changes: 8 additions & 0 deletions Assets/Code/CameraControl.meta

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

57 changes: 57 additions & 0 deletions Assets/Code/CameraControl/ControlModeSwitcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using UnityEngine;
using System.Linq;
using System;

public class ControlModeSwitcher : MonoBehaviour {
[System.Serializable]
public class ControlMode {
public KeyCode KeyCode;
public MonoBehaviour Behaviour;
}

public ControlMode[] ControlModes;

public KeyCode[] ModeSwitchKeys;

private ControlMode currentMode;

void Start() {
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
if (this.ControlModes.Any()) {
this.SetMode(this.ControlModes[0]);
}
foreach (var mode in this.ControlModes) {
if (mode != this.currentMode) {
mode.Behaviour.enabled = false;
}
}
}

void Update() {
foreach (var mode in this.ControlModes) {
if (Input.GetKeyDown(mode.KeyCode)) {
this.SetMode(mode);
}
}
if (this.currentMode != null && this.ModeSwitchKeys != null) {
foreach (var keyCode in this.ModeSwitchKeys) {
if (Input.GetKeyDown(keyCode)) {
int currentIndex = Array.IndexOf(this.ControlModes, this.currentMode);
this.SetMode(this.ControlModes[(currentIndex + 1) % this.ControlModes.Length]);
}
}
}
}

void SetMode(ControlMode mode) {
if (this.currentMode == mode) {
return;
}
if (this.currentMode != null) {
this.currentMode.Behaviour.enabled = false;
}
this.currentMode = mode;
this.currentMode.Behaviour.enabled = true;
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ public class FirstPersonController : MonoBehaviour {
[Range(1f, 5f)]
public float MovementSpeed = 1f;

[Range(1, 200f)]
public float LookSensitivity = 10f;
[Range(1, 500f)]
public float LookSensitivity = 200f;

[Range(1, 500f)]
public float MouseSensitivity = 3;

[Range(1, 100f)]
public float JumpStrength = 2f;
Expand All @@ -22,23 +25,29 @@ public class FirstPersonController : MonoBehaviour {
private float timeInAir = 0f;
private bool jumpLocked = false;

void Start () {
public LayerMask CollisionLayers;

void OnEnable() {
this.characterController = this.GetComponent<CharacterController>();
this.cameraTransform = this.GetComponentInChildren<Camera>().transform;
Cursor.visible = false;
this.cameraTilt = this.cameraTransform.localRotation.eulerAngles.x;
}

void Update () {
bool touchesGround = this.onGround();
float runMultiplier = 1f + 2f * Input.GetAxis("Run");
float y = this.transform.position.y;
this.characterController.Move(this.transform.forward * Input.GetAxis("Move Y") * Time.deltaTime * this.MovementSpeed * runMultiplier + this.transform.right * Input.GetAxis("Move X") * Time.deltaTime * this.MovementSpeed * runMultiplier);
Vector3 movementVector = this.transform.forward * Input.GetAxis("Move Y") + this.transform.right * Input.GetAxis("Move X");
if (movementVector.sqrMagnitude > 1) {
movementVector.Normalize(); // this prevents diagonal movement form being too fast
}
this.characterController.Move(movementVector * Time.deltaTime * this.MovementSpeed * runMultiplier);
float verticalMovement = this.transform.position.y - y;
if (verticalMovement < 0) {
this.transform.position += Vector3.down * verticalMovement;
}
this.transform.rotation = Quaternion.AngleAxis(Input.GetAxis("Look X") * Time.deltaTime * this.LookSensitivity, Vector3.up) * this.transform.rotation;
this.cameraTilt = Mathf.Clamp(this.cameraTilt - Input.GetAxis("Look Y") * this.LookSensitivity * Time.deltaTime, -90f, 90f);
this.transform.localRotation = Quaternion.AngleAxis(Input.GetAxis("Mouse Look X") * this.MouseSensitivity + Input.GetAxis("Look X") * this.LookSensitivity * Time.deltaTime, Vector3.up) * this.transform.rotation;
this.cameraTilt = Mathf.Clamp(this.cameraTilt - Input.GetAxis("Mouse Look Y") * this.MouseSensitivity - Input.GetAxis("Look Y") * this.LookSensitivity * Time.deltaTime, -90f, 90f);
this.cameraTransform.localRotation = Quaternion.AngleAxis(this.cameraTilt, Vector3.right);

if (touchesGround) {
Expand All @@ -64,18 +73,14 @@ void Update () {
this.verticalSpeed = 2f;
}
this.characterController.Move(Vector3.up * Time.deltaTime * this.verticalSpeed);
}

if (Input.GetKeyDown(FlightController.OnOffKey)) {
var flyBehaviour = this.GetComponent<FlightController>();
if (flyBehaviour != null) {
this.GetComponent<FlightController>().enabled = true;
}
this.cameraTilt = 24;
}
public void Enable() {
this.verticalSpeed = 0;
}

private bool onGround() {
var ray = new Ray(this.transform.position, Vector3.down);
return Physics.SphereCast(ray, this.characterController.radius, this.characterController.height / 2 - this.characterController.radius + 0.1f);
return Physics.SphereCast(ray, this.characterController.radius, this.characterController.height / 2 - this.characterController.radius + 0.1f, this.CollisionLayers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
using UnityEngine;

public class FlightController : MonoBehaviour {
public float Velocity = 3;

[Range(0f, 20f)]
public float Velocity;

public const KeyCode OnOffKey = KeyCode.M;
[Range(1, 500f)]
public float LookSensitivity = 200f;

public void OnEnable() {
this.GetComponent<FirstPersonController>().enabled = false;
this.transform.position = this.transform.position - Vector3.up * this.transform.position.y + Vector3.up * (GameObject.FindObjectOfType<MapGenerator>().Height * MapGenerator.BlockSize + 2f);
this.transform.position = this.transform.position - Vector3.up * this.transform.position.y + Vector3.up * (GameObject.FindObjectOfType<MapBehaviour>().Map.Height * InfiniteMap.BLOCK_SIZE + 2f);
var cameraTransform = this.transform.GetChild(0);
cameraTransform.rotation = Quaternion.Euler(cameraTransform.rotation.eulerAngles - Vector3.right * cameraTransform.rotation.eulerAngles.x + Vector3.right * 24f);
}
Expand All @@ -20,11 +18,7 @@ void Update () {
var direction = this.transform.forward + Vector3.down * this.transform.forward.y;
this.transform.position += direction.normalized * this.Velocity * Time.deltaTime;

if (Input.GetKeyDown(FlightController.OnOffKey)) {
this.enabled = false;
this.GetComponent<FirstPersonController>().enabled = true;
}

this.Velocity = Mathf.Clamp(this.Velocity + Input.GetAxis("Move Y") * Time.deltaTime * 2f, 0f, 20f);
this.Velocity = Mathf.Clamp(this.Velocity + Input.GetAxis("Move Y") * Time.deltaTime * 4f, 0f, 20f);
this.transform.rotation = Quaternion.Euler(Vector3.up * (Input.GetAxis("Look X") + Input.GetAxis("Mouse Look X")) * Time.deltaTime * this.LookSensitivity) * this.transform.rotation;
}
}
44 changes: 44 additions & 0 deletions Assets/Code/CameraControl/FreeCameraController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FreeCameraController : MonoBehaviour
{
[Range(1f, 10f)]
public float MovementSpeed = 2f;

[Range(1, 500f)]
public float LookSensitivity = 200f;

[Range(1, 500f)]
public float MouseSensitivity = 3;

private CharacterController characterController;
private Transform cameraTransform;

private float cameraTilt = 0f;

void OnEnable() {
this.characterController = this.GetComponent<CharacterController>();
this.cameraTransform = this.GetComponentInChildren<Camera>().transform;
this.cameraTilt = this.cameraTransform.localRotation.eulerAngles.x;
}

void Update() {
Vector3 movementVector = this.cameraTransform.forward * Input.GetAxis("Move Y")
+ this.cameraTransform.right * Input.GetAxis("Move X")
+ Vector3.up * (Input.GetAxis("Move Up/Down") + Input.GetAxisRaw("Jump"));

if (movementVector.sqrMagnitude > 1) {
movementVector.Normalize();
}
if (Input.GetAxisRaw("Run") > 0.1f) {
movementVector *= 4;
}
this.characterController.Move(movementVector * Time.deltaTime * this.MovementSpeed);

this.transform.localRotation = Quaternion.AngleAxis(Input.GetAxis("Mouse Look X") * this.MouseSensitivity + Input.GetAxis("Look X") * this.LookSensitivity * Time.deltaTime, Vector3.up) * this.transform.rotation;
this.cameraTilt = Mathf.Clamp(this.cameraTilt - Input.GetAxis("Mouse Look Y") * this.MouseSensitivity - Input.GetAxis("Look Y") * this.LookSensitivity * Time.deltaTime, -90f, 90f);
this.cameraTransform.localRotation = Quaternion.AngleAxis(this.cameraTilt, Vector3.right);
}
}

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

8 changes: 8 additions & 0 deletions Assets/Code/Culling.meta

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

84 changes: 84 additions & 0 deletions Assets/Code/Culling/Chunk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Chunk {
public readonly Bounds Bounds;

public List<Renderer> Renderers;
public List<GameObject> GameObjects;
public List<Portal> Portals;
public List<Room> Rooms;

private Dictionary<Vector3Int, Renderer[]> renderersByPosition;

public bool ExteriorBlocksVisible = true;
public bool InRenderRange {
get;
private set;
}

public Chunk(Bounds bounds) {
this.Bounds = bounds;
this.Renderers = new List<Renderer>();
this.Portals = new List<Portal>();
this.Rooms = new List<Room>();
this.renderersByPosition = new Dictionary<Vector3Int, Renderer[]>();
this.GameObjects = new List<GameObject>();
this.InRenderRange = true;
}

public void SetInRenderRange(bool value) {
this.InRenderRange = value;
foreach (var gameObject in this.GameObjects) {
gameObject.SetActive(value);
}
// This only works for small rooms.
// It will fail if a room has blocks outside the render range and close to the player.
foreach (var room in this.Rooms) {
foreach (var slot in room.Slots) {
slot.GameObject.SetActive(value);
}
}
}

public void SetExteriorVisibility(bool value) {
if (this.ExteriorBlocksVisible == value) {
return;
}
foreach (var renderer in this.Renderers) {
renderer.shadowCastingMode = value ? UnityEngine.Rendering.ShadowCastingMode.On : UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
}
this.ExteriorBlocksVisible = value;
}

public void SetRoomVisibility(bool value) {
foreach (var room in this.Rooms) {
room.SetVisibility(value);
}
}

public void AddBlock(Slot slot) {
if (this.renderersByPosition.ContainsKey(slot.Position)) {
foreach (var renderer in this.renderersByPosition[slot.Position]) {
this.Renderers.Remove(renderer);
}
}
var renderers = slot.GameObject.GetComponentsInChildren<Renderer>();
this.renderersByPosition[slot.Position] = renderers;
this.Renderers.AddRange(renderers);
this.ExteriorBlocksVisible = true;
this.GameObjects.Add(slot.GameObject);
slot.GameObject.SetActive(this.InRenderRange);
}

public void RemoveBlock(Slot slot) {
if (!this.renderersByPosition.ContainsKey(slot.Position)) {
return;
}
foreach (var renderer in this.renderersByPosition[slot.Position]) {
this.Renderers.Remove(renderer);
}
this.GameObjects.Remove(slot.GameObject);
}
}
Loading