/// <summary> /// /// </summary> private void DisplayLayerDensity() { CellLayer[] layers = _manager.Layers; float minDensity = layers.Min(layer => layer.Density); float maxDensity = layers.Max(layer => layer.Density); StackAnalyser analyser = _manager.Analyser; //change color of material property block _materialprops.SetColor("_Color", _layerDensityColor); foreach (var layer in layers) { float value = Remap(layer.Density, minDensity, maxDensity, 0.0f, 1.0f); Color color = Color.Lerp(Color.white, _layerDensityColor, value); foreach (var cell in layer.Cells) { // skip dead cells if (cell.State == 0) { continue; } //change color of material property block _materialprops.SetColor("_Color", color); cell.Renderer.SetPropertyBlock(_materialprops); } } }
/// <summary> /// /// </summary> private void Start() { _model = GetComponent <StackModel>(); _analyser = GetComponent <StackAnalyser>(); _properties = new MaterialPropertyBlock(); ResetDisplay(); }
/// <summary> /// /// </summary> private void DisplayAge() { StackAnalyser analyser = _manager.Analyser; //apply material props to each obj renderer foreach (var layer in _manager.Layers) { foreach (var cell in layer.Cells) { // skip dead cells if (cell.State == 0) { continue; } // map age to color float value = Remap(cell.Age, 0.0f, Mathf.Max(_ageDisplayMax, analyser.MaxAge), 0.0f, 1.0f); Color color = Color.Lerp(Color.white, _ageColor, value); //change color of material property block _materialprops.SetColor("_Color", color); cell.Renderer.SetPropertyBlock(_materialprops); } } }
/// <summary> /// /// </summary> private void Awake() { _layers = new CellLayer[_layerCount]; // instantiate layers for (int i = 0; i < _layerCount; i++) { CellLayer copy = Instantiate(_layerPrefab, transform); copy.transform.localPosition = new Vector3(0.0f, i, 0.0f); // create cell layer copy.Initialize(_cellPrefab, _rowCount, _columnCount); _layers[i] = copy; } // create rule _analyser = new StackAnalyser(this); MyCA rule = new MyCA(_analyser); // create model _model = new CAModel2D(rule, _rowCount, _columnCount); // initialize model _initializer.Initialize(_model.CurrentState); // center manager gameobject at the world origin transform.localPosition = new Vector3(_columnCount, _layerCount, _rowCount) * -0.5f; }
/// <summary> /// /// </summary> private void DisplayStackDensity() { CellLayer[] layers = _manager.Layers; StackAnalyser analyser = _manager.Analyser; Index3[] neighb = Neighborhoods.Moore3Cen; //apply material props to each obj renderer for (int k = 0; k < layers.Length; k++) { CellLayer layer = layers[k]; int m = layer.Rows; int n = layer.Columns; Cell[,] cells = layer.Cells; for (int i = 0; i < m; i++) { // Note: keep the 2nd index on the inner loop for better cache locality for (int j = 0; j < m; j++) { Cell cell = cells[i, j]; // skip dead cells if (cell.State == 0) { continue; } // map density to color int sum = analyser.GetNeighborSum3(i, j, k, neighb); float value = Remap(sum, 0, neighb.Length, 0, 1); Color color = Color.Lerp(Color.white, _stackDensityColor, value); //change color of material property block _materialprops.SetColor("_Color", color); cell.Renderer.SetPropertyBlock(_materialprops); } } } }
/// <summary> /// /// </summary> /// <param name="offsets"></param> public MyCA(StackAnalyser stackAnalyser) { _analyser = stackAnalyser; }
/// <summary> /// /// </summary> private void Start() { _model = GetComponent <StackModel>(); _analyser = GetComponent <StackAnalyser>(); }