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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using UnityEngine;
using UnityEditor;
using System.Collections;
using AC;

[CustomEditor (typeof (SortingMap))]

[System.Serializable]
public class SortingMapEditor : Editor
{
	
	private static GUIContent
		insertContent = new GUIContent("+", "Insert node"),
		deleteContent = new GUIContent("-", "Delete node");
	
	private static GUILayoutOption
		labelWidth = GUILayout.MaxWidth (40f),
		buttonWidth = GUILayout.MaxWidth (20f);
	
	
	public override void OnInspectorGUI()
	{
		SortingMap _target = (SortingMap) target;

		EditorGUILayout.BeginVertical ("Button");
			_target.mapType = (SortingMapType) EditorGUILayout.EnumPopup ("Affect sprite's:", _target.mapType);
			_target.affectScale = EditorGUILayout.Toggle ("Affect Character scale?", _target.affectScale);
			if (_target.affectScale)
			{
				_target.affectSpeed = EditorGUILayout.Toggle ("Affect Character speed?", _target.affectSpeed);
				_target.originScale = EditorGUILayout.IntField ("Start scale (%):", _target.originScale);
			}
		EditorGUILayout.EndVertical ();

		EditorGUILayout.Space ();

		foreach (SortingArea area in _target.sortingAreas)
		{
			int i = _target.sortingAreas.IndexOf (area);

			EditorGUILayout.BeginVertical("Button");
			EditorGUILayout.BeginHorizontal ();

			area.color = EditorGUILayout.ColorField (area.color);

			EditorGUILayout.LabelField ("Position:", GUILayout.Width (50f));
			area.z = EditorGUILayout.FloatField (area.z, GUILayout.Width (80f));

			if (_target.mapType == SortingMapType.OrderInLayer)
			{
				EditorGUILayout.LabelField ("Order:", labelWidth);
				area.order = EditorGUILayout.IntField (area.order);
			}
			else if (_target.mapType == SortingMapType.SortingLayer)
			{
				EditorGUILayout.LabelField ("Layer:", labelWidth);
				area.layer = EditorGUILayout.TextField (area.layer);
			}

			if (GUILayout.Button (insertContent, EditorStyles.miniButtonLeft, buttonWidth))
			{
				Undo.RecordObject (_target, "Add area");
				if (i < _target.sortingAreas.Count - 1)
				{
					_target.sortingAreas.Insert (i+1, new SortingArea (area, _target.sortingAreas[i+1]));
				}
				else
				{
					_target.sortingAreas.Insert (i+1, new SortingArea (area));
				}
				break;
			}
			if (GUILayout.Button (deleteContent, EditorStyles.miniButtonRight, buttonWidth))
			{
				Undo.RecordObject (_target, "Delete area");
				_target.sortingAreas.Remove (area);
				break;
			}

			EditorGUILayout.EndHorizontal ();

			if (_target.affectScale)
			{
				area.scale = EditorGUILayout.IntField ("End scale (%):", area.scale);
			}

			EditorGUILayout.EndVertical();
		}

		if (GUILayout.Button ("Add area"))
		{
			Undo.RecordObject (_target, "Add area");

			if (_target.sortingAreas.Count > 0)
			{
				SortingArea lastArea = _target.sortingAreas [_target.sortingAreas.Count - 1];
				_target.sortingAreas.Add (new SortingArea (lastArea));
			}
			else
			{
				_target.sortingAreas.Add (new SortingArea (_target.transform.position.z + 1f, 1));
			}
		}

		EditorGUILayout.Space ();

		if (AdvGame.GetReferences () && AdvGame.GetReferences ().settingsManager && AdvGame.GetReferences ().settingsManager.IsTopDown ())
		{}
		else
		{
			if (GUILayout.Button ("Face active camera"))
			{
				Undo.RecordObject (_target, "Face active camera");
				Vector3 forwardVector = Camera.main.transform.forward;
				_target.transform.forward = -forwardVector;
				EditorUtility.SetDirty (_target);
			}
		}

		if (_target.affectScale && _target.sortingAreas.Count > 1)
		{
			if (GUILayout.Button ("Interpolate in-between scales"))
			{
				Undo.RecordObject (_target, "Interpolate scales");
				_target.SetInBetweenScales ();
				EditorUtility.SetDirty (_target);
			}
		}
		
		if (GUI.changed)
		{
			EditorUtility.SetDirty (_target);
		}
	}


	private void OnSceneGUI ()
	{
		SortingMap _target = (SortingMap) target;
		
		for (int i=0; i<_target.sortingAreas.Count; i++)
		{
			Vector3 newPosition = _target.GetAreaPosition (i);
			newPosition = Handles.PositionHandle (newPosition, Quaternion.identity);
			_target.sortingAreas [i].z = (newPosition - _target.transform.position).magnitude;

			Vector3 midPoint = _target.transform.position;
			if (i == 0)
			{
				midPoint += _target.transform.forward * _target.sortingAreas [i].z / 2f;
			}
			else
			{
				midPoint += _target.transform.forward * (_target.sortingAreas [i].z + _target.sortingAreas [i-1].z) / 2f;
			}

			Handles.Label (midPoint, _target.sortingAreas [i].order.ToString());
		}
		
		if (GUI.changed)
		{
			EditorUtility.SetDirty (_target);
		}
	}

	
}

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

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