Skip to content

Commit 345a8cd

Browse files
committed
Merge pull request #3 from asarium/develop
Prepare for release 0.3
2 parents 29492cf + ae1cb6e commit 345a8cd

20 files changed

Lines changed: 454 additions & 99 deletions

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,5 @@ Backup*/
108108
UpgradeLog*.XML
109109

110110
### Plugin specific ignores ###
111-
assets/Plugins/
111+
assets/**/*.dll
112+
assets/**/*.zip

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "TacLib"]
2+
path = TacLib
3+
url = https://github.com/taraniselsu/TacLib.git

PAPIPlugin/Arrays/PAPIArray.cs

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ namespace PAPIPlugin.Arrays
1313
{
1414
public class PAPIArray : AbstractLightArray, IConfigNode
1515
{
16-
private const int PAPIPartCount = 4;
16+
public const int DefaultPartCount = 4;
1717

18-
private const float PAPILightRadius = 10.0f;
18+
public const float DefaultLightRadius = 10.0f;
1919

20-
private const double DefaultTargetGlidePath = 6;
20+
public const double DefaultTargetGlidePath = 6;
2121

2222
/// <summary>
2323
/// If the difference of the gliepath from the target is more than this the whole array will show either red or white.
2424
/// </summary>
25-
private const double DefaultBadGlidepathVariance = 1.5;
26-
27-
private static readonly Vector3 PAPILightDifference = Vector3.right * PAPILightRadius * 1.5f;
25+
public const double DefaultGlideslopeTolerance = 1.5;
2826

2927
private GameObject _papiGameObject;
3028

@@ -34,8 +32,8 @@ public class PAPIArray : AbstractLightArray, IConfigNode
3432

3533
public PAPIArray()
3634
{
37-
TargetGlidePath = DefaultTargetGlidePath;
38-
BadGlidepathVariance = DefaultBadGlidepathVariance;
35+
TargetGlideslope = DefaultTargetGlidePath;
36+
GlideslopeTolerance = DefaultGlideslopeTolerance;
3937

4038
EnabledChanged += (sender, args) =>
4139
{
@@ -51,22 +49,34 @@ public PAPIArray()
5149
};
5250
}
5351

54-
public double BadGlidepathVariance { get; set; }
52+
public double GlideslopeTolerance { get; set; }
5553

56-
public double TargetGlidePath { get; set; }
54+
public double TargetGlideslope { get; set; }
5755

5856
public double Longitude { get; set; }
5957

6058
public double Latitude { get; set; }
6159

6260
public double Heading { get; set; }
6361

62+
public double HeightAboveTerrain { get; set; }
63+
64+
public int PartCount { get; set; }
65+
66+
public float LightRadius { get; set; }
67+
68+
public float LightDistance { get; set; }
69+
6470
#region IConfigNode Members
6571

6672
public void Load(ConfigNode node)
6773
{
68-
BadGlidepathVariance = node.ConvertValue("BadGlidepath", DefaultBadGlidepathVariance);
69-
TargetGlidePath = node.ConvertValue("TargetGlidepath", DefaultTargetGlidePath);
74+
GlideslopeTolerance = node.ConvertValue("GlideslopeTolerance", DefaultGlideslopeTolerance);
75+
TargetGlideslope = node.ConvertValue("TargetGlideslope", DefaultTargetGlidePath);
76+
HeightAboveTerrain = node.ConvertValue("Height", 0);
77+
PartCount = node.ConvertValue("PartCount", DefaultPartCount);
78+
LightRadius = node.ConvertValue("LightRadius", DefaultLightRadius);
79+
LightDistance = node.ConvertValue("LightDistance", LightRadius * 0.5f);
7080

7181
try
7282
{
@@ -110,6 +120,11 @@ public override void Update()
110120

111121
var currentCamera = Camera.main;
112122

123+
if (currentCamera == null)
124+
{
125+
return;
126+
}
127+
113128
var relativePosition = _papiGameObject.transform.InverseTransformPoint(currentCamera.transform.position);
114129

115130
var normalizedPosition = relativePosition.normalized;
@@ -120,9 +135,9 @@ public override void Update()
120135

121136
var angle = 90 - Math.Acos(normalDot) * (180 / Math.PI);
122137

123-
var difference = angle - TargetGlidePath;
138+
var difference = angle - TargetGlideslope;
124139

125-
for (var i = 0; i < PAPIPartCount; i++)
140+
for (var i = 0; i < PartCount; i++)
126141
{
127142
if (directionDot <= 0)
128143
{
@@ -184,15 +199,13 @@ private void InitializePAPIParts(double lat, double lon, double heading)
184199
_papiGameObject.transform.localRotation = Quaternion.LookRotation(headingVector, surfaceNormal);
185200

186201
var maxHeight = double.MinValue;
187-
_partObjects = new GameObject[PAPIPartCount];
188-
for (var i = 0; i < PAPIPartCount; i++)
202+
_partObjects = new GameObject[PartCount];
203+
for (var i = 0; i < PartCount; i++)
189204
{
190-
var obj = new GameObject();
191-
192-
AddPAPIPart(obj);
205+
var obj = AddPAPIPart();
193206

194207
obj.transform.parent = _papiGameObject.transform;
195-
obj.transform.localPosition = (i - (PAPIPartCount / 2)) * PAPILightDifference;
208+
obj.transform.localPosition = GetLocalLighPosition(i);
196209

197210
maxHeight = Math.Max(maxHeight, parentBody.GetSurfaceHeight(Latitude, Longitude));
198211

@@ -201,10 +214,26 @@ private void InitializePAPIParts(double lat, double lon, double heading)
201214

202215
maxHeight = Math.Max(0, maxHeight);
203216
_relativeSurfacePosition =
204-
parentBody.transform.InverseTransformPoint(parentBody.GetWorldSurfacePosition(lat, lon, maxHeight + PAPILightRadius * 0.5));
217+
parentBody.transform.InverseTransformPoint(parentBody.GetWorldSurfacePosition(lat, lon, maxHeight + HeightAboveTerrain + LightRadius));
205218
_papiGameObject.transform.localPosition = _relativeSurfacePosition;
206219
}
207220

221+
/// <summary>
222+
/// Gets the local position given a zero-based index.
223+
/// </summary>
224+
/// <param name="i">The index of the light, zero-based</param>
225+
/// <returns>A local position specifying the light position</returns>
226+
private Vector3 GetLocalLighPosition(int i)
227+
{
228+
var countHalf = PartCount / 2.0;
229+
230+
var offsetMult = (float) (i - countHalf - 0.5);
231+
232+
var distance = LightRadius + LightDistance;
233+
234+
return Vector3.right * offsetMult * distance;
235+
}
236+
208237
private static Vector3d Orthonormalise(Vector3d direction, Vector3d firstVector)
209238
{
210239
// This is basically the first step of a Gram–Schmidt process
@@ -213,48 +242,46 @@ private static Vector3d Orthonormalise(Vector3d direction, Vector3d firstVector)
213242
return direction - Vector3d.Dot(firstVector, direction) * firstVector;
214243
}
215244

216-
private static void AddPAPIPart(GameObject obj)
245+
private GameObject AddPAPIPart()
217246
{
218-
var lineRenderer = obj.AddComponent<LineRenderer>();
219-
220-
lineRenderer.useWorldSpace = false;
221-
lineRenderer.transform.parent = obj.transform;
222-
lineRenderer.transform.localPosition = Vector3.zero;
223-
lineRenderer.transform.eulerAngles = Vector3.zero;
224-
225-
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
226-
lineRenderer.SetColors(Color.red, Color.red);
227-
lineRenderer.SetWidth(PAPILightRadius, PAPILightRadius);
228-
lineRenderer.SetVertexCount(2);
229-
lineRenderer.SetPosition(0, Vector3.zero);
230-
lineRenderer.SetPosition(1, Vector3.up * PAPILightRadius);
247+
var obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
248+
249+
var material = new Material(Shader.Find("Particles/Additive"));
250+
obj.renderer.sharedMaterial = material;
251+
252+
obj.transform.localScale = new Vector3(LightRadius, LightRadius, LightRadius);
253+
254+
var sphereCollider = obj.GetComponent<SphereCollider>();
255+
sphereCollider.enabled = false;
256+
257+
return obj;
231258
}
232259

233260
private void UpdatePAPIPart(int index, double difference, float alpha)
234261
{
235262
var gameObj = _partObjects[index];
236263

237-
var lineRenderer = gameObj.GetComponent<LineRenderer>();
238-
239264
var color = GetArrayPartColor(index, difference);
240265
color.a = alpha;
241-
lineRenderer.SetColors(color, color);
266+
267+
gameObj.renderer.material.SetColor("_TintColor", color);
242268
}
243269

244270
private Color GetArrayPartColor(int index, double difference)
245271
{
246-
if (difference < -BadGlidepathVariance)
272+
if (difference < -GlideslopeTolerance)
247273
{
248274
return Color.red;
249275
}
250-
if (difference > BadGlidepathVariance)
276+
if (difference > GlideslopeTolerance)
251277
{
252278
return Color.white;
253279
}
254280

255281
// This should map temp into [-1, 1]
256-
double temp = index - (PAPIPartCount / 2);
257-
temp = temp / (PAPIPartCount / 2);
282+
double temp = index - (PartCount / 2);
283+
// ReSharper disable once PossibleLossOfFraction
284+
temp = temp / (PartCount / 2);
258285

259286
return temp > difference ? Color.red : Color.white;
260287
}

PAPIPlugin/Impl/DefaultLightArrayManager.cs

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
#region Usings
22

33
using System;
4-
using System.Collections.Generic;
54
using System.Diagnostics;
65
using System.Linq;
76
using PAPIPlugin.Interfaces;
87
using PAPIPlugin.Internal;
8+
using PAPIPlugin.UI;
9+
using Tac;
10+
using UnityEngine;
911

1012
#endregion
1113

1214
namespace PAPIPlugin.Impl
1315
{
1416
public class DefaultLightArrayManager : ILightArrayManager
1517
{
18+
private readonly Icon<DefaultLightArrayManager> _groupWindowIcon;
19+
20+
private GroupWindow<ILightArrayConfig> _groupWindow;
21+
1622
private ILightArrayConfig _lightConfig;
1723

24+
public DefaultLightArrayManager()
25+
{
26+
_groupWindowIcon = new Icon<DefaultLightArrayManager>(new Rect(Screen.width * 0.8f, 0.0f, 80.0f, 20.0f), "icon.png", "Light groups",
27+
"Opens the light group overview", OnIconClickHandler);
28+
_groupWindowIcon.SetVisible(true);
29+
}
30+
1831
#region ILightArrayManager Members
1932

2033
public event EventHandler ParsingFinished;
@@ -25,23 +38,17 @@ public ILightArrayConfig LightConfig
2538
set
2639
{
2740
if (Equals(_lightConfig, value))
41+
{
2842
return;
43+
}
2944

3045
_lightConfig = value;
3146

3247
InitializeConfig(_lightConfig);
3348
}
3449
}
3550

36-
private void InitializeConfig(ILightArrayConfig lightConfig)
37-
{
38-
foreach (var lightArray in lightConfig.LightArrayGroups.SelectMany(group => group.LightArrays))
39-
{
40-
lightArray.InitializeDisplay(this);
41-
}
42-
}
43-
44-
public void LoadConfig()
51+
public ILightArrayConfig LoadConfig()
4552
{
4653
Util.LogInfo("Starting to parse light definitions...");
4754

@@ -56,6 +63,8 @@ public void LoadConfig()
5663
LightConfig.LightArrayGroups.Count(), LightConfig.LightArrayGroups.Sum(group => group.LightArrays.Count()), stopwatch.Elapsed));
5764

5865
OnParsingFinished();
66+
67+
return LightConfig;
5968
}
6069

6170
public void Update()
@@ -73,6 +82,27 @@ public void Dispose()
7382

7483
#endregion
7584

85+
private void OnIconClickHandler()
86+
{
87+
if (_groupWindow == null)
88+
{
89+
_groupWindow = new GroupWindow<ILightArrayConfig>(LightConfig);
90+
_groupWindow.SetVisible(true);
91+
}
92+
else
93+
{
94+
_groupWindow.ToggleVisible();
95+
}
96+
}
97+
98+
private void InitializeConfig(ILightArrayConfig lightConfig)
99+
{
100+
foreach (var lightArray in lightConfig.LightArrayGroups.SelectMany(group => group.LightArrays))
101+
{
102+
lightArray.InitializeDisplay(this);
103+
}
104+
}
105+
76106
protected virtual void OnParsingFinished()
77107
{
78108
var handler = ParsingFinished;
@@ -90,6 +120,13 @@ protected virtual void OnParsingFinished()
90120
protected virtual void Dispose(bool disposing)
91121
{
92122
LightConfig.Destroy();
123+
124+
_groupWindowIcon.SetVisible(false);
125+
126+
if (_groupWindow != null)
127+
{
128+
_groupWindow.SetVisible(false);
129+
}
93130
}
94131
}
95132
}

0 commit comments

Comments
 (0)