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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using AC;

[CustomEditor(typeof(Paths))]
public class PathsEditor : Editor
{
	
	private static GUIContent
		insertContent = new GUIContent("+", "Insert node"),
		deleteContent = new GUIContent("-", "Delete node");

	private static GUILayoutOption
		buttonWidth = GUILayout.MaxWidth(20f);
	
	
	public override void OnInspectorGUI()
	{
		Paths _target = (Paths) target;
		
		int numNodes = _target.nodes.Count;
		if (numNodes < 1)
		{
			numNodes = 1;
			_target.nodes = ResizeList (_target.nodes, numNodes);
		}

		//EditorGUILayout.LabelField("Nodes: " + (numNodes - 1).ToString());
		_target.nodePause = EditorGUILayout.FloatField ("Wait time (s):", _target.nodePause);
 		_target.pathSpeed = (PathSpeed) EditorGUILayout.EnumPopup("Walk or run:", (PathSpeed) _target.pathSpeed);
		_target.pathType = (AC_PathType) EditorGUILayout.EnumPopup ("Path type:", (AC_PathType) _target.pathType);
		_target.affectY = EditorGUILayout.Toggle ("Override gravity?", _target.affectY);

		// List nodes
		for (int i=1; i<_target.nodes.Count; i++)
		{

			EditorGUILayout.BeginVertical("Button");
				EditorGUILayout.BeginHorizontal ();
					_target.nodes[i] = EditorGUILayout.Vector3Field ("Node " + i + ": ", _target.nodes[i]);
					
					if (GUILayout.Button (insertContent, EditorStyles.miniButtonLeft, buttonWidth))
					{
						Undo.RecordObject (_target, "Add path node");
						Vector3 newNodePosition;
						newNodePosition = _target.nodes[i] + new Vector3 (1.0f, 0f, 0f);
						_target.nodes.Insert (i+1, newNodePosition);
						numNodes += 1;
					}
					if (GUILayout.Button (deleteContent, EditorStyles.miniButtonRight, buttonWidth))
					{
						Undo.RecordObject (_target, "Delete path node");
						_target.nodes.RemoveAt (i);
						numNodes -= 1;
					}
				EditorGUILayout.EndHorizontal ();
			EditorGUILayout.EndVertical();
		}

		if (numNodes == 1 && GUILayout.Button("Add node"))
		{
			Undo.RecordObject (_target, "Add path node");
			numNodes += 1;
		}
		
		_target.nodes[0] = _target.transform.position;
		_target.nodes = ResizeList (_target.nodes, numNodes);

		if (GUI.changed)
		{
			EditorUtility.SetDirty ((Paths) target);
		}
	}
	
	
	private void OnSceneGUI ()
	{
		Paths _target = (Paths) target;
		
		// Go through each element in the nodesArray array and display its stuff
		for (int i=0; i<_target.nodes.Count; i++)
		{
			if (i>0 && !Application.isPlaying)
			{
				_target.nodes[i] = Handles.PositionHandle (_target.nodes[i], Quaternion.identity);
			}
			
			Handles.Label (_target.nodes[i], i.ToString());
		}
		
		if (GUI.changed)
			EditorUtility.SetDirty (_target);
	}

	
	private List<Vector3> ResizeList (List<Vector3> list, int listSize)
	{
		if (list.Count < listSize)
		{
			// Increase size of list
			while (list.Count < listSize)
			{
				Vector3 newNodePosition;
				if (list.Count > 0)
				{
					newNodePosition = list[list.Count-1] + new Vector3 (1.0f, 0f, 0f);
				}
				else
				{
					newNodePosition = Vector3.zero;
				}
				list.Add (newNodePosition);
			}
		}
		else if (list.Count > listSize)
		{
			// Decrease size of list
			while (list.Count > listSize)
			{
				list.RemoveAt (list.Count - 1);
			}
		}
		return (list);
	}

}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Navigation/Editor/PathsEditor.cs

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