Ejemplo n.º 1
0
        private void AsyncGenerationCompleted()
        {
            if (_slots.Count != _size)
            {
                throw new Exception($"slots List size must be equals the slot machine size {_size} ");
            }
            var slotSize = _slots[0]?.rectTransform.sizeDelta;

            if (!slotSize.HasValue)
            {
                throw new Exception($"Slot size doesn't have a value");
            }

            Matrix = new Slot[_dimension.x, _dimension.y];
            for (var x = 0; x < _dimension.x; x++)
            {
                for (var y = 0; y < _dimension.y; y++)
                {
                    //- define
                    var location   = new Vector2Int(x, y);
                    var targetSlot = _slots[x * _dimension.y + y];

                    //- assign
                    targetSlot.Initialize(this, location);
                    Matrix[x, y] = targetSlot;
                }
            }
            AssignColumns();
        }
Ejemplo n.º 2
0
        private Vector2 LocationToPosition(Vector2Int inLocation, Vector2 inSlotSize)
        {
            var spacing      = new Vector2(_parentMachine.Config.spacing.x * inLocation.y, -_parentMachine.Config.spacing.y * inLocation.x);
            var slotPosition = new Vector2(inSlotSize.x * inLocation.y, -inSlotSize.y * inLocation.x);

            return(_parentMachine.Config.padding + slotPosition + spacing);
        }
Ejemplo n.º 3
0
 public void Initialize(SlotMachine inMachine, Vector2Int inLocation)
 {
     _parentMachine = inMachine;
     _location      = inLocation;
     RandomSymbol();
     UpdatePosition();
     name = $"Slot [{_location.ToString()}]";
     rectTransform.localScale = Vector3.one;
 }
Ejemplo n.º 4
0
        public void GenerateSlots(GenerateType inType, Vector2Int inDimension)
        {
            _dimension = inDimension;

            ClearMachine();
            switch (inType)
            {
            case GenerateType.Asynchronous:
                _size = _dimension.x * _dimension.y;
                SpawnSlotAsync(0);
                break;

            case GenerateType.Synchronous:
                var loader = new AssetsLoader();
                loader.Load <GameObject>(slotReference, GenerateSlotSync);
                break;
            }
        }
Ejemplo n.º 5
0
        private void GenerateSlotSync(GameObject inSlotPrefab, AsyncOperationHandle <GameObject> operationHandle)
        {
            Matrix = new Slot[_dimension.x, _dimension.y];
            for (var x = 0; x < _dimension.x; x++)
            {
                for (var y = 0; y < _dimension.y; y++)
                {
                    //- define
                    var location   = new Vector2Int(x, y);
                    var targetSlot = Instantiate(inSlotPrefab, slotsHolder).GetComponent <Slot>();

                    //- assign
                    targetSlot.Initialize(this, location);
                    Matrix[x, y] = targetSlot;
                }
            }
            Addressables.Release(operationHandle);     //release the slot prefab
            AssignColumns();
        }