private void OnDrawGizmos() //ao desenhar o gizmos da unity //para testes { if (showGizmosOnInspector) { Gizmos.DrawWireSphere(transform.position, startingCount * agentDensity); //desenhar o circulo de spawn dos agentes Gizmos.color = new Color(0f, 0.8f, 0f, 1f); Gizmos.DrawWireSphere(transform.position, neighborRadius); //desenhar o circulo de alcance dos agentes //para testes Gizmos.color = new Color(0.8f, 0f, 0f, 1f); Gizmos.DrawWireSphere(transform.position, neighborRadius * avoidanceRadiusMultiplier); //desenhar o circulo de "evasao" dos agentes //para testes if (flockBehavior.GetType() == typeof(CompositeBehavior)) //se for um composite behavior { CompositeBehavior compositeBehavior = (CompositeBehavior)flockBehavior; if (compositeBehavior.flockBehaviors != null) //se nao for null { for (int i = 0; i < compositeBehavior.flockBehaviors.Length; i++) //para cada comportamento no array { if (compositeBehavior.flockBehaviors[i].GetType() == typeof(StayInRadiusBehavior)) //se for um stayInRadius behavior { ((StayInRadiusBehavior)compositeBehavior.flockBehaviors[i]).OnDrawGizmos(); //desenhar o gizmos (se possivel) } } } } } }
public void Patrol() { Debug.Log("Patrol Enter"); animalBehavior = docileStateBehavior; stateAnim.SetBool("pursue", false); }
public void GUI_AddBehavior(CompositeBehavior compositeBehavior) //adicionar um comportamento { int newArraySize = 0; //incializar valores if (compositeBehavior.flockBehaviors == null) //se nao existir o array, criar { compositeBehavior.flockBehaviors = new FlockBehavior[0]; compositeBehavior.behaviorsWeights = new float[0]; } newArraySize = compositeBehavior.flockBehaviors.Length + 1; //pegar tamanho + 1 FlockBehavior[] newFlockBehaviors = new FlockBehavior[newArraySize]; //incializar valores float[] newBehaviorsWeights = new float[newArraySize]; for (int i = 0; i < newArraySize - 1; i++) //para cada elemento antigo, re adicionar no novo array { newFlockBehaviors[i] = compositeBehavior.flockBehaviors[i]; newBehaviorsWeights[i] = compositeBehavior.behaviorsWeights[i]; } newBehaviorsWeights[newArraySize - 1] = 1f; //adicionar valor default ao novo elemento compositeBehavior.flockBehaviors = newFlockBehaviors; //setar novos arrays no lguar dos antigos compositeBehavior.behaviorsWeights = newBehaviorsWeights; }
/** * Remove one exist field for one exist behavior. */ private void RemoveBehavior(CompositeBehavior cb) { // Get exist behavior array's length. var oldCount = cb.behaviors.Length; // Check there is only one exist behavior. if (oldCount == 1) { // Set behavior array and weight array to null. cb.behaviors = null; cb.behaviorsWeights = null; } else { // Create a new behavior array(one less length). var newBehaviors = new FlockBehavior[oldCount - 1]; // Create a new float array(one less length). var newWeights = new float[oldCount - 1]; // Assign previous behaviors and weights unless the last behavior and weight. for (var i = 0; i < oldCount - 1; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.behaviorsWeights[i]; } // Assign new behavior array and weight array back. cb.behaviors = newBehaviors; cb.behaviorsWeights = newWeights; } }
// Start is called before the first frame update protected void Start() { behavior = Object.Instantiate(behaviorTemplate); squareMaxspeed = maxSpeed * maxSpeed; squareNeighborRadius = neigbourgRadius * neigbourgRadius; squareAvoidanceRadius = squareNeighborRadius * avoidanceRadiusMultiplier * avoidanceRadiusMultiplier; //SpawnInitialAgentCount(); }
public override void OnInspectorGUI() { //setup CompositeBehavior cb = (CompositeBehavior)target; EditorGUILayout.BeginVertical(); //check for behaviors if (cb.behaviors == null || cb.behaviors.Length == 0) { EditorGUILayout.BeginVertical(); EditorGUILayout.HelpBox("No behaviors in array.", MessageType.Warning); EditorGUILayout.EndVertical(); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Number", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.LabelField("Behaviors", GUILayout.MinWidth(60f)); EditorGUILayout.LabelField("Weights", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); //EditorGUI.BeginChangeCheck(); for (int i = 0; i < cb.behaviors.Length; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); cb.behaviors[i] = (FlockBehavior)EditorGUILayout.ObjectField(cb.behaviors[i], typeof(FlockBehavior), false, GUILayout.MinWidth(60f)); cb.weights[i] = EditorGUILayout.FloatField(cb.weights[i], GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); if (GUILayout.Button("Add Behavior")) { AddBehavior(cb); EditorUtility.SetDirty(cb); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); if (cb.behaviors != null && cb.behaviors.Length > 0) { if (GUILayout.Button("Remove Behavior")) { RemoveBehavior(cb); EditorUtility.SetDirty(cb); } } EditorGUILayout.EndHorizontal(); }
public void when_behavior_is_executed_then_behavior_tracks_invocation() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var behavior = new CompositeBehavior(i => true); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(1, behavior.Invocations.Count); Assert.Same(invocation, behavior.Invocations[0]); }
public override void OnInspectorGUI() { CompositeBehavior cb = (CompositeBehavior)target; //check for behaviors if (cb.behaviors == null || cb.behaviors.Length == 0) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("No behaviors in array.", MessageType.Warning); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); //TODO Have space or indent of specific width EditorGUILayout.LabelField("Behaviors", GUILayout.MinWidth(60f)); EditorGUILayout.LabelField("Weights", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); //Check for changes on cb.behaviors and cb.weights EditorGUI.BeginChangeCheck(); for (int i = 0; i < cb.behaviors.Length; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); cb.behaviors[i] = (FlockBehavior)EditorGUILayout.ObjectField(cb.behaviors[i], typeof(FlockBehavior), false, GUILayout.MinWidth(60f)); cb.weights[i] = EditorGUILayout.FloatField(cb.weights[i], GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); } //if there were changes, set dirty if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(cb); } } if (GUILayout.Button("Add Behavior")) { addBehavior(cb); EditorUtility.SetDirty(cb); } if (cb.behaviors != null && cb.behaviors.Length > 0) { if (GUILayout.Button("Remove Behavior")) { removeBehavior(cb); EditorUtility.SetDirty(cb); } } }
void AddBehavior(CompositeBehavior cb) { int oldCount = (cb.behaviors != null) ? cb.behaviors.Length : 0; FlockBehavior[] newBehaviors = new FlockBehavior[oldCount + 1]; float[] newWeights = new float[oldCount + 1]; for (int i = 0; i < oldCount; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } newWeights[oldCount] = 1f; cb.behaviors = newBehaviors; cb.weights = newWeights; }
void AddBehavior(CompositeBehavior cb) { int n = ((cb.behaviors != null) ? cb.behaviors.Length : 0) + 1; FlockBehavior[] newBehaviors = new FlockBehavior[n]; float[] newWeights = new float[n]; for (int i = 0; i < n - 1; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } newWeights[n - 1] = 1f; cb.behaviors = newBehaviors; cb.weights = newWeights; }
public override void OnInspectorGUI() { CompositeBehavior cb = (CompositeBehavior)target; EditorGUILayout.BeginHorizontal(); EditorGUILayout.EndHorizontal(); GUILayout.Label("Composite Behavior Inspector", EditorStyles.boldLabel); if (cb.behaviors == null || cb.behaviors.Length == 0) { GUILayout.Space(10f); EditorGUILayout.HelpBox("No Behaviors in array.", MessageType.Warning); } else { GUILayout.Space(10f); EditorGUI.BeginChangeCheck(); for (int i = 0; i < cb.behaviors.Length; i++) { EditorGUILayout.BeginHorizontal(); cb.behaviors[i] = (FlockBehavior)EditorGUILayout.ObjectField(cb.behaviors[i], typeof(FlockBehavior), false); cb.weights[i] = EditorGUILayout.FloatField(cb.weights[i]); EditorGUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(cb); } } GUILayout.Space(10f); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add")) { cb.AddBehavior(); EditorUtility.SetDirty(cb); } GUI.enabled = !(cb.behaviors == null || cb.behaviors.Length == 0); if (GUILayout.Button("Remove")) { RemoveBehavior(cb); EditorUtility.SetDirty(cb); } GUI.enabled = true; GUILayout.EndHorizontal(); }
// Add and remove behavior methods void AddBehavior(CompositeBehavior cb) { // get the original size of the array int oldCount = (cb.behaviors != null ? cb.behaviors.Length : 0); FlockBehavior[] newBehaviors = new FlockBehavior[oldCount + 1]; float[] newWeights = new float[oldCount + 1]; for (int i = 0; i < oldCount; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } newWeights[oldCount] = 1f; cb.behaviors = newBehaviors; cb.weights = newWeights; }
public void when_behavior_throws_then_invocation_is_still_recorded() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var behavior = new CompositeBehavior(i => true) { Invoke = { new DelegateBehavior(i => { throw new ArgumentException(); }) } }; mock.Behaviors.Add(behavior); Assert.Throws <ArgumentException>(() => mock.Invoke(invocation)); Assert.Equal(1, behavior.Invocations.Count); Assert.Same(invocation, behavior.Invocations[0]); }
public void when_behavior_throws_then_invocation_is_still_recorded() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var behavior = new CompositeBehavior(i => true) { Invoke = { new DelegateBehavior(i => { throw new ArgumentException(); }) } }; mock.Behaviors.Add(behavior); Assert.Throws<ArgumentException>(() => mock.Invoke(invocation)); Assert.Equal(1, behavior.Invocations.Count); Assert.Same(invocation, behavior.Invocations[0]); }
void RemoveBehavior(CompositeBehavior cb) { int oldCount = cb.behaviors.Length; if (oldCount == 1) { cb.behaviors = null; cb.weights = null; return; } FlockBehavior[] newBehaviors = new FlockBehavior[oldCount - 1]; float[] newWeights = new float[oldCount - 1]; for (int i = 0; i < oldCount - 1; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } cb.behaviors = newBehaviors; cb.weights = newWeights; }
void RemoveBehavior(CompositeBehavior cb) { int n = cb.behaviors.Length - 1; if (n == 0) { cb.behaviors = null; cb.weights = null; return; } FlockBehavior[] newBehaviors = new FlockBehavior[n]; float[] newWeights = new float[n]; for (int i = 0; i < n; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } cb.behaviors = newBehaviors; cb.weights = newWeights; }
public void when_aspect_stops_further_aspects_on_phase_then_does_not_invoke_next_aspect() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List <string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke-not"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public void when_aspects_configured_then_invokes_in_order() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List <string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
/** * Add one new field for one new behavior. */ private void AddBehavior(CompositeBehavior cb) { // First check if new behavior array is not null and have at least one behavior. var oldCount = cb.behaviors?.Length ?? 0; // Create a new behavior array(one more length). var newBehaviors = new FlockBehavior[oldCount + 1]; // Create a new float array(one more length). var newWeights = new float[oldCount + 1]; // Assign previous behaviors and weights. for (var i = 0; i < oldCount; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.behaviorsWeights[i]; } // Set the new behavior's weight to 1f. newWeights[oldCount] = 1f; // Assign new behavior array and weight array back. cb.behaviors = newBehaviors; cb.behaviorsWeights = newWeights; }
public void GUI_RemoveBehavior(CompositeBehavior compositeBehavior, int position) //remover um comportamento { position = Mathf.Clamp(position, 0, compositeBehavior.flockBehaviors.Length); //ajustar posicao para nao passar o array int newArraySize = 0; //incializar valores if (compositeBehavior.flockBehaviors != null) //se existir o array, pegar tamanho + 1 { newArraySize = compositeBehavior.flockBehaviors.Length - 1; } FlockBehavior[] newFlockBehaviors = new FlockBehavior[newArraySize]; //incializar valores float[] newBehaviorsWeights = new float[newArraySize]; for (int i = 0; i < newArraySize; i++) //para cada elemento antigo, re adicionar no novo array { newFlockBehaviors[i] = compositeBehavior.flockBehaviors[i >= position ? i + 1 : i]; newBehaviorsWeights[i] = compositeBehavior.behaviorsWeights[i >= position ? i + 1 : i]; } compositeBehavior.flockBehaviors = newArraySize == 0 ? null : newFlockBehaviors; //setar novos arrays no lguar dos antigos compositeBehavior.behaviorsWeights = newArraySize == 0 ? null : newBehaviorsWeights; }
private void RemoveBehavior(CompositeBehavior cb) { int oldCount = cb.BehaviorList.Length; if (oldCount == 1) { cb.BehaviorList = null; cb.Weights = null; return; } else { FlockBehavior[] newBehaviors = new FlockBehavior[oldCount - 1]; float[] newWeights = new float[oldCount - 1]; for (int i = 0; i < oldCount; i++) { newBehaviors[i] = cb.BehaviorList[i]; newWeights[i] = cb.Weights[i]; } cb.BehaviorList = newBehaviors; cb.Weights = newWeights; }//3060 4176 }
// --------- private void OnBehaviorsChanged(CompositeBehavior newVal) { flockTargetDropdown.options.Clear(); for (int i = 0; i < newVal.behaviors.Length; i++) { if (newVal.behaviors[i] != null) { flockTargetDropdown.options.Add(new TMP_Dropdown.OptionData() { text = newVal.behaviors[i].name }); } } flockTargetDropdown.options.Add(new TMP_Dropdown.OptionData() { text = "None" }); if (flockTargetDropdown.options.Count - 1 < flockTargetDropdown.value) { flockTargetDropdown.SetValueWithoutNotify(flockTargetDropdown.options.Count - 1); } flockTargetDropdown.RefreshShownValue(); }
public override void OnInspectorGUI() { //create reference to the composite behavior CompositeBehavior cb = (CompositeBehavior)target; // Create an object to keep track of positions //Creates a rect wherever the cursor is Rect r = EditorGUILayout.BeginHorizontal(); //Gives us a baseline cursor to tell where the fields should appear r.height = EditorGUIUtility.singleLineHeight; //If nothing is in here, put up a warning if (cb.behaviors == null || cb.behaviors.Length == 0) { EditorGUILayout.HelpBox("No Behaviors in array.", MessageType.Warning); EditorGUILayout.EndHorizontal(); r = EditorGUILayout.BeginHorizontal(); r.height = EditorGUIUtility.singleLineHeight; } else // If there are behaviors { //give ourselves a margin on the left r.x = 30f; /* columns of behaviors and weights */ // Create width of behavior to be expandable r.width = EditorGUIUtility.currentViewWidth - 95f; EditorGUI.LabelField(r, "Behaviors"); r.x = EditorGUIUtility.currentViewWidth - 65f; r.width = 60f; EditorGUI.LabelField(r, "Weights"); //push the cursor down r.y += EditorGUIUtility.singleLineHeight * 1.2f; EditorGUI.BeginChangeCheck(); //For each behavior we have, show it on the line for (int i = 0; i < cb.behaviors.Length; i++) { r.x = 5f; r.width = 20f; EditorGUI.LabelField(r, i.ToString()); r.x = 30f; r.width = EditorGUIUtility.currentViewWidth - 95f; //Show a field for the behavior cb.behaviors[i] = (FlockBehavior)EditorGUI.ObjectField(r, cb.behaviors[i], typeof(FlockBehavior), false); // same idea for the weights r.x = EditorGUIUtility.currentViewWidth - 65f; r.width = 60f; cb.weights[i] = EditorGUI.FloatField(r, cb.weights[i]); r.y += EditorGUIUtility.singleLineHeight * 1.1f; } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(cb); } } // Add some buttons for functionality EditorGUILayout.EndHorizontal(); r.x = 5f; r.width = EditorGUIUtility.currentViewWidth - 10f; r.y += EditorGUIUtility.singleLineHeight * 0.5f; // check if button has been pressed if (GUI.Button(r, "Add Behavior")) { // Add behavior AddBehavior(cb); //Let's unity know this scriptable object has been changed and needs to be saved EditorUtility.SetDirty(cb); } r.y += EditorGUIUtility.singleLineHeight * 1.5f; if (cb.behaviors != null && cb.behaviors.Length > 0) { if (GUI.Button(r, "Remove Behavior")) { // remove behavior RemoveBehavior(cb); EditorUtility.SetDirty(cb); } } }
public override void OnInspectorGUI() //sobrescrever a funcao de desenhar no inspector da classe especificada { CompositeBehavior compositeBehavior = (CompositeBehavior)target; //inicializar valores DrawDefaultInspector(); //desenhar o inspector default if (compositeBehavior.flockBehaviors == null || compositeBehavior.flockBehaviors.Length == 0) //se nao existir ou nao tiverem comportamentos no array flockBehaviors { EditorGUILayout.BeginHorizontal(); //iniciar horizontal EditorGUILayout.HelpBox("No Behaviors in Array!", MessageType.Warning); //marcar um aviso EditorGUILayout.EndHorizontal(); //resetar horizontal } else //caso contrario { EditorGUILayout.BeginHorizontal(); //iniciar horizontal GUILayout.Space(18); EditorGUILayout.LabelField(new GUIContent("Behaviors"), EditorStyles.boldLabel, GUILayout.MaxWidth(75)); GUILayout.FlexibleSpace(); //espaco auto reajustavel EditorGUILayout.LabelField(new GUIContent("Weights"), EditorStyles.boldLabel, GUILayout.MaxWidth(60)); EditorGUILayout.EndHorizontal(); //finalizar horizontal for (int i = 0; i < compositeBehavior.flockBehaviors.Length; i++) //para cada comportamento no array { EditorGUILayout.BeginHorizontal(); //inciar horizontal EditorGUILayout.LabelField(new GUIContent("" + i), GUILayout.MaxWidth(12)); compositeBehavior.flockBehaviors[i] = (FlockBehavior)EditorGUILayout.ObjectField(compositeBehavior.flockBehaviors[i], typeof(FlockBehavior), false); GUILayout.Space(3); compositeBehavior.behaviorsWeights[i] = EditorGUILayout.FloatField(compositeBehavior.behaviorsWeights[i]); EditorGUILayout.EndHorizontal(); //finalizar horizontal } } EditorGUILayout.Space(); //espaco EditorGUILayout.BeginHorizontal(); //inciar horizontal if (GUILayout.Button(new GUIContent("Add Behavior"))) //caso pressionar o botao, adicionar um comportamento { GUI_AddBehavior(compositeBehavior); } EditorGUI.BeginDisabledGroup(compositeBehavior.flockBehaviors == null || compositeBehavior.flockBehaviors.Length == 0); //se nao existir ou nao tiverem comportamentos no array flockBehaviors //inciar grupo "desativado" if (GUILayout.Button(new GUIContent("Remove Behavior"))) //caso pressionar o botao, remover um comportamento { GUI_RemoveBehavior(compositeBehavior, auxRemovePosition); } EditorGUILayout.EndHorizontal(); //finalizar horizontal EditorGUILayout.BeginHorizontal(); //inciar horizontal GUILayout.FlexibleSpace(); //espaco auto reajustavel auxRemovePosition = EditorGUILayout.IntField(auxRemovePosition, GUILayout.MaxWidth(100)); EditorGUI.EndDisabledGroup(); //finalizar grupo "desativado" EditorGUILayout.EndHorizontal(); //finalizar horizontal }
public void when_aspects_configured_then_invokes_in_order() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List<string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
//Wandering public void SheepWander() { Debug.Log("Wander Enter"); animalBehavior = docileStateBehavior; stateAnim.SetBool("flee", false); }
public void when_aspect_stops_further_aspects_on_phase_then_does_not_invoke_next_aspect() { var mock = new TestMock(); var invocation = new TestInvocation(() => null); var order = new List<string>(); var behavior = new CompositeBehavior(i => true); behavior.Before.Add(new DelegateBehavior(i => order.Add("before"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke"))); behavior.Invoke.Add(new DelegateBehavior(i => order.Add("invoke-not"))); behavior.After.Add(new DelegateBehavior(i => order.Add("after"))); mock.Behaviors.Add(behavior); mock.Invoke(invocation); Assert.Equal(3, order.Count); Assert.Equal("before", order[0]); Assert.Equal("invoke", order[1]); Assert.Equal("after", order[2]); }
public override void OnInspectorGUI() { // setup CompositeBehavior cb = (CompositeBehavior)target; //Rect r = EditorGUILayout.BeginHorizontal(); //r.height = EditorGUIUtility.singleLineHeight; // check for behaviors if (cb.behaviors == null || cb.behaviors.Length == 0) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("No behaviors in array.", MessageType.Warning); EditorGUILayout.EndHorizontal(); } else { //r.height = EditorGUIUtility.singleLineHeight; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Number", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.LabelField("Behaviors", GUILayout.MinWidth(60f)); EditorGUILayout.LabelField("Weights", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); for (int i = 0; i < cb.behaviors.Length; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); cb.behaviors[i] = (FlockBehavior)EditorGUILayout.ObjectField(cb.behaviors[i], typeof(FlockBehavior), false, GUILayout.MinWidth(60f)); cb.weights[i] = EditorGUILayout.FloatField(cb.weights[i], GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(cb); } EditorGUILayout.Space(); } // Adauga butoanele Rect ab = EditorGUILayout.BeginHorizontal("Button"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.EndHorizontal(); //r.y += EditorGUIUtility.singleLineHeight * 0.5f; if (GUI.Button(ab, GUIContent.none)) { // Add behavior AddBehavior(cb); EditorUtility.SetDirty(cb); } GUILayout.Label("Add Behavior"); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (cb.behaviors != null && cb.behaviors.Length > 0) { Rect rb = EditorGUILayout.BeginHorizontal("Button"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.EndHorizontal(); //r.y += EditorGUIUtility.singleLineHeight * 0.5f; if (GUI.Button(rb, GUIContent.none)) { // Add behavior RemoveBehavior(cb); EditorUtility.SetDirty(cb); } GUILayout.Label("Remove Behavior"); EditorGUILayout.EndHorizontal(); } }
public override void OnInspectorGUI() { CompositeBehavior compBehavior = (CompositeBehavior)target; // Check for behaviours if (compBehavior.behaviors == null || compBehavior.behaviors.Length == 0) { EditorGUILayout.HelpBox("No behaviours in array.", MessageType.Warning); } else { EditorGUILayout.BeginHorizontal(); GUILayout.Space(20f); //EditorGUILayout.LabelField("Number", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.LabelField("Behaviors", GUILayout.MinWidth(60f)); EditorGUILayout.LabelField("Weights", GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); for (int i = 0; i < compBehavior.behaviors.Length; ++i) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i.ToString(), GUILayout.MaxWidth(15f)); compBehavior.behaviors[i] = (FlockBehavior)EditorGUILayout.ObjectField(compBehavior.behaviors[i], typeof(FlockBehavior), false, GUILayout.MinWidth(60f)); compBehavior.weights[i] = EditorGUILayout.FloatField(compBehavior.weights[i], GUILayout.MinWidth(60f), GUILayout.MaxWidth(60f)); EditorGUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(compBehavior); } } GUILayout.Space(10f); // Buttons to add and remove behaviours in our containers EditorGUILayout.BeginVertical(); if (GUILayout.Button("Add")) { AddBehavior(compBehavior); EditorUtility.SetDirty(compBehavior); } if (GUILayout.Button("Remove")) { RemoveBehavior(compBehavior); EditorUtility.SetDirty(compBehavior); } EditorGUILayout.EndVertical(); void AddBehavior(CompositeBehavior cb) { int oldCount = (cb.behaviors != null) ? cb.behaviors.Length : 0; FlockBehavior[] newBehaviors = new FlockBehavior[oldCount + 1]; float[] newWeights = new float[oldCount + 1]; for (int i = 0; i < oldCount; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } newWeights[oldCount] = 1f; cb.behaviors = newBehaviors; cb.weights = newWeights; } void RemoveBehavior(CompositeBehavior cb) { int oldCount = cb.behaviors.Length; if (oldCount == 1) { cb.behaviors = null; cb.weights = null; return; } FlockBehavior[] newBehaviors = new FlockBehavior[oldCount - 1]; float[] newWeights = new float[oldCount - 1]; for (int i = 0; i < oldCount - 1; i++) { newBehaviors[i] = cb.behaviors[i]; newWeights[i] = cb.weights[i]; } cb.behaviors = newBehaviors; cb.weights = newWeights; } }
public override void OnInspectorGUI() { //setup CompositeBehavior cb = (CompositeBehavior)target; Rect r = EditorGUILayout.BeginHorizontal(); r.height = EditorGUIUtility.singleLineHeight; //check for behaviors if (cb.behaviors == null || cb.behaviors.Length == 0) { EditorGUILayout.HelpBox("No behaviors in array.", MessageType.Warning); EditorGUILayout.EndHorizontal(); r = EditorGUILayout.BeginHorizontal(); r.height = EditorGUIUtility.singleLineHeight; } else { r.x = 30f; r.width = EditorGUIUtility.currentViewWidth - 95f; EditorGUI.LabelField(r, "Behaviors"); r.x = EditorGUIUtility.currentViewWidth - 65f; r.width = 60f; EditorGUI.LabelField(r, "Weights"); r.y += EditorGUIUtility.singleLineHeight * 1.2f; EditorGUI.BeginChangeCheck(); for (int i = 0; i < cb.behaviors.Length; i++) { r.x = 5f; r.width = 20f; EditorGUI.LabelField(r, i.ToString()); r.x = 30f; r.width = EditorGUIUtility.currentViewWidth - 95f; cb.behaviors[i] = (FlockBehavior)EditorGUI.ObjectField(r, cb.behaviors[i], typeof(FlockBehavior), false); r.x = EditorGUIUtility.currentViewWidth - 65f; r.width = 60f; cb.weights[i] = EditorGUI.FloatField(r, cb.weights[i]); r.y += EditorGUIUtility.singleLineHeight * 1.1f; } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(cb); } } EditorGUILayout.EndHorizontal(); r.x = 5f; r.width = EditorGUIUtility.currentViewWidth - 10f; r.y += EditorGUIUtility.singleLineHeight * 0.5f; if (GUI.Button(r, "Add Behavior")) { AddBehavior(cb); EditorUtility.SetDirty(cb); } r.y += EditorGUIUtility.singleLineHeight * 1.5f; if (cb.behaviors != null && cb.behaviors.Length > 0) { if (GUI.Button(r, "Remove Behavior")) { RemoveBehavior(cb); EditorUtility.SetDirty(cb); } } }
//Fleeing and Hiding public void SheepFleeAndHide() { Debug.Log("Hide Enter"); animalBehavior = fleeStateBehaviour; stateAnim.SetBool("flee", true); }
public void Pursue() { Debug.Log("Pursue Enter"); animalBehavior = pounceStateBehavior; stateAnim.SetBool("pursue", true); }
public override void OnInspectorGUI() { //setup CompositeBehavior cb = (CompositeBehavior)target; //check for behaviors if (cb.behaviors == null || cb.behaviors.Length == 0) { GUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("No behaviors in array!", MessageType.Warning); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Label("Behaviors"); GUILayout.Label("Weights"); GUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); for (int i = 0; i < cb.behaviors.Length; i++) { GUILayout.BeginHorizontal(); //GUILayout.Label( i.ToString()); cb.behaviors[i] = (FlockBehavior)EditorGUI.ObjectField( GUILayoutUtility.GetRect(100f, 20f), cb.behaviors[i], typeof(FlockBehavior), false ); cb.weights[i] = EditorGUI.FloatField( GUILayoutUtility.GetRect(10f, 20f), cb.weights[i] ); GUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(cb); } } GUILayout.BeginHorizontal(); if (GUI.Button(GUILayoutUtility.GetRect(100f, 20f), "Add Behavior")) { AddBehavior(cb); EditorUtility.SetDirty(cb); } GUILayout.EndHorizontal(); if (cb.behaviors != null && cb.behaviors.Length > 0) { GUILayout.BeginHorizontal(); if (GUI.Button(GUILayoutUtility.GetRect(100f, 20f), "Remove Behavior")) { RemoveBehavior(cb); EditorUtility.SetDirty(cb); } GUILayout.EndHorizontal(); } }