Beispiel #1
0
        public QuantityInfo(QuantityType quantityType, [NotNull] Enum[] units, [NotNull] Enum baseUnit, [NotNull] IQuantity zero, [NotNull] BaseDimensions baseDimensions)
        {
            if (quantityType == QuantityType.Undefined)
            {
                throw new ArgumentException("Quantity type can not be undefined.", nameof(quantityType));
            }
            if (units == null)
            {
                throw new ArgumentNullException(nameof(units));
            }
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }
            if (zero == null)
            {
                throw new ArgumentNullException(nameof(zero));
            }
            if (baseDimensions == null)
            {
                throw new ArgumentNullException(nameof(baseDimensions));
            }

            Name           = quantityType.ToString();
            QuantityType   = quantityType;
            UnitType       = UnitEnumTypes.First(t => t.Name == $"{quantityType}Unit");
            UnitInfos      = units.Select(unit => new UnitInfo(unit)).ToArray();
            UnitNames      = UnitInfos.Select(unitInfo => unitInfo.Name).ToArray();
            Units          = units;
            BaseUnitInfo   = new UnitInfo(baseUnit);
            BaseUnit       = BaseUnitInfo.Value;
            Zero           = zero;
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions;
        }
Beispiel #2
0
        /// <summary>
        ///     Constructs an instance.
        /// </summary>
        /// <param name="name">Name of the quantity.</param>
        /// <param name="unitInfos">The information about the units for this quantity.</param>
        /// <param name="baseUnit">The base unit enum value.</param>
        /// <param name="zero">The zero quantity.</param>
        /// <param name="baseDimensions">The base dimensions of the quantity.</param>
        /// <param name="quantityType">The the quantity type. Defaults to Undefined.</param>
        /// <exception cref="ArgumentException">Quantity type can not be undefined.</exception>
        /// <exception cref="ArgumentNullException">If units -or- baseUnit -or- zero -or- baseDimensions is null.</exception>
        public QuantityInfo([NotNull] string name, [NotNull] UnitInfo[] unitInfos, [NotNull] Enum baseUnit, [NotNull] IQuantity zero, [NotNull] BaseDimensions baseDimensions,
                            QuantityType quantityType = QuantityType.Undefined)
        {
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }

            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));

            Name           = name;
            UnitType       = UnitEnumTypes.First(t => t.Name == $"{name}Unit");
            UnitInfos      = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos));
            BaseUnitInfo   = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));

            // Obsolete members
            UnitNames    = UnitInfos.Select(unitInfo => unitInfo.Name).ToArray();
            Units        = UnitInfos.Select(unitInfo => unitInfo.Value).ToArray();
            BaseUnit     = BaseUnitInfo.Value;
            QuantityType = quantityType;
        }
        /// <summary>
        ///     Constructs an instance.
        /// </summary>
        /// <param name="quantityType">The quantity enum value.</param>
        /// <param name="unitInfos">The information about the units for this quantity.</param>
        /// <param name="baseUnit">The base unit enum value.</param>
        /// <param name="zero">The zero quantity.</param>
        /// <param name="baseDimensions">The base dimensions of the quantity.</param>
        /// <exception cref="ArgumentException">Quantity type can not be undefined.</exception>
        /// <exception cref="ArgumentNullException">If units -or- baseUnit -or- zero -or- baseDimensions is null.</exception>
        public QuantityInfo(QuantityType quantityType, [NotNull] UnitInfo[] unitInfos, [NotNull] Enum baseUnit, [NotNull] IQuantity zero, [NotNull] BaseDimensions baseDimensions)
        {
            if (quantityType == QuantityType.Undefined)
            {
                throw new ArgumentException("Quantity type can not be undefined.", nameof(quantityType));
            }
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }

            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));


            Name           = quantityType.ToString();
            QuantityType   = quantityType;
            UnitType       = UnitEnumTypes.First(t => t.Name == $"{quantityType}Unit");
            UnitInfos      = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos));
            BaseUnitInfo   = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));

            // Obsolete members
#pragma warning disable 618
            UnitNames = UnitInfos.Select(unitInfo => unitInfo.Name).ToArray();
            Units     = UnitInfos.Select(unitInfo => unitInfo.Value).ToArray();
            BaseUnit  = BaseUnitInfo.Value;
#pragma warning restore 618
        }
