Steps to get it working

This commit is contained in:
Pascal Serrarens 2026-03-09 17:49:55 +01:00
parent c1dcc83827
commit e709ea4e60
20 changed files with 698 additions and 4215 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 129468cd2362336149b803fa12f962c0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,146 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!206 &-7807188484574405462
BlendTree:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Blend Tree
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: b8a731a1533b8c960b3f3688d4922a24, type: 2}
m_Threshold: 0
m_Position: {x: 0, y: 1}
m_TimeScale: 10
m_CycleOffset: 0
m_DirectBlendParameter: Forward
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ab82ff68e62ea3b1c8e6523f8d46c142, type: 2}
m_Threshold: 0.5
m_Position: {x: -1, y: 0}
m_TimeScale: 5
m_CycleOffset: 0
m_DirectBlendParameter: Forward
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 91229db5e929c379bbfd5bf417848488, type: 2}
m_Threshold: 1
m_Position: {x: 1, y: 0}
m_TimeScale: 5
m_CycleOffset: 0
m_DirectBlendParameter: Forward
m_Mirror: 0
m_BlendParameter: Rotate
m_BlendParameterY: Forward
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_NormalizedBlendValues: 0
m_BlendType: 3
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: AntAnimator
serializedVersion: 5
m_AnimatorParameters:
- m_Name: Forward
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Rotate
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: 2310030155210667225}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1101 &2088305737403053393
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 1
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1107 &2310030155210667225
AnimatorStateMachine:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 5197032680816450026}
m_Position: {x: 80, y: 250, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 40, y: 500, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 5197032680816450026}
--- !u!1102 &5197032680816450026
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: AntWalk
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 2088305737403053393}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: -7807188484574405462}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: d4b9f32bef604abd5953647ad53ca0f7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 9100000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ab82ff68e62ea3b1c8e6523f8d46c142
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 91229db5e929c379bbfd5bf417848488
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b8a731a1533b8c960b3f3688d4922a24
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -11,12 +11,19 @@ namespace Passer.CreatureControl {
protected Creature creature;
public virtual void OnEnable() {
creature = (Creature)target;
creature = target as Creature;
if (creature == null)
return;
creature.targetToRootTranslation = creature.transform.position - creature.targetRig.transform.position;
creature.targetToRootRotation = Quaternion.Inverse(creature.targetRig.transform.rotation) * creature.transform.rotation;
serializedObject.Update();
if (!IsPrefab(creature))
InitTargets(creature);
InitTargets(creature);
serializedObject.ApplyModifiedProperties();
}
public static bool IsPrefab(Creature creature) {
@ -27,18 +34,40 @@ namespace Passer.CreatureControl {
#region Targets
protected virtual void InitTargets(Creature creature) {
TargetsRigInspector(creature, "TargetRig");
}
protected void TargetsRigInspector(Creature creature, string targetRigResourceName) {
Creature.CheckTargetRig(creature, targetRigResourceName);
if (creature.targetRig.gameObject.hideFlags != HideFlags.None) {
creature.targetRig.gameObject.hideFlags = HideFlags.None;
EditorApplication.DirtyHierarchyWindowSorting();
if (creature.CheckTargetRig("TargetRig")) {
EditorUtility.SetDirty(creature);
AssetDatabase.SaveAssets();
}
}
}
#endregion Targets
#endregion Targets
private bool initialize = true;
// public Vector3 targetToRootTranslation;
// public Quaternion targetToRootRotation;
public virtual void OnSceneGUI() {
if (Application.isPlaying)
return;
if (creature.enabled == false || creature.targetRig == null)
return;
// if (this.initialize) {
// creature.targetToRootTranslation = creature.transform.position - creature.targetRig.transform.position;
// creature.targetToRootRotation = Quaternion.Inverse(creature.targetRig.transform.rotation) * creature.transform.rotation;
// this.initialize = false;
// }
creature.targetRig.PoseLimbs();
creature.UpdateBones();
}
// protected virtual void UpdateBones() {
// Vector3 newPosition = creature.targetRig.transform.position + targetToRootTranslation;
// Quaternion newOrientation = creature.targetRig.transform.rotation * targetToRootRotation;
// creature.transform.SetPositionAndRotation(newPosition, newOrientation);
// }
}
}

View File

@ -11,38 +11,26 @@ namespace Passer.CreatureControl {
base.OnEnable();
insect = target as Insect;
insect.targetToRootTranslation = insect.transform.position - insect.targetRig.transform.position;
insect.targetToRootRotation = Quaternion.Inverse(insect.targetRig.transform.rotation) * insect.transform.rotation;
insect.targetRig.MatchTo(insect);
}
#region Inspector
public override void OnInspectorGUI() {
EditorGUIUtility.wideMode = true;
serializedObject.Update();
SerializedProperty targetRigProp = serializedObject.FindProperty(nameof(Creature.targetRig));
targetRigProp.objectReferenceValue = (TargetRig)EditorGUILayout.ObjectField("Target Rig", targetRigProp.objectReferenceValue, typeof(TargetRig), true);
TargetsInspector(insect);
// EditorGUILayout.Space();
// SerializedProperty leftFrontLegProp = serializedObject.FindProperty(nameof(Insect.leftFrontLeg));
// Leg_Editor.Inspector(leftFrontLegProp);
// SerializedProperty leftMiddleLegProp = serializedObject.FindProperty(nameof(Insect.leftMiddleLeg));
// Leg_Editor.Inspector(leftMiddleLegProp);
// SerializedProperty leftHindLegProp = serializedObject.FindProperty(nameof(Insect.leftHindLeg));
// Leg_Editor.Inspector(leftHindLegProp);
// SerializedProperty rightFrontLegProp = serializedObject.FindProperty(nameof(Insect.rightFrontLeg));
// Leg_Editor.Inspector(rightFrontLegProp);
// SerializedProperty rightMiddleLegProp = serializedObject.FindProperty(nameof(Insect.rightMiddleLeg));
// Leg_Editor.Inspector(rightMiddleLegProp);
// SerializedProperty rightHindLegProp = serializedObject.FindProperty(nameof(Insect.rightHindLeg));
// Leg_Editor.Inspector(rightHindLegProp);
TargetsInspector();
AnimatorInspector();
serializedObject.ApplyModifiedProperties();
}
static bool showTargets;
private void TargetsInspector(Insect insect) {
private void TargetsInspector() {
GUIContent text = new(
"Targets",
"The target transforms controlling the body parts"
@ -51,6 +39,7 @@ namespace Passer.CreatureControl {
if (showTargets) {
EditorGUI.indentLevel++;
SerializedProperty leftFrontLegProp = serializedObject.FindProperty(nameof(Insect.leftFrontLeg));
Leg_Editor.Inspector(leftFrontLegProp);
SerializedProperty leftMiddleLegProp = serializedObject.FindProperty(nameof(Insect.leftMiddleLeg));
@ -65,15 +54,73 @@ namespace Passer.CreatureControl {
SerializedProperty rightHindLegProp = serializedObject.FindProperty(nameof(Insect.rightHindLeg));
Leg_Editor.Inspector(rightHindLegProp);
// insect.headTarget = (HeadTarget)HumanoidTarget_Editor.Inspector(insect.headTarget, "Head Target");
// insect.leftHandTarget = (HandTarget)HandTarget_Editor.Inspector(insect.leftHandTarget, "Left Hand Target");
// insect.rightHandTarget = (HandTarget)HandTarget_Editor.Inspector(insect.rightHandTarget, "Right Hand Target");
// insect.hipsTarget = (HipsTarget)HumanoidTarget_Editor.Inspector(insect.hipsTarget, "Hips Target");
// insect.leftFootTarget = (FootTarget)FootTarget_Editor.Inspector(insect.leftFootTarget, "Left Foot Target");
// insect.rightFootTarget = (FootTarget)FootTarget_Editor.Inspector(insect.rightFootTarget, "Right Foot Target");
EditorGUI.indentLevel--;
}
}
private void AnimatorInspector() {
GUIContent text = new(
"Animator",
"Standard Unity Animator Controller for animating the character"
);
SerializedProperty targetRigProp = serializedObject.FindProperty(nameof(Insect.targetRig));
if (targetRigProp == null)
return;
SerializedObject targetRigObj = new(targetRigProp.objectReferenceValue);
SerializedProperty animatorControllerProp = targetRigObj.FindProperty(nameof(TargetRig.animator));
animatorControllerProp.objectReferenceValue = (Animator)EditorGUILayout.ObjectField(text, animatorControllerProp.objectReferenceValue, typeof(Animator), true);
}
#endregion Inspector
#region Scene
[System.NonSerialized]
private bool initialize = true;
public override void OnSceneGUI() {
if (Application.isPlaying)
return;
if (insect.enabled == false || insect.targetRig == null)
return;
// if (this.initialize) {
// this.targetToRootTranslation = insect.transform.position - insect.targetRig.transform.position;
// this.targetToRootRotation = Quaternion.Inverse(insect.targetRig.transform.rotation) * insect.transform.rotation;
// insect.targetRig.MatchTo(insect);
// this.initialize = false;
// }
insect.targetRig.PoseLimbs();
insect.UpdateBones();
}
// protected override void UpdateBones() {
// base.UpdateBones();
// if (insect.targetRig.leftFrontLeg != null)
// insect.targetRig.leftFrontLeg.UpdateBones(insect.leftFrontLeg);
// if (insect.targetRig.leftMiddleLeg != null)
// insect.targetRig.leftMiddleLeg.UpdateBones(insect.leftMiddleLeg);
// if (insect.targetRig.leftBackLeg != null)
// insect.targetRig.leftBackLeg.UpdateBones(insect.leftHindLeg);
// if (insect.targetRig.rightFrontLeg != null)
// insect.targetRig.rightFrontLeg.UpdateBones(insect.rightFrontLeg);
// if (insect.targetRig.rightMiddleLeg != null)
// insect.targetRig.rightMiddleLeg.UpdateBones(insect.rightMiddleLeg);
// if (insect.targetRig.rightBackLeg != null)
// insect.targetRig.rightBackLeg.UpdateBones(insect.rightHindLeg);
// }
#endregion Scene
}
}

View File

@ -2,25 +2,67 @@ using UnityEngine;
namespace Passer.CreatureControl {
public class Creature : MonoBehaviour {
/// <summary>The target bones rig</summary>
/// The target bones rig contain the target pose of the creature
/// The creature movements will try to move the creature such that the target pose is reached
/// as closely as possible
public TargetRig targetRig;
public class Creature : MonoBehaviour {
/// <summary>The target bones rig</summary>
/// The target bones rig contain the target pose of the creature
/// The creature movements will try to move the creature such that the target pose is reached
/// as closely as possible
public TargetRig targetRig;
public Transform creatureRig;
/// <summary>Match the target rig transform to the humanoid transform</summary>
public static void CheckTargetRig(Creature creature, string targetRigResourceName) {
if (creature.targetRig == null) {
GameObject targetsRigPrefab = Resources.Load<GameObject>(targetRigResourceName);
GameObject targetRig = Instantiate(targetsRigPrefab);
targetRig.name = "Target Rig";
public Vector3 targetToRootTranslation;
public Quaternion targetToRootRotation;
targetRig.transform.SetPositionAndRotation(creature.transform.position, creature.transform.rotation);
targetRig.transform.SetParent(creature.transform);
creature.targetRig = targetRig.GetComponent<TargetRig>();
/// <summary>
/// Ensure a target rig is available
/// </summary>
/// <param name="targetRigResourceName">The name of the target rig resource</param>
/// <returns>True when the creature rig has been updated</returns>
/// The parameter is used to instantiate a new target rig when none has been found.
public bool CheckTargetRig(string targetRigResourceName) {
if (this.targetRig == null) {
// See if there is a target rig, but we just haven't found it
this.targetRig = this.GetComponentInChildren<TargetRig>();
if (this.targetRig == null) {
GameObject targetsRigPrefab = Resources.Load<GameObject>(targetRigResourceName);
GameObject targetRig = Instantiate(targetsRigPrefab);
targetRig.name = "Target Rig";
targetRig.transform.SetPositionAndRotation(this.transform.position, this.transform.rotation);
targetRig.transform.SetParent(this.transform);
this.targetRig = targetRig.GetComponent<TargetRig>();
}
return true;
}
else
return false;
}
/// <summary>
/// Ensure that the creature rig is available
/// </summary>
/// <returns>True when the creature rig has been updated</returns>
public bool CheckCreatureRig() {
if (this.creatureRig == null) {
SkinnedMeshRenderer[] skinnedMeshRenderers = this.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers) {
Transform rendererParent = skinnedMeshRenderer.transform.parent;
if (this.creatureRig == null || this.creatureRig == rendererParent)
this.creatureRig = rendererParent;
else
Debug.LogWarning("Unclear avatar root");
}
return this.creatureRig != null;
}
else
return false;
}
public virtual void UpdateBones() {
Vector3 newPosition = this.targetRig.transform.position + targetToRootTranslation;
Quaternion newOrientation = this.targetRig.transform.rotation * targetToRootRotation;
this.transform.SetPositionAndRotation(newPosition, newOrientation);
}
}
}
}

View File

@ -9,5 +9,26 @@ namespace Passer.CreatureControl {
public Leg rightMiddleLeg;
public Leg rightHindLeg;
protected virtual void Update() {
UpdateBones();
}
public override void UpdateBones() {
base.UpdateBones();
if (this.targetRig.leftFrontLeg != null)
this.targetRig.leftFrontLeg.UpdateBones(this.leftFrontLeg);
if (this.targetRig.leftMiddleLeg != null)
this.targetRig.leftMiddleLeg.UpdateBones(this.leftMiddleLeg);
if (this.targetRig.leftBackLeg != null)
this.targetRig.leftBackLeg.UpdateBones(this.leftHindLeg);
if (this.targetRig.rightFrontLeg != null)
this.targetRig.rightFrontLeg.UpdateBones(this.rightFrontLeg);
if (this.targetRig.rightMiddleLeg != null)
this.targetRig.rightMiddleLeg.UpdateBones(this.rightMiddleLeg);
if (this.targetRig.rightBackLeg != null)
this.targetRig.rightBackLeg.UpdateBones(this.rightHindLeg);
}
}
}

View File

@ -14,7 +14,23 @@ namespace Passer.CreatureControl {
public Quaternion targetToBoneFemur;
public Quaternion targetToBoneTibia;
private void Start() { }
public void MatchTo(Leg leg) {
this.femurTarget.position = leg.femur.position;
this.tibiaTarget.position = leg.tibia.position;
this.tarsusTarget.position = leg.tarsus.position;
targetToBoneFemur = TargetRig.TargetToBoneRotation(leg.femur, leg.tibia);
targetToBoneTibia = TargetRig.TargetToBoneRotation(leg.tibia, leg.tarsus);
this.target.position = this.tarsusTarget.position;
this.target.rotation = this.tarsusTarget.rotation;
}
public virtual void OnDrawGizmosSelected() {
if (this.enabled == false)
return;
if (target != null && legTarget == null) {
legTarget = target.GetComponent<LegTarget>();
if (legTarget == null)
@ -28,21 +44,28 @@ namespace Passer.CreatureControl {
if (tibiaTarget != null && this.tarsusTarget != null)
Gizmos.DrawLine(this.tibiaTarget.position, this.tarsusTarget.position);
if (this.enabled)
PoseLimb();
PoseLimb();
}
/// <summary>
/// Pose the target limb
/// </summary>
public void PoseLimb() {
if (target == null)
return;
Quaternion femurOrientation = FemurRotation(target.position);
Quaternion tibiaOrientation = TibiaRotation(target.position);
Quaternion tarsusrientation = TarsusRotation(target.rotation);
Quaternion tarsusOrientation = TarsusRotation(target.rotation);
SetFemurOrientation(femurTarget, femurOrientation);
SetTibiaOrientation(tibiaTarget, tibiaOrientation);
SetTarsusOrientation(tarsusTarget, tarsusrientation);
femurTarget.rotation = femurOrientation;
tibiaTarget.rotation = tibiaOrientation;
tarsusTarget.rotation = tarsusOrientation;
}
public void UpdateBones(Leg leg) {
UpdateFemur(leg.femur);
UpdateTibia(leg.tibia);
}
protected Quaternion FemurRotation(Vector3 targetPosition) {
@ -83,45 +106,6 @@ namespace Passer.CreatureControl {
return targetRotation;
}
private void SetFemurOrientation(Transform bone, Quaternion orientation) {
if (this.femurTarget == null)
return;
// Debug.DrawRay(femur.position, orientation * Vector3.forward, Color.blue);
// Debug.DrawRay(femur.position, orientation * Vector3.up, Color.green);
bone.rotation = orientation;
}
private void SetTibiaOrientation(Transform bone, Quaternion orientation) {
if (this.tibiaTarget == null)
return;
bone.rotation = orientation;
}
private void SetTarsusOrientation(Transform bone, Quaternion orientation) {
if (this.tarsusTarget == null)
return;
bone.rotation = orientation;
}
// public void MatchToCreature(Transform femurBone, Transform tibiaBone, Transform tarsusBone) {
// TargetRig.MoveTargetToBone(femurTarget, femurBone);
// TargetRig.MoveTargetToBone(tibiaTarget, tibiaBone);
// TargetRig.MoveTargetToBone(tarsusTarget, tarsusBone);
// targetToBoneFemur = TargetRig.TargetToBoneRotation(femurBone, tibiaBone);
// targetToBoneTibia = TargetRig.TargetToBoneRotation(tibiaBone, tarsusBone);
// }
public void MatchToCreature(Leg leg) {
TargetRig.MoveTargetToBone(this.femurTarget, leg.femur);
TargetRig.MoveTargetToBone(this.tibiaTarget, leg.tibia);
TargetRig.MoveTargetToBone(this.tarsusTarget, leg.tarsus);
targetToBoneFemur = TargetRig.TargetToBoneRotation(leg.femur, leg.tibia);
targetToBoneTibia = TargetRig.TargetToBoneRotation(leg.tibia, leg.tarsus);
}
public void UpdateFemur(Transform femurBone) {
if (femurBone == null || this.femurTarget == null)
return;
@ -136,15 +120,6 @@ namespace Passer.CreatureControl {
tibiaBone.rotation = this.tibiaTarget.rotation * targetToBoneTibia;
}
// public void UpdateBones(Transform femurBone, Transform tibiaBone) {
// UpdateFemur(femurBone);
// UpdateTibia(tibiaBone);
// }
public void UpdateBones(Leg leg) {
UpdateFemur(leg.femur);
UpdateTibia(leg.tibia);
}
#region Math
public static float CosineRule(float a, float b, float c) {

View File

@ -15,38 +15,31 @@ namespace Passer.CreatureControl {
public Animator animator;
public void PoseLimbs() {
leftBackLeg.PoseLimb();
leftMiddleLeg.PoseLimb();
leftFrontLeg.PoseLimb();
rightBackLeg.PoseLimb();
rightMiddleLeg.PoseLimb();
rightFrontLeg.PoseLimb();
this.leftBackLeg.PoseLimb();
this.leftMiddleLeg.PoseLimb();
this.leftFrontLeg.PoseLimb();
this.rightBackLeg.PoseLimb();
this.rightMiddleLeg.PoseLimb();
this.rightFrontLeg.PoseLimb();
}
public void MatchTo(Insect insect) {
if (insect == null)
return;
if (leftFrontLeg != null && insect.leftFrontLeg != null)
leftFrontLeg.MatchToCreature(insect.leftFrontLeg);
if (leftMiddleLeg != null && insect.leftMiddleLeg != null)
leftMiddleLeg.MatchToCreature(insect.leftMiddleLeg);
if (leftBackLeg != null && insect.leftHindLeg != null)
leftBackLeg.MatchToCreature(insect.leftHindLeg);
if (rightFrontLeg != null && insect.rightFrontLeg != null)
rightFrontLeg.MatchToCreature(insect.rightFrontLeg);
if (rightMiddleLeg != null && insect.rightMiddleLeg != null)
rightMiddleLeg.MatchToCreature(insect.rightMiddleLeg);
if (rightBackLeg != null && insect.rightHindLeg != null)
rightBackLeg.MatchToCreature(insect.rightHindLeg);
}
if (this.leftFrontLeg != null && insect.leftFrontLeg != null)
this.leftFrontLeg.MatchTo(insect.leftFrontLeg);
if (this.leftMiddleLeg != null && insect.leftMiddleLeg != null)
this.leftMiddleLeg.MatchTo(insect.leftMiddleLeg);
if (this.leftBackLeg != null && insect.leftHindLeg != null)
this.leftBackLeg.MatchTo(insect.leftHindLeg);
public static void MoveTargetToBone(Transform target, Transform bone) {
if (target == null || bone == null)
return;
target.position = bone.position;
if (this.rightFrontLeg != null && insect.rightFrontLeg != null)
this.rightFrontLeg.MatchTo(insect.rightFrontLeg);
if (this.rightMiddleLeg != null && insect.rightMiddleLeg != null)
this.rightMiddleLeg.MatchTo(insect.rightMiddleLeg);
if (this.rightBackLeg != null && insect.rightHindLeg != null)
this.rightBackLeg.MatchTo(insect.rightHindLeg);
}
public static Quaternion TargetToBoneRotation(Transform bone, Transform nextBone) {

View File

@ -8,14 +8,16 @@ namespace Passer.CreatureControl {
protected Ant ant;
public override void OnEnable() {
base.OnEnable();
this.ant = target as Ant;
base.OnEnable();
}
protected override void InitTargets(Creature creature) {
TargetsRigInspector(creature, "InsectTargetRig");
creature.targetRig.MatchTo(ant);
if (creature.CheckTargetRig("InsectTargetRig")) {
EditorUtility.SetDirty(creature);
AssetDatabase.SaveAssets();
}
}
}

View File

@ -10,17 +10,17 @@ public class NanoBrainComponent_Editor : Editor {
protected static VisualElement inspectorContainer;
protected NanoBrain component;
private SerializedProperty brainProp;
// private SerializedProperty brainProp;
ClusterInspector.GraphView board;
// ClusterInspector.GraphView board;
public void OnEnable() {
component = target as NanoBrain;
if (Application.isPlaying == false && serializedObject != null) {
string propertyName = nameof(NanoBrain.defaultBrain);
brainProp = serializedObject.FindProperty(propertyName);
}
// if (Application.isPlaying == false) {
// string propertyName = nameof(NanoBrain.defaultBrain);
// brainProp = serializedObject.FindProperty(propertyName);
// }
}
public override VisualElement CreateInspectorGUI() {
@ -32,6 +32,7 @@ public class NanoBrainComponent_Editor : Editor {
VisualElement root = new();
if (Application.isPlaying == false) {
SerializedProperty brainProp = serializedObject.FindProperty(nameof(NanoBrain.defaultBrain));
PropertyField brainField = new(brainProp) {
label = "Nano Brain"
};

View File

@ -24,9 +24,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 217096157536176665}
serializedVersion: 2
m_LocalRotation: {x: 0.74910194, y: 0.00000013411044, z: -0.000000059604638, w: 0.6624548}
m_LocalPosition: {x: -0.0000000060071543, y: 0.000000016929238, z: 0.017614825}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalRotation: {x: 0.77590793, y: 0.0000000745058, z: -0, w: 0.6308461}
m_LocalPosition: {x: 0.0000000055879354, y: -0.000000052154064, z: 0.060080294}
m_LocalScale: {x: 1, y: 1.0000001, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2520372565419969361}
@ -59,7 +59,7 @@ Transform:
serializedVersion: 2
m_LocalRotation: {x: -0.30156508, y: 0.57948434, z: 0.24379016, w: 0.71681434}
m_LocalPosition: {x: 0.02, y: 0.04, z: -0.045}
m_LocalScale: {x: 3.4107811, y: 3.4107819, z: 3.4107828}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7566832081299524197}
@ -80,7 +80,7 @@ MonoBehaviour:
femurTarget: {fileID: 2087731612450819825}
tibiaTarget: {fileID: 7566832081299524197}
tarsusTarget: {fileID: 7011186323915432702}
target: {fileID: 0}
target: {fileID: 8947192729555298471}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &714113386832462525
@ -120,6 +120,7 @@ Transform:
- {fileID: 976560727556484423}
- {fileID: 2087731612450819825}
- {fileID: 7879963364189984297}
- {fileID: 7749216888518554378}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5050182668285619700
@ -186,8 +187,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 816003872898039836}
serializedVersion: 2
m_LocalRotation: {x: -0.3146679, y: 0.17643316, z: 0.007831901, w: -0.9326276}
m_LocalPosition: {x: 0.0000000016946835, y: -0.0000000055879354, z: 0.024077274}
m_LocalRotation: {x: -0.43374863, y: 0.17390014, z: 0.030802093, w: -0.8835565}
m_LocalPosition: {x: 0.000000005601242, y: -0.000000011175871, z: 0.08212241}
m_LocalScale: {x: 0.9999999, y: 0.9999999, z: 0.9999999}
m_ConstrainProportionsScale: 0
m_Children: []
@ -218,9 +219,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1193554740936415000}
serializedVersion: 2
m_LocalRotation: {x: -0.17473988, y: 0.20808172, z: 0.03781085, w: 0.9616332}
m_LocalRotation: {x: -0.17474017, y: 0.20808172, z: 0.03781092, w: 0.96163315}
m_LocalPosition: {x: 0.02, y: 0.04, z: -0.02}
m_LocalScale: {x: 3.4107826, y: 3.4107833, z: 3.410782}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3873135409852464941}
@ -241,9 +242,88 @@ MonoBehaviour:
femurTarget: {fileID: 976560727556484423}
tibiaTarget: {fileID: 3873135409852464941}
tarsusTarget: {fileID: 3355004770557811387}
target: {fileID: 0}
target: {fileID: 2041764967651498327}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &1274558016778403244
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5063380583403966759}
- component: {fileID: 5901752940167040716}
m_Layer: 0
m_Name: LeftFront_Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5063380583403966759
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1274558016778403244}
serializedVersion: 2
m_LocalRotation: {x: 0.10340257, y: 0.19714029, z: 0.72879976, w: 0.6475296}
m_LocalPosition: {x: -0.046431404, y: 0, z: 0.03821565}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 7205358139259001258}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5901752940167040716
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1274558016778403244}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fda62ae0dd837da8cb37ba5c7396c6a3, type: 3}
m_Name:
m_EditorClassIdentifier:
leg: {fileID: 5655676289343650514}
--- !u!1 &1311826990935111104
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7205358139259001258}
m_Layer: 0
m_Name: RightFeetTarget
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7205358139259001258
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1311826990935111104}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5063380583403966759}
- {fileID: 8947192729555298471}
- {fileID: 2714894253296331867}
m_Father: {fileID: 7749216888518554378}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1584550513300851516
GameObject:
m_ObjectHideFlags: 0
@ -269,9 +349,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1584550513300851516}
serializedVersion: 2
m_LocalRotation: {x: -0.08576885, y: 0.91269386, z: 0.3088702, w: 0.25344208}
m_LocalRotation: {x: -0.08576884, y: 0.9126938, z: 0.30887017, w: 0.25344205}
m_LocalPosition: {x: 0.02, y: 0.04, z: -0.06}
m_LocalScale: {x: 3.410783, y: 3.4107823, z: 3.4107835}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8557148899078362646}
@ -292,9 +372,54 @@ MonoBehaviour:
femurTarget: {fileID: 7879963364189984297}
tibiaTarget: {fileID: 8557148899078362646}
tarsusTarget: {fileID: 2520372565419969361}
target: {fileID: 0}
target: {fileID: 5692380185316106944}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &1713014906338526394
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2041764967651498327}
- component: {fileID: 5161185486818915569}
m_Layer: 0
m_Name: RightFront_Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2041764967651498327
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1713014906338526394}
serializedVersion: 2
m_LocalRotation: {x: -0.30181327, y: -0.7707289, z: -0.53122467, w: -0.18079302}
m_LocalPosition: {x: 0.0464314, y: 0, z: 0.038215645}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5423145689824655178}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5161185486818915569
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1713014906338526394}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fda62ae0dd837da8cb37ba5c7396c6a3, type: 3}
m_Name:
m_EditorClassIdentifier:
leg: {fileID: 5856460076900731150}
--- !u!1 &1864955302254048131
GameObject:
m_ObjectHideFlags: 0
@ -319,8 +444,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1864955302254048131}
serializedVersion: 2
m_LocalRotation: {x: 0.80736995, y: 0.0000005066394, z: -0.000000059604638, w: 0.59004563}
m_LocalPosition: {x: -0.000000010239469, y: 0.0000000013652621, z: 0.014121527}
m_LocalRotation: {x: 0.80736995, y: 0.0000005364418, z: -0.000000059604645, w: 0.5900456}
m_LocalPosition: {x: -0.000000037252903, y: 0.000000004656613, z: 0.048165448}
m_LocalScale: {x: 0.9999998, y: 1, z: 1.0000001}
m_ConstrainProportionsScale: 0
m_Children:
@ -351,13 +476,58 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1915398292779927248}
serializedVersion: 2
m_LocalRotation: {x: -0.3146679, y: 0.17643316, z: 0.007831901, w: -0.9326276}
m_LocalPosition: {x: 0.0000000016946835, y: -0.0000000055879354, z: 0.024077274}
m_LocalScale: {x: 0.9999999, y: 0.9999999, z: 0.9999999}
m_LocalRotation: {x: 0.48380893, y: -0.27507204, z: 0.20774257, w: 0.8044298}
m_LocalPosition: {x: -0.000000012424491, y: 0.000000059604638, z: 0.08482451}
m_LocalScale: {x: 1, y: 0.9999999, z: 0.9999999}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8557148899078362646}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &3332996726411066313
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2714894253296331867}
- component: {fileID: 1809147440043247228}
m_Layer: 0
m_Name: LeftHind_Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2714894253296331867
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3332996726411066313}
serializedVersion: 2
m_LocalRotation: {x: 0.31411165, y: -0.6442087, z: 0.69609904, w: 0.042132646}
m_LocalPosition: {x: -0.06812622, y: 0, z: -0.13232349}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 7205358139259001258}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1809147440043247228
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3332996726411066313}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fda62ae0dd837da8cb37ba5c7396c6a3, type: 3}
m_Name:
m_EditorClassIdentifier:
leg: {fileID: 3124099709297356894}
--- !u!1 &3399675694450404938
GameObject:
m_ObjectHideFlags: 0
@ -382,9 +552,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3399675694450404938}
serializedVersion: 2
m_LocalRotation: {x: -0.08555651, y: 0.6380308, z: 0.42223927, w: 0.63820904}
m_LocalPosition: {x: -0.00000001637985, y: -0.0000000055879363, z: 0.017485214}
m_LocalScale: {x: 0.99999994, y: 0.99999994, z: 1}
m_LocalRotation: {x: -0.085556746, y: 0.63803077, z: 0.42223954, w: 0.638209}
m_LocalPosition: {x: -0.0000000013192283, y: 0.000000007450581, z: 0.05963828}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8607306932134183899}
@ -413,8 +583,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3451781382000154612}
serializedVersion: 2
m_LocalRotation: {x: -0.44156942, y: -0.45806083, z: -0.5668181, w: -0.5233678}
m_LocalPosition: {x: 0.000000013656518, y: 0, z: 0.024214728}
m_LocalRotation: {x: -0.4415694, y: -0.45806083, z: -0.5668182, w: -0.52336776}
m_LocalPosition: {x: 0.00000003946985, y: 0.000000007450581, z: 0.08259117}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -444,13 +614,170 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4305921432289450317}
serializedVersion: 2
m_LocalRotation: {x: -0.08555651, y: 0.6380308, z: 0.42223927, w: 0.63820904}
m_LocalPosition: {x: -0.00000001637985, y: -0.0000000055879363, z: 0.017485214}
m_LocalScale: {x: 0.99999994, y: 0.99999994, z: 1}
m_LocalRotation: {x: 0.0186554, y: -0.91329664, z: -0.13089564, w: -0.3852372}
m_LocalPosition: {x: -0.000000002654222, y: -0.000000018626451, z: 0.06042937}
m_LocalScale: {x: 1.0000001, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3873135409852464941}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4660290424194713574
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5692380185316106944}
- component: {fileID: 3728648486592150019}
m_Layer: 0
m_Name: RighHind_Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5692380185316106944
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4660290424194713574}
serializedVersion: 2
m_LocalRotation: {x: 0.25241286, y: 0.31570747, z: -0.7996064, w: 0.44412404}
m_LocalPosition: {x: 0.06352237, y: 0, z: -0.13232347}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5423145689824655178}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3728648486592150019
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4660290424194713574}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fda62ae0dd837da8cb37ba5c7396c6a3, type: 3}
m_Name:
m_EditorClassIdentifier:
leg: {fileID: 8323677930838830493}
--- !u!1 &5154280738306998510
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7749216888518554378}
m_Layer: 0
m_Name: Body
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7749216888518554378
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5154280738306998510}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5423145689824655178}
- {fileID: 7205358139259001258}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &5247258062333951271
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8947192729555298471}
- component: {fileID: 2480483197969394137}
m_Layer: 0
m_Name: RightMiddle_Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8947192729555298471
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5247258062333951271}
serializedVersion: 2
m_LocalRotation: {x: 0.096186325, y: 0.093534976, z: -0.9225138, w: 0.36189467}
m_LocalPosition: {x: 0.09000008, y: 0, z: -0.030000018}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 7205358139259001258}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2480483197969394137
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5247258062333951271}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fda62ae0dd837da8cb37ba5c7396c6a3, type: 3}
m_Name:
m_EditorClassIdentifier:
leg: {fileID: 4196034226083389076}
--- !u!1 &5294138259856841286
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5423145689824655178}
m_Layer: 0
m_Name: LeftFeetTarget
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5423145689824655178
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5294138259856841286}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2041764967651498327}
- {fileID: 8660658904332009209}
- {fileID: 5692380185316106944}
m_Father: {fileID: 7749216888518554378}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &5930454242050132924
GameObject:
m_ObjectHideFlags: 0
@ -476,9 +803,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5930454242050132924}
serializedVersion: 2
m_LocalRotation: {x: 0.08395476, y: 0.91604495, z: 0.27771258, w: -0.27692783}
m_LocalRotation: {x: 0.083954774, y: 0.9160449, z: 0.27771264, w: -0.2769278}
m_LocalPosition: {x: -0.02, y: 0.04, z: -0.06}
m_LocalScale: {x: 3.4107823, y: 3.4107852, z: 3.410783}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6229249450306020558}
@ -499,7 +826,7 @@ MonoBehaviour:
femurTarget: {fileID: 1138231466888029713}
tibiaTarget: {fileID: 6229249450306020558}
tarsusTarget: {fileID: 3473835942814004862}
target: {fileID: 0}
target: {fileID: 2714894253296331867}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &6227205784071755847
@ -526,9 +853,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6227205784071755847}
serializedVersion: 2
m_LocalRotation: {x: 0.65185237, y: -0.00000028312206, z: 0.000000113621354, w: 0.7583459}
m_LocalPosition: {x: 0.000000004914944, y: -0.0000000049149436, z: 0.011160721}
m_LocalScale: {x: 1, y: 0.9999999, z: 0.99999994}
m_LocalRotation: {x: 0.6518526, y: -0, z: -0.0000000018626451, w: 0.7583457}
m_LocalPosition: {x: 0.0000000018626451, y: 0, z: 0.038066804}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5350519918537018444}
@ -558,9 +885,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6521710740082976927}
serializedVersion: 2
m_LocalRotation: {x: 0.65185237, y: -0.00000028312206, z: 0.000000113621354, w: 0.7583459}
m_LocalPosition: {x: 0.000000004914944, y: -0.0000000049149436, z: 0.011160721}
m_LocalScale: {x: 1, y: 0.9999999, z: 0.99999994}
m_LocalRotation: {x: 0.6604676, y: 0.00000008940697, z: -0.000000040978193, w: 0.7508546}
m_LocalPosition: {x: -0.0000000037252903, y: -0.000000018626451, z: 0.038066793}
m_LocalScale: {x: 0.99999994, y: 1, z: 0.99999994}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3355004770557811387}
@ -591,9 +918,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6621691774974300190}
serializedVersion: 2
m_LocalRotation: {x: -0.29419467, y: -0.5819551, z: -0.23783171, w: 0.7198708}
m_LocalRotation: {x: -0.2941947, y: -0.581955, z: -0.23783173, w: 0.71987075}
m_LocalPosition: {x: -0.02, y: 0.04, z: -0.045}
m_LocalScale: {x: 3.410782, y: 3.410783, z: 3.4107823}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5102382635668602733}
@ -614,7 +941,7 @@ MonoBehaviour:
femurTarget: {fileID: 5158943779127512027}
tibiaTarget: {fileID: 5102382635668602733}
tarsusTarget: {fileID: 5832494694235077857}
target: {fileID: 0}
target: {fileID: 8660658904332009209}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &6934656281848074513
@ -641,8 +968,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6934656281848074513}
serializedVersion: 2
m_LocalRotation: {x: -0.44156942, y: -0.45806083, z: -0.5668181, w: -0.5233678}
m_LocalPosition: {x: 0.000000013656518, y: 0, z: 0.024214728}
m_LocalRotation: {x: 0.38045272, y: -0.47525725, z: -0.4792211, w: 0.63224477}
m_LocalPosition: {x: -0.000000022731541, y: 0.000000044703476, z: 0.0835303}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -672,9 +999,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8313487703600456217}
serializedVersion: 2
m_LocalRotation: {x: 0.80736995, y: 0.0000005066394, z: -0.000000059604638, w: 0.59004563}
m_LocalPosition: {x: -0.000000010239469, y: 0.0000000013652621, z: 0.014121527}
m_LocalScale: {x: 0.9999998, y: 1, z: 1.0000001}
m_LocalRotation: {x: 0.8123012, y: -0.000000059604645, z: -0.000000044703484, w: 0.58323824}
m_LocalPosition: {x: -0.0000000060535967, y: 0.000000013969839, z: 0.048165455}
m_LocalScale: {x: 1, y: 1.0000001, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7011186323915432702}
@ -704,8 +1031,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8534431202702769095}
serializedVersion: 2
m_LocalRotation: {x: 0.74910194, y: 0.00000013411044, z: -0.000000059604638, w: 0.6624548}
m_LocalPosition: {x: -0.0000000060071543, y: 0.000000016929238, z: 0.017614825}
m_LocalRotation: {x: 0.65619105, y: 0.00000010430813, z: 0.000000014901161, w: 0.7545948}
m_LocalPosition: {x: -0.000000018626451, y: 0.051201936, z: 0.0314326}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
@ -737,9 +1064,9 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9008164333968854526}
serializedVersion: 2
m_LocalRotation: {x: -0.16464043, y: -0.208467, z: -0.035625506, w: 0.96341366}
m_LocalRotation: {x: -0.16464062, y: -0.208467, z: -0.035625543, w: 0.96341366}
m_LocalPosition: {x: -0.02, y: 0.04, z: -0.02}
m_LocalScale: {x: 3.4107828, y: 3.410783, z: 3.4107833}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8607306932134183899}
@ -760,6 +1087,51 @@ MonoBehaviour:
femurTarget: {fileID: 7827425323228862897}
tibiaTarget: {fileID: 8607306932134183899}
tarsusTarget: {fileID: 5350519918537018444}
target: {fileID: 0}
target: {fileID: 5063380583403966759}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &9173392299445808517
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8660658904332009209}
- component: {fileID: 1575680200966242828}
m_Layer: 0
m_Name: LeftMiddle_Target
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8660658904332009209
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9173392299445808517}
serializedVersion: 2
m_LocalRotation: {x: -0.05136092, y: 0.062381554, z: -0.97098094, w: -0.22509275}
m_LocalPosition: {x: -0.090000086, y: 0, z: -0.03}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5423145689824655178}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1575680200966242828
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9173392299445808517}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fda62ae0dd837da8cb37ba5c7396c6a3, type: 3}
m_Name:
m_EditorClassIdentifier:
leg: {fileID: 6327345715726789984}

View File

@ -26,7 +26,6 @@ namespace Passer.CreatureControl {
public Receptor foodReceptor;
public Receptor homeReceptor;
public new Rigidbody rigidbody;
public Animator animator;
public float forwardSpeed = 1;
public float rotationSpeed = 1;
@ -34,23 +33,18 @@ namespace Passer.CreatureControl {
public Vector3 angularVelocity;
protected virtual void Awake() {
this.animator = GetComponentInChildren<Animator>();
if (this.animator == null && this.transform.parent != null)
this.animator = this.transform.parent.GetComponentInChildren<Animator>();
if (this.targetRig != null)
this.animator = this.targetRig.animator;
this.nanoBrain = GetComponentInChildren<NanoBrain>();
this.rigidbody = GetComponentInParent<Rigidbody>();
this.rigidbody.isKinematic = false;
}
void Start() {
Cluster brain = this.nanoBrain.brain;
if (brain != null) {
// brain outputs
this.pheromoneSteering = brain.GetNucleus("Pheromone Steering");
if (brain.GetNucleus("Home Pheromones") is Neuron homePheromones)
homePheromones.WhenFiring += PlaceHomePheromone;
if (brain.GetNucleus("Food Pheromones") is Neuron foodPheromones)
@ -84,7 +78,9 @@ namespace Passer.CreatureControl {
}
// Update is called once per frame
void Update() {
protected override void Update() {
base.Update();
UpdateBeat();
UpdateSmell();
@ -95,9 +91,7 @@ namespace Passer.CreatureControl {
this.linearVelocity = (1 - inertia) * (Time.deltaTime * localForce.normalized) + inertia * this.linearVelocity;
this.linearVelocity = this.linearVelocity.normalized * 0.2f;
// Vector3 linearVelocityWorld = this.transform.TransformVector(this.linearVelocity);
// this.rigidbody.linearVelocity = linearVelocityWorld;
this.animator.SetFloat("forward speed", this.linearVelocity.z * this.forwardSpeed);
this.animator.SetFloat("Forward", this.linearVelocity.z * this.forwardSpeed);
// Rotate towards the movement direction
if (this.linearVelocity != Vector3.zero) {
@ -113,9 +107,7 @@ namespace Passer.CreatureControl {
LinearAlgebra.Angles.Normalize(eulerAngleChange.z)
);
Vector3 angularVelocity = 5f * Mathf.Deg2Rad * eulerAngleChange;
//rigidbody.angularVelocity = angularVelocity;
this.animator.SetFloat("rotate speed", eulerAngleChange.y / 45 * this.rotationSpeed);
this.animator.SetFloat("Rotate", eulerAngleChange.y / 45 * this.rotationSpeed);
}
}
@ -123,7 +115,7 @@ namespace Passer.CreatureControl {
float lastBeatTime = 0;
void UpdateBeat() {
if (lastBeatTime == 0) {
ulong delay = (ulong)(UnityEngine.Random.value * beatInterval);
ulong delay = (ulong)(Random.value * beatInterval);
lastBeatTime = Time.time - delay;
}
if (Time.time - lastBeatTime >= beatInterval) {
@ -152,22 +144,6 @@ namespace Passer.CreatureControl {
Pheromone pheromone = thing.GetComponentInParent<Pheromone>();
if (pheromone == null)
return;
// if (hasFood == null)
// return;
// if ((hasFood.outputValue.x > 0 && pheromone.type == Pheromone.Type.Home) ||
// (hasFood.outputValue.x < 0 && pheromone.type == Pheromone.Type.Food)) {
// Vector3 smellDirection = this.transform.InverseTransformPoint(pheromone.transform.position);
// float distance = smellDirection.magnitude;
// float angle = Vector3.Angle(Vector3.forward, smellDirection);
// if (angle < smellAngle && smellDirection.magnitude > 0.05) {
// float intensity = pheromone.StrengthAt(distance);//strength * (1 / distance);
// pheromoneSteering?.ProcessStimulus(pheromone.GetInstanceID(), smellDirection.normalized * intensity,
// pheromone.type.ToString() + " pheromone");
// //Debug.DrawLine(this.transform.position, pheromone.transform.position, Color.magenta);
// }
// }
Vector3 smellDirection = this.transform.InverseTransformPoint(pheromone.transform.position);
float distance = smellDirection.magnitude;
@ -177,12 +153,9 @@ namespace Passer.CreatureControl {
Vector3 smell = smellDirection.normalized * intensity;
switch (pheromone.type) {
case Pheromone.Type.Food:
//foodSmell?.ProcessStimulus(pheromone.GetInstanceID(), smell, "food pheromone");
foodReceptor?.ProcessStimulus(smellDirection.normalized * intensity, pheromone.GetInstanceID(), "food pheromone");
break;
case Pheromone.Type.Home:
//pheromoneSteering?.ProcessStimulus(pheromone.GetInstanceID(), smell, "home pheromone");
//homeSmell?.ProcessStimulus(pheromone.GetInstanceID(), smell, "home pheromone");
homeReceptor?.ProcessStimulus(smellDirection.normalized * intensity, pheromone.GetInstanceID(), "home pheromone");
break;
}
@ -204,8 +177,7 @@ namespace Passer.CreatureControl {
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && distance > 0.05) {
float intensity = food.StrengthAt(distance); //strength * (1 / distance);
//foodSmell?.ProcessStimulus(food.GetInstanceID(), smellDirection.normalized * intensity, "food");
float intensity = food.StrengthAt(distance);
foodReceptor?.ProcessStimulus(smellDirection.normalized * intensity, food.GetInstanceID(), "food");
Debug.DrawLine(this.transform.position, food.transform.position, Color.red);
}
@ -224,8 +196,7 @@ namespace Passer.CreatureControl {
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && distance > 0.05) {
float intensity = nest.StrengthAt(distance); //strength * (1 / distance);
//homeSmell?.ProcessStimulus(nest.GetInstanceID(), smellDirection.normalized * intensity, "nest");
float intensity = nest.StrengthAt(distance);
Vector3 value = smellDirection.normalized * intensity;
homeReceptor?.ProcessStimulus(value, nest.GetInstanceID(), "nest");
Debug.DrawLine(this.transform.position, nest.transform.position, Color.red);
@ -236,13 +207,13 @@ namespace Passer.CreatureControl {
Vector3 touchDirection = Vector3.zero;
if (isTouching)
touchDirection = this.transform.InverseTransformVector(touchLeft.transform.forward);
hitLeft?.SetBias(touchDirection); //, other.GetInstanceID(), "Touch Left");
hitLeft?.SetBias(touchDirection);
}
void OnAntennaTouchRight(Collider other, bool isTouching) {
Vector3 touchDirection = Vector3.zero;
if (isTouching)
touchDirection = this.transform.InverseTransformVector(touchRight.transform.forward);
hitRight?.SetBias(touchDirection); //, other.GetInstanceID(), "Touch Right");
hitRight?.SetBias(touchDirection);
}
}

View File

@ -4,7 +4,6 @@ using UnityEngine;
namespace Passer.CreatureControl {
public class AntsNest : Odorant {
public Ant antPrefab;
public uint numberOfAnts = 1;
public bool spawnAnt = false;
@ -13,14 +12,18 @@ namespace Passer.CreatureControl {
protected virtual void Start() {
StartCoroutine(SpawnAnts());
}
private static readonly WaitForSeconds _waitForSeconds0_2 = new(0.2f);
IEnumerator SpawnAnts() {
while (numberOfAnts > 0) {
Ant ant = Instantiate(antPrefab);
ant.transform.eulerAngles = 360 * Random.value * Vector3.up;
ant.transform.position = this.transform.position + ant.transform.forward * 0.1F;
ant.name = "Ant " + (++antCount);
numberOfAnts--;
yield return new WaitForSeconds(0.2f);
if (antPrefab != null) {
while (numberOfAnts > 0) {
Ant ant = Instantiate(antPrefab);
ant.transform.eulerAngles = 360 * Random.value * Vector3.up;
ant.transform.position = this.transform.position + ant.transform.forward * 0.1F;
ant.name = "Ant " + (++antCount);
numberOfAnts--;
yield return _waitForSeconds0_2;
}
}
}