├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md └── Scripts ├── AITasks.meta ├── AITasks ├── TaskHolder.cs ├── TaskHolder.cs.meta ├── TaskManager.cs └── TaskManager.cs.meta ├── Actions.meta ├── Actions ├── ClickFunctionality.cs └── ClickFunctionality.cs.meta ├── Camera.meta ├── Camera ├── CameraMovement.cs └── CameraMovement.cs.meta ├── GameManager.cs ├── GameManager.cs.meta ├── Generation.meta ├── Generation ├── EnableDynamicNavMeshGeneration.cs ├── EnableDynamicNavMeshGeneration.cs.meta ├── TerrainGenerator.cs └── TerrainGenerator.cs.meta ├── Inventory.meta ├── Inventory ├── ResourceHolder.cs └── ResourceHolder.cs.meta ├── NavMesh.meta ├── NavMesh ├── UnityScripts.meta └── UnityScripts │ ├── Scripts.meta │ └── Scripts │ ├── NavMeshComponents.asmdef │ ├── NavMeshComponents.asmdef.meta │ ├── NavMeshLink.cs │ ├── NavMeshLink.cs.meta │ ├── NavMeshModifier.cs │ ├── NavMeshModifier.cs.meta │ ├── NavMeshModifierVolume.cs │ ├── NavMeshModifierVolume.cs.meta │ ├── NavMeshSurface.cs │ └── NavMeshSurface.cs.meta ├── TerrainProperties.meta ├── TerrainProperties ├── TerrainProperties.cs ├── TerrainProperties.cs.meta ├── TerrainPropertiesHolder.cs └── TerrainPropertiesHolder.cs.meta ├── UI.meta └── UI ├── UIManager.cs └── UIManager.cs.meta /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - Version [e.g. 2018.01.01] YYYY/MM/DD 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | Assets/AssetStoreTools* 7 | 8 | # Visual Studio cache directory 9 | .vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | *.opendb 26 | 27 | # Unity3D generated meta files 28 | *.pidb.meta 29 | *.pdb.meta 30 | 31 | # Unity3D Generated File On Crash Reports 32 | sysinfo.txt 33 | 34 | # Builds 35 | *.apk 36 | *.unitypackage 37 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at thatunityproject@gmail.com The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Luka Rolak 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute and/or sublicense, and to permit persons to whom the Software is 7 | furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 | SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Sample for realtime navmesh generation in Unity engine 2 | 3 | See [version history](https://github.com/lukarolak/That-Unity-project/wiki/Version-history) for the current asset package. 4 | 5 | All scripts can be found on this repository, Asset packages are being uploaded to [Google drive](https://drive.google.com/drive/folders/1TdKbqoXSJM_Ob3aApAwYdPo8NrYAttHR?usp=sharing). 6 | 7 | *** 8 | [![](https://s8.postimg.cc/xi6ak61r9/ezgif.com-video-to-gif.gif)](https://postimg.cc/image/pco8m0di9/) 9 | 10 | -------------------------------------------------------------------------------- /Scripts/AITasks.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a32a02ef5f7d314e86e122398d0bbbb 3 | folderAsset: yes 4 | timeCreated: 1530801476 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/AITasks/TaskHolder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.AI; 5 | public class TaskHolder : MonoBehaviour { 6 | public TaskManager.TaskType Task; 7 | public TaskManager.MinionProperties Properties; 8 | // Use this for initialization 9 | void Start () { 10 | Properties.WorkStatus = TaskManager.TaskListEnum.Idle; 11 | } 12 | 13 | // Update is called once per frame 14 | void Update () { 15 | print(ResourceHolder.PlayersResources[0].Ore); 16 | if(Task.TaskList == TaskManager.TaskListEnum.Mine){ 17 | if(Task.Destination != null){ 18 | gameObject.GetComponent().SetDestination(Task.Destination.position); 19 | }else{ 20 | Task.TaskList = TaskManager.TaskListEnum.Idle; 21 | } 22 | Properties.WorkStatus = TaskManager.TaskListEnum.Mine; 23 | } 24 | } 25 | void OnCollisionEnter(Collision collisionInfo){ 26 | if(collisionInfo.gameObject.transform == Task.Destination){ 27 | collisionInfo.gameObject.GetComponent().ChangeTerrain(TerrainProperties.TerrainOpertations.Mine); 28 | Properties.WorkStatus = TaskManager.TaskListEnum.Idle; 29 | ResourceHolder.PlayersResources[Properties.PlayerID].Ore++; 30 | Task.TaskList = TaskManager.TaskListEnum.Idle; 31 | Properties.WorkStatus = TaskManager.TaskListEnum.Idle; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Scripts/AITasks/TaskHolder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c31c44914ef6bd42a1942f486020078 3 | timeCreated: 1530801534 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/AITasks/TaskManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.AI; 5 | public class TaskManager : MonoBehaviour { 6 | public enum TaskListEnum{ 7 | Mine, Idle 8 | } 9 | [System.Serializable] 10 | public struct TaskType{ 11 | public TaskListEnum TaskList; 12 | public Transform Destination; 13 | public int PlayerID; 14 | } 15 | public struct MinionProperties{ 16 | public int PlayerID; 17 | public TaskListEnum WorkStatus; 18 | } 19 | public static List TaskQueue = new List(); 20 | // Use this for initialization 21 | void Start () { 22 | } 23 | 24 | // Update is called once per frame 25 | void Update () { 26 | if(TaskQueue.Count>0){ 27 | if(TaskQueue[0].TaskList == TaskListEnum.Mine){ 28 | GameObject[] Miners = GameObject.FindGameObjectsWithTag("Miner"); 29 | foreach(GameObject Miner in Miners){ 30 | if(Miner.GetComponent().Task.TaskList == TaskListEnum.Idle && Miner.GetComponent().Properties.PlayerID == TaskQueue[0].PlayerID){ 31 | Miner.GetComponent().Task = TaskQueue[0]; 32 | TaskQueue.RemoveAt(0); 33 | break; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Scripts/AITasks/TaskManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7ccfbe28db1369429cd0eaf47da3430 3 | timeCreated: 1530792756 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Actions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b9e0281a84bcfb48a2cdaafca767c7b 3 | folderAsset: yes 4 | timeCreated: 1530801465 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Actions/ClickFunctionality.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ClickFunctionality : MonoBehaviour { 6 | 7 | // Use this for initialization 8 | void Start () { 9 | 10 | } 11 | 12 | // Update is called once per frame 13 | void Update () { 14 | if(GameManager._GameState == GameManager.GameStates.Game){ 15 | if(Input.GetMouseButtonUp(GameManager._KeyBindsSettings.ClickRight)){ 16 | RaycastHit Hit; 17 | Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 18 | if (Physics.Raycast(ray,out Hit, Mathf.Infinity)) 19 | if(Hit.transform.gameObject.GetComponent().TerrainCharacteristic.Mineable){ 20 | TaskManager.TaskType Task; 21 | Task.Destination = Hit.transform; 22 | Task.TaskList = TaskManager.TaskListEnum.Mine; 23 | Task.PlayerID = 0; 24 | TaskManager.TaskQueue.Add(Task); 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Scripts/Actions/ClickFunctionality.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a14bb6953aacc1b408e0edf9f735c9e8 3 | timeCreated: 1530791509 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Camera.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4aa9b5387d435d408bc84979fce22fc 3 | folderAsset: yes 4 | timeCreated: 1530791179 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Camera/CameraMovement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class CameraMovement : MonoBehaviour { 6 | private Vector3 MoveToPosition; 7 | // Use this for initialization 8 | void Start () { 9 | MoveToPosition = Camera.main.transform.position; 10 | } 11 | 12 | // Update is called once per frame 13 | void Update () { 14 | if(GameManager._GameState == GameManager.GameStates.Game){ 15 | Transform CameraTransfrom = Camera.main.transform; 16 | if(Input.GetKey(GameManager._KeyBindsSettings.Up)){ 17 | MoveToPosition += new Vector3(0,0,GameManager._GameSettings.MapScrollSpeed); 18 | } 19 | if(Input.GetKey(GameManager._KeyBindsSettings.Left)){ 20 | MoveToPosition += new Vector3(-GameManager._GameSettings.MapScrollSpeed,0,0); 21 | } 22 | if(Input.GetKey(GameManager._KeyBindsSettings.Right)){ 23 | MoveToPosition += new Vector3(GameManager._GameSettings.MapScrollSpeed,0,0); 24 | } 25 | if(Input.GetKey(GameManager._KeyBindsSettings.Down)){ 26 | MoveToPosition += new Vector3(0,0,-GameManager._GameSettings.MapScrollSpeed); 27 | } 28 | CameraTransfrom.position = Vector3.MoveTowards(CameraTransfrom.position,MoveToPosition,Mathf.Sqrt(Vector3.Distance(CameraTransfrom.position,MoveToPosition)*0.008f)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Scripts/Camera/CameraMovement.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4772bb0e3b2a98146b45629dc2e3950e 3 | timeCreated: 1530789665 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/GameManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class GameManager : MonoBehaviour { 6 | public static bool _EnableDeveloperLogs; 7 | public bool EnableDeveloperLogs = true; 8 | public static GameObject _ScriptHolder; 9 | public enum LogTier{ 10 | Log,Success,Fail,Warning,Error 11 | }; 12 | [System.Serializable] 13 | public struct KeyBinds{ 14 | public KeyCode Up; 15 | public KeyCode Down; 16 | public KeyCode Left; 17 | public KeyCode Right; 18 | public int ClickRight; //0 left,1 right, 2 middle 19 | } 20 | public static KeyBinds _KeyBindsSettings; 21 | [System.Serializable] 22 | public struct GameSettingsStruct{ 23 | public float MapScrollSpeed; 24 | public int NumberOfPlayers; 25 | } 26 | public static GameSettingsStruct _GameSettings; 27 | public GameSettingsStruct GameSettings; 28 | public KeyBinds KeyBindsSettings; 29 | public enum GameStates{ 30 | Game 31 | }; 32 | public static GameStates _GameState; 33 | public static bool _EnableDynamicNavMeshGeneration; 34 | 35 | // Use this for initialization 36 | void Start () { 37 | _EnableDynamicNavMeshGeneration = false; 38 | _EnableDeveloperLogs = EnableDeveloperLogs; 39 | _KeyBindsSettings = KeyBindsSettings; 40 | _GameSettings = GameSettings; 41 | _GameState = GameStates.Game; 42 | _ScriptHolder = gameObject; 43 | } 44 | 45 | // Update is called once per frame 46 | void Update () { 47 | } 48 | public static void Log(string Message, LogTier Tier = LogTier.Log){ 49 | if(_EnableDeveloperLogs == false) 50 | return; 51 | switch(Tier){ 52 | case LogTier.Success: 53 | Debug.Log(""+Message+""); 54 | break; 55 | case LogTier.Fail: 56 | Debug.Log(""+Message+""); 57 | break; 58 | case LogTier.Warning: 59 | Debug.LogWarning(Message); 60 | break; 61 | case LogTier.Error: 62 | Debug.LogError(Message); 63 | break; 64 | default: 65 | Debug.Log(Message); 66 | break; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Scripts/GameManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 43b830abf7fdb3343a780b11adc55317 3 | timeCreated: 1530730843 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: -100 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Generation.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d62121752b38dc442970a0d81d5fccf2 3 | folderAsset: yes 4 | timeCreated: 1530789565 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Generation/EnableDynamicNavMeshGeneration.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class EnableDynamicNavMeshGeneration : MonoBehaviour { 6 | 7 | // Use this for initialization 8 | void Start () { 9 | } 10 | 11 | // Update is called once per frame 12 | void Update () { 13 | GameManager._EnableDynamicNavMeshGeneration = true; 14 | Destroy(gameObject.GetComponent()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Scripts/Generation/EnableDynamicNavMeshGeneration.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3a11cd415e36d943bc82078cc5f7062 3 | timeCreated: 1530806352 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 100 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Generation/TerrainGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.AI; 5 | public class TerrainGenerator : MonoBehaviour { 6 | public int GridSize = 10; 7 | public GameObject[] TerrainObjects; 8 | public GameObject WalkableTerrainHolder; 9 | public int NavMeshGenerationCalls = 0; 10 | public GameObject Player; 11 | // Use this for initialization 12 | void Start () { 13 | GameManager.Log("Creating Grid"); 14 | GenerateGrid(); 15 | GameManager.Log("Creating Grid -> SUCCESS",GameManager.LogTier.Success); 16 | //GameManager._EnableDynamicNavMeshGeneration = true; 17 | } 18 | 19 | // Update is called once per frame 20 | void Update () { 21 | 22 | } 23 | void GenerateGrid(){ 24 | List WalkableTerrain = FindWalkableTerrain(); 25 | WalkableTerrainHolder = Instantiate(new GameObject("WalkableTerrainHolder"),new Vector3(0,0,0),Quaternion.identity); 26 | for(int i = 0; i < GridSize; i++){ 27 | for(int j = 0; j < GridSize; j++){ 28 | int ObjectID = Random.Range(0,TerrainObjects.Length); 29 | GameObject InstantiedObject = Instantiate(TerrainObjects[ObjectID],new Vector3(i,0,j),Quaternion.identity); 30 | if(WalkableTerrain.Contains(ObjectID)) 31 | InstantiedObject.transform.parent = WalkableTerrainHolder.transform; 32 | } 33 | } 34 | WalkableTerrainHolder.AddComponent(); 35 | WalkableTerrainHolder.GetComponent().collectObjects = CollectObjects.Children; 36 | RegenerateNavMesh(); 37 | SpawnPlayer(); 38 | } 39 | List FindWalkableTerrain(){ 40 | List WalkableTerrain = new List(); 41 | for(int i = 0; i < TerrainObjects.Length;i++){ 42 | if(TerrainObjects[i].GetComponent().TerrainCharacteristic.Walkable) 43 | WalkableTerrain.Add(i); 44 | } 45 | return WalkableTerrain; 46 | } 47 | public void RegenerateNavMesh(){ 48 | WalkableTerrainHolder.GetComponent().BuildNavMesh(); 49 | NavMeshGenerationCalls++; 50 | } 51 | public void SpawnPlayer(){ 52 | Instantiate(Player,WalkableTerrainHolder.transform.GetChild(Random.Range(0,WalkableTerrainHolder.transform.childCount-1)).transform.position,Quaternion.identity); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Scripts/Generation/TerrainGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2d14ec342d9ac347a4048e5e3f01cdb 3 | timeCreated: 1530729170 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Inventory.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df6f7af771711a24fb66f20f4abe6f99 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Inventory/ResourceHolder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ResourceHolder : MonoBehaviour { 6 | [System.Serializable] 7 | public struct Resources{ 8 | public int PlayerID; 9 | public int Ore; 10 | } 11 | public static Resources[] PlayersResources; 12 | // Use this for initialization 13 | void Start () { 14 | PlayersResources = new Resources[GameManager._GameSettings.NumberOfPlayers]; 15 | for(int i = 0; i < PlayersResources.Length; i++){ 16 | PlayersResources[i].PlayerID = i; 17 | } 18 | } 19 | 20 | // Update is called once per frame 21 | void Update () { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Scripts/Inventory/ResourceHolder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7fdb3fdb7a5020640b700d9639e892d4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/NavMesh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e943814e780c1b4f83887485c08ed6c 3 | folderAsset: yes 4 | timeCreated: 1530732883 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8506d4d429aae344ab98057e5bcfb4b6 3 | folderAsset: yes 4 | timeCreated: 1530732890 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3f75367503c9d94e9a7a0e94a9bb2d7 3 | folderAsset: yes 4 | timeCreated: 1530732925 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshComponents.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NavMeshComponents", 3 | "references": [], 4 | "optionalUnityReferences": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": false 8 | } -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshComponents.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c4dd21966739024fbd72155091d199e 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshLink.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace UnityEngine.AI 4 | { 5 | [ExecuteInEditMode] 6 | [DefaultExecutionOrder(-101)] 7 | [AddComponentMenu("Navigation/NavMeshLink", 33)] 8 | [HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#documentation-draft")] 9 | public class NavMeshLink : MonoBehaviour 10 | { 11 | [SerializeField] 12 | int m_AgentTypeID; 13 | public int agentTypeID { get { return m_AgentTypeID; } set { m_AgentTypeID = value; UpdateLink(); } } 14 | 15 | [SerializeField] 16 | Vector3 m_StartPoint = new Vector3(0.0f, 0.0f, -2.5f); 17 | public Vector3 startPoint { get { return m_StartPoint; } set { m_StartPoint = value; UpdateLink(); } } 18 | 19 | [SerializeField] 20 | Vector3 m_EndPoint = new Vector3(0.0f, 0.0f, 2.5f); 21 | public Vector3 endPoint { get { return m_EndPoint; } set { m_EndPoint = value; UpdateLink(); } } 22 | 23 | [SerializeField] 24 | float m_Width; 25 | public float width { get { return m_Width; } set { m_Width = value; UpdateLink(); } } 26 | 27 | [SerializeField] 28 | int m_CostModifier = -1; 29 | public int costModifier { get { return m_CostModifier; } set { m_CostModifier = value; UpdateLink(); } } 30 | 31 | [SerializeField] 32 | bool m_Bidirectional = true; 33 | public bool bidirectional { get { return m_Bidirectional; } set { m_Bidirectional = value; UpdateLink(); } } 34 | 35 | [SerializeField] 36 | bool m_AutoUpdatePosition; 37 | public bool autoUpdate { get { return m_AutoUpdatePosition; } set { SetAutoUpdate(value); } } 38 | 39 | [SerializeField] 40 | int m_Area; 41 | public int area { get { return m_Area; } set { m_Area = value; UpdateLink(); } } 42 | 43 | NavMeshLinkInstance m_LinkInstance = new NavMeshLinkInstance(); 44 | 45 | Vector3 m_LastPosition = Vector3.zero; 46 | Quaternion m_LastRotation = Quaternion.identity; 47 | 48 | static readonly List s_Tracked = new List(); 49 | 50 | void OnEnable() 51 | { 52 | AddLink(); 53 | if (m_AutoUpdatePosition && m_LinkInstance.valid) 54 | AddTracking(this); 55 | } 56 | 57 | void OnDisable() 58 | { 59 | RemoveTracking(this); 60 | m_LinkInstance.Remove(); 61 | } 62 | 63 | public void UpdateLink() 64 | { 65 | m_LinkInstance.Remove(); 66 | AddLink(); 67 | } 68 | 69 | static void AddTracking(NavMeshLink link) 70 | { 71 | #if UNITY_EDITOR 72 | if (s_Tracked.Contains(link)) 73 | { 74 | Debug.LogError("Link is already tracked: " + link); 75 | return; 76 | } 77 | #endif 78 | 79 | if (s_Tracked.Count == 0) 80 | NavMesh.onPreUpdate += UpdateTrackedInstances; 81 | 82 | s_Tracked.Add(link); 83 | } 84 | 85 | static void RemoveTracking(NavMeshLink link) 86 | { 87 | s_Tracked.Remove(link); 88 | 89 | if (s_Tracked.Count == 0) 90 | NavMesh.onPreUpdate -= UpdateTrackedInstances; 91 | } 92 | 93 | void SetAutoUpdate(bool value) 94 | { 95 | if (m_AutoUpdatePosition == value) 96 | return; 97 | m_AutoUpdatePosition = value; 98 | if (value) 99 | AddTracking(this); 100 | else 101 | RemoveTracking(this); 102 | } 103 | 104 | void AddLink() 105 | { 106 | #if UNITY_EDITOR 107 | if (m_LinkInstance.valid) 108 | { 109 | Debug.LogError("Link is already added: " + this); 110 | return; 111 | } 112 | #endif 113 | 114 | var link = new NavMeshLinkData(); 115 | link.startPosition = m_StartPoint; 116 | link.endPosition = m_EndPoint; 117 | link.width = m_Width; 118 | link.costModifier = m_CostModifier; 119 | link.bidirectional = m_Bidirectional; 120 | link.area = m_Area; 121 | link.agentTypeID = m_AgentTypeID; 122 | m_LinkInstance = NavMesh.AddLink(link, transform.position, transform.rotation); 123 | if (m_LinkInstance.valid) 124 | m_LinkInstance.owner = this; 125 | 126 | m_LastPosition = transform.position; 127 | m_LastRotation = transform.rotation; 128 | } 129 | 130 | bool HasTransformChanged() 131 | { 132 | if (m_LastPosition != transform.position) return true; 133 | if (m_LastRotation != transform.rotation) return true; 134 | return false; 135 | } 136 | 137 | void OnDidApplyAnimationProperties() 138 | { 139 | UpdateLink(); 140 | } 141 | 142 | static void UpdateTrackedInstances() 143 | { 144 | foreach (var instance in s_Tracked) 145 | { 146 | if (instance.HasTransformChanged()) 147 | instance.UpdateLink(); 148 | } 149 | } 150 | 151 | #if UNITY_EDITOR 152 | void OnValidate() 153 | { 154 | m_Width = Mathf.Max(0.0f, m_Width); 155 | 156 | if (!m_LinkInstance.valid) 157 | return; 158 | 159 | UpdateLink(); 160 | 161 | if (!m_AutoUpdatePosition) 162 | { 163 | RemoveTracking(this); 164 | } 165 | else if (!s_Tracked.Contains(this)) 166 | { 167 | AddTracking(this); 168 | } 169 | } 170 | #endif 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshLink.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6eeb5dc026fdf4b488bc7ae0138ab719 3 | timeCreated: 1477924439 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: 92f4afa3e25264f5b964937ccea49ff2, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshModifier.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace UnityEngine.AI 4 | { 5 | [ExecuteInEditMode] 6 | [AddComponentMenu("Navigation/NavMeshModifier", 32)] 7 | [HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#documentation-draft")] 8 | public class NavMeshModifier : MonoBehaviour 9 | { 10 | [SerializeField] 11 | bool m_OverrideArea; 12 | public bool overrideArea { get { return m_OverrideArea; } set { m_OverrideArea = value; } } 13 | 14 | [SerializeField] 15 | int m_Area; 16 | public int area { get { return m_Area; } set { m_Area = value; } } 17 | 18 | [SerializeField] 19 | bool m_IgnoreFromBuild; 20 | public bool ignoreFromBuild { get { return m_IgnoreFromBuild; } set { m_IgnoreFromBuild = value; } } 21 | 22 | // List of agent types the modifier is applied for. 23 | // Special values: empty == None, m_AffectedAgents[0] =-1 == All. 24 | [SerializeField] 25 | List m_AffectedAgents = new List(new int[] { -1 }); // Default value is All 26 | 27 | static readonly List s_NavMeshModifiers = new List(); 28 | 29 | public static List activeModifiers 30 | { 31 | get { return s_NavMeshModifiers; } 32 | } 33 | 34 | void OnEnable() 35 | { 36 | if (!s_NavMeshModifiers.Contains(this)) 37 | s_NavMeshModifiers.Add(this); 38 | } 39 | 40 | void OnDisable() 41 | { 42 | s_NavMeshModifiers.Remove(this); 43 | } 44 | 45 | public bool AffectsAgentType(int agentTypeID) 46 | { 47 | if (m_AffectedAgents.Count == 0) 48 | return false; 49 | if (m_AffectedAgents[0] == -1) 50 | return true; 51 | return m_AffectedAgents.IndexOf(agentTypeID) != -1; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshModifier.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e3fdca004f2d45fe8abbed571a8abd5 3 | timeCreated: 1477924411 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: cc7b9475dbddf4f9088d327d6e10ab77, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshModifierVolume.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace UnityEngine.AI 4 | { 5 | [ExecuteInEditMode] 6 | [AddComponentMenu("Navigation/NavMeshModifierVolume", 31)] 7 | [HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#documentation-draft")] 8 | public class NavMeshModifierVolume : MonoBehaviour 9 | { 10 | [SerializeField] 11 | Vector3 m_Size = new Vector3(4.0f, 3.0f, 4.0f); 12 | public Vector3 size { get { return m_Size; } set { m_Size = value; } } 13 | 14 | [SerializeField] 15 | Vector3 m_Center = new Vector3(0, 1.0f, 0); 16 | public Vector3 center { get { return m_Center; } set { m_Center = value; } } 17 | 18 | [SerializeField] 19 | int m_Area; 20 | public int area { get { return m_Area; } set { m_Area = value; } } 21 | 22 | // List of agent types the modifier is applied for. 23 | // Special values: empty == None, m_AffectedAgents[0] =-1 == All. 24 | [SerializeField] 25 | List m_AffectedAgents = new List(new int[] { -1 }); // Default value is All 26 | 27 | static readonly List s_NavMeshModifiers = new List(); 28 | 29 | public static List activeModifiers 30 | { 31 | get { return s_NavMeshModifiers; } 32 | } 33 | 34 | void OnEnable() 35 | { 36 | if (!s_NavMeshModifiers.Contains(this)) 37 | s_NavMeshModifiers.Add(this); 38 | } 39 | 40 | void OnDisable() 41 | { 42 | s_NavMeshModifiers.Remove(this); 43 | } 44 | 45 | public bool AffectsAgentType(int agentTypeID) 46 | { 47 | if (m_AffectedAgents.Count == 0) 48 | return false; 49 | if (m_AffectedAgents[0] == -1) 50 | return true; 51 | return m_AffectedAgents.IndexOf(agentTypeID) != -1; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshModifierVolume.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35e95dc5ff2b64380880dd7ac5922847 3 | timeCreated: 1477924430 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: cc7b9475dbddf4f9088d327d6e10ab77, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshSurface.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace UnityEngine.AI 4 | { 5 | public enum CollectObjects 6 | { 7 | All = 0, 8 | Volume = 1, 9 | Children = 2, 10 | } 11 | 12 | [ExecuteInEditMode] 13 | [DefaultExecutionOrder(-102)] 14 | [AddComponentMenu("Navigation/NavMeshSurface", 30)] 15 | [HelpURL("https://github.com/Unity-Technologies/NavMeshComponents#documentation-draft")] 16 | public class NavMeshSurface : MonoBehaviour 17 | { 18 | [SerializeField] 19 | int m_AgentTypeID; 20 | public int agentTypeID { get { return m_AgentTypeID; } set { m_AgentTypeID = value; } } 21 | 22 | [SerializeField] 23 | CollectObjects m_CollectObjects = CollectObjects.All; 24 | public CollectObjects collectObjects { get { return m_CollectObjects; } set { m_CollectObjects = value; } } 25 | 26 | [SerializeField] 27 | Vector3 m_Size = new Vector3(10.0f, 10.0f, 10.0f); 28 | public Vector3 size { get { return m_Size; } set { m_Size = value; } } 29 | 30 | [SerializeField] 31 | Vector3 m_Center = new Vector3(0, 2.0f, 0); 32 | public Vector3 center { get { return m_Center; } set { m_Center = value; } } 33 | 34 | [SerializeField] 35 | LayerMask m_LayerMask = ~0; 36 | public LayerMask layerMask { get { return m_LayerMask; } set { m_LayerMask = value; } } 37 | 38 | [SerializeField] 39 | NavMeshCollectGeometry m_UseGeometry = NavMeshCollectGeometry.RenderMeshes; 40 | public NavMeshCollectGeometry useGeometry { get { return m_UseGeometry; } set { m_UseGeometry = value; } } 41 | 42 | [SerializeField] 43 | int m_DefaultArea; 44 | public int defaultArea { get { return m_DefaultArea; } set { m_DefaultArea = value; } } 45 | 46 | [SerializeField] 47 | bool m_IgnoreNavMeshAgent = true; 48 | public bool ignoreNavMeshAgent { get { return m_IgnoreNavMeshAgent; } set { m_IgnoreNavMeshAgent = value; } } 49 | 50 | [SerializeField] 51 | bool m_IgnoreNavMeshObstacle = true; 52 | public bool ignoreNavMeshObstacle { get { return m_IgnoreNavMeshObstacle; } set { m_IgnoreNavMeshObstacle = value; } } 53 | 54 | [SerializeField] 55 | bool m_OverrideTileSize; 56 | public bool overrideTileSize { get { return m_OverrideTileSize; } set { m_OverrideTileSize = value; } } 57 | [SerializeField] 58 | int m_TileSize = 256; 59 | public int tileSize { get { return m_TileSize; } set { m_TileSize = value; } } 60 | [SerializeField] 61 | bool m_OverrideVoxelSize; 62 | public bool overrideVoxelSize { get { return m_OverrideVoxelSize; } set { m_OverrideVoxelSize = value; } } 63 | [SerializeField] 64 | float m_VoxelSize; 65 | public float voxelSize { get { return m_VoxelSize; } set { m_VoxelSize = value; } } 66 | 67 | // Currently not supported advanced options 68 | [SerializeField] 69 | bool m_BuildHeightMesh; 70 | public bool buildHeightMesh { get { return m_BuildHeightMesh; } set { m_BuildHeightMesh = value; } } 71 | 72 | // Reference to whole scene navmesh data asset. 73 | [UnityEngine.Serialization.FormerlySerializedAs("m_BakedNavMeshData")] 74 | [SerializeField] 75 | NavMeshData m_NavMeshData; 76 | public NavMeshData navMeshData { get { return m_NavMeshData; } set { m_NavMeshData = value; } } 77 | 78 | // Do not serialize - runtime only state. 79 | NavMeshDataInstance m_NavMeshDataInstance; 80 | Vector3 m_LastPosition = Vector3.zero; 81 | Quaternion m_LastRotation = Quaternion.identity; 82 | 83 | static readonly List s_NavMeshSurfaces = new List(); 84 | 85 | public static List activeSurfaces 86 | { 87 | get { return s_NavMeshSurfaces; } 88 | } 89 | 90 | void OnEnable() 91 | { 92 | Register(this); 93 | AddData(); 94 | } 95 | 96 | void OnDisable() 97 | { 98 | RemoveData(); 99 | Unregister(this); 100 | } 101 | 102 | public void AddData() 103 | { 104 | if (m_NavMeshDataInstance.valid) 105 | return; 106 | 107 | if (m_NavMeshData != null) 108 | { 109 | m_NavMeshDataInstance = NavMesh.AddNavMeshData(m_NavMeshData, transform.position, transform.rotation); 110 | m_NavMeshDataInstance.owner = this; 111 | } 112 | 113 | m_LastPosition = transform.position; 114 | m_LastRotation = transform.rotation; 115 | } 116 | 117 | public void RemoveData() 118 | { 119 | m_NavMeshDataInstance.Remove(); 120 | m_NavMeshDataInstance = new NavMeshDataInstance(); 121 | } 122 | 123 | public NavMeshBuildSettings GetBuildSettings() 124 | { 125 | var buildSettings = NavMesh.GetSettingsByID(m_AgentTypeID); 126 | if (buildSettings.agentTypeID == -1) 127 | { 128 | Debug.LogWarning("No build settings for agent type ID " + agentTypeID, this); 129 | buildSettings.agentTypeID = m_AgentTypeID; 130 | } 131 | 132 | if (overrideTileSize) 133 | { 134 | buildSettings.overrideTileSize = true; 135 | buildSettings.tileSize = tileSize; 136 | } 137 | if (overrideVoxelSize) 138 | { 139 | buildSettings.overrideVoxelSize = true; 140 | buildSettings.voxelSize = voxelSize; 141 | } 142 | return buildSettings; 143 | } 144 | 145 | public void BuildNavMesh() 146 | { 147 | var sources = CollectSources(); 148 | 149 | // Use unscaled bounds - this differs in behaviour from e.g. collider components. 150 | // But is similar to reflection probe - and since navmesh data has no scaling support - it is the right choice here. 151 | var sourcesBounds = new Bounds(m_Center, Abs(m_Size)); 152 | if (m_CollectObjects == CollectObjects.All || m_CollectObjects == CollectObjects.Children) 153 | { 154 | sourcesBounds = CalculateWorldBounds(sources); 155 | } 156 | 157 | var data = NavMeshBuilder.BuildNavMeshData(GetBuildSettings(), 158 | sources, sourcesBounds, transform.position, transform.rotation); 159 | 160 | if (data != null) 161 | { 162 | data.name = gameObject.name; 163 | RemoveData(); 164 | m_NavMeshData = data; 165 | if (isActiveAndEnabled) 166 | AddData(); 167 | } 168 | } 169 | 170 | public AsyncOperation UpdateNavMesh(NavMeshData data) 171 | { 172 | var sources = CollectSources(); 173 | 174 | // Use unscaled bounds - this differs in behaviour from e.g. collider components. 175 | // But is similar to reflection probe - and since navmesh data has no scaling support - it is the right choice here. 176 | var sourcesBounds = new Bounds(m_Center, Abs(m_Size)); 177 | if (m_CollectObjects == CollectObjects.All || m_CollectObjects == CollectObjects.Children) 178 | sourcesBounds = CalculateWorldBounds(sources); 179 | 180 | return NavMeshBuilder.UpdateNavMeshDataAsync(data, GetBuildSettings(), sources, sourcesBounds); 181 | } 182 | 183 | static void Register(NavMeshSurface surface) 184 | { 185 | if (s_NavMeshSurfaces.Count == 0) 186 | NavMesh.onPreUpdate += UpdateActive; 187 | 188 | if (!s_NavMeshSurfaces.Contains(surface)) 189 | s_NavMeshSurfaces.Add(surface); 190 | } 191 | 192 | static void Unregister(NavMeshSurface surface) 193 | { 194 | s_NavMeshSurfaces.Remove(surface); 195 | 196 | if (s_NavMeshSurfaces.Count == 0) 197 | NavMesh.onPreUpdate -= UpdateActive; 198 | } 199 | 200 | static void UpdateActive() 201 | { 202 | for (var i = 0; i < s_NavMeshSurfaces.Count; ++i) 203 | s_NavMeshSurfaces[i].UpdateDataIfTransformChanged(); 204 | } 205 | 206 | void AppendModifierVolumes(ref List sources) 207 | { 208 | // Modifiers 209 | List modifiers; 210 | if (m_CollectObjects == CollectObjects.Children) 211 | { 212 | modifiers = new List(GetComponentsInChildren()); 213 | modifiers.RemoveAll(x => !x.isActiveAndEnabled); 214 | } 215 | else 216 | { 217 | modifiers = NavMeshModifierVolume.activeModifiers; 218 | } 219 | 220 | foreach (var m in modifiers) 221 | { 222 | if ((m_LayerMask & (1 << m.gameObject.layer)) == 0) 223 | continue; 224 | if (!m.AffectsAgentType(m_AgentTypeID)) 225 | continue; 226 | var mcenter = m.transform.TransformPoint(m.center); 227 | var scale = m.transform.lossyScale; 228 | var msize = new Vector3(m.size.x * Mathf.Abs(scale.x), m.size.y * Mathf.Abs(scale.y), m.size.z * Mathf.Abs(scale.z)); 229 | 230 | var src = new NavMeshBuildSource(); 231 | src.shape = NavMeshBuildSourceShape.ModifierBox; 232 | src.transform = Matrix4x4.TRS(mcenter, m.transform.rotation, Vector3.one); 233 | src.size = msize; 234 | src.area = m.area; 235 | sources.Add(src); 236 | } 237 | } 238 | 239 | List CollectSources() 240 | { 241 | var sources = new List(); 242 | var markups = new List(); 243 | 244 | List modifiers; 245 | if (m_CollectObjects == CollectObjects.Children) 246 | { 247 | modifiers = new List(GetComponentsInChildren()); 248 | modifiers.RemoveAll(x => !x.isActiveAndEnabled); 249 | } 250 | else 251 | { 252 | modifiers = NavMeshModifier.activeModifiers; 253 | } 254 | 255 | foreach (var m in modifiers) 256 | { 257 | if ((m_LayerMask & (1 << m.gameObject.layer)) == 0) 258 | continue; 259 | if (!m.AffectsAgentType(m_AgentTypeID)) 260 | continue; 261 | var markup = new NavMeshBuildMarkup(); 262 | markup.root = m.transform; 263 | markup.overrideArea = m.overrideArea; 264 | markup.area = m.area; 265 | markup.ignoreFromBuild = m.ignoreFromBuild; 266 | markups.Add(markup); 267 | } 268 | 269 | if (m_CollectObjects == CollectObjects.All) 270 | { 271 | NavMeshBuilder.CollectSources(null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources); 272 | } 273 | else if (m_CollectObjects == CollectObjects.Children) 274 | { 275 | NavMeshBuilder.CollectSources(transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources); 276 | } 277 | else if (m_CollectObjects == CollectObjects.Volume) 278 | { 279 | Matrix4x4 localToWorld = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); 280 | var worldBounds = GetWorldBounds(localToWorld, new Bounds(m_Center, m_Size)); 281 | NavMeshBuilder.CollectSources(worldBounds, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources); 282 | } 283 | 284 | if (m_IgnoreNavMeshAgent) 285 | sources.RemoveAll((x) => (x.component != null && x.component.gameObject.GetComponent() != null)); 286 | 287 | if (m_IgnoreNavMeshObstacle) 288 | sources.RemoveAll((x) => (x.component != null && x.component.gameObject.GetComponent() != null)); 289 | 290 | AppendModifierVolumes(ref sources); 291 | 292 | return sources; 293 | } 294 | 295 | static Vector3 Abs(Vector3 v) 296 | { 297 | return new Vector3(Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z)); 298 | } 299 | 300 | static Bounds GetWorldBounds(Matrix4x4 mat, Bounds bounds) 301 | { 302 | var absAxisX = Abs(mat.MultiplyVector(Vector3.right)); 303 | var absAxisY = Abs(mat.MultiplyVector(Vector3.up)); 304 | var absAxisZ = Abs(mat.MultiplyVector(Vector3.forward)); 305 | var worldPosition = mat.MultiplyPoint(bounds.center); 306 | var worldSize = absAxisX * bounds.size.x + absAxisY * bounds.size.y + absAxisZ * bounds.size.z; 307 | return new Bounds(worldPosition, worldSize); 308 | } 309 | 310 | Bounds CalculateWorldBounds(List sources) 311 | { 312 | // Use the unscaled matrix for the NavMeshSurface 313 | Matrix4x4 worldToLocal = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); 314 | worldToLocal = worldToLocal.inverse; 315 | 316 | var result = new Bounds(); 317 | foreach (var src in sources) 318 | { 319 | switch (src.shape) 320 | { 321 | case NavMeshBuildSourceShape.Mesh: 322 | { 323 | var m = src.sourceObject as Mesh; 324 | result.Encapsulate(GetWorldBounds(worldToLocal * src.transform, m.bounds)); 325 | break; 326 | } 327 | case NavMeshBuildSourceShape.Terrain: 328 | { 329 | // Terrain pivot is lower/left corner - shift bounds accordingly 330 | var t = src.sourceObject as TerrainData; 331 | result.Encapsulate(GetWorldBounds(worldToLocal * src.transform, new Bounds(0.5f * t.size, t.size))); 332 | break; 333 | } 334 | case NavMeshBuildSourceShape.Box: 335 | case NavMeshBuildSourceShape.Sphere: 336 | case NavMeshBuildSourceShape.Capsule: 337 | case NavMeshBuildSourceShape.ModifierBox: 338 | result.Encapsulate(GetWorldBounds(worldToLocal * src.transform, new Bounds(Vector3.zero, src.size))); 339 | break; 340 | } 341 | } 342 | // Inflate the bounds a bit to avoid clipping co-planar sources 343 | result.Expand(0.1f); 344 | return result; 345 | } 346 | 347 | bool HasTransformChanged() 348 | { 349 | if (m_LastPosition != transform.position) return true; 350 | if (m_LastRotation != transform.rotation) return true; 351 | return false; 352 | } 353 | 354 | void UpdateDataIfTransformChanged() 355 | { 356 | if (HasTransformChanged()) 357 | { 358 | RemoveData(); 359 | AddData(); 360 | } 361 | } 362 | 363 | #if UNITY_EDITOR 364 | bool UnshareNavMeshAsset() 365 | { 366 | // Nothing to unshare 367 | if (m_NavMeshData == null) 368 | return false; 369 | 370 | // Prefab parent owns the asset reference 371 | var prefabType = UnityEditor.PrefabUtility.GetPrefabType(this); 372 | if (prefabType == UnityEditor.PrefabType.Prefab) 373 | return false; 374 | 375 | // An instance can share asset reference only with its prefab parent 376 | var prefab = UnityEditor.PrefabUtility.GetPrefabParent(this) as NavMeshSurface; 377 | if (prefab != null && prefab.navMeshData == navMeshData) 378 | return false; 379 | 380 | // Don't allow referencing an asset that's assigned to another surface 381 | for (var i = 0; i < s_NavMeshSurfaces.Count; ++i) 382 | { 383 | var surface = s_NavMeshSurfaces[i]; 384 | if (surface != this && surface.m_NavMeshData == m_NavMeshData) 385 | return true; 386 | } 387 | 388 | // Asset is not referenced by known surfaces 389 | return false; 390 | } 391 | 392 | void OnValidate() 393 | { 394 | if (UnshareNavMeshAsset()) 395 | { 396 | Debug.LogWarning("Duplicating NavMeshSurface does not duplicate the referenced navmesh data", this); 397 | m_NavMeshData = null; 398 | } 399 | 400 | var settings = NavMesh.GetSettingsByID(m_AgentTypeID); 401 | if (settings.agentTypeID != -1) 402 | { 403 | // When unchecking the override control, revert to automatic value. 404 | const float kMinVoxelSize = 0.01f; 405 | if (!m_OverrideVoxelSize) 406 | m_VoxelSize = settings.agentRadius / 3.0f; 407 | if (m_VoxelSize < kMinVoxelSize) 408 | m_VoxelSize = kMinVoxelSize; 409 | 410 | // When unchecking the override control, revert to default value. 411 | const int kMinTileSize = 16; 412 | const int kMaxTileSize = 1024; 413 | const int kDefaultTileSize = 256; 414 | 415 | if (!m_OverrideTileSize) 416 | m_TileSize = kDefaultTileSize; 417 | // Make sure tilesize is in sane range. 418 | if (m_TileSize < kMinTileSize) 419 | m_TileSize = kMinTileSize; 420 | if (m_TileSize > kMaxTileSize) 421 | m_TileSize = kMaxTileSize; 422 | } 423 | } 424 | #endif 425 | } 426 | } 427 | -------------------------------------------------------------------------------- /Scripts/NavMesh/UnityScripts/Scripts/NavMeshSurface.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a5ac11cc976e418e8d13136b07e1f52 3 | timeCreated: 1477658803 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: e4f97225bcfb64760a1c81f460837f01, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scripts/TerrainProperties.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 560305a442fee96448220e0ea9ee89a0 3 | folderAsset: yes 4 | timeCreated: 1530789581 5 | licenseType: Free 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/TerrainProperties/TerrainProperties.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class TerrainProperties : MonoBehaviour { 6 | [System.Serializable] 7 | public struct TerrainCharacteristic{ 8 | public bool Walkable; 9 | public bool Mineable; 10 | public List TerrainLevels; 11 | } 12 | [System.Serializable] 13 | public struct TerrainEvolution{ 14 | public TerrainOpertations Operation; 15 | public GameObject LevelObject; 16 | public GameObject ParticleEffect; 17 | } 18 | public enum TerrainOpertations{ 19 | Mine 20 | } 21 | // Use this for initialization 22 | void Start () { 23 | 24 | } 25 | 26 | // Update is called once per frame 27 | void Update () { 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Scripts/TerrainProperties/TerrainProperties.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d53671dd3f49d347b95b4d8e01b8c27 3 | timeCreated: 1530731645 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/TerrainProperties/TerrainPropertiesHolder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.AI; 5 | public class TerrainPropertiesHolder : MonoBehaviour { 6 | 7 | public TerrainProperties.TerrainCharacteristic TerrainCharacteristic; 8 | // Use this for initialization 9 | void Start () { 10 | if(TerrainCharacteristic.Walkable == true && GameManager._EnableDynamicNavMeshGeneration){ 11 | gameObject.transform.parent = GameManager._ScriptHolder.GetComponent().WalkableTerrainHolder.transform; 12 | GameManager._ScriptHolder.GetComponent().RegenerateNavMesh(); 13 | } 14 | } 15 | // Update is called once per frame 16 | void Update () { 17 | 18 | } 19 | public void ChangeTerrain(TerrainProperties.TerrainOpertations Operation){ 20 | foreach(TerrainProperties.TerrainEvolution TerrainInfo in TerrainCharacteristic.TerrainLevels){ 21 | if(TerrainInfo.Operation == Operation){ 22 | Instantiate(TerrainInfo.LevelObject,gameObject.transform.position,Quaternion.identity); 23 | if(TerrainInfo.ParticleEffect != null) 24 | Instantiate(TerrainInfo.ParticleEffect,gameObject.transform.position,Quaternion.identity); 25 | Destroy(gameObject); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Scripts/TerrainProperties/TerrainPropertiesHolder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b24df8092943bbe478bab4f96474fa74 3 | timeCreated: 1530731864 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0a057b098106ea4d8db8e3225cfa000 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/UI/UIManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | public class UIManager : MonoBehaviour { 6 | public GameObject Canvas; 7 | // Use this for initialization 8 | void Start () { 9 | Canvas = GameObject.FindGameObjectWithTag("UIElement"); 10 | } 11 | 12 | // Update is called once per frame 13 | void Update () { 14 | Canvas.transform.GetChild(0).transform.GetChild(0).GetComponent().text = "Ore: " + ResourceHolder.PlayersResources[0].Ore.ToString(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Scripts/UI/UIManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 544d9a26e9eab7e4bb933d53dea51845 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | --------------------------------------------------------------------------------