Skip to content

Commit

Permalink
Redo how AI scripts get added as components to allow flexable design.
Browse files Browse the repository at this point in the history
  • Loading branch information
thewithz committed Nov 4, 2020
1 parent 11c81c5 commit 82a7a75
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 159 deletions.
20 changes: 12 additions & 8 deletions OdysseyNow/Assets/ModeDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ private void Awake() {
case "Cat and Mouse":
// load cat and mouse after calibration
calibration.GetComponent<CalibrationDirectorNew>().afterCalibration.AddListener(StartCatAndMouse);
AI.transform.Find("CatAndMouse").gameObject.SetActive(true);
break;
case "Super Cat and Mouse":
calibration.GetComponent<CalibrationDirectorNew>().afterCalibration.AddListener(StartSuperCatAndMouse);
AI.transform.Find("SCAM-Stonehenge").gameObject.SetActive(true);
break;
case "Haunted House":
break;
Expand Down Expand Up @@ -55,25 +53,29 @@ private void StartCatAndMouse() {
calibration.SetActive(false);
var p1 = ElementSettings.FindFromNameAndTag("PlayerTarget", "Player1");
var p2 = ElementSettings.FindFromNameAndTag("PlayerTarget", "Player2");
var game = AI.transform.Find("CatAndMouse").gameObject;

var p1Input = (LocalInputManager.ControlScheme) System.Enum.Parse(typeof(LocalInputManager.ControlScheme),
PlayerPrefs.GetString("P1Input"));
var p2Input = (LocalInputManager.ControlScheme) System.Enum.Parse(typeof(LocalInputManager.ControlScheme),
PlayerPrefs.GetString("P2Input"));
if (p1Input == LocalInputManager.ControlScheme.AI) {
p1.GetComponent<NavMeshAgent>().enabled = true;
p1.GetComponent<CatAI>().enabled = true;
p1.GetComponent<CatAI>().level = PlayerPrefs.GetInt("ai1");
game.GetComponent<CatAI>().enabled = true;
game.GetComponent<CatAI>().level = PlayerPrefs.GetInt("ai1");
}

if (p2Input == LocalInputManager.ControlScheme.AI) {
p2.GetComponent<NavMeshAgent>().enabled = true;
p2.GetComponent<MouseAI>().enabled = true;
p2.GetComponent<MouseAI>().level = PlayerPrefs.GetInt("ai2");
game.GetComponent<MouseAI>().enabled = true;
game.GetComponent<MouseAI>().level = PlayerPrefs.GetInt("ai2");
}

if (p1Input == LocalInputManager.ControlScheme.AI || p2Input == LocalInputManager.ControlScheme.AI)
if (p1Input == LocalInputManager.ControlScheme.AI || p2Input == LocalInputManager.ControlScheme.AI) {
game.SetActive(true);
AI.SetActive(true);
}

}

private void StartSuperCatAndMouse() {
Expand All @@ -97,8 +99,10 @@ private void StartSuperCatAndMouse() {
p2.GetComponent<MouseAI>().level = PlayerPrefs.GetInt("ai2");
}

if (p1Input == LocalInputManager.ControlScheme.AI || p2Input == LocalInputManager.ControlScheme.AI)
if (p1Input == LocalInputManager.ControlScheme.AI || p2Input == LocalInputManager.ControlScheme.AI) {
AI.transform.Find("SCAM-Stonehenge").gameObject.SetActive(true);
AI.SetActive(true);
}
}

private void StartTennis() {
Expand Down
120 changes: 60 additions & 60 deletions OdysseyNow/Assets/Scenes/Card4.unity
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,28 @@ GameObject:
type: 3}
m_PrefabInstance: {fileID: 5755280646347381175}
m_PrefabAsset: {fileID: 0}
--- !u!195 &21414806
NavMeshAgent:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 21414805}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 2
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!1 &24524509
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -459,7 +481,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 93647768}
- component: {fileID: 93647769}
m_Layer: 0
m_Name: SCAM-Stonehenge
m_TagString: Untagged
Expand All @@ -483,24 +504,6 @@ Transform:
m_Father: {fileID: 511151602}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &93647769
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 93647767}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f9b2cec6d6faf4e66b565d5dd0684f81, type: 3}
m_Name:
m_EditorClassIdentifier:
player1: {fileID: 0}
player2: {fileID: 0}
p_distance: 0
stone: {fileID: 536115980}
water: {fileID: 1661881854}
cheese: {fileID: 2051804292}
--- !u!1 &102701091
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2664,12 +2667,6 @@ SpriteMask:
m_BackSortingOrder: 0
m_IsCustomRangeActive: 0
m_SpriteSortPoint: 0
--- !u!1 &620542788 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5755280645900333751, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
m_PrefabInstance: {fileID: 5755280646347381175}
m_PrefabAsset: {fileID: 0}
--- !u!1 &636592681
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -5770,12 +5767,6 @@ MonoBehaviour:
m_Area: 1
m_IgnoreFromBuild: 0
m_AffectedAgents: ffffffff
--- !u!1 &1072673124 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 621243042690390921, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
m_PrefabInstance: {fileID: 5755280646347381175}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1078363361
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -7945,6 +7936,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1405386638}
- component: {fileID: 1405386640}
- component: {fileID: 1405386639}
m_Layer: 0
m_Name: CatAndMouse
Expand Down Expand Up @@ -7976,13 +7968,29 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1405386637}
m_Enabled: 0
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b6aa0652006149c41b9fca129b5a01d5, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 192006097}
mouse: {fileID: 21414805}
level: 1
--- !u!114 &1405386640
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1405386637}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 293ba996f8d224288996decbbd8734e0, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 620542788}
level: 0
target: {fileID: 5755280646347381178}
cat: {fileID: 5755280646347381176}
level: 1
--- !u!1 &1414869717
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -33928,12 +33936,12 @@ PrefabInstance:
- target: {fileID: 621243040746300459, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.x
value: 2.02
value: 0
objectReference: {fileID: 0}
- target: {fileID: 621243040746300459, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.y
value: 1.59
value: 0
objectReference: {fileID: 0}
- target: {fileID: 621243042690390925, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
Expand All @@ -33948,12 +33956,12 @@ PrefabInstance:
- target: {fileID: 621243042690390925, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.x
value: 1.94
value: -4.54
objectReference: {fileID: 0}
- target: {fileID: 621243042690390925, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.78
value: 3.25
objectReference: {fileID: 0}
- target: {fileID: 621243042690390926, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
Expand Down Expand Up @@ -34133,22 +34141,22 @@ PrefabInstance:
- target: {fileID: 5755280646094463702, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.x
value: 2.06
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5755280646094463702, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.84
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5755280646298115440, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.y
value: 0.81
value: -2.43
objectReference: {fileID: 0}
- target: {fileID: 5755280646298115440, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.36
value: 3.37
objectReference: {fileID: 0}
- target: {fileID: 5755280646298115440, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
Expand Down Expand Up @@ -34367,30 +34375,22 @@ NavMeshAgent:
m_GameObject: {fileID: 5755280646347381176}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.21
m_Speed: 1.5
m_Acceleration: 300
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 3000
m_AngularSpeed: 120
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 0.35
m_Height: 2
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!114 &5755280646347381178
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
--- !u!4 &5755280646347381178 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 621243040746300459, guid: 6335a3f5d84d6421eb04d6f447784f85,
type: 3}
m_PrefabInstance: {fileID: 5755280646347381175}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5755280646347381176}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 293ba996f8d224288996decbbd8734e0, type: 3}
m_Name:
m_EditorClassIdentifier:
target: {fileID: 1072673124}
level: 0
9 changes: 5 additions & 4 deletions OdysseyNow/Assets/Scripts/AI/card4/catAndMouse/cat/CatAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ public class CatAI : MonoBehaviour {
private float period = 2f;
private NavMeshAgent agent;

public GameObject target;
public Transform target;
public GameObject cat;
public int level;

// Start is called before the first frame update
private void Start() {
// Agent tend to rotate game object, that can be
// undesirable
agent = GetComponent<NavMeshAgent>();
agent = cat.GetComponent<NavMeshAgent>();

agent.updateRotation = false;
agent.updateUpAxis = false;
Expand All @@ -25,13 +26,13 @@ private void Update() {
return;
}

if ((transform.position - target.transform.position).magnitude < 1) {
if ((transform.position - target.position).magnitude < 1) {
Debug.Log("Cat has the mouse.");
}

switch (level) {
case 1:
agent.SetDestination(target.transform.position);
agent.SetDestination(target.position);
// if (Time.time > nextActionTime) {
// nextActionTime += Time.time + period;
// agent.SetDestination(new Vector3(Random.Range(-4, 4), Random.Range(-4, 4), 0));
Expand Down
10 changes: 6 additions & 4 deletions OdysseyNow/Assets/Scripts/AI/card4/catAndMouse/mouse/MouseAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public class MouseAI : MonoBehaviour {
private float e = 1f;

public Transform target;
public GameObject mouse;
public int level;


// Start is called before the first frame update
private void Start() {
// Agent tend to rotate game object, that can be
// undesirable
agent = GetComponent<NavMeshAgent>();
agent = mouse.GetComponent<NavMeshAgent>();

agent.updateRotation = false;
agent.updateUpAxis = false;
Expand All @@ -49,8 +51,8 @@ private void Update() {

switch (level) {
case 1:
Mouse();
//agent.SetDestination(target.position);
//Mouse();
agent.SetDestination(target.position);
break;
case 2:
break;
Expand Down Expand Up @@ -102,7 +104,7 @@ private void CreateInitialMatrix(int?[,] q) {
q[state, 4] = grid[mr, mc + 1] == 1 ? 0 : (int?) null; // west
break;
case 13:
q[state, 3] = grid[mr, mc - 1] == 1 ? 0 : (int?) null; // east
q[state, 3] = grid[mr, mc - 1] == 1 ? 0 : (int?) null; // east
q[state, 4] = null; // west
break;
default:
Expand Down
Loading

0 comments on commit 82a7a75

Please sign in to comment.