public void Initialize() { if (isInitialized) { Debug.Log("Building Carousel."); CleanUp(); } GenerateDisplays(displayCasePrefab, shaderModelPrefab, materials.materials.Count); // Swap materials on each model for (int _i = 0; _i < displays.Count; _i++) { DisplayCase _display = displays[_i]; _display.ChangeModelMaterial(materials.materials[_i]); _display.gameObject.name = "Display Case: " + _display.GetModelRenderer().sharedMaterial.shader; } startPosition = transform.position; displayCaseSelector.Initialize(displays); displayCaseSelector.onSelectionChange += OnSelectionChange; isInitialized = true; }
private void OnSelectionChange(DisplayCase _previousCase, DisplayCase _currentCase) { if (_currentCase == null) { text.enabled = false; return; } text.enabled = true; text.text = _currentCase.GetModelRenderer().sharedMaterial.shader.ToString(); }
private void OnSelectionChange(DisplayCase _previousDisplay, DisplayCase _currentDisplay) { onSelection?.Invoke(this); startPosition = transform.position; endPosition = new Vector3(staggerDisplayOffset.x * (displayCaseSelector.GetCurrentIndex() * -1), startPosition.y, startPosition.z); totalAccumulatedTime = 0; isRunning = true; onDisplayChange?.Invoke(_previousDisplay, _currentDisplay); }
/// <summary> /// Creates and caches a list of DisplayCases /// </summary> /// <param name="_display">What display case do you want to generate?</param> /// <param name="_modelToSpawnInside">What GameObject do you want to generate inside the display case?</param> /// <param name="_quantity">How many displays would you like to generate?</param> /// <returns></returns> private void GenerateDisplays(DisplayCase _display, GameObject _modelToSpawnInside, int _quantity) { displays.Clear(); for (int _i = 0; _i < _quantity; _i++) { // Create a display DisplayCase _displayCase = Instantiate(_display, transform); _displayCase.Initialize(_modelToSpawnInside, itemOffset); _displayCase.SetDisplayPosition(_displayCase.GetDisplayWorldPosition() + staggerDisplayOffset * _i + individualDisplayOffset); _displayCase.onClick += OnDisplayCaseClick; // Cache display displays.Add(_displayCase); } }
/// <summary> /// Invoked when the user clicks on the display case /// </summary> /// <param name="_displayCase"></param> private void OnDisplayCaseClick(DisplayCase _displayCase) { displayCaseSelector.Select(_displayCase); }