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
168
169
170
171
172
173
174
175
176
177
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"ActionCharRender.cs"
 * 
 *	This Action overrides Character
 *	render settings.
 * 
 */

using UnityEngine;
using System.Collections;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

[System.Serializable]
public class ActionCharRender : Action
{

	public int constantID = 0;
	public bool isPlayer;
	public Char _char;

	public RenderLock renderLock_sorting;
	public SortingMapType mapType;
	public int sortingOrder;
	public string sortingLayer;

	public RenderLock renderLock_scale;
	public int scale;

	public RenderLock renderLock_direction;
	public CharDirection direction;
	
	
	public ActionCharRender ()
	{
		this.isDisplayed = true;
		title = "Character: Change rendering";
	}
	
	
	override public float Run ()
	{
		if (isPlayer)
		{
			_char = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
		}
		else if (isAssetFile && constantID != 0)
		{
			// Attempt to find the correct scene object
			ConstantID idObject = Serializer.returnComponent <ConstantID> (constantID);
			if (idObject != null && idObject.GetComponent <Char>())
			{
				_char = idObject.GetComponent <Char>();
			}
		}

		if (_char)
		{
			if (renderLock_sorting == RenderLock.Set)
			{
				if (mapType == SortingMapType.OrderInLayer)
				{
					_char.SetSorting (sortingOrder);
				}
				else if (mapType == SortingMapType.SortingLayer)
				{
					_char.SetSorting (sortingLayer);
				}
			}
			else if (renderLock_sorting == RenderLock.Release)
			{
				_char.ReleaseSorting ();
			}

			if (_char.animEngine == null)
			{
				_char.ResetAnimationEngine ();
			}
			
			if (_char.animEngine != null)
			{
				_char.animEngine.ActionCharRenderRun (this);
			}
		}

		return 0f;
	}
	
	
	#if UNITY_EDITOR
	
	override public void ShowGUI ()
	{
		isPlayer = EditorGUILayout.Toggle ("Is Player?", isPlayer);
		if (isPlayer)
		{
			if (Application.isPlaying)
			{
				_char = GameObject.FindWithTag (Tags.player).GetComponent <AC.Char>();
			}
			else
			{
				_char = AdvGame.GetReferences ().settingsManager.GetDefaultPlayer ();
			}
		}
		else
		{
			_char = (Char) EditorGUILayout.ObjectField ("Character:", _char, typeof (Char), true);
			
			if (_char && _char.GetComponent <ConstantID>())
			{
				constantID = _char.GetComponent <ConstantID>().constantID;
			}
		}

		if (_char)
		{
			EditorGUILayout.Space ();
			renderLock_sorting = (RenderLock) EditorGUILayout.EnumPopup ("Sorting:", renderLock_sorting);
			if (renderLock_sorting == RenderLock.Set)
			{
				mapType = (SortingMapType) EditorGUILayout.EnumPopup ("Sorting type:", mapType);
				if (mapType == SortingMapType.OrderInLayer)
				{
					sortingOrder = EditorGUILayout.IntField ("New order:", sortingOrder);
				}
				else if (mapType == SortingMapType.SortingLayer)
				{
					sortingLayer = EditorGUILayout.TextField ("New layer:", sortingLayer);
				}
			}

			if (_char.animEngine == null)
			{
				_char.ResetAnimationEngine ();
			}
			if (_char.animEngine)
			{
				_char.animEngine.ActionCharRenderGUI (this);
			}
		}
		else
		{
			EditorGUILayout.HelpBox ("This Action requires a Character before more options will show.", MessageType.Info);
		}

		EditorGUILayout.Space ();
		AfterRunningOption ();
	}
	
	
	public override string SetLabel ()
	{
		string labelAdd = "";
		
		if (isPlayer)
		{
			labelAdd = " (Player)";
		}
		else if (_char)
		{
			labelAdd = " (" + _char.name + ")";
		}

		return labelAdd;
	}
	
	#endif
	
}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Actions/ActionCharRender.cs

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