void DO_SNAP_BUTTON(Rect r, VectorPref pref) { if (GUI.Button(r, snapContent, buttonStyle)) { if (Event.current.button == 0) { pref.ENABLE.Set(!pref.ENABLE); } else { var menu = new GenericMenu(); menu.AddItem(new GUIContent(pref.ENABLE.name), pref.ENABLE, () => pref.X.Set(!pref.X)); menu.AddSeparator(""); menu.AddItem(new GUIContent(Snap.SNAP_SNAP_USEHOTKEYS.name), Snap.SNAP_SNAP_USEHOTKEYS, () => Snap.SNAP_SNAP_USEHOTKEYS.Set(!Snap.SNAP_SNAP_USEHOTKEYS)); menu.AddSeparator(""); menu.AddItem(new GUIContent(Snap.SNAP_AUTOAPPLY.name), Snap.SNAP_AUTOAPPLY, () => Snap.SNAP_AUTOAPPLY.Set(!Snap.SNAP_AUTOAPPLY)); menu.AddSeparator(""); menu.AddItem(new GUIContent(pref.X.name), pref.X, () => pref.X.Set(!pref.X)); menu.AddItem(new GUIContent(pref.Y.name), pref.Y, () => pref.Y.Set(!pref.Y)); menu.AddItem(new GUIContent(pref.Z.name), pref.Z, () => pref.Z.Set(!pref.Z)); menu.AddSeparator(""); menu.AddItem(new GUIContent(pref.USE_LOCAL.name), pref.USE_LOCAL, () => pref.USE_LOCAL.Set(!pref.USE_LOCAL)); menu.AddSeparator(""); menu.AddItem(new GUIContent("Open Unity Snap Settings"), false, () => EditorApplication.ExecuteMenuItem("Edit/Snap Settings...")); menu.AddItem(new GUIContent("Open Plugin Snap Settings"), false, SnapWindow.Open); menu.ShowAsContext(); } } var en = (bool)pref.ENABLE; if (IsSnapInverted()) { en = !en; } if (Event.current.type == EventType.Repaint && en) { var oldColor = GUI.color; GUI.color *= enableColor; buttonStyle.Draw(r, snapContent, true, true, false, true); GUI.color = oldColor; } }
void DrawVector(VectorPref pref) { if (GUILayout.Button(pref.ENABLE.name)) { pref.ENABLE.Set(!pref.ENABLE); } if (Event.current.type == EventType.Repaint && pref.ENABLE) { GUI.skin.button.Draw(GUILayoutUtility.GetLastRect(), pref.ENABLE.name, true, true, false, true); } GUILayout.BeginHorizontal(); if (GUILayout.Button("X", EditorStyles.miniButtonLeft, new GUILayoutOption[0])) { pref.X.Set(!pref.X); } if (Event.current.type == EventType.Repaint && pref.X) { GUI.skin.button.Draw(GUILayoutUtility.GetLastRect(), pref.X.name, true, true, false, true); } if (GUILayout.Button("Y", EditorStyles.miniButtonMid, new GUILayoutOption[0])) { pref.Y.Set(!pref.Y); } if (Event.current.type == EventType.Repaint && pref.Y) { GUI.skin.button.Draw(GUILayoutUtility.GetLastRect(), pref.Y.name, true, true, false, true); } if (GUILayout.Button("Z", EditorStyles.miniButtonRight, new GUILayoutOption[0])) { pref.Z.Set(!pref.Z); } if (Event.current.type == EventType.Repaint && pref.Z) { GUI.skin.button.Draw(GUILayoutUtility.GetLastRect(), pref.Z.name, true, true, false, true); } GUILayout.EndHorizontal(); }
static bool DO_SNAPACTION(Transform t, VectorPref pref, ref PRF[] prefKeys, int undoTextIndex) { p = v; if (pref.X) { v.x = (float)Math.Round(v.x / EditorPrefs.GetFloat(prefKeys[0].key, prefKeys[0].def), 0) * EditorPrefs.GetFloat(prefKeys[0].key, prefKeys[0].def); } if (pref.Y) { v.y = (float)Math.Round(v.y / EditorPrefs.GetFloat(prefKeys[1].key, prefKeys[1].def), 0) * EditorPrefs.GetFloat(prefKeys[1].key, prefKeys[1].def); } if (pref.Z) { v.z = (float)Math.Round(v.z / EditorPrefs.GetFloat(prefKeys[2].key, prefKeys[2].def), 0) * EditorPrefs.GetFloat(prefKeys[2].key, prefKeys[2].def); } if (float.IsNaN(v.x)) { v.x = p.x; } if (float.IsNaN(v.y)) { v.y = p.y; } if (float.IsNaN(v.z)) { v.z = p.z; } b = p != v; if (b) { Undo.RecordObject(t, UNDO_TEXT[undoTextIndex]); } return(b); }