diff --git a/Assets/Scripts/ScenarioEditor/Managers/ScenarioControllablesManager.cs b/Assets/Scripts/ScenarioEditor/Managers/ScenarioControllablesManager.cs index a84d6102e..9c920c8eb 100644 --- a/Assets/Scripts/ScenarioEditor/Managers/ScenarioControllablesManager.cs +++ b/Assets/Scripts/ScenarioEditor/Managers/ScenarioControllablesManager.cs @@ -120,6 +120,7 @@ private void OnMapChanged(ScenarioMapManager.MapMetaData mapData) if (!controllable.IsEditableOnMap) controllable.Dispose(); } + LoadMapControllables(); } @@ -135,7 +136,7 @@ private void LoadMapControllables() var scenarioControllable = mapSignal.CurrentSignalLight.gameObject.AddComponent(); scenarioControllable.Uid = mapSignal.UID; var policy = new List(mapSignal.DefaultControlPolicy); - scenarioControllable.Setup(source, mapSignalVariant,policy); + scenarioControllable.Setup(source, mapSignalVariant, policy); var boxCollider = scenarioControllable.gameObject.AddComponent(); boxCollider.isTrigger = true; var meshRenderers = scenarioControllable.GetComponentsInChildren(); @@ -146,11 +147,12 @@ private void LoadMapControllables() boxCollider.size = Vector3.one; continue; } + var bounds = meshRenderers[0].bounds; for (var i = 1; i < meshRenderers.Length; i++) bounds.Encapsulate(meshRenderers[i].bounds); - boxCollider.center = bounds.center-scenarioControllable.transform.position; - boxCollider.size = bounds.extents*2; + boxCollider.center = bounds.center - scenarioControllable.transform.position; + boxCollider.size = bounds.extents * 2; } } @@ -162,7 +164,13 @@ private void InstanceOnScenarioReset() for (var i = Controllables.Count - 1; i >= 0; i--) { var controllable = Controllables[i]; - if (!controllable.IsEditableOnMap) continue; + if (!controllable.IsEditableOnMap) + { + controllable.Policy = + new List(controllable.Variant.controllable.DefaultControlPolicy); + continue; + } + controllable.RemoveFromMap(); controllable.Dispose(); } diff --git a/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEditPanel.cs b/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEditPanel.cs index 68ed4455a..0069862bb 100644 --- a/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEditPanel.cs +++ b/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEditPanel.cs @@ -124,8 +124,8 @@ private void SetPolicy(List policy) Policy = policy; if (policy != null) { - while (entries.Count < policy.Count) AddPolicyEntry(); - while (entries.Count > policy.Count) RemovePolicyEntry(entries[0]); + while (entries.Count < policy.Count) AddPolicyEntry(updatePolicy: false); + while (entries.Count > policy.Count) RemovePolicyEntry(entries[0], updatePolicy: false); for (var i = 0; i < entries.Count; i++) { @@ -168,7 +168,8 @@ public void AddPolicyEntryWithUndo() { var newEntry = ScenarioManager.Instance.prefabsPools.GetInstance(policyEntryPrefab.gameObject) .GetComponent(); - var undoRecord = new GenericUndo(newEntry, "Undo adding a policy entry", RemovePolicyEntry); + var undoRecord = new GenericUndo(newEntry, "Undo adding a policy entry", + entry => RemovePolicyEntry(entry)); ScenarioManager.Instance.GetExtension().RegisterRecord(undoRecord); AddPolicyEntry(newEntry); } @@ -177,7 +178,8 @@ public void AddPolicyEntryWithUndo() /// Add a single policy entry to this edit panel /// /// Policy entry to be added - private void AddPolicyEntry(PolicyEntry newEntry = null) + /// Should the policy be updated + private void AddPolicyEntry(PolicyEntry newEntry = null, bool updatePolicy = true) { if (newEntry == null) newEntry = ScenarioManager.Instance.prefabsPools.GetInstance(policyEntryPrefab.gameObject) @@ -186,6 +188,8 @@ private void AddPolicyEntry(PolicyEntry newEntry = null) newEntry.Initialize(this, validActions, validStates, validActions[0], ""); newEntry.transform.SetParent(transform); newEntry.gameObject.SetActive(true); + if (updatePolicy) + UpdatePolicy(); UnityUtilities.LayoutRebuild(transform as RectTransform); } @@ -215,12 +219,14 @@ public void RemovePolicyEntryWithUndo(PolicyEntry entry) /// Remove the policy entry from this edit panel /// /// Policy entry to be removed - public void RemovePolicyEntry(PolicyEntry entry) + /// Should the policy be updated + public void RemovePolicyEntry(PolicyEntry entry, bool updatePolicy = true) { entry.gameObject.SetActive(false); entries.Remove(entry); entry.Deinitialize(); - UpdatePolicy(); + if (updatePolicy) + UpdatePolicy(); UnityUtilities.LayoutRebuild(transform as RectTransform); } @@ -268,6 +274,7 @@ public void PastePolicy() pasteAction.Invoke(); return; } + //Ask for replacing current policy var popupData = new ConfirmationPopup.PopupData { diff --git a/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEntry.cs b/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEntry.cs index 60dceb96e..a06d6588f 100644 --- a/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEntry.cs +++ b/Assets/Scripts/ScenarioEditor/UI/EditElement/Controllables/PolicyEntry.cs @@ -273,7 +273,7 @@ public void Remove() /// Is policy valid for the given controllable private bool Validate() { - return !string.IsNullOrEmpty(Policy.Action) && !string.IsNullOrEmpty(Policy.Value); + return !string.IsNullOrEmpty(Policy.Action); } } } \ No newline at end of file