A simple action to teleport NavMesh Agent to a position on scene.
☀/*
*
* Adventure Creator
* by Chris Burton, 2013-2016
*
* "ActionTemplate.cs"
*
* This is a blank action template.
*
*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionNavMeshWrap : Action
{
// Declare variables here
public bool isPlayer;
public UnityEngine.AI.NavMeshAgent Agent;
public Transform WarpPosition;
public ActionNavMeshWrap()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Navmesh Wrap";
description = "Wraps Navmesh position";
}
public override void AssignValues(List<ActionParameter> parameters)
{
base.AssignValues(parameters);
if (isPlayer)
{
Agent = KickStarter.player.GetComponent<UnityEngine.AI.NavMeshAgent>();
}
}
override public float Run ()
{
/*
* This function is called when the action is performed.
*
* The float to return is the time that the game
* should wait before moving on to the next action.
* Return 0f to make the action instantenous.
*
* For actions that take longer than one frame,
* you can return "defaultPauseTime" to make the game
* re-run this function a short time later. You can
* use the isRunning boolean to check if the action is
* being run for the first time, eg:
*/
if (Agent && WarpPosition)
{
Agent.Warp(WarpPosition.position);
}
return 0f;
}
#if UNITY_EDITOR
override public void ShowGUI ()
{
// Action-specific Inspector GUI code here
isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer);
if (isPlayer)
{
if (Application.isPlaying)
{
Agent = KickStarter.player.GetComponent<UnityEngine.AI.NavMeshAgent>();
}
else if (AdvGame.GetReferences().settingsManager)
{
Agent = AdvGame.GetReferences().settingsManager.GetDefaultPlayer().GetComponent<UnityEngine.AI.NavMeshAgent>();
}
}
else
Agent = (UnityEngine.AI.NavMeshAgent)EditorGUILayout.ObjectField("Navmesh Agent:", Agent, typeof(UnityEngine.AI.NavMeshAgent), true);
WarpPosition = (Transform)EditorGUILayout.ObjectField("Warp Position:", WarpPosition, typeof(Transform), true);
AfterRunningOption ();
}
public override string SetLabel ()
{
// Return a string used to describe the specific action's job.
if (isPlayer)
{
return " (Player)";
}
else if (Agent)
{
return (" (" + Agent.name + " - " + WarpPosition.ToString() + ")");
}
return "";
}
#endif
}
}