Jump to content

Throttle Gauge - 2nd Needle


Recommended Posts

Hey Guys,

I'm trying to get a second Throttle Needle to show up in the Throttle Indicator next to the Navball.

I'm instantiating a new Gauge by:

[FONT=Consolas] [CODE][COLOR=#009695]public[/COLOR][COLOR=#333333] Gauge 2ndGauge [/COLOR][COLOR=#333333]=[/COLOR][COLOR=#009695] new[/COLOR][COLOR=#333333] Gauge [/COLOR][COLOR=#333333]()[/COLOR][COLOR=#333333]; [/COLOR][/CODE][/FONT][CODE][FONT=Consolas][COLOR=#333333]2ndGauge [/COLOR][COLOR=#333333]=[/COLOR][COLOR=#333333] Instantiate [/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]FlightUIController[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]fetch[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]thr[/COLOR][COLOR=#333333])[/COLOR][COLOR=#009695]as[/COLOR][COLOR=#333333] Gauge[/COLOR][COLOR=#333333];[/COLOR][/FONT][/CODE]

Then copying select values from [COLOR=#333333]'[/COLOR][FONT=Consolas][COLOR=#333333]FlightUIController[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]fetch[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]thr' [/COLOR][/FONT]gauge (Not sure this is even necessary since I am instantiating it.

I know the gauges are independent as I get different instanceIDs from each and hence I am able to manipulate the gauge independently by enabling/disabling the stock gauge and the 2nd gauge opposite one another. How can I get a 2nd needle to actually show up? Am I missing some GUI stuff? I also can't seem to find the texture for the stock needle either.


Thanks in advance! Edited by wrcsubers
Link to comment
Share on other sites

Does anything below help?

[LOG 14:45:01.511] gauge_thr:
[LOG 14:45:01.511] - Transform:
[LOG 14:45:01.512] .position = (1.0, 0.1, -0.8)
[LOG 14:45:01.513] .localPosition = (0.0, 0.1, -0.8)
[LOG 14:45:01.513] .eulerAngles = (0.0, 0.0, 339.2)
[LOG 14:45:01.513] .localEulerAngles = (0.0, 0.0, 339.2)
[LOG 14:45:01.514] .right = (0.9, -0.4, 0.0)
[LOG 14:45:01.514] .up = (0.4, 0.9, 0.0)
[LOG 14:45:01.515] .forward = (0.0, 0.0, 1.0)
[LOG 14:45:01.515] .rotation = (0.0, 0.0, -0.2, 1.0)
[LOG 14:45:01.516] .localRotation = (0.0, 0.0, -0.2, 1.0)
[LOG 14:45:01.516] .localScale = (0.5, 0.5, 0.5)
[LOG 14:45:01.517] .parent = MapCollapse_navball (UnityEngine.Transform)
[LOG 14:45:01.517] .worldToLocalMatrix = 1.88782 -0.71683 0.00000 -1.88719
0.71683 1.88782 0.00000 -0.95552
0.00000 0.00000 2.01933 1.67109
0.00000 0.00000 0.00000 1.00000

[LOG 14:45:01.518] .localToWorldMatrix = 0.46296 0.17579 0.00000 1.04167
-0.17579 0.46296 0.00000 0.11062
0.00000 0.00000 0.49521 -0.82754
0.00000 0.00000 0.00000 1.00000

[LOG 14:45:01.519] .root = ScreenSafeUI (UnityEngine.Transform)
[LOG 14:45:01.520] .childCount = 1
[LOG 14:45:01.520] .lossyScale = (0.5, 0.5, 0.5)
[LOG 14:45:01.521] .hasChanged = True
[LOG 14:45:01.521] .transform = gauge_thr (UnityEngine.Transform)
[LOG 14:45:01.521] .rigidbody =
[LOG 14:45:01.522] .rigidbody2D =
[LOG 14:45:01.522] .camera =
[LOG 14:45:01.523] .light =
[LOG 14:45:01.523] .animation =
[LOG 14:45:01.523] .constantForce =
[LOG 14:45:01.524] .renderer =
[LOG 14:45:01.524] .audio = gauge_thr (UnityEngine.AudioSource)
[LOG 14:45:01.525] .guiText =
[LOG 14:45:01.525] .networkView =
[LOG 14:45:01.525] .guiElement =
[LOG 14:45:01.526] .guiTexture =
[LOG 14:45:01.526] .collider =
[LOG 14:45:01.527] .collider2D =
[LOG 14:45:01.527] .hingeJoint =
[LOG 14:45:01.528] .particleEmitter =
[LOG 14:45:01.528] .particleSystem =
[LOG 14:45:01.528] .gameObject = gauge_thr (UnityEngine.GameObject)
[LOG 14:45:01.529] .active = True
[LOG 14:45:01.529] .tag = Untagged
[LOG 14:45:01.530] .name = gauge_thr
[LOG 14:45:01.530] .hideFlags = None
[LOG 14:45:01.531] - Gauge:
[LOG 14:45:01.531] .minRot = 50
[LOG 14:45:01.531] .maxRot = -20
[LOG 14:45:01.532] .maxValue = 1
[LOG 14:45:01.532] .minValue = 0
[LOG 14:45:01.533] .responsiveness = 6
[LOG 14:45:01.533] .logarithmic = 0
[LOG 14:45:01.533] .rotationAxis = (0.0, 0.0, 1.0)
[LOG 14:45:01.534] .ledRanges = GaugeLEDRange[]
[LOG 14:45:01.534] .pointer = gauge_thr (UnityEngine.Transform)
[LOG 14:45:01.534] .led = overthrottleLED (LED)
[LOG 14:45:01.535] .rawValue = 0
[LOG 14:45:01.535] .Value = 0
[LOG 14:45:01.536] .useGUILayout = True
[LOG 14:45:01.536] .enabled = True
[LOG 14:45:01.537] .isActiveAndEnabled = True
[LOG 14:45:01.537] .transform = gauge_thr (UnityEngine.Transform)
[LOG 14:45:01.537] .rigidbody =
[LOG 14:45:01.538] .rigidbody2D =
[LOG 14:45:01.538] .camera =
[LOG 14:45:01.539] .light =
[LOG 14:45:01.539] .animation =
[LOG 14:45:01.539] .constantForce =
[LOG 14:45:01.540] .renderer =
[LOG 14:45:01.540] .audio = gauge_thr (UnityEngine.AudioSource)
[LOG 14:45:01.540] .guiText =
[LOG 14:45:01.541] .networkView =
[LOG 14:45:01.541] .guiElement =
[LOG 14:45:01.542] .guiTexture =
[LOG 14:45:01.542] .collider =
[LOG 14:45:01.542] .collider2D =
[LOG 14:45:01.543] .hingeJoint =
[LOG 14:45:01.543] .particleEmitter =
[LOG 14:45:01.543] .particleSystem =
[LOG 14:45:01.544] .gameObject = gauge_thr (UnityEngine.GameObject)
[LOG 14:45:01.544] .active = True
[LOG 14:45:01.545] .tag = Untagged
[LOG 14:45:01.545] .name = gauge_thr
[LOG 14:45:01.545] .hideFlags = None
[LOG 14:45:01.546] - AudioSource:
[LOG 14:45:01.546] .volume = 1
[LOG 14:45:01.547] .pitch = 1
[LOG 14:45:01.547] .time = 0
[LOG 14:45:01.548] .timeSamples = 0
[LOG 14:45:01.548] .clip =
[LOG 14:45:01.548] .isPlaying = False
[LOG 14:45:01.549] .loop = False
[LOG 14:45:01.549] .ignoreListenerVolume = False
[LOG 14:45:01.550] .playOnAwake = True
[LOG 14:45:01.550] .ignoreListenerPause = False
[LOG 14:45:01.551] .velocityUpdateMode = Auto
[LOG 14:45:01.551] .panLevel = 1
[LOG 14:45:01.552] .bypassEffects = False
[LOG 14:45:01.552] .bypassListenerEffects = False
[LOG 14:45:01.552] .bypassReverbZones = False
[LOG 14:45:01.553] .dopplerLevel = 1
[LOG 14:45:01.553] .spread = 0
[LOG 14:45:01.554] .priority = 128
[LOG 14:45:01.554] .mute = False
[LOG 14:45:01.555] .minDistance = 1
[LOG 14:45:01.555] .maxDistance = 500
[LOG 14:45:01.555] .pan = 0
[LOG 14:45:01.556] .rolloffMode = Logarithmic
[ERR 14:45:01.556] minVolume is not supported anymore. Use min-, maxDistance and rolloffMode instead.

[LOG 14:45:01.557] .minVolume = 0
[ERR 14:45:01.557] maxVolume is not supported anymore. Use min-, maxDistance and rolloffMode instead.

[LOG 14:45:01.557] .maxVolume = 0
[ERR 14:45:01.558] rolloffFactor is not supported anymore. Use min-, maxDistance and rolloffMode instead.

[LOG 14:45:01.558] .rolloffFactor = 0
[LOG 14:45:01.559] .enabled = True
[LOG 14:45:01.559] .isActiveAndEnabled = True
[LOG 14:45:01.559] .transform = gauge_thr (UnityEngine.Transform)
[LOG 14:45:01.560] .rigidbody =
[LOG 14:45:01.560] .rigidbody2D =
[LOG 14:45:01.561] .camera =
[LOG 14:45:01.561] .light =
[LOG 14:45:01.561] .animation =
[LOG 14:45:01.562] .constantForce =
[LOG 14:45:01.562] .renderer =
[LOG 14:45:01.562] .audio = gauge_thr (UnityEngine.AudioSource)
[LOG 14:45:01.563] .guiText =
[LOG 14:45:01.563] .networkView =
[LOG 14:45:01.564] .guiElement =
[LOG 14:45:01.564] .guiTexture =
[LOG 14:45:01.564] .collider =
[LOG 14:45:01.565] .collider2D =
[LOG 14:45:01.565] .hingeJoint =
[LOG 14:45:01.565] .particleEmitter =
[LOG 14:45:01.566] .particleSystem =
[LOG 14:45:01.566] .gameObject = gauge_thr (UnityEngine.GameObject)
[LOG 14:45:01.567] .active = True
[LOG 14:45:01.567] .tag = Untagged
[LOG 14:45:01.567] .name = gauge_thr
[LOG 14:45:01.568] .hideFlags = None
[LOG 14:45:01.568] ->
[LOG 14:45:01.568] pointer:
[LOG 14:45:01.569] - Transform:
[LOG 14:45:01.569] .position = (0.9, 0.2, -0.8)
[LOG 14:45:01.570] .localPosition = (-0.2, 0.0, 0.0)
[LOG 14:45:01.570] .eulerAngles = (71.2, 270.0, 90.0)
[LOG 14:45:01.570] .localEulerAngles = (90.0, 180.0, 0.0)
[LOG 14:45:01.571] .right = (-0.9, 0.3, 0.0)
[LOG 14:45:01.571] .up = (0.0, 0.0, -1.0)
[LOG 14:45:01.572] .forward = (-0.3, -0.9, 0.0)
[LOG 14:45:01.572] .rotation = (0.1, 0.7, -0.7, -0.1)
[LOG 14:45:01.572] .localRotation = (0.0, 0.7, -0.7, 0.0)
[LOG 14:45:01.573] .localScale = (0.0, 0.2, 0.0)
[LOG 14:45:01.573] .parent = gauge_thr (UnityEngine.Transform)
[LOG 14:45:01.574] .worldToLocalMatrix = -45.18611 15.37603 0.00000 39.65510
0.00000 0.00000 -12.65023 -10.46862
-23.43932 -68.88200 -0.00001 32.33171
0.00000 0.00000 0.00000 1.00000

[LOG 14:45:01.575] .localToWorldMatrix = -0.01983 0.00000 -0.00443 0.92967
0.00675 0.00000 -0.01301 0.15303
0.00000 -0.07905 0.00000 -0.82754
0.00000 0.00000 0.00000 1.00000

[LOG 14:45:01.575] .root = ScreenSafeUI (UnityEngine.Transform)
[LOG 14:45:01.576] .childCount = 0
[LOG 14:45:01.576] .lossyScale = (0.0, 0.1, 0.0)
[LOG 14:45:01.577] .hasChanged = True
[LOG 14:45:01.577] .transform = pointer (UnityEngine.Transform)
[LOG 14:45:01.577] .rigidbody =
[LOG 14:45:01.578] .rigidbody2D =
[LOG 14:45:01.578] .camera =
[LOG 14:45:01.578] .light =
[LOG 14:45:01.579] .animation =
[LOG 14:45:01.579] .constantForce =
[LOG 14:45:01.579] .renderer = pointer (UnityEngine.MeshRenderer)
[LOG 14:45:01.580] .audio =
[LOG 14:45:01.580] .guiText =
[LOG 14:45:01.581] .networkView =
[LOG 14:45:01.581] .guiElement =
[LOG 14:45:01.581] .guiTexture =
[LOG 14:45:01.582] .collider =
[LOG 14:45:01.582] .collider2D =
[LOG 14:45:01.582] .hingeJoint =
[LOG 14:45:01.583] .particleEmitter =
[LOG 14:45:01.583] .particleSystem =
[LOG 14:45:01.584] .gameObject = pointer (UnityEngine.GameObject)
[LOG 14:45:01.584] .active = True
[LOG 14:45:01.584] .tag = Untagged
[LOG 14:45:01.585] .name = pointer
[LOG 14:45:01.585] .hideFlags = None
[LOG 14:45:01.585] - MeshFilter:
[LOG 14:45:01.586] .mesh = Plane01 Instance (UnityEngine.Mesh)
[LOG 14:45:01.586] .sharedMesh = Plane01 Instance (UnityEngine.Mesh)
[LOG 14:45:01.587] .transform = pointer (UnityEngine.Transform)
[LOG 14:45:01.587] .rigidbody =
[LOG 14:45:01.588] .rigidbody2D =
[LOG 14:45:01.588] .camera =
[LOG 14:45:01.588] .light =
[LOG 14:45:01.589] .animation =
[LOG 14:45:01.589] .constantForce =
[LOG 14:45:01.589] .renderer = pointer (UnityEngine.MeshRenderer)
[LOG 14:45:01.590] .audio =
[LOG 14:45:01.590] .guiText =
[LOG 14:45:01.591] .networkView =
[LOG 14:45:01.591] .guiElement =
[LOG 14:45:01.591] .guiTexture =
[LOG 14:45:01.592] .collider =
[LOG 14:45:01.592] .collider2D =
[LOG 14:45:01.592] .hingeJoint =
[LOG 14:45:01.593] .particleEmitter =
[LOG 14:45:01.593] .particleSystem =
[LOG 14:45:01.594] .gameObject = pointer (UnityEngine.GameObject)
[LOG 14:45:01.594] .active = True
[LOG 14:45:01.594] .tag = Untagged
[LOG 14:45:01.595] .name = pointer
[LOG 14:45:01.595] .hideFlags = None
[LOG 14:45:01.595] - MeshRenderer:
[LOG 14:45:01.596] .isPartOfStaticBatch = False
[LOG 14:45:01.596] .worldToLocalMatrix = -45.18611 15.37603 0.00000 39.65510
0.00000 0.00000 -12.65023 -10.46862
-23.43932 -68.88200 -0.00001 32.33171
0.00000 0.00000 0.00000 1.00000

[LOG 14:45:01.597] .localToWorldMatrix = -0.01983 0.00000 -0.00443 0.92967
0.00675 0.00000 -0.01301 0.15303
0.00000 -0.07905 0.00000 -0.82754
0.00000 0.00000 0.00000 1.00000

[LOG 14:45:01.598] .enabled = True
[LOG 14:45:01.599] .castShadows = False
[LOG 14:45:01.599] .receiveShadows = False
[LOG 14:45:01.600] .material = gauge_needle_left (Instance) (UnityEngine.Material)
[LOG 14:45:01.600] .sharedMaterial = gauge_needle_left (Instance) (UnityEngine.Material)
[LOG 14:45:01.601] .sharedMaterials = UnityEngine.Material[]
[LOG 14:45:01.601] .materials = UnityEngine.Material[]
[LOG 14:45:01.602] .bounds = Center: (0.9, 0.2, -0.8), Extents: (0.0, 0.0, 0.0)
[LOG 14:45:01.602] .lightmapIndex = -1
[LOG 14:45:01.603] .lightmapTilingOffset = (1.0, 1.0, 0.0, 0.0)
[LOG 14:45:01.603] .isVisible = False
[LOG 14:45:01.604] .useLightProbes = False
[LOG 14:45:01.604] .lightProbeAnchor =
[LOG 14:45:01.605] .sortingLayerName =
[LOG 14:45:01.605] .sortingLayerID = 0
[LOG 14:45:01.605] .sortingOrder = 0
[LOG 14:45:01.606] .transform = pointer (UnityEngine.Transform)
[LOG 14:45:01.606] .rigidbody =
[LOG 14:45:01.607] .rigidbody2D =
[LOG 14:45:01.607] .camera =
[LOG 14:45:01.607] .light =
[LOG 14:45:01.608] .animation =
[LOG 14:45:01.608] .constantForce =
[LOG 14:45:01.608] .renderer = pointer (UnityEngine.MeshRenderer)
[LOG 14:45:01.609] .audio =
[LOG 14:45:01.609] .guiText =
[LOG 14:45:01.610] .networkView =
[LOG 14:45:01.610] .guiElement =
[LOG 14:45:01.611] .guiTexture =
[LOG 14:45:01.611] .collider =
[LOG 14:45:01.611] .collider2D =
[LOG 14:45:01.612] .hingeJoint =
[LOG 14:45:01.612] .particleEmitter =
[LOG 14:45:01.612] .particleSystem =
[LOG 14:45:01.613] .gameObject = pointer (UnityEngine.GameObject)
[LOG 14:45:01.613] .active = True
[LOG 14:45:01.614] .tag = Untagged
[LOG 14:45:01.614] .name = pointer
[LOG 14:45:01.614] .hideFlags = None Edited by wrcsubers
Link to comment
Share on other sites

[quote name='wrcsubers']I'm trying to get a second Throttle Needle to show up in the Throttle Indicator next to the Navball.

I'm instantiating a new Gauge by:
[snip]
I know the gauges are independent as I get different instanceIDs from each and hence I am able to manipulate the gauge independently by enabling/disabling the stock gauge and the 2nd gauge opposite one another. How can I get a 2nd needle to actually show up? Am I missing some GUI stuff?[/QUOTE]
You only cloned the Gauge component and not any of its visual bits (the pointer itself is a child containing a MeshFilter and MeshRenderer). Just make sure you get it all
[code][KSPAddon(KSPAddon.Startup.Flight, false)]
public class SecondThrottleNeedle : MonoBehaviour
{
private Gauge _gauge;

private void Start()
{
var source = FlightUIController.fetch.thr.gameObject;
var clone = Object.Instantiate(source, source.transform.position, source.transform.rotation) as GameObject;

_gauge = clone.GetComponent<Gauge>();
_gauge.setValue(0.5f);
_gauge.transform.GetChild(0).renderer.material.color = Color.blue;

clone.transform.parent = source.transform.parent;

StartCoroutine(MoveGauge());
}


private void OnDestroy()
{
_gauge.Do(g => Destroy(g.gameObject));
}


private IEnumerator MoveGauge()
{
_gauge.minValue = 0f;
_gauge.maxValue = 100f;

while (true)
{
yield return new WaitForSeconds(1f);

var newValue = (_gauge.maxValue - _gauge.minValue) * UnityEngine.Random.value + _gauge.minValue;
_gauge.setValue(newValue);
}
}
}[/code]
Link to comment
Share on other sites

[quote name='xEvilReeperx']You only cloned the Gauge component and not any of its visual bits (the pointer itself is a child containing a MeshFilter and MeshRenderer). Just make sure you get it all
[code][KSPAddon(KSPAddon.Startup.Flight, false)]
public class SecondThrottleNeedle : MonoBehaviour
{
private Gauge _gauge;

private void Start()
{
var source = FlightUIController.fetch.thr.gameObject;
var clone = Object.Instantiate(source, source.transform.position, source.transform.rotation) as GameObject;

_gauge = clone.GetComponent<Gauge>();
_gauge.setValue(0.5f);
_gauge.transform.GetChild(0).renderer.material.color = Color.blue;

clone.transform.parent = source.transform.parent;

StartCoroutine(MoveGauge());
}


private void OnDestroy()
{
_gauge.Do(g => Destroy(g.gameObject));
}


private IEnumerator MoveGauge()
{
_gauge.minValue = 0f;
_gauge.maxValue = 100f;

while (true)
{
yield return new WaitForSeconds(1f);

var newValue = (_gauge.maxValue - _gauge.minValue) * UnityEngine.Random.value + _gauge.minValue;
_gauge.setValue(newValue);
}
}
}[/code][/QUOTE]

You're not so evil now are ya?! Thanks a bunch that did the trick. How do you know if an object has children? I guess I assumed that EVERYTHING got cloned, but I guess not...

Thanks Again, I'll make sure to mention you when I publish =)
Link to comment
Share on other sites

Actually I just double-checked and confused Destroy with Instantiate. Destroy on a Component will destroy only the component, while you're right that Instantiating will clone everything. Did you set the parent of the new clone to the same as the thrust pointer and did you give it a different value? It might have been working the whole time :blush:
Link to comment
Share on other sites

[quote name='xEvilReeperx']Actually I just double-checked and confused Destroy with Instantiate. Destroy on a Component will destroy only the component, while you're right that Instantiating will clone everything. Did you set the parent of the new clone to the same as the thrust pointer and did you give it a different value? It might have been working the whole time :blush:[/QUOTE]

That I'm not sure of... Here is what I had:

[LIST]
[*]A single Needle
[LIST]
[*]2nd Gauge was set to 0
[*]Throttle was variable
[*]When both were 'enabled = true' I got the average of the two, ie Full Throttle meant the needle was at 50%
[*]When one or the other was disabled it showed just the value of each individual value.
[/LIST]
[/LIST]

I think you were right in that I was not cloning the visual parts, ie the pointer.
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...