Skip to content

Commit

Permalink
feat. add task system
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-Yulin committed Jun 27, 2024
1 parent 1c7c71a commit 695470b
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Assets/Script/DT/RouteGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class KeyPoint
{
public Vector3 pos = Vector3.zero;
Expand All @@ -14,7 +15,7 @@ public KeyPoint(Vector3 pos, bool grab = false, bool wait = false)
this.wait = wait;
}
}

[System.Serializable]
public class Route
{
public List<KeyPoint> routes = new List<KeyPoint>();
Expand All @@ -26,8 +27,10 @@ public Route(List<KeyPoint> turningPoints)
}
for (int i = 1; i < turningPoints.Count; i++)
{

KeyPoint start = turningPoints[i-1];
KeyPoint end = turningPoints[i];
Debug.Log(start.pos.ToString() + ' ' + end.pos.ToString());
float dist = (start.pos - end.pos).magnitude;
int sigment = (int)(dist * 20f);
for (int j = 0; j <= sigment; j++)
Expand Down
3 changes: 2 additions & 1 deletion Assets/Script/ObjectSpaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public void UpdateObject(string cat, Vector3 pos, Vector3 rot, Vector3 size)
}
if (!pre_found)
{
CreateObject(id, cat, pos, rot, size);
id++;
CreateObject(id, cat, pos, rot, size);

}
}

Expand Down
98 changes: 98 additions & 0 deletions Assets/Script/TaskManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class ArmTask
{
public enum Type
{
Finished,
MoveObject
}
public Type type = Type.Finished;

// moveObject
public Vector3 move_start;
public Vector3 move_end;

public void InitAsMoveObject(Vector3 start, Vector3 end)
{
type = Type.MoveObject;
move_start = start;
move_end = end;
}
}
public class TaskManager : MonoBehaviour
{
public ArmTask task = new ArmTask();

public Transform ArmEnd;
public IKController IKSolver;
public RouteGenerator routeGenerator;

Coroutine taskRoutine;

GameObject taskSouce;

public void GetTask(ArmTask t, GameObject sender)
{

if (task.type == ArmTask.Type.Finished)
{
task = t;
taskSouce = sender;
Debug.Log("New " + task.type.ToString() + " task assigned.");

if (taskRoutine != null)
{
}
else
{
taskRoutine = StartCoroutine(ExecuteMoveObject());
}
}
else
{
Debug.Log("Current task not finished.");
}

}

IEnumerator ExecuteMoveObject()
{
Debug.Log("Start move object coroutine.");
// generate the action sequence
List<KeyPoint> turningPoint = new List<KeyPoint>();
turningPoint.Add(new KeyPoint(ArmEnd.position, false));
turningPoint.Add(new KeyPoint(task.move_start, true));
turningPoint.Add(new KeyPoint(task.move_end, false));
routeGenerator.SetRoute(turningPoint);



yield return new WaitForSeconds(3);
taskRoutine = null;
task = new ArmTask();
try
{
taskSouce.GetComponent<ObjectFrame>().CancelAim();
}
catch { }

Debug.Log("Task Finished");
yield break;
}

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions Assets/Script/TaskManager.cs.meta

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

18 changes: 18 additions & 0 deletions Assets/Script/UI/ObjectFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,26 @@ public enum Type
ObjectFrame source;
[SerializeField] Material aimMat;
[SerializeField] LineRenderer Line;
[SerializeField] TaskManager taskManager;

// for detect type;
ObjectFrame dist;
[SerializeField] Material objectMat;

public void SendTask()
{
if (taskManager)
{
ArmTask t = new ArmTask();
t.InitAsMoveObject(source.Frame.transform.position, Frame.transform.position);
taskManager.GetTask(t, gameObject);
}
else
{
Debug.Log("TaskManager not found.");
}
}

public void InitFrame(Type t, Vector3 pos, Vector3 rot, Vector3 scale)
{
type = t;
Expand All @@ -53,6 +68,9 @@ public void UpdateFrame(string cat, Vector3 pos, Vector3 rot, Vector3 scale)
public void CancelAim()
{
Debug.Log("Cancel Aim");



if (type == Type.Aim)
{
source.transform.Find("Frame").gameObject.GetComponent<ObjectManipulator>().ManipulationType = Microsoft.MixedReality.Toolkit.Utilities.ManipulationHandFlags.OneHanded;
Expand Down

0 comments on commit 695470b

Please sign in to comment.