/// <summary> /// Method invoked when a new controllable is registered /// </summary> /// <param name="controllable">Controllable that is registered</param> private void OnControllableRegistered(ScenarioControllable controllable) { if (customEditPanels.TryGetValue(controllable.Variant.controllable.GetType(), out var customPanel)) { customPanel.InitializeControllable(controllable); } }
/// <summary> /// Method called when another scenario element has been selected /// </summary> /// <param name="selectedElement">Scenario element that has been selected</param> private void OnSelectedOtherElement(ScenarioElement selectedElement) { if (SelectedControllable != null) { policyEditPanel.SubmitChangedInputs(); } if (enabledCustomPanel != null) { enabledCustomPanel.Setup(null, null); enabledCustomPanel.PanelObject.SetActive(false); enabledCustomPanel = null; } SelectedControllable = selectedElement as ScenarioControllable; //Disable edit panel if there are no valid actions or states if (SelectedControllable == null) { policyEditPanel.Setup(null, null); gameObject.SetActive(false); } else { var controllable = SelectedControllable.Variant.controllable; if (controllable.ValidActions.Length == 0 && controllable.ValidStates.Length == 0) { policyEditPanel.Setup(null, null); gameObject.SetActive(false); return; } if (customEditPanels.TryGetValue(controllable.GetType(), out enabledCustomPanel)) { enabledCustomPanel.Setup(SelectedControllable, SelectedControllable.Policy); policyEditPanel.gameObject.SetActive(false); } else { policyEditPanel.Setup(SelectedControllable.Variant.controllable, SelectedControllable.Policy); policyEditPanel.gameObject.SetActive(true); } gameObject.SetActive(true); UnityUtilities.LayoutRebuild(transform as RectTransform); } }
/// <summary> /// Adds an controllable node to the json /// </summary> /// <param name="data">Json object where data will be added</param> /// <param name="controllable">Scenario controllable to serialize</param> private static void AddControllableNode(JSONNode data, ScenarioControllable controllable) { var controllableNode = new JSONObject(); data.Add(controllableNode); controllableNode.Add("uid", new JSONString(controllable.Uid)); controllableNode.Add("policy", Utility.SerializeControlPolicy(controllable.Policy)); controllableNode.Add("spawned", controllable.IsEditableOnMap); if (!controllable.IsEditableOnMap) { return; } controllableNode.Add("name", new JSONString(controllable.Variant.Name)); var transform = new JSONObject(); controllableNode.Add("transform", transform); var position = new JSONObject().WriteVector3(controllable.TransformToMove.position); transform.Add("position", position); var rotation = new JSONObject().WriteVector3(controllable.TransformToRotate.rotation.eulerAngles); transform.Add("rotation", rotation); }
/// <summary> /// Unregisters the controllable in the manager /// </summary> /// <param name="controllable">Controllable to register</param> public void UnregisterControllable(ScenarioControllable controllable) { Controllables.Remove(controllable); ControllableUnregistered?.Invoke(controllable); }
/// <summary> /// Registers the controllable in the manager /// </summary> /// <param name="controllable">Controllable to register</param> public void RegisterControllable(ScenarioControllable controllable) { Controllables.Add(controllable); ControllableRegistered?.Invoke(controllable); }