示例#1
0
        private void RecalculateUnit(EasySnapUnit unit)
        {
            EasySnapUnit relative = (string.IsNullOrEmpty(unit.RelativeUnit)) ? null : Units[unit.RelativeUnit];

            if (relative != null && relative.UnityUnits == 0)
            {
                RecalculateUnit(relative);
            }

            if (unit.UnitName == EasySnapUnit.DefaultUnitName)
            {
                unit.UnityUnits = 1;
                return;
            }

            float  value = unit.Value;
            string from  = unit.RelativeUnit;
            string to    = Units[unit.RelativeUnit].RelativeUnit;

            while (!string.IsNullOrEmpty(to))
            {
                value = Convert(value, from, to);
                from  = to;
                to    = Units[to].RelativeUnit;
            }

            unit.UnityUnits = value;
        }
示例#2
0
        public static EasySnapUnit Load(string key)
        {
            EasySnapUnit unit = new EasySnapUnit();

            unit.UnitName     = EditorPrefs.GetString(key + "_NAME");
            unit.Value        = EditorPrefs.GetFloat(key + "_VALUE");
            unit.RelativeUnit = EditorPrefs.GetString(key + "_RELATIVE");

            return(unit);
        }
示例#3
0
        public static EasySnapUnit Load(string key)
        {
            EasySnapUnit unit = new EasySnapUnit();

            unit.UnitName = EditorPrefs.GetString(key + "_NAME");
            unit.Value = EditorPrefs.GetFloat(key + "_VALUE");
            unit.RelativeUnit = EditorPrefs.GetString(key + "_RELATIVE");

            return unit;
        }
示例#4
0
        private void AddUnit(string name, float value, string relative)
        {
            EasySnapUnit unit = new EasySnapUnit();

            unit.UnitName     = name;
            unit.Value        = value;
            unit.RelativeUnit = relative;

            Units[name] = unit;
        }
示例#5
0
        private void LoadUnits()
        {
            int count = EditorPrefs.GetInt(EasySnapSettings.UnitsKey);

            Units.Clear();
            for (int i = 0; i < count; i++)
            {
                EasySnapUnit unit = EasySnapUnit.Load(EasySnapSettings.UnitsKey + "_" + i);
                Units[unit.UnitName] = unit;
            }

            SelectedUnitIndex = EditorPrefs.GetInt(EasySnapSettings.UnitsKey + "_CURRENT");
        }
示例#6
0
        public bool RenameUnit(string currentName, string newName)
        {
            if (Units.ContainsKey(newName))
            {
                return(false);
            }

            EasySnapUnit unit = Units[currentName];

            Units.Remove(currentName);
            Units[newName] = unit;

            unit.UnitName = newName;

            foreach (var u in Units.Values)
            {
                if (u.RelativeUnit == currentName)
                {
                    u.RelativeUnit = newName;
                }
            }

            return(true);
        }
