Commit c0aed9fa authored by ffperes's avatar ffperes

Lab 4 - Scene 4 - A skeleton of FSM

My first attempt to elaborate a base for a FSM
parent 4353c969
......@@ -6,7 +6,7 @@
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace></RootNamespace>
<ProjectGuid>{4F260D9A-13DC-3512-D9AC-A60A53AB9973}</ProjectGuid>
<ProjectGuid>{0FD570BA-8C7F-CE49-F793-E3BAF842F800}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AssemblyName>Assembly-CSharp</AssemblyName>
......@@ -45,21 +45,17 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Navigation\Scripts\Agent.cs" />
<Compile Include="Assets\Navigation\Scripts\AgentController.cs" />
<Compile Include="Assets\Navigation\Scripts\Node.cs" />
<Reference Include="UnityEngine.Advertisements">
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/Advertisements/UnityEngine.Advertisements.dll</HintPath>
</Reference>
<Compile Include="Assets\Scripts\Agent.cs" />
<Compile Include="Assets\Scripts\AgentController.cs" />
<Compile Include="Assets\Scripts\FSM1.cs" />
<Compile Include="Assets\Scripts\Node.cs" />
<Compile Include="Assets\Scripts\State.cs" />
<Reference Include="UnityEngine.UI">
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Analytics">
<HintPath>C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/UnityAnalytics/UnityEngine.Analytics.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>C:/Program Files/Unity/Editor/Data/Managed/Mono.Cecil.dll</HintPath>
</Reference>
......
fileFormatVersion: 2
guid: 85c628519477c5d478b58947831ab25f
folderAsset: yes
timeCreated: 1449242297
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 9dab7d92d3b86f5469f96363340da683
timeCreated: 1449239739
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 64e5afc2300c2a34d9fd9c4cc5c80098
timeCreated: 1449243157
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -147,5 +147,15 @@ public class Agent : MonoBehaviour {
shortestPath.Reverse();
return shortestPath;
}
public List<Node> getPath()
{
return path;
}
public void setPath(Vector3 goingTo)
{
path = Astar(getClosestNode(transform.position), getClosestNode(goingTo));
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FSM1 : Agent {
private State currentState, previousState;
private List<State> states = new List<State>(); //holds all possible states
public GameObject chasing;
public Rigidbody rb;
public State getState(int index){
return states[index];
}
public void setState(State state){
currentState = state;
}
public void changeState(State state){
// to be able to return to its previous state
previousState = currentState;
// change the state been parsed to the current state
currentState = state;
}
void Start () {
rb = GetComponent<Rigidbody>();
// adding my states to a list
states.Add(new Stopped(this));
states.Add(new PitStop(this));
states.Add(new Racing(this));
currentState = states[0];
currentState.runState ();
}
// Update is called once per frame
void Update () {
// keep following the nodes track when space bar is pressed
if (Input.GetKeyDown(KeyCode.Space)){
currentState = states[2];
}
// stop the agent when the space bar is not pressed anymore
if (Input.GetKeyUp(KeyCode.Space)){
currentState = states[0];
}
foreach(State s in states){
s.runState();
}
}
}
fileFormatVersion: 2
guid: fca013fecdc13bc44a8a07e8fc76430e
timeCreated: 1449243222
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class State{
protected FSM1 FSM_Manager;
protected bool stopped = false;
public State(FSM1 _manager){
FSM_Manager = _manager;
}
public State(){
}
public void runState(){
}
}
public class Stopped : State{
public Stopped(FSM1 _manager) {
}
protected void onResume(){
}
protected void onRun() {
}
}
public class PitStop : State{
public PitStop(FSM1 m_){
}
protected void onResume(){
}
protected void onRun(){
}
}
public class Racing : State{
public Racing(FSM1 m_){
}
protected void onResume(){
}
protected void onRun(){
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 1831d822692d0904bb8bfd56decbbc80
timeCreated: 1449240568
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2008
Project("{6E2C92F5-0465-E7FA-DB22-8484BE11699A}") = "Labs", "Assembly-CSharp.csproj", "{0FD570BA-8C7F-CE49-F793-E3BAF842F800}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0FD570BA-8C7F-CE49-F793-E3BAF842F800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FD570BA-8C7F-CE49-F793-E3BAF842F800}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FD570BA-8C7F-CE49-F793-E3BAF842F800}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FD570BA-8C7F-CE49-F793-E3BAF842F800}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Assembly-CSharp.csproj
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = null
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.inheritsSet = Mono
$2.inheritsScope = text/x-csharp
$2.scope = text/x-csharp
$0.TextStylePolicy = $3
$3.FileWidth = 120
$3.TabWidth = 4
$3.IndentWidth = 4
$3.EolMarker = Unix
$3.inheritsSet = Mono
$3.inheritsScope = text/plain
$3.scope = text/plain
EndGlobalSection
EndGlobal
Markdown is supported
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