| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine.Events; |
| | 4 | |
|
| | 5 | | public enum EntityAction |
| | 6 | | { |
| | 7 | | SELECT = 0, |
| | 8 | | LOCK = 1, |
| | 9 | | DELETE = 2, |
| | 10 | | SHOW = 3 |
| | 11 | | } |
| | 12 | |
|
| | 13 | | public interface IInspectorController |
| | 14 | | { |
| | 15 | | event Action<BIWEntity> OnEntityClick; |
| | 16 | | event Action<BIWEntity> OnEntityDelete; |
| | 17 | | event Action<BIWEntity> OnEntityLock; |
| | 18 | | event Action<BIWEntity> OnEntityChangeVisibility; |
| | 19 | | event Action<BIWEntity, string> OnEntityRename; |
| | 20 | |
|
| | 21 | | ISceneLimitsController sceneLimitsController { get; } |
| | 22 | |
|
| | 23 | | void Initialize(IInspectorView inspectorView); |
| | 24 | | void Dispose(); |
| | 25 | | void OpenEntityList(); |
| | 26 | | void SetEntityList(List<BIWEntity> sceneEntities); |
| | 27 | | void ClearList(); |
| | 28 | | void CloseList(); |
| | 29 | | void EntityActionInvoked(EntityAction action, BIWEntity entityToApply, EntityListAdapter adapter); |
| | 30 | | void EntityRename(BIWEntity entity, string newName); |
| | 31 | | void SetCloseButtonsAction(UnityAction call); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public class InspectorController : IInspectorController |
| | 35 | | { |
| | 36 | | public event Action<BIWEntity> OnEntityClick; |
| | 37 | | public event Action<BIWEntity> OnEntityDelete; |
| | 38 | | public event Action<BIWEntity> OnEntityLock; |
| | 39 | | public event Action<BIWEntity> OnEntityChangeVisibility; |
| | 40 | | public event Action<BIWEntity, string> OnEntityRename; |
| | 41 | |
|
| 0 | 42 | | public ISceneLimitsController sceneLimitsController => inspectorView.sceneLimitsController; |
| | 43 | |
|
| | 44 | | internal IInspectorView inspectorView; |
| | 45 | |
|
| | 46 | | public void Initialize(IInspectorView inspectorView) |
| | 47 | | { |
| 10 | 48 | | this.inspectorView = inspectorView; |
| | 49 | |
|
| 10 | 50 | | inspectorView.OnEntityActionInvoked += EntityActionInvoked; |
| 10 | 51 | | inspectorView.OnEntityRename += EntityRename; |
| | 52 | |
|
| 10 | 53 | | inspectorView.ConfigureSceneLimits(new SceneLimitsController()); |
| 10 | 54 | | CloseList(); |
| 10 | 55 | | } |
| | 56 | |
|
| | 57 | | public void Dispose() |
| | 58 | | { |
| 10 | 59 | | inspectorView.OnEntityActionInvoked -= EntityActionInvoked; |
| 10 | 60 | | inspectorView.OnEntityRename -= EntityRename; |
| 10 | 61 | | } |
| | 62 | |
|
| | 63 | | public void OpenEntityList() |
| | 64 | | { |
| 1 | 65 | | if (inspectorView.entityList != null) |
| | 66 | | { |
| 0 | 67 | | if (inspectorView.entities != null) |
| 0 | 68 | | inspectorView.entityList.SetContent(inspectorView.entities); |
| | 69 | |
|
| 0 | 70 | | inspectorView.entityList.SetActive(true); |
| | 71 | | } |
| | 72 | |
|
| 1 | 73 | | inspectorView.SetActive(true); |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | public void SetEntityList(List<BIWEntity> sceneEntities) |
| | 77 | | { |
| 1 | 78 | | inspectorView.SetEntitiesList(sceneEntities); |
| | 79 | |
|
| 1 | 80 | | if (inspectorView.entityList != null && |
| | 81 | | inspectorView.entityList.isActive && |
| | 82 | | inspectorView.entities != null) |
| | 83 | | { |
| 0 | 84 | | inspectorView.entityList.SetContent(inspectorView.entities); |
| | 85 | | } |
| 1 | 86 | | } |
| | 87 | |
|
| | 88 | | public void ClearList() |
| | 89 | | { |
| 1 | 90 | | inspectorView.ClearEntitiesList(); |
| | 91 | |
|
| 1 | 92 | | if (inspectorView.entityList != null) |
| 0 | 93 | | inspectorView.entityList.RemoveAdapters(); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | public void CloseList() |
| | 97 | | { |
| 11 | 98 | | inspectorView.SetActive(false); |
| | 99 | |
|
| 11 | 100 | | if (inspectorView.entityList != null) |
| 0 | 101 | | inspectorView.entityList.SetActive(false); |
| 11 | 102 | | } |
| | 103 | |
|
| | 104 | | public void EntityActionInvoked(EntityAction action, BIWEntity entityToApply, EntityListAdapter adapter) |
| | 105 | | { |
| | 106 | | switch (action) |
| | 107 | | { |
| | 108 | | case EntityAction.SELECT: |
| | 109 | |
|
| 1 | 110 | | OnEntityClick?.Invoke(entityToApply); |
| 1 | 111 | | break; |
| | 112 | | case EntityAction.LOCK: |
| | 113 | |
|
| 1 | 114 | | OnEntityLock?.Invoke(entityToApply); |
| 1 | 115 | | break; |
| | 116 | | case EntityAction.DELETE: |
| | 117 | |
|
| 1 | 118 | | OnEntityDelete?.Invoke(entityToApply); |
| 1 | 119 | | break; |
| | 120 | | case EntityAction.SHOW: |
| 1 | 121 | | OnEntityChangeVisibility?.Invoke(entityToApply); |
| | 122 | | break; |
| | 123 | | } |
| 1 | 124 | | } |
| | 125 | |
|
| 2 | 126 | | public void EntityRename(BIWEntity entity, string newName) { OnEntityRename?.Invoke(entity, newName); } |
| | 127 | |
|
| 2 | 128 | | public void SetCloseButtonsAction(UnityAction call) { inspectorView.SetCloseButtonsAction(call); } |
| | 129 | | } |