private void OnDestroy() { // Detach from events map.OnMapUpdate -= OnMapUpdate; dataLayers.OnLayerVisibilityChange -= OnLayerVisibilityChange; // Stop coroutines if (drawingArea != null) { StopCoroutine(drawingArea); } if (planningOutputPanel != null) { outputPanel.DestroyPanel(planningOutputPanel.gameObject); planningOutputPanel = null; } // Clear icons foreach (var cell in planningCells) { cell.ClearIcon(); } // Destroy pulsating cell if (pulsatingCell != null) { Destroy(pulsatingCell.gameObject); pulsatingCell = null; } // Destroy containers if (iconContainer != null) { Destroy(iconContainer.gameObject); iconContainer = null; } if (flagger != null) { Destroy(flagger.gameObject); flagger = null; } // Destroy materials foreach (var mat in materialsMap) { Destroy(mat.Value); } // Clear list and maps typologiesMap.Clear(); materialsMap.Clear(); planningCells.Clear(); planningCellsMap.Clear(); planningGroups.Clear(); }
public void Awake() { TestCommand = IntProp.Select(x => x > 0).ToReactiveCommand <int>(); TestCommand.Subscribe(val => { Debug.unityLogger.Log($"val = {val} IntProp.Value = {IntProp.Value}"); IntProp.Value -= 1; }); ChangeColor = Flagger.ToMVVMReactiveCommand(); ChangeColor.Subscribe(_ => Color.Value = Random.ColorHSV()); }
public void Init(TypologyLibrary typologyLibrary, GridData grid, List <Typology> typologies) { this.grid = grid; this.typologies = typologies; dataLayers.OnLayerVisibilityChange += OnLayerVisibilityChange; // Create typologies map foreach (var entry in typologyLibrary.typologies) { typologiesMap.Add(entry.name, entry); } // Cache grid transformations gridCoordsToCell = new Distance(grid.countX / (grid.east - grid.west), grid.countY / (grid.south - grid.north)); gridCellToCoords = new Distance((grid.east - grid.west) / grid.countX, (grid.south - grid.north) / grid.countY); // Create pulsating cell (inside map) pulsatingCell = Instantiate(pulsatingCellPrefab, map.transform, false); pulsatingCell.name = pulsatingCellPrefab.name; pulsatingCell.Init((float)(gridCellToCoords.x * GeoCalculator.Deg2Meters)); // Create icon container (inside map) iconContainer = new GameObject("Typology Icons").transform; iconContainer.SetParent(map.transform, false); // Attach to events map.OnMapUpdate += OnMapUpdate; // Update output panel planningOutputPanel = Instantiate(outputPrefab); planningOutputPanel.Init(); planningOutputPanel.name = outputPrefab.name; planningOutputPanel.SetTypologies(typologies); planningOutputPanel.SetTargetValues(targetValues); SetOutput(); planningOutputPanel.UpdateOutput(); // Create flagger flagger = Instantiate(flaggerPrefab); flagger.name = flaggerPrefab.name; flagger.Init(grid, planningOutputPanel); }