Beispiel #4
0
        /// <summary>
        /// Gets the <see cref="UnitInfo"/> whose <see cref="BaseUnits"/> is a subset of <paramref name="baseUnits"/>.
        /// </summary>
        /// <example>Length.Info.GetUnitInfoFor(unitSystemWithFootAsLengthUnit) returns <see cref="UnitInfo" /> for <see cref="LengthUnit.Foot" />.</example>
        /// <param name="baseUnits">The <see cref="BaseUnits"/> to check against.</param>
        /// <returns>The <see cref="UnitInfo"/> that has <see cref="BaseUnits"/> that is a subset of <paramref name="baseUnits"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="baseUnits"/> is null.</exception>
        /// <exception cref="InvalidOperationException">No unit was found that is a subset of <paramref name="baseUnits"/>.</exception>
        /// <exception cref="InvalidOperationException">More than one unit was found that is a subset of <paramref name="baseUnits"/>.</exception>
        public UnitInfo GetUnitInfoFor(BaseUnits baseUnits)
        {
            if (baseUnits == null)
            {
                throw new ArgumentNullException(nameof(baseUnits));
            }

            var matchingUnitInfos = UnitInfos
                                    .Where((unitInfo) => unitInfo.BaseUnits.IsSubsetOf(baseUnits))
                                    .Take(2)
                                    .ToArray();

            var firstUnitInfo = matchingUnitInfos.FirstOrDefault();

            if (firstUnitInfo == null)
            {
                throw new InvalidOperationException($"No unit was found that is a subset of {nameof(baseUnits)}");
            }

            if (matchingUnitInfos.Length > 1)
            {
                throw new InvalidOperationException($"More than one unit was found that is a subset of {nameof(baseUnits)}");
            }

            return(firstUnitInfo);
        }
Beispiel #5
0
    public void Shoot(Rigidbody2D p_RgdBody, UnitInfos p_UnitInfos, GameObject p_Player, string p_Direction)
    {
        if (lastShoot == 0f || (Time.time - lastShoot) > p_UnitInfos.getTimerProjectile())
        {
            var newBullet     = Instantiate(bulletPrefab, p_Player.transform.position, p_Player.transform.rotation).gameObject;
            var bulletRgdBody = newBullet.GetComponent <Rigidbody2D>();

            var bulletVelocity = new Vector2(0f, 0f);
            switch (p_Direction)
            {
            case "right":
                bulletVelocity.x = p_UnitInfos.getProjectileVitesse();
                break;

            case "left":
                bulletVelocity.x = -p_UnitInfos.getProjectileVitesse();
                break;

            case "top":
                bulletVelocity.y = p_UnitInfos.getProjectileVitesse();
                break;

            case "bottom":
                bulletVelocity.y = -p_UnitInfos.getProjectileVitesse();
                break;
            }

            _computeBonuses(ref newBullet);

            bulletRgdBody.velocity = bulletVelocity;
            Destroy(newBullet.gameObject, p_UnitInfos.getProjectileRange());

            lastShoot = Time.time;
        }
    }
Beispiel #6
0
        /// <summary>
        /// Gets an <see cref="IEnumerable{T}"/> of <see cref="UnitInfo"/> that have <see cref="BaseUnits"/> that is a subset of <paramref name="baseUnits"/>.
        /// </summary>
        /// <param name="baseUnits">The <see cref="BaseUnits"/> to check against.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="UnitInfo"/> that have <see cref="BaseUnits"/> that is a subset of <paramref name="baseUnits"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="baseUnits"/> is null.</exception>
        public IEnumerable <UnitInfo> GetUnitInfosFor(BaseUnits baseUnits)
        {
            if (baseUnits is null)
            {
                throw new ArgumentNullException(nameof(baseUnits));
            }

            return(UnitInfos.Where((unitInfo) => unitInfo.BaseUnits.IsSubsetOf(baseUnits)));
        }
Beispiel #7
0
        /// <summary>
        ///     Constructs an instance.
        /// </summary>
        /// <param name="name">Name of the quantity.</param>
        /// <param name="unitType">The unit enum type, such as <see cref="LengthUnit" />.</param>
        /// <param name="unitInfos">The information about the units for this quantity.</param>
        /// <param name="baseUnit">The base unit enum value.</param>
        /// <param name="zero">The zero quantity.</param>
        /// <param name="baseDimensions">The base dimensions of the quantity.</param>
        /// <param name="quantityType">The the quantity type. Defaults to Undefined.</param>
        /// <exception cref="ArgumentException">Quantity type can not be undefined.</exception>
        /// <exception cref="ArgumentNullException">If units -or- baseUnit -or- zero -or- baseDimensions is null.</exception>
        public QuantityInfo(string name, Type unitType, UnitInfo[] unitInfos, Enum baseUnit, IQuantity zero, Dimensions baseDimensions,
                            QuantityType quantityType = QuantityType.Undefined)
        {
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }

            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));

            Name           = name ?? throw new ArgumentNullException(nameof(name));
            UnitType       = unitType ?? throw new ArgumentNullException(nameof(unitType));
            UnitInfos      = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos));
            BaseUnitInfo   = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));

            // Obsolete members
            QuantityType = quantityType;
        }
