Ejemplo n.º 1
0
 public static string GetAbbreviation(LevelUnit unit, [CanBeNull] Culture culture)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
Ejemplo n.º 2
0
 public static void HasConversion(this PropertyBuilder <Level> propertyBuilder, LevelUnit unit) =>
 propertyBuilder.HasConversion(v => v.As(unit), v => new Level(v, unit));
Ejemplo n.º 3
0
        /// <summary>
        ///     Converts this Level to another Level with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Level with the specified unit.</returns>
        public Level ToUnit(LevelUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new Level(convertedValue, unit));
        }
Ejemplo n.º 4
0
 public static Level From(double value, LevelUnit fromUnit)
Ejemplo n.º 5
0
 public static string GetAbbreviation(LevelUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Dynamically convert from value and unit enum <see cref="LevelUnit" /> to <see cref="Level" />.
 /// </summary>
 /// <param name="value">Value to convert from.</param>
 /// <param name="fromUnit">Unit to convert from.</param>
 /// <returns>Level unit value.</returns>
 public static Level?From(QuantityValue?value, LevelUnit fromUnit)
 {
     return(value.HasValue ? new Level((double)value.Value, fromUnit) : default(Level?));
 }
Ejemplo n.º 7
0
        public static string GetAbbreviation(LevelUnit unit, [CanBeNull] IFormatProvider provider)
        {
            provider = provider ?? UnitSystem.DefaultCulture;

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
Ejemplo n.º 8
0
 public string ToString(LevelUnit unit, CultureInfo culture, string format, params object[] args)
 {
     return(string.Format(culture, format, UnitFormatter.GetFormatArgs(unit, As(unit), culture, args)));
 }
Ejemplo n.º 9
0
        /// <summary>
        ///     Get unit abbreviation string.
        /// </summary>
        /// <param name="unit">Unit to get abbreviation for.</param>
        /// <returns>Unit abbreviation string.</returns>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static string GetAbbreviation(LevelUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Ejemplo n.º 10
0
 public static string GetAbbreviation(LevelUnit unit, CultureInfo culture = null)
 {
     return(UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit));
 }
Ejemplo n.º 11
0
 public string ToString(LevelUnit unit, CultureInfo culture = null, int significantDigitsAfterRadix = 2)
 {
     return(ToString(unit, culture, UnitFormatter.GetFormat(As(unit), significantDigitsAfterRadix)));
 }
Ejemplo n.º 12
0
 /// <summary>
 ///     Creates the quantity with the given numeric value and unit.
 /// </summary>
 /// <param name="value">The numeric value to construct this quantity with.</param>
 /// <param name="unit">The unit representation to construct this quantity with.</param>
 /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
 public Level(double value, LevelUnit unit)
 {
     _value = value;
     _unit  = unit;
 }
Ejemplo n.º 13
0
        /// <summary>
        ///     Converts this Duration to another Duration with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Duration with the specified unit.</returns>
        public Level ToUnit(LevelUnit unit)
        {
            var convertedValue = GetValueAs(unit);

            return(new Level(convertedValue, unit));
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Convert to the unit representation <paramref name="unit" />.
 /// </summary>
 /// <returns>Value converted to the specified unit.</returns>
 public double As(LevelUnit unit) => GetValueAs(unit);
Ejemplo n.º 15
0
 /// <summary>
 ///     Get string representation of value and unit. Using current UI culture and two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <returns>String representation.</returns>
 public string ToString(LevelUnit unit)
 {
     return(ToString(unit, null, 2));
 }
Ejemplo n.º 16
0
 public static Level From(double value, LevelUnit fromUnit)
 {
     return(new Level((double)value, fromUnit));
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     Get string representation of value and unit. Using two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <param name="culture">Culture to use for localization and number formatting.</param>
 /// <returns>String representation.</returns>
 public string ToString(LevelUnit unit, [CanBeNull] Culture culture)
 {
     return(ToString(unit, culture, 2));
 }
Ejemplo n.º 18
0
 public static bool TryParseUnit(string str, out LevelUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
Ejemplo n.º 19
0
 /// <summary>
 ///     Get string representation of value and unit. Using two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <param name="provider">Format to use for localization and number formatting. Defaults to <see cref="UnitSystem.DefaultCulture" />.</param>
 /// <returns>String representation.</returns>
 public string ToString(LevelUnit unit, [CanBeNull] IFormatProvider provider)
 {
     return(ToString(unit, provider, 2));
 }
Ejemplo n.º 20
0
        /// <summary>
        ///     Parse a unit string.
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="unit">The parsed unit if successful.</param>
        /// <returns>True if successful, otherwise false.</returns>
        /// <example>
        ///     Length.TryParseUnit("m", new CultureInfo("en-US"));
        /// </example>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out LevelUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <LevelUnit>(str, provider, out unit));
        }
Ejemplo n.º 21
0
 Level(double numericValue, LevelUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }
Ejemplo n.º 22
0
        public static void renderGUI(int vpos)
        {
            vpos += OET_lib.ToolLib.header("<b>Init / Save / Load</b>\nSave or Load the Scene with JSON.", vpos, false);

            int   width   = Screen.width;
            float btWidth = width < 160 ? width - 20 : 160;

            GUI.Label(new Rect(10, vpos, 150, 20), "+x");
            Num_x = EditorGUI.IntSlider(new Rect(90, vpos, width - 100, 20), Num_x, 1, 20);

            GUI.Label(new Rect(10, vpos + 50, 150, 20), "+z");
            Num_z = EditorGUI.IntSlider(new Rect(90, vpos + 50, width - 100, 20), Num_z, 1, 20);

            GUI.enabled = !OET_io.lib.LevelIsLoaded;


            // Init button
            if (GUI.Button(new Rect(width / 2 - btWidth / 2, vpos + 100, btWidth, 25), "Init") && initialized == false)
            {
                // This will force a database reload
                new LevelObjectDatabase();

                GameObject _platform = new GameObject("LOADED LEVEL");

                _CreateSingleton();

                Undo.RegisterCreatedObjectUndo(_platform, "Init the level");

                //GameObject _prefab = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Old/Environment/Hallway/Hallway_Floor.prefab", typeof(GameObject)) as GameObject;

                for (int i = -Num_x; i <= Num_x; i++)
                {
                    for (int j = -Num_z; j <= Num_z; j++)
                    {
                        GameObject _instance = Instantiate(tileObject.Prefab, new Vector3(i * OET_grid.lib.size_x, 0, j * OET_grid.lib.size_z), Quaternion.identity);
                        _instance.name = tileObject.Path;

                        //Edge + Wall
                        if (i == -Num_x || i == Num_x || j == -Num_z || j == Num_z)
                        {
                            _AddNavMeshModifier(_instance, OET_lib.NavMeshAreas.NotWalkable);

                            GameObject _wall = Instantiate(tileObject.Prefab, new Vector3(i * OET_grid.lib.size_x, OET_grid.lib.size_y, j * OET_grid.lib.size_z), Quaternion.identity);
                            _wall.transform.SetParent(_platform.transform);
                            Undo.RegisterCreatedObjectUndo(_wall, "Init the level");
                            OET_io.lib.ActiveGameObjects.Add(_wall);
                            _AddNavMeshModifier(_wall, OET_lib.NavMeshAreas.NotWalkable);
                        }
                        else if (_instance.GetComponent <LevelUnit>() == null)
                        {
                            LevelUnit LU = _instance.AddComponent <LevelUnit>() as LevelUnit;
                            LU.defaultState = LevelUnitStates.Floor;
                            _AddNavMeshModifier(_instance, OET_lib.NavMeshAreas.Walkable);
                        }

                        _instance.transform.SetParent(_platform.transform);
                        Undo.RegisterCreatedObjectUndo(_instance, "Init the level");
                        OET_io.lib.ActiveGameObjects.Add(_instance);
                    }
                }


                GameObject NavSurface = GameObject.Find("NavMeshSurface");

                if (NavSurface)
                {
                    NavSurface.GetComponent <NavMeshSurface>().BuildNavMesh();
                }


                OET_io.lib.SetDirty(true);
            }

            tileObject = EditorGUI.ObjectField(
                new Rect(width / 2 + btWidth / 2 + 8, vpos + 100, btWidth, 25),
                tileObject,
                typeof(LevelEditorObject)) as LevelEditorObject;

            GUI.enabled = OET_io.lib.LevelIsLoaded;

            // Save button
            if (GUI.Button(new Rect(width / 2 - btWidth / 2, vpos + 150, btWidth, 25), "Save"))
            {
                OET_io.lib.SaveCurrentLevel();
            }

            // Save As button
            if (GUI.Button(new Rect(width / 2 - btWidth / 2, vpos + 200, btWidth, 25), "Save As"))
            {
                string savePath = EditorUtility.SaveFilePanel("Save Level", Application.dataPath, "New Level.level", "level");
                if (savePath == "" || savePath == default(string))
                {
                    return;
                }
                OET_io.lib.SaveCurrentLevel(savePath);
            }

            // Close button
            if (GUI.Button(new Rect(width / 2 - btWidth / 2, vpos + 250, btWidth, 25), "Close"))
            {
                if (OET_io.lib.IsDirty)
                {
                    switch (EditorUtility.DisplayDialogComplex(
                                "Save Level", "Do you want to save your level?",
                                "Save", "Don't Save", "Cancel"))
                    {
                    case 0:     // Save
                        string savePath = EditorUtility.SaveFilePanel("Save Level", Application.dataPath, "New Level.level", "level");
                        if (savePath == "" || savePath == default(string))
                        {
                            return;
                        }
                        OET_io.lib.SaveCurrentLevel(savePath);
                        OET_io.lib.CloseLevel();
                        break;

                    case 1:     // Don't Save
                        OET_io.lib.CloseLevel();
                        break;

                    case 2:     // Cancel
                        break;
                    }
                }

                OET_io.lib.CloseLevel();
            }

            GUI.enabled = true;

            // Load button
            if (GUI.Button(new Rect(width / 2 - btWidth / 2, vpos + 300, btWidth, 25), "Load"))
            {
                if (OET_io.lib.LevelIsLoaded && OET_io.lib.IsDirty)
                {
                    switch (EditorUtility.DisplayDialogComplex(
                                "Save Level", "Do you want to save your level?",
                                "Save", "Don't Save", "Cancel"))
                    {
                    case 0:         // Save
                        string savePath = EditorUtility.SaveFilePanel("Save Level", Application.dataPath, "New Level.level", "level");
                        if (savePath == "" || savePath == default(string))
                        {
                            return;
                        }
                        OET_io.lib.SaveCurrentLevel(savePath);
                        OET_io.lib.CloseLevel();
                        break;

                    case 1:         // Don't Save
                        OET_io.lib.CloseLevel();
                        break;

                    case 2:         // Cancel
                        break;
                    }
                }

                string openPath = EditorUtility.OpenFilePanel("Open Level", Application.dataPath, "level");
                if (openPath == "" || openPath == default(string))
                {
                    return;
                }
                OET_io.lib.OpenLevel(openPath);
            }
        }
Ejemplo n.º 23
0
        public static Level From(QuantityValue value, LevelUnit fromUnit)
#endif
        {
            return(new Level((double)value, fromUnit));
        }
Ejemplo n.º 24
0
 /// <summary>
 ///     Get string representation of value and unit. Using two significant digits after radix.
 /// </summary>
 /// <param name="unit">Unit representation to use.</param>
 /// <param name="cultureName">Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to <see cref="UnitSystem" />'s default culture.</param>
 /// <returns>String representation.</returns>
 public string ToString(LevelUnit unit, [CanBeNull] string cultureName)
 {
     return(ToString(unit, cultureName, 2));
 }
Ejemplo n.º 25
0
        public static string GetAbbreviation(
            LevelUnit unit,
#if WINDOWS_UWP
            [CanBeNull] string cultureName)
Ejemplo n.º 26
0
 public string ToString(LevelUnit unit, [CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix)
 {
     double value = As(unit);
     string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
     return ToString(unit, provider, format);
 }