-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an FPS indicator and an object tree viewer helper class.
1 parent
7e66841
commit 0af0c6e
Showing
6 changed files
with
142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// LICENSE: Public Domain | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
namespace FPS | ||
{ | ||
[KSPAddon(KSPAddon.Startup.EveryScene, false)] | ||
public class FPSIndicator : MonoBehaviour | ||
{ | ||
// Compute average FPS over this many frames | ||
private const int NUM_SAMPLES = 10; | ||
|
||
private float[] times; | ||
private int cur_sample = 0; | ||
|
||
private Rect pos; | ||
private string fps; | ||
private GUIStyle style = null; | ||
|
||
FPSIndicator() | ||
{ | ||
times = new float[NUM_SAMPLES]; | ||
|
||
float time = Time.realtimeSinceStartup; | ||
for (int i = 0; i < NUM_SAMPLES; i++) | ||
times[i] = time; | ||
} | ||
|
||
public void LateUpdate() | ||
{ | ||
float time = Time.realtimeSinceStartup; | ||
float delta = time - times[cur_sample]; | ||
times[cur_sample] = time; | ||
cur_sample = (cur_sample+1) % NUM_SAMPLES; | ||
|
||
fps = (NUM_SAMPLES / delta).ToString("F1"); | ||
} | ||
|
||
public void OnGUI() | ||
{ | ||
if (style == null) | ||
{ | ||
pos = new Rect(Screen.width - 60, 0, 50, 60); | ||
|
||
style = new GUIStyle(GUI.skin.label); | ||
style.alignment = TextAnchor.UpperRight; | ||
style.normal.textColor = new Color(0.7f, 0.7f, 0.7f, 0.5f); | ||
} | ||
|
||
GUI.Label(pos, fps, style); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// LICENSE: Public Domain | ||
|
||
using System; | ||
using UnityEngine; | ||
|
||
// A wrapper class for viewing GameObject hierarchy in the debugger. | ||
// To use, add a watch for "UnityObjectTree.Wrap(whatever)". | ||
class UnityObjectTree | ||
{ | ||
public GameObject _self; | ||
public Component[] components; | ||
|
||
public override string ToString() | ||
{ | ||
return _self.ToString(); | ||
} | ||
|
||
UnityObjectTree(GameObject obj, UnityObjectTree parent = null) { | ||
this._self = obj; | ||
this.components = obj.GetComponents<Component>(); | ||
this.z_parent = parent; | ||
} | ||
|
||
public static UnityObjectTree Wrap(GameObject obj) { | ||
return new UnityObjectTree(obj); | ||
} | ||
public static UnityObjectTree Wrap(Component obj) { | ||
return new UnityObjectTree(obj.gameObject); | ||
} | ||
|
||
private UnityObjectTree[] z_children; | ||
public UnityObjectTree[] children | ||
{ | ||
get { | ||
if (z_children == null && _self.transform) | ||
{ | ||
z_children = new UnityObjectTree[_self.transform.childCount]; | ||
for (int i = 0; i < _self.transform.childCount; i++) | ||
z_children[i] = new UnityObjectTree(_self.transform.GetChild(i).gameObject, this); | ||
} | ||
return z_children; | ||
} | ||
} | ||
|
||
private UnityObjectTree z_parent; | ||
public UnityObjectTree parent | ||
{ | ||
get { | ||
if (z_parent == null && _self.transform && _self.transform.parent) | ||
z_parent = new UnityObjectTree(_self.transform.parent.gameObject); | ||
return z_parent; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters