Updating swarm weights
This commit is contained in:
parent
a1d1f7ba24
commit
c86b01ae57
@ -52,6 +52,7 @@
|
|||||||
<Compile Include="Assets/NanoBrain/VisualEditor/Editor/NanoBrainEditor.cs" />
|
<Compile Include="Assets/NanoBrain/VisualEditor/Editor/NanoBrainEditor.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/VisualEditor/Editor/NanoBrainInspector.cs" />
|
<Compile Include="Assets/NanoBrain/VisualEditor/Editor/NanoBrainInspector.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/Editor/NanoBrain_Editor.cs" />
|
<Compile Include="Assets/NanoBrain/Editor/NanoBrain_Editor.cs" />
|
||||||
|
<Compile Include="Assets/Scenes/Boids/Scripts/Editor/SwarmControl_Editor.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/Editor/NeuroidWindow.cs" />
|
<Compile Include="Assets/NanoBrain/Editor/NeuroidWindow.cs" />
|
||||||
<Compile Include="Assets/NanoBrain/VisualEditor/Editor/NanoBrainComponent_Editor.cs" />
|
<Compile Include="Assets/NanoBrain/VisualEditor/Editor/NanoBrainComponent_Editor.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -8,15 +8,18 @@ public class NanoBrainComponent_Editor : Editor {
|
|||||||
protected static VisualElement mainContainer;
|
protected static VisualElement mainContainer;
|
||||||
protected static VisualElement inspectorContainer;
|
protected static VisualElement inspectorContainer;
|
||||||
|
|
||||||
|
protected NanoBrainComponent component;
|
||||||
private SerializedProperty brainProp;
|
private SerializedProperty brainProp;
|
||||||
|
|
||||||
public void OnEnable() {
|
public void OnEnable() {
|
||||||
|
component = target as NanoBrainComponent;
|
||||||
|
|
||||||
if (Application.isPlaying == false)
|
if (Application.isPlaying == false)
|
||||||
brainProp = serializedObject.FindProperty(nameof(NanoBrainComponent.defaultBrain));
|
brainProp = serializedObject.FindProperty(nameof(NanoBrainComponent.defaultBrain));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override VisualElement CreateInspectorGUI() {
|
public override VisualElement CreateInspectorGUI() {
|
||||||
NanoBrainComponent component = target as NanoBrainComponent;
|
//NanoBrainComponent component = target as NanoBrainComponent;
|
||||||
NanoBrainObj brain = Application.isPlaying ? component.brain : component.defaultBrain;
|
NanoBrainObj brain = Application.isPlaying ? component.brain : component.defaultBrain;
|
||||||
|
|
||||||
if (Application.isPlaying == false)
|
if (Application.isPlaying == false)
|
||||||
@ -35,8 +38,9 @@ public class NanoBrainComponent_Editor : Editor {
|
|||||||
root.styleSheets.Add(Resources.Load<StyleSheet>("GraphStyles"));
|
root.styleSheets.Add(Resources.Load<StyleSheet>("GraphStyles"));
|
||||||
|
|
||||||
if (Application.isPlaying == false) {
|
if (Application.isPlaying == false) {
|
||||||
PropertyField brainField = new(brainProp);
|
PropertyField brainField = new(brainProp) {
|
||||||
brainField.label = "Nano Brain";
|
label = "Nano Brain"
|
||||||
|
};
|
||||||
root.Add(brainField);
|
root.Add(brainField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -395,8 +395,10 @@ public class NanoBrainInspector : Editor {
|
|||||||
if (so.targetObject == null)
|
if (so.targetObject == null)
|
||||||
return;
|
return;
|
||||||
so.Update();
|
so.Update();
|
||||||
|
|
||||||
if (this.currentNucleus == null)
|
if (this.currentNucleus == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name);
|
this.currentNucleus.name = EditorGUILayout.TextField(this.currentNucleus.name);
|
||||||
if (this.currentNucleus is Perceptoid currentPerceptoid)
|
if (this.currentNucleus is Perceptoid currentPerceptoid)
|
||||||
currentPerceptoid.thingType = EditorGUILayout.IntField("Thing Type", currentPerceptoid.thingType);
|
currentPerceptoid.thingType = EditorGUILayout.IntField("Thing Type", currentPerceptoid.thingType);
|
||||||
|
|||||||
@ -70,7 +70,7 @@ public class NanoBrainObj : ScriptableObject, ISerializationCallbackReceiver {
|
|||||||
public void GarbageCollection() {
|
public void GarbageCollection() {
|
||||||
HashSet<Nucleus> visitedNuclei = new();
|
HashSet<Nucleus> visitedNuclei = new();
|
||||||
MarkNuclei(visitedNuclei, this.root);
|
MarkNuclei(visitedNuclei, this.root);
|
||||||
Debug.Log($"Garbage collection found {visitedNuclei.Count} Nuclei");
|
//Debug.Log($"Garbage collection found {visitedNuclei.Count} Nuclei");
|
||||||
this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
|
this.nuclei.RemoveAll(nucleus => visitedNuclei.Contains(nucleus) == false);
|
||||||
this.perceptei.RemoveAll(perceptoid => visitedNuclei.Contains(perceptoid) == false);
|
this.perceptei.RemoveAll(perceptoid => visitedNuclei.Contains(perceptoid) == false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -221,6 +221,7 @@ MeshRenderer:
|
|||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!33 &231291189
|
--- !u!33 &231291189
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
@ -332,6 +333,7 @@ MeshRenderer:
|
|||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!33 &246180157
|
--- !u!33 &246180157
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
@ -375,7 +377,7 @@ MonoBehaviour:
|
|||||||
inertia: 0.8
|
inertia: 0.8
|
||||||
alignmentForce: 2
|
alignmentForce: 2
|
||||||
cohesionForce: 2
|
cohesionForce: 2
|
||||||
avoidanceForce: 1
|
avoidanceForce: 100
|
||||||
separationDistance: 0.3
|
separationDistance: 0.3
|
||||||
perceptionDistance: 2
|
perceptionDistance: 2
|
||||||
boundaryForce: 5
|
boundaryForce: 5
|
||||||
@ -515,6 +517,7 @@ MeshRenderer:
|
|||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!33 &704151346
|
--- !u!33 &704151346
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
@ -550,14 +553,14 @@ Light:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 837238090}
|
m_GameObject: {fileID: 837238090}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
serializedVersion: 11
|
serializedVersion: 12
|
||||||
m_Type: 1
|
m_Type: 1
|
||||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||||
m_Intensity: 1
|
m_Intensity: 1
|
||||||
m_Range: 10
|
m_Range: 10
|
||||||
m_SpotAngle: 30
|
m_SpotAngle: 30
|
||||||
m_InnerSpotAngle: 21.80208
|
m_InnerSpotAngle: 21.80208
|
||||||
m_CookieSize: 10
|
m_CookieSize2D: {x: 10, y: 10}
|
||||||
m_Shadows:
|
m_Shadows:
|
||||||
m_Type: 2
|
m_Type: 2
|
||||||
m_Resolution: -1
|
m_Resolution: -1
|
||||||
@ -845,6 +848,7 @@ MeshRenderer:
|
|||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!33 &1690670940
|
--- !u!33 &1690670940
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
@ -956,6 +960,7 @@ MeshRenderer:
|
|||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!33 &1738679981
|
--- !u!33 &1738679981
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
@ -1104,6 +1109,7 @@ MeshRenderer:
|
|||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
|
m_MaskInteraction: 0
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
--- !u!33 &1924016464
|
--- !u!33 &1924016464
|
||||||
MeshFilter:
|
MeshFilter:
|
||||||
|
|||||||
@ -21,7 +21,7 @@ MonoBehaviour:
|
|||||||
_name: Root
|
_name: Root
|
||||||
synapses:
|
synapses:
|
||||||
- nucleusId: -112538112
|
- nucleusId: -112538112
|
||||||
weight: 1
|
weight: 10
|
||||||
curvePreset: 0
|
curvePreset: 0
|
||||||
curve:
|
curve:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@ -80,11 +80,29 @@ MonoBehaviour:
|
|||||||
_curvePreset: 0
|
_curvePreset: 0
|
||||||
curve:
|
curve:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Curve: []
|
m_Curve:
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 0
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 1
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0
|
||||||
|
outWeight: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 1
|
||||||
|
value: 1
|
||||||
|
inSlope: 1
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0
|
||||||
|
outWeight: 0
|
||||||
m_PreInfinity: 2
|
m_PreInfinity: 2
|
||||||
m_PostInfinity: 2
|
m_PostInfinity: 2
|
||||||
m_RotationOrder: 4
|
m_RotationOrder: 4
|
||||||
curveMax: 0
|
curveMax: 1
|
||||||
average: 0
|
average: 0
|
||||||
inverse: 0
|
inverse: 0
|
||||||
exponent: 1
|
exponent: 1
|
||||||
|
|||||||
8
Assets/Scenes/Boids/Scripts/Editor.meta
Normal file
8
Assets/Scenes/Boids/Scripts/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2b86e8b28533d905899af9666a98e804
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
32
Assets/Scenes/Boids/Scripts/Editor/SwarmControl_Editor.cs
Normal file
32
Assets/Scenes/Boids/Scripts/Editor/SwarmControl_Editor.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CustomEditor(typeof(SwarmControl))]
|
||||||
|
public class SwarmControl_Editor : Editor {
|
||||||
|
public override void OnInspectorGUI() {
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
|
DrawDefaultInspector();
|
||||||
|
|
||||||
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
|
|
||||||
|
SwarmControl swarmControl = (SwarmControl)target;
|
||||||
|
NanoBrainObj[] nanoBrains = FindObjectsByType<NanoBrainObj>(FindObjectsSortMode.None);
|
||||||
|
|
||||||
|
foreach (NanoBrainObj brain in nanoBrains) {
|
||||||
|
UpdateWeight(brain, "Avoidance", swarmControl.avoidanceForce);
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
Debug.Log("Updated weights");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void UpdateWeight(NanoBrainObj brain, string name, float weight) {
|
||||||
|
Nucleus root = brain.root;
|
||||||
|
foreach (Synapse synapse in root.synapses) {
|
||||||
|
if (synapse.nucleus.name == name) {
|
||||||
|
synapse.weight = weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: df2bd18155543a1a09fefea3252981e0
|
||||||
Loading…
x
Reference in New Issue
Block a user