public void Link(Contexts contexts, IEntity entity) { Contexts = contexts; Entity = (MapEditorEntity)entity; //TODO : How to solve this repeated code? var evtListeners = GetComponents <IEventListener>(); foreach (IEventListener listener in evtListeners) { listener.RegisterEvents(contexts, entity); } var collisionListeners = GetComponents <ICollisionController>(); foreach (var collisionController in collisionListeners) { collisionController.Initialize(contexts, entity); } var selectionController = GetComponents <ISelectionController>(); foreach (var controller in selectionController) { controller.Initialize(contexts, entity); } OnLink(Contexts, Entity); }
protected override void Execute(List <GameEntity> entities) { foreach (var tickEntity in entities) { if (_contexts.meta.tickService.instance.IsTick(tickEntity, TickEnum.MapEditor_AssetLoading) == false) { return; } var assetBays = _contexts.mapEditor.GetEntities(MapEditorMatcher.AssetBay); if (assetBays.Length == 0) { return; } var assetBay = assetBays.Single(); var assets = _contexts.meta.gridEditorService.service.GetAssets(); var mapEditor = _contexts.mapEditor.GetEntityWithAssetBay(assetBay.assetBay.id); var mapEditorView = mapEditor.mapEditor.view; var views = mapEditorView.AssetBay.GetCurrentViews(); var viewsDifference = views.Count - assets.Count; if (viewsDifference < 0) { var viewsToCreate = Math.Abs(viewsDifference); //Create required views var newViews = mapEditorView.AssetBay.CreateViews(viewsToCreate); for (var i = 0; i < viewsToCreate; i++) { views.Add(newViews[i]); } } if (viewsDifference > 0) { //Remove extra views //TODO : Consider pooling the extra views for performance var extraViews = mapEditorView.AssetBay.GetCurrentViews(); for (int i = viewsDifference - 1; i >= 0; i--) { var entity = _contexts.mapEditor.GetEntityWithId(extraViews[i].GetEntityId()); entity.isDestroyed = true; } } for (int i = 0; i < assets.Count; i++) { var asset = assets[i]; var view = views[i]; MapEditorEntity entity = null; if (view.GetEntityId() == -1) { entity = _contexts.mapEditor.CreateEntity(); _contexts.meta.viewService.instance.LinkAsset(_contexts, entity, view); entity.AddAssetData(asset); } else { entity = _contexts.mapEditor.GetEntityWithId(view.GetEntityId()); entity.ReplaceAssetData(asset); } } } }
public void OnDestroyed(MapEditorEntity entity) { Debug.Log("Destroy gameobject"); Destroy(gameObject); }
public void Unlink() { Entity = null; }
protected virtual void OnLink(Contexts contexts, MapEditorEntity entity) { }
public void OnAssetData(MapEditorEntity entity, IMapEditorAssetData assetData) { _renderer.sprite = Resources.Load <Sprite>(assetData.GetDisplaySpritePath()); }
protected override void OnLink(Contexts contexts, MapEditorEntity entity) { entity.AddMapEditor(this); }