Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"NavigationMesh.cs"
 * 
 *	This script is used by the MeshCollider
 *  navigation method to define the pathfinding area.
 * 
 */

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using AC;

public class NavigationMesh : MonoBehaviour
{
	
	private int originalLayer;


	private void Awake ()
	{
		Hide ();
	}
	
	
	public void TurnOn ()
	{
		SceneSettings sceneSettings = GameObject.FindWithTag (Tags.gameEngine).GetComponent <SceneSettings>();
		
		if (sceneSettings && sceneSettings.navigationMethod == AC_NavigationMethod.meshCollider)
		{
			if (LayerMask.NameToLayer (AdvGame.GetReferences ().settingsManager.navMeshLayer) == -1)
			{
				Debug.LogWarning ("Can't find layer " + AdvGame.GetReferences ().settingsManager.navMeshLayer + " - please define it in the Tags Manager and list it in the Settings Manager.");
			}
			else if (AdvGame.GetReferences ().settingsManager.navMeshLayer != "")
			{
				gameObject.layer = LayerMask.NameToLayer (AdvGame.GetReferences ().settingsManager.navMeshLayer);
			}
			
			if (GetComponent <Collider>() == null)
			{
				Debug.LogWarning ("A Collider component must be attached to " + this.name + " for pathfinding to work - please attach one.");
			}
		}
		else if (sceneSettings)
		{
			Debug.LogWarning ("Cannot enable NavMesh " + this.name + " as this scene's Navigation Method is Unity Navigation.");
		}
		else
		{
			Debug.LogWarning ("Cannot enable NavMesh - no SceneSettings found.");
		}
	}
	
	
	public void TurnOff ()
	{
		gameObject.layer = LayerMask.NameToLayer (AdvGame.GetReferences ().settingsManager.deactivatedLayer);
	}
	
	

	public void Hide ()
	{
		if (this.GetComponent <MeshRenderer>())
		{
			this.GetComponent <MeshRenderer>().enabled = false;
		}
	}
	
	
	public void Show ()
	{
		if (this.GetComponent <MeshRenderer>() && this.GetComponent <MeshFilter>() && this.GetComponent <MeshCollider>() && this.GetComponent <MeshCollider>().sharedMesh)
		{
			this.GetComponent <MeshFilter>().mesh = this.GetComponent <MeshCollider>().sharedMesh;
			this.GetComponent <MeshRenderer>().enabled = true;
			this.GetComponent <MeshRenderer>().castShadows = false;
			this.GetComponent <MeshRenderer>().receiveShadows = false;
		}
	}
	
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Navigation/NavigationMesh.cs

Diff revisions: vs.
Revision Author Commited Message
83 FMMortaroli picture FMMortaroli Tue 13 May, 2014 11:32:51 +0000