public static void BehaviorTarget(Property property) { var value = (EntityBehavior.BehaviorTargetProperty)(property.value); Entity behaviorTarget = value.targetEntity.entity; string text; if (value.targetEntityIsActivator) { text = "Activators"; } else if (behaviorTarget != null) { // only temporarily, so the name won't be "Target": EntityReferencePropertyManager.SetBehaviorTarget(null); EntityReferencePropertyManager.Next(behaviorTarget); text = EntityReferencePropertyManager.GetName(); EntityReferencePropertyManager.SetBehaviorTarget(behaviorTarget); // put it back } else { return; } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(GUIIconSet.instance.target, alignedLabelStyle.Value, GUILayout.ExpandWidth(false)); if (GUILayout.Button("<i>" + text + "</i>", GUILayout.ExpandWidth(false))) { BehaviorTargetPicker(GUIPanel.guiGameObject, VoxelArrayEditor.instance, EntityReferencePropertyManager.CurrentEntity(), newValue => { property.value = newValue; }); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
private void EntityPropertiesGUI() { Entity singleSelectedEntity = null; if (selectedEntities.Count == 1) { singleSelectedEntity = selectedEntities[0]; } EntityReferencePropertyManager.Reset(singleSelectedEntity); // could be null and that's fine (?) GUILayout.BeginVertical(GUI.skin.box); PropertiesObjectGUI(editEntity); GUILayout.EndVertical(); if (singleSelectedEntity != null && !(singleSelectedEntity is PlayerObject)) { GUILayout.BeginHorizontal(); if (GUIUtils.HighlightedButton("Clone")) { if (singleSelectedEntity is ObjectEntity) { ObjectEntity clone = (ObjectEntity)(singleSelectedEntity.Clone()); var pickerGUI = gameObject.AddComponent <FacePickerGUI>(); pickerGUI.voxelArray = voxelArray; pickerGUI.message = "Tap to place clone"; pickerGUI.pickAction = () => { if (!voxelArray.PlaceObject(clone)) { DialogGUI.ShowMessageDialog(gameObject, ActionBarGUI.OBJECT_NO_ROOM_ERROR); } }; } else if (singleSelectedEntity is Substance) { Substance clone = (Substance)(singleSelectedEntity.Clone()); clone.defaultPaint = voxelArray.GetSelectedPaint(); clone.defaultPaint.addSelected = false; clone.defaultPaint.storedSelected = false; voxelArray.substanceToCreate = clone; var createGUI = gameObject.AddComponent <CreateSubstanceGUI>(); createGUI.voxelArray = voxelArray; } } if (GUIUtils.HighlightedButton("Delete")) { DeleteButton(); } GUILayout.EndHorizontal(); } if (selectedEntities.Count > 1) { if (GUIUtils.HighlightedButton("Delete")) { DeleteButton(); } } TutorialGUI.TutorialHighlight("change sensor"); if (GUILayout.Button("Change Sensor")) { TypePickerGUI sensorMenu = gameObject.AddComponent <TypePickerGUI>(); sensorMenu.title = "Change Sensor"; sensorMenu.categories = new PropertiesObjectType[][] { GameScripts.sensors }; sensorMenu.handler = (PropertiesObjectType type) => { foreach (Entity entity in selectedEntities) { entity.sensor = (Sensor)type.Create(); } voxelArray.unsavedChanges = true; UpdateEditEntity(); }; } TutorialGUI.ClearHighlight(); GUILayout.BeginVertical(GUI.skin.box); PropertiesObjectGUI(editSensor, " Sensor"); GUILayout.EndVertical(); TutorialGUI.TutorialHighlight("add behavior"); if (GUILayout.Button("Add Behavior")) { NewBehaviorGUI behaviorMenu = gameObject.AddComponent <NewBehaviorGUI>(); behaviorMenu.title = "Add Behavior"; behaviorMenu.self = singleSelectedEntity; behaviorMenu.voxelArray = voxelArray; behaviorMenu.handler = (PropertiesObjectType behaviorType) => { foreach (Entity entity in selectedEntities) { EntityBehavior newBehavior = (EntityBehavior)behaviorType.Create(); // with multiple selected entities, NewBehaviorGUI doesn't check if behaviors // are valid for the selected entities if (newBehavior.targetEntity.entity == null && !newBehavior.targetEntityIsActivator && !newBehavior.BehaviorObjectType().rule(entity)) { continue; } entity.behaviors.Add(newBehavior); EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, newBehavior); } voxelArray.unsavedChanges = true; UpdateEditEntity(); scrollVelocity = new Vector2(0, 2000 * editBehaviors.Count); // scroll to bottom }; } TutorialGUI.ClearHighlight(); Color guiBaseColor = GUI.backgroundColor; StoredEntityBehavior behaviorToRemove = null; foreach (StoredEntityBehavior storedBehavior in editBehaviors) { TutorialGUI.TutorialHighlight("behaviors"); Entity behaviorTarget = null; if (storedBehavior.sharedTarget) { behaviorTarget = storedBehavior.allBehaviors[0].targetEntity.entity; } if (behaviorTarget != null) { EntityReferencePropertyManager.Next(behaviorTarget); GUI.backgroundColor = guiBaseColor * EntityReferencePropertyManager.GetColor(); } EntityReferencePropertyManager.SetBehaviorTarget(behaviorTarget); GUILayout.BeginVertical(GUI.skin.box); GUI.backgroundColor = guiBaseColor; PropertiesObjectGUI(storedBehavior, " Behavior", () => EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, storedBehavior.allBehaviors[0])); if (GUILayout.Button("Remove")) { behaviorToRemove = storedBehavior; } GUILayout.EndVertical(); // clear this every time, in case the next target is the same EntityReferencePropertyManager.SetBehaviorTarget(null); } if (behaviorToRemove != null) { foreach (Entity entity in selectedEntities) { foreach (EntityBehavior remove in behaviorToRemove.allBehaviors) { if (entity.behaviors.Remove(remove)) { break; } } } voxelArray.unsavedChanges = true; UpdateEditEntity(); EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, behaviorToRemove.allBehaviors[0]); } if (mismatchedSelectedBehaviorCounts) { GUILayout.BeginVertical(GUI.skin.box); GUILayout.Label("(other behaviors...)", GUIStyleSet.instance.labelTitle); GUILayout.EndVertical(); } }