Skip to content

Commit

Permalink
[NavMeshFollower] Added nav mesh follower. Updated project to unity 2…
Browse files Browse the repository at this point in the history
…021.
  • Loading branch information
kafeijao committed Sep 8, 2023
1 parent 5699465 commit 35d5b75
Show file tree
Hide file tree
Showing 12 changed files with 1,023 additions and 274 deletions.
File renamed without changes.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ FodyWeavers.xsd
/.vscode
NStrip.exe
lib_names
ManagedLibs/*.dll
ManagedLibs/*.db
.ManagedLibs/*.dll
.ManagedLibs/*.db
lib_names.xml
655 changes: 446 additions & 209 deletions Directory.Build.props

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions EyeMovementFix/EyeMovementFix.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Folder Include="out" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk"/>
6 changes: 6 additions & 0 deletions Kafe_CVR_CCKs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EyeMovementFix", "EyeMoveme
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CVRSuperMario64", "CVRSuperMario64\CVRSuperMario64.csproj", "{A73A34C6-2E5F-451D-A8CB-412F85000C5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NavMeshFollower", "NavMeshFollower\NavMeshFollower.csproj", "{B64DE9CC-C0EE-43AE-99FB-4B3262308B04}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{A73A34C6-2E5F-451D-A8CB-412F85000C5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A73A34C6-2E5F-451D-A8CB-412F85000C5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A73A34C6-2E5F-451D-A8CB-412F85000C5A}.Release|Any CPU.Build.0 = Release|Any CPU
{B64DE9CC-C0EE-43AE-99FB-4B3262308B04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B64DE9CC-C0EE-43AE-99FB-4B3262308B04}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B64DE9CC-C0EE-43AE-99FB-4B3262308B04}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B64DE9CC-C0EE-43AE-99FB-4B3262308B04}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
178 changes: 178 additions & 0 deletions NavMeshFollower/CCK/FollowerInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.AI;

using ABI.CCK.Components;
using NavMeshFollower.Properties;

namespace Kafe.NavMeshFollower.CCK;

[InitializeOnLoad]
public static class FollowerInfoInitializer {
static FollowerInfoInitializer() {
const string symbol = "KAFE_CVR_CCK_NAV_MESH_FOLLOWER_EXISTS";
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
if (defines.Contains(symbol)) return;
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, $"{defines};{symbol}");
Debug.Log($"Added {symbol} Scripting Symbol.");
}
}

public class FollowerInfo : MonoBehaviour {

[SerializeField] public string version = AssemblyInfoParams.Version;

[SerializeField] public CVRSpawnable spawnable;
[SerializeField] public NavMeshAgent navMeshAgent;

[SerializeField] public Animator humanoidAnimator;

[SerializeField] public bool hasLookAt;
[SerializeField] public Transform lookAtTargetTransform;
[SerializeField] public Transform headTransform;

[SerializeField] public bool hasVRIK;

// VRIK Left Arm
[SerializeField] public bool hasLeftArmIK;
[SerializeField] public Transform vrikLeftArmTargetTransform;
[SerializeField] public Transform leftHandAttachmentPoint;

// VRIK Right Arm
[SerializeField] public bool hasRightArmIK;
[SerializeField] public Transform vrikRightArmTargetTransform;
[SerializeField] public Transform rightHandAttachmentPoint;
}

[CanEditMultipleObjects]
[CustomEditor(typeof(FollowerInfo))]
public class FollowerInfoEditor : Editor {

SerializedProperty spawnable;
SerializedProperty navMeshAgent;
SerializedProperty humanoidAnimator;

SerializedProperty hasLookAt;
SerializedProperty lookAtTargetTransform;
SerializedProperty headTransform;

SerializedProperty hasLeftArmIK;
SerializedProperty vrikLeftArmTargetTransform;
SerializedProperty leftHandAttachmentPoint;

SerializedProperty hasRightArmIK;
SerializedProperty vrikRightArmTargetTransform;
SerializedProperty rightHandAttachmentPoint;

private void OnEnable() {

spawnable = serializedObject.FindProperty("spawnable");
navMeshAgent = serializedObject.FindProperty("navMeshAgent");
humanoidAnimator = serializedObject.FindProperty("humanoidAnimator");

hasLookAt = serializedObject.FindProperty("hasLookAt");
lookAtTargetTransform = serializedObject.FindProperty("lookAtTargetTransform");
headTransform = serializedObject.FindProperty("headTransform");

hasLeftArmIK = serializedObject.FindProperty("hasLeftArmIK");
vrikLeftArmTargetTransform = serializedObject.FindProperty("vrikLeftArmTargetTransform");
leftHandAttachmentPoint = serializedObject.FindProperty("leftHandAttachmentPoint");

hasRightArmIK = serializedObject.FindProperty("hasRightArmIK");
vrikRightArmTargetTransform = serializedObject.FindProperty("vrikRightArmTargetTransform");
rightHandAttachmentPoint = serializedObject.FindProperty("rightHandAttachmentPoint");
}

private bool ValidateComponent(string propertyName, Component component, Transform spawnableTransform, bool? shouldBeEnabled){
if (component == null) {
EditorGUILayout.HelpBox($"{propertyName} needs to be assigned!", MessageType.Error);
return false;
}
var valid = true;
if (!component.transform.IsChildOf(spawnableTransform)) {
EditorGUILayout.HelpBox($"{propertyName} needs to be either on the same component or deeper in the hierarchy of the CVRSpawnable!", MessageType.Error);
valid = false;
}
if (shouldBeEnabled.HasValue && component is MonoBehaviour behavior && behavior.enabled != shouldBeEnabled.Value) {
var status = shouldBeEnabled.Value ? "enabled" : "disabled";
EditorGUILayout.HelpBox($"{propertyName} component should be {status}!", MessageType.Error);
valid = false;
}
return valid;
}


public override void OnInspectorGUI() {

if (Application.isPlaying) {
EditorGUILayout.HelpBox("You can't edit this script play mode!", MessageType.Warning);
return;
}

serializedObject.Update();

var behavior = (FollowerInfo) target;

EditorGUILayout.LabelField("Base Setup", EditorStyles.boldLabel);

EditorGUILayout.PropertyField(spawnable);
var spawnableObject = spawnable.objectReferenceValue as CVRSpawnable;
if (spawnableObject == null) {
EditorGUILayout.HelpBox("The CVRSpawnable needs to be assigned!", MessageType.Error);
return;
}
ValidateComponent(nameof(spawnable), spawnableObject, spawnableObject.transform, true);

EditorGUILayout.PropertyField(navMeshAgent);
ValidateComponent(nameof(navMeshAgent), navMeshAgent.objectReferenceValue as NavMeshAgent, spawnableObject.transform, false);

EditorGUILayout.Space();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Look At Setup", EditorStyles.boldLabel);

EditorGUILayout.PropertyField(hasLookAt);
if (hasLookAt.boolValue) {

EditorGUILayout.PropertyField(lookAtTargetTransform);
ValidateComponent(nameof(lookAtTargetTransform), lookAtTargetTransform.objectReferenceValue as Transform, spawnableObject.transform, null);

EditorGUILayout.PropertyField(headTransform);
ValidateComponent(nameof(headTransform), headTransform.objectReferenceValue as Transform, spawnableObject.transform, null);
}

EditorGUILayout.Space();
EditorGUILayout.Separator();
EditorGUILayout.LabelField("Humanoid IK Setup", EditorStyles.boldLabel);

if (hasRightArmIK.boolValue || hasLeftArmIK.boolValue) {
EditorGUILayout.PropertyField(humanoidAnimator);
var animator = humanoidAnimator.objectReferenceValue as Animator;
if (ValidateComponent(nameof(humanoidAnimator), animator, spawnableObject.transform, null)) {
if (!animator!.isHuman) {
EditorGUILayout.HelpBox($"{nameof(humanoidAnimator)} needs to be a humanoid animator, as we need to get the hand transform references.", MessageType.Error);
}
}
EditorGUILayout.HelpBox($"{nameof(humanoidAnimator)} You can add the bool parameter #SpawnedByMe to this animator, it will set by the mod to be true on followers you spawn.", MessageType.Info);
}

EditorGUILayout.Space();
EditorGUILayout.PropertyField(hasLeftArmIK);
if (hasLeftArmIK.boolValue) {
EditorGUILayout.PropertyField(vrikLeftArmTargetTransform);
ValidateComponent(nameof(vrikLeftArmTargetTransform), vrikLeftArmTargetTransform.objectReferenceValue as Transform, spawnableObject.transform, null);
EditorGUILayout.PropertyField(leftHandAttachmentPoint);
ValidateComponent(nameof(leftHandAttachmentPoint), leftHandAttachmentPoint.objectReferenceValue as Transform, spawnableObject.transform, null);
}

EditorGUILayout.Space();
EditorGUILayout.PropertyField(hasRightArmIK);
if (hasRightArmIK.boolValue) {
EditorGUILayout.PropertyField(vrikRightArmTargetTransform);
ValidateComponent(nameof(vrikRightArmTargetTransform), vrikRightArmTargetTransform.objectReferenceValue as Transform, spawnableObject.transform, null);
EditorGUILayout.PropertyField(rightHandAttachmentPoint);
ValidateComponent(nameof(rightHandAttachmentPoint), rightHandAttachmentPoint.objectReferenceValue as Transform, spawnableObject.transform, null);
}

serializedObject.ApplyModifiedProperties();
}
}
6 changes: 6 additions & 0 deletions NavMeshFollower/NavMeshFollower.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputPath>F:\UnityProjects\ChilloutVR\2021\NavMeshRealtimeBaker\Assets\Kafeijao.CCK\</OutputPath>
</PropertyGroup>
</Project>
15 changes: 15 additions & 0 deletions NavMeshFollower/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;
using NavMeshFollower.Properties;

[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyTitle(nameof(NavMeshFollower))]
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
[assembly: AssemblyProduct(nameof(NavMeshFollower))]

namespace NavMeshFollower.Properties;
internal static class AssemblyInfoParams {
public const string Version = "0.0.1";
public const string Author = "kafeijao";
}
Loading

0 comments on commit 35d5b75

Please sign in to comment.