示例#7
0
        private void OnGUI()
        {
            settings.IsMajorGridEnabled = EditorGUILayout.Toggle("Enable Major Grid", settings.IsMajorGridEnabled);
            settings.MajorGridSize      = EditorGUILayout.Vector3Field("Major Grid Size", settings.MajorGridSize);

            //settings.AlignToCenterOfCell = EditorGUILayout.Toggle("Snap to Cell Center", settings.AlignToCenterOfCell);
            settings.DrawAxes = EditorGUILayout.Toggle("Draw Axes", settings.DrawAxes);

            float buttonSize = EditorGUILayout.FloatField("Button Size", settings.ButtonSize);

            if (buttonSize > EasySnapSettingsEditorWindow.MinButtonSize)
            {
                settings.ButtonSize = buttonSize;
            }

            EditorGUILayout.Space();
            showKeyOptions = EditorGUILayout.Foldout(showKeyOptions, "Keys");

            if (showKeyOptions)
            {
                KeyCode code = KeyCode.None;

                if (KeyCodeField("SnappingOverride", "Snapping Override Key", settings.SnapOverrideKey, out code))
                {
                    settings.SnapOverrideKey = code;
                }
                if (KeyCodeField("RealignPosition", "Re-align Position Key", settings.ReAlignPositionKey, out code))
                {
                    settings.ReAlignPositionKey = code;
                }
                if (KeyCodeField("PositionSnappingToggle", "Snapping Toggle Key", settings.PositionSnappingToggleKey, out code))
                {
                    settings.PositionSnappingToggleKey = code;
                }
                if (KeyCodeField("VisibilityToggle", "Visibility Toggle Key", settings.VisibilityToggleKey, out code))
                {
                    settings.VisibilityToggleKey = code;
                }
            }

            EditorGUILayout.Space();
            showColourOptions = EditorGUILayout.Foldout(showColourOptions, "Colours");

            if (showColourOptions)
            {
                settings.xColourMinor = EditorGUILayout.ColorField("Minor X", settings.xColourMinor);
                settings.xColourMajor = EditorGUILayout.ColorField("Major X", settings.xColourMajor);

                EditorGUILayout.Space();

                settings.yColourMinor = EditorGUILayout.ColorField("Minor Y", settings.yColourMinor);
                settings.yColourMajor = EditorGUILayout.ColorField("Major Y", settings.yColourMajor);

                EditorGUILayout.Space();

                settings.zColourMinor = EditorGUILayout.ColorField("Minor Z", settings.zColourMinor);
                settings.zColourMajor = EditorGUILayout.ColorField("Major Z", settings.zColourMajor);
            }

            EditorGUILayout.Space();
            showUnitOptions = EditorGUILayout.Foldout(showUnitOptions, "Units");

            if (showUnitOptions)
            {
                int toDelete = -1;
                GUI.changed = false;

                unitScrollPosition = GUILayout.BeginScrollView(unitScrollPosition);

                for (int i = 0; i < settings.Units.Count; i++)
                {
                    EasySnapUnit unit = settings.Units.Values.ElementAt(i);

                    GUI.enabled = (i != 0);

                    EditorGUILayout.BeginHorizontal();

                    string name = EditorGUILayout.TextField(unit.UnitName);
                    if (name != unit.UnitName)
                    {
                        settings.RenameUnit(unit.UnitName, name);
                    }

                    float value = EditorGUILayout.FloatField(unit.Value);

                    if (value > 0)
                    {
                        unit.Value = value;
                    }

                    string[] unitNames        = GetUnitConversionNames(unit.UnitName);
                    int      currentSelection = IndexOf(ref unitNames, unit.RelativeUnit);

                    int relative = EditorGUILayout.Popup(currentSelection, unitNames);

                    if (relative != currentSelection)
                    {
                        unit.RelativeUnit = unitNames[relative];
                        unit.Value        = settings.Convert(unit.Value, unitNames[currentSelection], unit.RelativeUnit);
                    }

                    if (GUILayout.Button("Delete"))
                    {
                        toDelete = i;
                    }

                    EditorGUILayout.EndHorizontal();
                }

                GUILayout.EndScrollView();

                GUI.enabled = true;

                if (GUILayout.Button("New.."))
                {
                    EasySnapUnit unit = new EasySnapUnit();
                    unit.UnitName     = GetUniqueUnitName();
                    unit.Value        = 1;
                    unit.RelativeUnit = EasySnapUnit.DefaultUnitName;

                    settings.Units[unit.UnitName] = unit;

                    GUI.changed = true;
                }

                if (toDelete >= 0)
                {
                    settings.RemoveUnit(toDelete);
                }

                if (GUI.changed)
                {
                    settings.RecalculateUnits();
                }
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Restore Defaults"))
            {
                settings.RestoreDefaults();
            }

            if (GUI.changed)
            {
                SceneView.RepaintAll();
            }
        }
        private void OnGUI()
        {
            settings.IsMajorGridEnabled = EditorGUILayout.Toggle("Enable Major Grid", settings.IsMajorGridEnabled);
            settings.MajorGridSize = EditorGUILayout.Vector3Field("Major Grid Size", settings.MajorGridSize);

            //settings.AlignToCenterOfCell = EditorGUILayout.Toggle("Snap to Cell Center", settings.AlignToCenterOfCell);
            settings.DrawAxes = EditorGUILayout.Toggle("Draw Axes", settings.DrawAxes);

            float buttonSize = EditorGUILayout.FloatField("Button Size", settings.ButtonSize);

            if (buttonSize > EasySnapSettingsEditorWindow.MinButtonSize)
                settings.ButtonSize = buttonSize;

            EditorGUILayout.Space();
            showKeyOptions = EditorGUILayout.Foldout(showKeyOptions, "Keys");

            if(showKeyOptions)
            {
                KeyCode code = KeyCode.None;

                if (KeyCodeField("SnappingOverride", "Snapping Override Key", settings.SnapOverrideKey, out code))
                    settings.SnapOverrideKey = code;
                if (KeyCodeField("RealignPosition", "Re-align Position Key", settings.ReAlignPositionKey, out code))
                    settings.ReAlignPositionKey = code;
                if (KeyCodeField("PositionSnappingToggle", "Snapping Toggle Key", settings.PositionSnappingToggleKey, out code))
                    settings.PositionSnappingToggleKey = code;
                if (KeyCodeField("VisibilityToggle", "Visibility Toggle Key", settings.VisibilityToggleKey, out code))
                    settings.VisibilityToggleKey = code;
            }

            EditorGUILayout.Space();
            showColourOptions = EditorGUILayout.Foldout(showColourOptions, "Colours");

            if (showColourOptions)
            {
                settings.xColourMinor = EditorGUILayout.ColorField("Minor X", settings.xColourMinor);
                settings.xColourMajor = EditorGUILayout.ColorField("Major X", settings.xColourMajor);

                EditorGUILayout.Space();

                settings.yColourMinor = EditorGUILayout.ColorField("Minor Y", settings.yColourMinor);
                settings.yColourMajor = EditorGUILayout.ColorField("Major Y", settings.yColourMajor);

                EditorGUILayout.Space();

                settings.zColourMinor = EditorGUILayout.ColorField("Minor Z", settings.zColourMinor);
                settings.zColourMajor = EditorGUILayout.ColorField("Major Z", settings.zColourMajor);
            }

            EditorGUILayout.Space();
            showUnitOptions = EditorGUILayout.Foldout(showUnitOptions, "Units");

            if (showUnitOptions)
            {
                int toDelete = -1;
                GUI.changed = false;

                unitScrollPosition = GUILayout.BeginScrollView(unitScrollPosition);

                for (int i = 0; i < settings.Units.Count; i++)
                {
                    EasySnapUnit unit = settings.Units.Values.ElementAt(i);

                    GUI.enabled = (i != 0);

                    EditorGUILayout.BeginHorizontal();

                    string name = EditorGUILayout.TextField(unit.UnitName);
                    if (name != unit.UnitName)
                        settings.RenameUnit(unit.UnitName, name);

                    float value = EditorGUILayout.FloatField(unit.Value);

                    if (value > 0)
                        unit.Value = value;

                    string[] unitNames = GetUnitConversionNames(unit.UnitName);
                    int currentSelection = IndexOf(ref unitNames, unit.RelativeUnit);

                    int relative = EditorGUILayout.Popup(currentSelection, unitNames);

                    if (relative != currentSelection)
                    {
                        unit.RelativeUnit = unitNames[relative];
                        unit.Value = settings.Convert(unit.Value, unitNames[currentSelection], unit.RelativeUnit);
                    }

                    if (GUILayout.Button("Delete"))
                        toDelete = i;

                    EditorGUILayout.EndHorizontal();
                }

                GUILayout.EndScrollView();

                GUI.enabled = true;

                if (GUILayout.Button("New.."))
                {
                    EasySnapUnit unit = new EasySnapUnit();
                    unit.UnitName = GetUniqueUnitName();
                    unit.Value = 1;
                    unit.RelativeUnit = EasySnapUnit.DefaultUnitName;

                    settings.Units[unit.UnitName] = unit;

                    GUI.changed = true;
                }

                if (toDelete >= 0)
                    settings.RemoveUnit(toDelete);

                if(GUI.changed)
                    settings.RecalculateUnits();
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Restore Defaults"))
                settings.RestoreDefaults();

            if (GUI.changed)
                SceneView.RepaintAll();
        }
示例#9
0
        private void RecalculateUnit(EasySnapUnit unit)
        {
            EasySnapUnit relative = (string.IsNullOrEmpty(unit.RelativeUnit)) ? null : Units[unit.RelativeUnit];

            if (relative != null && relative.UnityUnits == 0)
                RecalculateUnit(relative);

            if (unit.UnitName == EasySnapUnit.DefaultUnitName)
            {
                unit.UnityUnits = 1;
                return;
            }

            float value = unit.Value;
            string from = unit.RelativeUnit;
            string to = Units[unit.RelativeUnit].RelativeUnit;

            while (!string.IsNullOrEmpty(to))
            {
                value = Convert(value, from, to);
                from = to;
                to = Units[to].RelativeUnit;
            }

            unit.UnityUnits = value;
        }
示例#10
0
        private void AddUnit(string name, float value, string relative)
        {
            EasySnapUnit unit = new EasySnapUnit();
            unit.UnitName = name;
            unit.Value = value;
            unit.RelativeUnit = relative;

            Units[name] = unit;
        }