Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
BV improvements and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Dec 11, 2019
1 parent a0fe8bc commit 9af2363
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 174 deletions.
5 changes: 4 additions & 1 deletion Assets/Scripts/NodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class NodeManager : MonoBehaviour
{
public const uint StaticNodeCount = 5000;//500000;
public const uint StaticNodeCount = 2500;//500000;

public static NodeManager Singleton;

Expand Down Expand Up @@ -44,6 +44,7 @@ private void InitialiseStaticNodes()
var gos = new List<GameObject>();
var t = transform;
var holder = new GameObject().transform;
holder.name = "StaticNodes";
holder.SetParent(t);

//create static nodes in a line
Expand All @@ -52,6 +53,7 @@ private void InitialiseStaticNodes()
var pos = (t.position + Vector3.right * (i - StaticNodeCount / 2f))
.Scale(2, 1, 1) + Vector3.right;
var go = Instantiate(refGo, pos, Quaternion.identity, holder);
go.name = $"StaticNode_{i}";
gos.Add(go);
}

Expand All @@ -65,6 +67,7 @@ private void InitialiseMovingNode()
var pos = (t.position + Vector3.left * (StaticNodeCount / 2f))
.Scale(2, 1, 1) + Vector3.right * 5.5f + Vector3.up * 2;
var go = Instantiate(movingNodePrefab, pos, Quaternion.identity, t);
go.name = "MovingNode";
var movingNode = go.GetComponent<MovingNode>();

MovingNodes.Add(movingNode);
Expand Down
12 changes: 10 additions & 2 deletions Assets/Scripts/SimulationManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;
using UnityEngine.Serialization;

public class SimulationManager : MonoBehaviour
Expand All @@ -16,6 +17,8 @@ public class SimulationManager : MonoBehaviour
/// </summary>
public const float K = 1f;

public const float FixedTimeStep = 0.002f;

public static SimulationManager Singleton;

[SerializeField]
Expand All @@ -27,7 +30,12 @@ public class SimulationManager : MonoBehaviour
[SerializeField]
[ReadOnly]
private float timer = 0f;


private void Awake()
{
Time.fixedDeltaTime = FixedTimeStep;
}

private void Start()
{
if(Singleton)
Expand Down
31 changes: 15 additions & 16 deletions Assets/Scripts/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class UIManager : MonoBehaviour
{
private const float MaxExpectedForce = 2f;
private const float MaxExpectedPos = 4000f;
private const float MaxExpectedVelocity = 4000f;
private const float MaxExpectedForce = 1.6f;
private const float MaxExpectedPos = NodeManager.StaticNodeCount;
private const float MaxExpectedVelocity = NodeManager.StaticNodeCount * (0.02f / SimulationManager.FixedTimeStep);

public static UIManager Singleton;

Expand Down Expand Up @@ -97,18 +97,18 @@ public void UpdateMovingNodeProps(object[] args, Type[] types)

var s = new string[args.Length];

var props = new float[3];
var propVals = new float[3];

for(var i = 0; i < args.Length; i++)
{
try
{
var obj = Convert.ChangeType(args[i], types[i]);
s[i] = obj.ToString();
var propObj = Convert.ChangeType(args[i], types[i]);
s[i] = propObj.ToString();

if(i <= 2)
{
props[i] = (float)obj;
propVals[i] = (float)propObj;
}
}
catch(Exception e)
Expand All @@ -123,17 +123,16 @@ public void UpdateMovingNodeProps(object[] args, Type[] types)
valTexts[i].text = s[i];
}

for(var i = 0; i < props.Length; i++)
for(var i = 0; i < propVals.Length; i++)
{
var prop = props[i];
var index = prop >= 0 ? 1 : 0;

for(var j = 0; j < negPosImages.Length; j++)
var propVal = propVals[i];
var index = propVal >= 0 ? 1 : 0;
for(var j = 0; j < negPosImages[i].Length; j++)
{
var image = negPosImages[i][index];
var fill = Mathf.Abs(prop / maxExpectedValues[i]);
image.fillAmount = index == j ? fill : 0;
image.color = Color.Lerp(Color.green, Color.red, fill);
var image = negPosImages[i][j];
image.fillAmount = j == index ? Mathf.Abs(propVal / maxExpectedValues[i]) : 0;
image.color = Color.Lerp(Color.green, Color.red, image.fillAmount);
}
}
}
Expand Down
61 changes: 47 additions & 14 deletions Assets/_Scenes/AutoSaves/MainLevel01_00.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ RectTransform:
- {fileID: 473891498}
- {fileID: 1550523838}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -1911,7 +1911,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &886562265
GameObject:
Expand Down Expand Up @@ -2372,12 +2372,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1012868764}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1915.5178, y: -2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_Father: {fileID: 1303950727}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1050715144
PrefabInstance:
Expand Down Expand Up @@ -3388,12 +3388,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1201339000}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1915.5178, y: -2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_Father: {fileID: 1303950727}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1201339003
MonoBehaviour:
Expand Down Expand Up @@ -3873,6 +3873,39 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1303950726
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1303950727}
m_Layer: 0
m_Name: '*Managers'
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1303950727
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1303950726}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1915.5178, y: 2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1878640518}
- {fileID: 1201339002}
- {fileID: 1012868766}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1409949054
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4798,12 +4831,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1878640516}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1915.5178, y: -2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_Father: {fileID: 1303950727}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1899093192
PrefabInstance:
Expand Down
61 changes: 47 additions & 14 deletions Assets/_Scenes/AutoSaves/MainLevel01_01.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ RectTransform:
- {fileID: 473891498}
- {fileID: 1550523838}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -1911,7 +1911,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &886562265
GameObject:
Expand Down Expand Up @@ -2372,12 +2372,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1012868764}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1915.5178, y: -2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_Father: {fileID: 1303950727}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1050715144
PrefabInstance:
Expand Down Expand Up @@ -3388,12 +3388,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1201339000}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1915.5178, y: -2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_Father: {fileID: 1303950727}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1201339003
MonoBehaviour:
Expand Down Expand Up @@ -3873,6 +3873,39 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1303950726
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1303950727}
m_Layer: 0
m_Name: '*Managers'
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1303950727
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1303950726}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1915.5178, y: 2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1878640518}
- {fileID: 1201339002}
- {fileID: 1012868766}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1409949054
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4798,12 +4831,12 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1878640516}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 1915.5178, y: -2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_Father: {fileID: 1303950727}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1899093192
PrefabInstance:
Expand Down
Loading

0 comments on commit 9af2363

Please sign in to comment.