Beispiel #8
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    public void NewSelectionOLD(List <Selectable> selected)
    {
        // Clear all the panels
        for (int i = 0; i < SelectionPanels.Count; i++)
        {
            SelectionPanels[i].Wipe();
        }
        _CurrentlySelected.Clear();
        _UnitInfos.Clear();

        // Cast Selectables to WorldObjects
        for (int i = 0; i < selected.Count; i++)
        {
            WorldObject obj = selected[i].GetComponent <WorldObject>();
            if (obj != null)
            {
                _CurrentlySelected.Add(obj);
            }
        }

        // Loop through selected WorldObjects
        for (int i = 0; i < _CurrentlySelected.Count; i++)
        {
            // As long as the WorldObject is a valid AI object
            if (GetUnitType(_CurrentlySelected[i]) != Unit.EUnitType.Undefined)
            {
                // First unit type
                if (_UnitInfos.Count == 0)
                {
                    // Add new type to known list
                    UnitInfos info = new UnitInfos {
                        _UnitType = GetUnitType(_CurrentlySelected[i]),
                        _Amount   = 1,
                        _Logo     = _CurrentlySelected[i].Logo
                    };
                    _UnitInfos.Add(info);
                }

                else
                {
                    // Loop through known unit types
                    for (int j = 0; j < _UnitInfos.Count; j++)
                    {
                        // This unit type is already known
                        if (GetUnitType(_CurrentlySelected[i]) == _UnitInfos[j]._UnitType)
                        {
                            // Add to unit amount
                            _UnitInfos[j]._Amount++;
                            break;
                        }

                        // Reached the end of the known unit types with no match
                        if (j + 1 == _UnitInfos.Count)
                        {
                            // Add new type to known list
                            UnitInfos info = new UnitInfos {
                                _UnitType = GetUnitType(_CurrentlySelected[i]),
                                _Amount   = 1,
                                _Logo     = _CurrentlySelected[i].Logo
                            };
                            _UnitInfos.Add(info);
                        }
                    }
                }
            }
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //
    /// </summary>
    public void RefreshPanels()
    {
        // Reset lists
        for (int i = 0; i < _UnitInfoPanels.Count; i++)
        {
            ObjectPooling.Despawn(_UnitInfoPanels[i].gameObject);
        }
        _UnitInfos.Clear();
        _UnitInfoPanels.Clear();

        // Add a new panel for each type of unit selected by the player
        for (int i = 0; i < _SelectedUnits.Count; i++)
        {
            // Check if this unit already exists in the info lists
            bool matchingType = false;
            for (int j = 0; j < _UnitInfos.Count; j++)
            {
                // Matching type to existing info
                if (_SelectedUnits[i].UnitType == _UnitInfos[j]._UnitType)
                {
                    // Add to count of the unit info
                    _UnitInfos[j]._Amount++;
                    matchingType = true;
                    break;
                }
            }

            // No unit infos match the selected unit were testing against
            if (!matchingType)
            {
                // Create a new iterator in the info lists
                UnitInfos info = new UnitInfos {
                    _UnitType   = _SelectedUnits[i].UnitType,
                    _Logo       = _SelectedUnits[i].Logo,
                    _CombatType = _SelectedUnits[i].CombatType,
                    _Amount     = 1
                };
                _UnitInfos.Add(info);
            }
        }

        // Create a new panel for each unit info
        for (int i = 0; i < _UnitInfos.Count; i++)
        {
            if (StencilObject != null)
            {
                // Spawn panel & pass unit info data
                UI_UnitInfoPanel panel = ObjectPooling.Spawn(StencilObject.gameObject).GetComponent <UI_UnitInfoPanel>();
                panel.LogoComponent.sprite = _UnitInfos[i]._Logo;
                panel.UnitName.text        = _UnitInfos[i]._UnitType.ToString();
                panel.AmountCounter.text   = _UnitInfos[i]._Amount.ToString();
                panel.SetPanelInfo(_UnitInfos[i]);
                panel.SetPlayer(_Player);

                // Set combat type logo
                switch (_UnitInfos[i]._CombatType)
                {
                case Unit.ECombatType.GroundInfantry:
                    panel.TypeComponent.sprite = GroundInfantryLogo;
                    break;

                case Unit.ECombatType.GroundVehicle:
                    panel.TypeComponent.sprite = GroundVehicleLogo;
                    break;

                case Unit.ECombatType.AirVehicle:
                    panel.TypeComponent.sprite = AirVehicleLogo;
                    break;

                default: break;
                }

                // Set anchoring position
                RectTransform rectT = panel.GetComponent <RectTransform>();
                panel.transform.SetParent(gameObject.transform);
                if (i > 0)
                {
                    // Not the first panel
                    rectT.anchoredPosition = new Vector2((StartingPositionX + (_PanelSize * i) + (OffsetX * i)), StartingPositionY);
                }
                else
                {
                    // First panel
                    rectT.anchoredPosition = new Vector2(StartingPositionX, StartingPositionY);
                }
                _UnitInfoPanels.Add(panel);
            }
        }
    }