Skip to content
Snippets Groups Projects
Commit d9f8b401 authored by Raymond Chia's avatar Raymond Chia
Browse files

blocks running.

parent 30ab581b
Branches
No related merge requests found
......@@ -484,12 +484,12 @@ MonoBehaviour:
- m_Target: {fileID: 7667070743931665524}
m_TargetAssemblyTypeName: BlockObjectClass, Assembly-CSharp
m_MethodName: SetInhalePeriod
m_Mode: 1
m_Mode: 4
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_FloatArgument: -1
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
......@@ -724,12 +724,12 @@ MonoBehaviour:
- m_Target: {fileID: 7667070743931665524}
m_TargetAssemblyTypeName: BlockObjectClass, Assembly-CSharp
m_MethodName: SetRuntime
m_Mode: 1
m_Mode: 4
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_FloatArgument: -1
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
......@@ -1589,12 +1589,12 @@ MonoBehaviour:
- m_Target: {fileID: 7667070743931665524}
m_TargetAssemblyTypeName: BlockObjectClass, Assembly-CSharp
m_MethodName: SetExhalePeriod
m_Mode: 1
m_Mode: 4
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_FloatArgument: -1
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
......
......@@ -888,6 +888,108 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &533764376
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 533764380}
- component: {fileID: 533764379}
- component: {fileID: 533764378}
- component: {fileID: 533764377}
m_Layer: 5
m_Name: CountdownCanvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &533764377
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 533764376}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &533764378
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 533764376}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
--- !u!223 &533764379
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 533764376}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 0
m_UpdateRectTransformForStandalone: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &533764380
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 533764376}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1225748239}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1 &559601515
GameObject:
m_ObjectHideFlags: 0
......@@ -1936,6 +2038,99 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1166148096}
m_CullTransparentMesh: 1
--- !u!1 &1225748237
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1225748239}
- component: {fileID: 1225748238}
- component: {fileID: 1225748241}
- component: {fileID: 1225748240}
m_Layer: 5
m_Name: CountdownObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1225748238
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1225748237}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fbdad22d46cbda74491fc7802d595cea, type: 3}
m_Name:
m_EditorClassIdentifier:
protocolHandlerObject: {fileID: 1600482173}
--- !u!224 &1225748239
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1225748237}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 533764380}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 250, y: 250}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1225748240
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1225748237}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text:
--- !u!222 &1225748241
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1225748237}
m_CullTransparentMesh: 1
--- !u!1 &1253916199
GameObject:
m_ObjectHideFlags: 0
......@@ -2571,9 +2766,21 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 1993962873}
m_TargetAssemblyTypeName: SceneLoaderClass, Assembly-CSharp
m_MethodName: LoadRunScene
- m_Target: {fileID: 473153906}
m_TargetAssemblyTypeName: UnityEngine.Behaviour, UnityEngine
m_MethodName: set_enabled
m_Mode: 6
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 1953068991}
m_TargetAssemblyTypeName: AnimateCircle, Assembly-CSharp
m_MethodName: MoveToCentre
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
......@@ -2583,6 +2790,18 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 1225748238}
m_TargetAssemblyTypeName: UnityEngine.Behaviour, UnityEngine
m_MethodName: set_enabled
m_Mode: 6
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 1
m_CallState: 2
--- !u!114 &1388192736
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -3265,6 +3484,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
numCyclesInput: {fileID: 1992066360}
blockControl: {fileID: 1785070519}
centreCircle: {fileID: 1953068988}
canvas: {fileID: 473153906}
countdownObject: {fileID: 1225748237}
runProtocol: 0
--- !u!4 &1600482175
Transform:
m_ObjectHideFlags: 0
......@@ -4234,7 +4457,7 @@ MonoBehaviour:
m_OnEndEdit:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
- m_Target: {fileID: 1600482174}
m_TargetAssemblyTypeName: ProtocolHandler, Assembly-CSharp
m_MethodName: UpdateNumCycles
m_Mode: 1
......@@ -4320,51 +4543,6 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1992066360}
m_CullTransparentMesh: 1
--- !u!1 &1993962872
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1993962874}
- component: {fileID: 1993962873}
m_Layer: 0
m_Name: SceneLoader
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1993962873
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1993962872}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5ad3403954b930245bcb454625932882, type: 3}
m_Name:
m_EditorClassIdentifier:
gameObjectToMove: {fileID: 1600482173}
--- !u!4 &1993962874
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1993962872}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.3704251, y: -0.23480365, z: 0.03030179}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2036898555
GameObject:
m_ObjectHideFlags: 0
......@@ -4597,4 +4775,4 @@ SceneRoots:
- {fileID: 473153907}
- {fileID: 2036898558}
- {fileID: 1600482175}
- {fileID: 1993962874}
- {fileID: 533764380}
......@@ -21,12 +21,18 @@ public class AnimateCircle : MonoBehaviour
private Vector3 inhaleVelocity = new Vector3(0.0f, 0.0f, 0.0f);
private Vector3 exhaleVelocity = new Vector3(0.0f, 0.0f, 0.0f);
private Transform parentTransform;
private Vector3 parentCentrePosition = new Vector3(0f, 0f, 0f);
private Vector3 parentOffsetPosition;
// Start is called before the first frame update
void Start()
{
is_inhale = true;
originalScale = this.transform.localScale;
scaleDiff = finalScale - originalScale;
parentTransform = this.GetComponentInParent<Transform>().parent.transform;
parentOffsetPosition = parentTransform.position;
StateReset();
this.enabled = false;
......@@ -54,6 +60,16 @@ public class AnimateCircle : MonoBehaviour
StateReset();
}
public void MoveToCentre()
{
parentTransform.position = parentCentrePosition;
}
public void MoveToOffset()
{
parentTransform.position = parentOffsetPosition;
}
private void OnDisable()
{
StateReset();
......
......@@ -10,9 +10,9 @@ public class BlockObjectClass : MonoBehaviour
public float ExhalePeriod { get; private set; }
public float MaxRuntime { get; private set; }
TMP_InputField inhalePeriodInput;
TMP_InputField exhalePeriodInput;
TMP_InputField runtimeInput;
TMP_InputField inhalePeriodTextInput;
TMP_InputField exhalePeriodTextInput;
TMP_InputField runtimeTextInput;
void Awake()
{
......@@ -26,17 +26,17 @@ public class BlockObjectClass : MonoBehaviour
name = go.name;
if (name == "Inhale")
{
inhalePeriodInput = go.GetComponent<TMP_InputField>();
inhalePeriodTextInput = go.GetComponent<TMP_InputField>();
SetInhalePeriod();
}
else if (name == "Exhale")
{
exhalePeriodInput = go.GetComponent<TMP_InputField>();
exhalePeriodTextInput = go.GetComponent<TMP_InputField>();
SetExhalePeriod();
}
else if (name == "Runtime")
{
runtimeInput = go.GetComponent<TMP_InputField>();
runtimeTextInput = go.GetComponent<TMP_InputField>();
SetRuntime();
}
}
......@@ -54,16 +54,38 @@ public class BlockObjectClass : MonoBehaviour
}
public void SetInhalePeriod()
public void SetInhalePeriod(float inhalePeriod=-1f)
{
InhalePeriod = (float)Convert.ToDouble(inhalePeriodInput.text);
if (inhalePeriod == -1)
{
InhalePeriod = (float)Convert.ToDouble(inhalePeriodTextInput.text);
}
else
{
InhalePeriod = inhalePeriod;
}
}
public void SetExhalePeriod()
public void SetExhalePeriod(float exhalePeriod=-1f)
{
ExhalePeriod = (float)Convert.ToDouble(exhalePeriodInput.text);
if (exhalePeriod == -1)
{
ExhalePeriod = (float)Convert.ToDouble(exhalePeriodTextInput.text);
}
else
{
ExhalePeriod = exhalePeriod;
}
}
public void SetRuntime()
public void SetRuntime(float runtimeInput=-1f)
{
MaxRuntime = (float)Convert.ToDouble(runtimeInput.text)*60;
if (runtimeInput == -1)
{
MaxRuntime = (float)Convert.ToDouble(runtimeTextInput.text) * 60;
}
else
{
MaxRuntime = runtimeInput;
}
}
}
......@@ -25,7 +25,7 @@ public class DisplayRuntimeValue : MonoBehaviour
public void DisplayRuntime()
{
TMP_Text displayText = this.GetComponent<TMP_Text>();
runtimeMinutes = protocolHandler.TotalRuntime / 60;
runtimeMinutes = protocolHandler.TotalRuntime;
string text = runtimeMinutes.ToString();
displayText.SetText(text);
}
......
......@@ -9,12 +9,19 @@ public class ProtocolHandler : MonoBehaviour
public static ProtocolHandler Instance;
public GameObject numCyclesInput;
public GameObject blockControl;
public GameObject centreCircle;
public Canvas canvas;
public GameObject countdownObject;
public float TotalRuntime { get; private set; }
public bool runProtocol = false; // not running
BlockHandler blockHandler;
List<GameObject> blockStack = new List<GameObject>();
AnimateCircle animateCircle;
RunCountdown runCountdown;
int nCycles = 1;
int currentBlockIndex = 0;
int previousBlockIndex = -1;
int currentCycle = 0;
static float timeBetweenBlocks = 3f; // seconds, not implemented
......@@ -33,21 +40,50 @@ public class ProtocolHandler : MonoBehaviour
// Start is called before the first frame update
void Start()
{
blockHandler = blockControl.GetComponent<BlockHandler>();
animateCircle = centreCircle.GetComponent<AnimateCircle>();
runCountdown = countdownObject.GetComponent<RunCountdown>();
}
// Update is called once per frame
void Update()
{
Debug.Log("is protocol running " + runProtocol);
Debug.Log("is circle animating " + animateCircle.enabled);
if (runProtocol && !animateCircle.enabled)
{
// if it's time to run and animation not running, then set to run and iterate
RunBlock(currentBlockIndex);
previousBlockIndex = currentBlockIndex;
currentBlockIndex++;
Debug.Log("Finished " + currentBlockIndex + " / " + blockStack.Count.ToString());
runProtocol = false;
}
else if (previousBlockIndex >= 0 && !animateCircle.enabled &&
currentBlockIndex < blockStack.Count)
{
runCountdown.enabled = true;
}
if (currentBlockIndex == blockStack.Count && !animateCircle.enabled)
{
// export data
currentBlockIndex = 0;
previousBlockIndex = -1;
currentCycle = 0;
runProtocol = false;
animateCircle.enabled = false;
animateCircle.MoveToOffset();
canvas.enabled = true;
}
}
// Update runtime by adding each block runtime, adding 3s for each block,
// and multiplying by cycles
public void UpdateTotalRuntime()
{
blockHandler = blockControl.GetComponent<BlockHandler>();
TotalRuntime = blockHandler.blockStackRuntime;
TotalRuntime = blockHandler.blockStackRuntime / 60;
TotalRuntime *= nCycles;
}
......@@ -64,7 +100,6 @@ public class ProtocolHandler : MonoBehaviour
foreach (var block in blockStack)
{
BlockObjectClass boc = block.GetComponent<BlockObjectClass>();
Debug.Log("boc " + i + " inhale: " + boc.InhalePeriod);
i++;
}
}
......@@ -79,9 +114,12 @@ public class ProtocolHandler : MonoBehaviour
i++;
}
}
}
public class ProtocolVariables
{
List<BlockObjectClass>
void RunBlock(int blockIndex)
{
blockHandler.SetRunningBlockIndex(blockIndex);
blockHandler.SetRunningBlock();
blockHandler.UpdateRunningBlock();
animateCircle.ResetAndRun();
}
}
\ No newline at end of file
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RunCountdown : MonoBehaviour
{
public GameObject protocolHandlerObject;
ProtocolHandler protocolHandler;
int maxCountdownValue = 3;
int countdown = 3;
float timer = 0;
Text displayText;
private void Awake()
{
protocolHandler = protocolHandlerObject.GetComponent<ProtocolHandler>();
displayText = GetComponent<Text>();
displayText.enabled = false;
enabled = false;
}
// Start is called before the first frame update
void Start()
{
displayText.fontSize = 32;
displayText.color = Color.red;
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if (timer >= 1)
{
countdown--;
timer = 0;
}
if (countdown <= 0)
{
protocolHandler.runProtocol = true;
displayText.enabled = false;
enabled = false;
}
displayText.text = countdown.ToString();
}
private void OnDisable()
{
timer = 0;
countdown = maxCountdownValue;
}
private void OnEnable()
{
displayText.enabled = true;
}
}
fileFormatVersion: 2
guid: fbdad22d46cbda74491fc7802d595cea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment