Skip to content

Commit

Permalink
Fixes #25 - use MovePlayer.cs instead of MoveSpawn.cs; updated Nav ta…
Browse files Browse the repository at this point in the history
…sk prefab accordingly; compatibility updates to TaskList.cs and Config.cs
  • Loading branch information
mjstarrett committed Mar 25, 2024
1 parent 1f225af commit 4caef08
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
"temp/":true,
"Temp/":true
},
"dotnet.defaultSolution": "lm.sln"
"dotnet.defaultSolution": "lm.sln",
"dotnet.preferCSharpExtension": true
}
10 changes: 5 additions & 5 deletions Assets/Landmarks/Prefabs/TASK_NavigationTask.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ MonoBehaviour:
repeat: 1
overideRepeat: {fileID: 0}
repeatCount: 1
hideTargetsDuringTask: 0
currentTask: {fileID: 0}
catchTrialCount: 0
skipOnCatch: []
Expand Down Expand Up @@ -295,7 +294,6 @@ MonoBehaviour:
repeat: 8
overideRepeat: {fileID: 8475965484490080533}
repeatCount: 1
hideTargetsDuringTask: 0
currentTask: {fileID: 0}
catchTrialCount: 0
skipOnCatch: []
Expand Down Expand Up @@ -612,7 +610,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 8477616651272562214}
- component: {fileID: 8477616651272562217}
- component: {fileID: 5335049405014025327}
m_Layer: 0
m_Name: MovePlayerToSpawn
m_TagString: Untagged
Expand All @@ -634,7 +632,7 @@ Transform:
m_Father: {fileID: 6279364624764035789}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &8477616651272562217
--- !u!114 &5335049405014025327
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -643,7 +641,7 @@ MonoBehaviour:
m_GameObject: {fileID: 8477616651272562215}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 201e9890d1a764c8ea736797b2ca29a6, type: 3}
m_Script: {fileID: 11500000, guid: 06f70e910a910495d8406095c39e603a, type: 3}
m_Name:
m_EditorClassIdentifier:
skip: 0
Expand Down Expand Up @@ -672,6 +670,8 @@ MonoBehaviour:
randomRotation: 0
scaledPlayer: 0
ignoreY: 0
useSnapPoint: 0
localOffsetFacing: {x: 0, y: 0, z: 0}
blockRepeat: 0
--- !u!1001 &9012772696151050461
PrefabInstance:
Expand Down
21 changes: 13 additions & 8 deletions Assets/Landmarks/Scripts/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class Config : MonoBehaviour
public int practiceTrialCount;
public List<string> levelNames = new List<string>();
public bool randomSceneOrder;
public bool singleSceneBuild;
[Tooltip("Read Only: Use as index for scence/condition")]
public int levelNumber;
public bool appendLogFiles = false;
Expand All @@ -68,9 +69,13 @@ public class Config : MonoBehaviour
public string expPath = "default";
[HideInInspector]
public string subjectPath = "default";
public string subject = "default";
public int id = 999;
[HideInInspector]
public string session = "default";
public string subject = "deprecated";
public int age = 999;
public bool biosexFemale;
[HideInInspector] public string session = "default";
[Min(1)] public int run = 1;
//[HideInInspector]
//public string level = "default";
[HideInInspector]
Expand Down Expand Up @@ -237,14 +242,14 @@ public void Save()
{
path = Application.persistentDataPath + "/" +
experiment + "/" +
subject + "/";
id + "/";
}

BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path + "progress.dat", FileMode.Create);

ExpData data = new ExpData();
data.id = subject;
data.id = id;
data.lastLevelFinished = levelNumber;
data.levelNames = new List<string>();
foreach (var lev in levelNames)
Expand All @@ -267,7 +272,7 @@ public void Load()
{
path = Application.persistentDataPath + "/" +
experiment + "/" +
subject + "/";
id + "/";
}
Debug.Log("Loading from " + path + "progress.dat");
if (File.Exists(path + "progress.dat"))
Expand All @@ -279,7 +284,7 @@ public void Load()
stream.Close();

// Replace current values with loaded values
subject = data.id;
id = data.id;
levelNumber = data.lastLevelFinished+1;

levelNames.Clear();
Expand All @@ -301,7 +306,7 @@ public void DeleteTemporaryProgressData()
{
path = Application.persistentDataPath + "/" +
experiment + "/" +
subject + "/";
id + "/";
}
File.Delete(path + "progress.dat");
}
Expand All @@ -310,7 +315,7 @@ public void DeleteTemporaryProgressData()
[System.Serializable]
class ExpData
{
public string id;
public int id;
public int lastLevelFinished;
public List<string> levelNames;

Expand Down
199 changes: 199 additions & 0 deletions Assets/Landmarks/Scripts/ExperimentTasks/MovePlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
Copyright (C) 2010 Jason Laczko
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;

public class MovePlayer : ExperimentTask {

[HideInInspector] public GameObject start;

[Header("Task-specific Properties")]
public GameObject destination;
public string destinationListName;
public ObjectList destinations;

public bool swap;

public bool randomRotation;
public bool scaledPlayer = false;
public bool ignoreY = false;
public bool useSnapPoint;
public Vector3 localOffsetFacing;

//variables used for block repetition
public bool blockRepeat;
public static int repetition;
private int count = 1;

public override void startTask () {
// Debug.Log("MS Repetition:"+repetition);
TASK_START();
}

public override void TASK_START()
{
base.startTask();

if (!manager) Start();


if (skip) {
log.log("INFO skip task " + name, 1);
return;
}

if (scaledPlayer)
{
start = scaledAvatar;
} else start = avatar;
// Debug.Log("Player identified: " + start.gameObject.name);

// Find destinations with string destinationsName
if (destinations == null && destinationListName != "") // only if destinations is blank and destinationsName is not
{
destinations = GameObject.Find(destinationListName).GetComponent<ObjectList>();
// Debug.Log("moving the " + start.gameObject.name + " to " + destinations.currentObject());
}
// otherwise, use destination or destinations.
if (destinations) {
destination = destinations.currentObject();
//Debug.Log("Destination selected: " + destination.name +
// " (" + destination.transform.position.x + ", " +
// destination.transform.position.z + ")");
}

// Temporary transforms that can be easily modified
var originPos = start.transform.position;
var originRot = start.transform.eulerAngles;
var terminusPos = useSnapPoint ? destination.transform.GetComponentInChildren<LM_SnapPoint>().transform.position :
destination.transform.position;
Debug.Log(terminusPos.y);
var terminusRot = useSnapPoint ? destination.transform.GetComponentInChildren<LM_SnapPoint>().transform.localEulerAngles :
destination.transform.eulerAngles;

// -----------------
// Move the player
// -----------------
// Character controller component must be disabled to move the player like this
if (localOffsetFacing != Vector3.zero) terminusPos += destination.transform.TransformDirection(localOffsetFacing);
if (ignoreY) terminusPos.y = originPos.y;
start.GetComponentInChildren<CharacterController>().enabled = false;
start.transform.position = terminusPos;
log.log("TASK_POSITION\t" + start.name + "\t" + this.GetType().Name + "\t" + start.transform.transform.position.ToString("f1"), 1);
start.GetComponentInChildren<CharacterController>().enabled = true;

// -----------------
// Rotate the player
// -----------------
// Turn off any FirstPersonController (FPC) components in order to modify
var fpc = start.GetComponent<FirstPersonController>();
if (fpc != null) fpc.enabled = false;
// Modify and/or set
if (localOffsetFacing != Vector3.zero)
{
Debug.LogWarning("Using the provided 'localOffsetFacing' property to point the player at the original destination.\n" +
"\tIf 'randomRotation' was selected, it will be ignored.");
start.transform.LookAt(destination.transform);
// level off the viewpoint
start.transform.eulerAngles = new Vector3(0f, start.transform.eulerAngles.y, 0f);
}
else
{
if (randomRotation) terminusRot.y = Random.Range(0, 360 - Mathf.Epsilon);
start.transform.eulerAngles = terminusRot;
}
manager.playerCamera.transform.localEulerAngles = Vector3.zero;
// turn the FPC back on
if (fpc != null) fpc.ResetMouselook();
if (fpc != null) fpc.enabled = true;



if (!isScaled)
{
/* MJS 2019
* It is not possible to simply rotate the unity standard asset firstpersoncontroller manually,
* so we need to access a modified firstpersoncontroller.cs script
* which will access a modified MouseLook.cs script to reset the mouselook
* which effectively forces it not to undo our manual rotation
*/
//avatar.GetComponent<FirstPersonController>().ResetMouselook();
}

log.log("TASK_ROTATE\t" + start.name + "\t" + this.GetType().Name + "\t" + start.transform.localEulerAngles.ToString("f1"), 1);


//Debug.Log("-------------------------------------------------");
//Debug.Log(start.transform.position);
//Debug.Log(destination.transform.position);
//Debug.Log(avatar.transform.position);
//Debug.Log("-------------------------------------------------");

if (swap)
{
destination.transform.position = originPos;
destination.transform.eulerAngles = originRot;
}

Debug.Log("Player at (" + manager.player.transform.position.x + ", " + manager.player.transform.position.y + ", " + manager.player.transform.position.z + ") and facing " + manager.player.transform.eulerAngles.y + "°");
}

public override bool updateTask () {
return true;
}
public override void endTask() {




TASK_END();
}

public override void TASK_END() {
base.endTask();
if ( destinations ) {
if (blockRepeat)
{
BlockIncrementation();
}
else
{
if (canIncrementLists) destinations.incrementCurrent();
}
destination = destinations.currentObject();
}
}

//Method to get implemented when the Block Increment boolean in the GUI is selected
public void BlockIncrementation()
{
//Debug.Log("count before increment: " + count);

//If the player has done # of repetitions equal to the parent task Repetition Value then set count back to 0 & move the Spawn Location to the next in the list
if (count == repetition)
{
count = 1;
if (canIncrementLists) destinations.incrementCurrent();
}
else //increment count
{
count++;
}
//Debug.Log("count after increment: " + count);
}
}
11 changes: 11 additions & 0 deletions Assets/Landmarks/Scripts/ExperimentTasks/MovePlayer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4caef08

Please sign in to comment.