private void Load() { xAxis = QtUtility.LoadBool("QT_Rot_xAxis"); yAxis = QtUtility.LoadBool("QT_Rot_yAxis"); zAxis = QtUtility.LoadBool("QT_Rot_zAxis"); //method = QTEditorTools.LoadInt("QT_SetRotMethod"); setRotOrigin = QtUtility.LoadInt("QT_SetRotOrigin"); axis = new Vector3(QtUtility.LoadFloat("QT_Rot_axis.x"), QtUtility.LoadFloat("QT_Rot_axis.y"), QtUtility.LoadFloat("QT_Rot_axis.z")); // Random Rotition MIN _randomMin = new Vector3(QtUtility.LoadFloat("QT_Rot_randomMin.x"), QtUtility.LoadFloat("QT_Rot_randomMin.y"), QtUtility.LoadFloat("QT_Rot_randomMin.z")); // Random Rotition MAX _randomMax = new Vector3(QtUtility.LoadFloat("QT_Rot_randomMax.x"), QtUtility.LoadFloat("QT_Rot_randomMax.y"), QtUtility.LoadFloat("QT_Rot_randomMax.z")); // If these are both zero, lets change that. if (_randomMin == Vector3.zero && _randomMax == Vector3.zero) { _randomMin = new Vector3(0f, 0f, 0f); _randomMax = new Vector3(10f, 10f, 10f); } translationType = QtUtility.LoadInt("QT_SetRotTranslationType"); isRelative = QtUtility.LoadInt("QT_SetRotIsRelative"); loaded = true; }
private void Load() { xAxis = QtUtility.LoadBool("QT_Scale_xAxis"); yAxis = QtUtility.LoadBool("QT_Scale_yAxis"); zAxis = QtUtility.LoadBool("QT_Scale_zAxis"); //method = QTEditorTools.LoadInt("QT_SetScaleMethod"); setScaleOrigin = QtUtility.LoadInt("QT_SetScaleOrigin"); axis = new Vector3(QtUtility.LoadFloat("QT_Scale_axis.x"), QtUtility.LoadFloat("QT_Scale_axis.y"), QtUtility.LoadFloat("QT_Scale_axis.z")); // Random Scaleition MIN _randomMin = new Vector3(QtUtility.LoadFloat("QT_Scale_randomMin.x"), QtUtility.LoadFloat("QT_Scale_randomMin.y"), QtUtility.LoadFloat("QT_Scale_randomMin.z")); // Random Scaleition MAX _randomMax = new Vector3(QtUtility.LoadFloat("QT_Scale_randomMax.x"), QtUtility.LoadFloat("QT_Scale_randomMax.y"), QtUtility.LoadFloat("QT_Scale_randomMax.z")); // If these are both zero, lets change that. if (_randomMin == Vector3.zero && _randomMax == Vector3.zero) { _randomMin = new Vector3(0.5f, 0.5f, 0.5f); _randomMax = new Vector3(2f, 2f, 2f); } translationType = QtUtility.LoadInt("QT_SetScaleTranslationType"); isRelative = QtUtility.LoadInt("QT_SetScaleIsRelative"); loaded = true; }
private void Save(bool perform) { // Axis QtUtility.SaveBool("QT_Rot_xAxis", xAxis); QtUtility.SaveBool("QT_Rot_yAxis", yAxis); QtUtility.SaveBool("QT_Rot_zAxis", zAxis); // Rotition QtUtility.SaveFloat("QT_Rot_axis.x", axis.x); QtUtility.SaveFloat("QT_Rot_axis.y", axis.y); QtUtility.SaveFloat("QT_Rot_axis.z", axis.z); // Random Rotition MIN QtUtility.SaveFloat("QT_Rot_randomMin.x", _randomMin.x); QtUtility.SaveFloat("QT_Rot_randomMin.y", _randomMin.y); QtUtility.SaveFloat("QT_Rot_randomMin.z", _randomMin.z); // Random Rotition MAX QtUtility.SaveFloat("QT_Rot_randomMax.x", _randomMax.x); QtUtility.SaveFloat("QT_Rot_randomMax.y", _randomMax.y); QtUtility.SaveFloat("QT_Rot_randomMax.z", _randomMax.z); // Origin QtUtility.SaveInt("QT_SetRotOrigin", setRotOrigin); QtUtility.SaveInt("QT_SetRotTranslationType", translationType); QtUtility.SaveInt("QT_SetRotIsRelative", isRelative); // We're performing the action, // Since this is all saved in QT_* strings, we can call "redo" since its basically the same thing. if (perform) { QtFunctions.RepeatRotation(); } }
private static void DrawButtons() { // Position // Set position functions QtFunctions.SetFunctions(true, true, 0); // Reset position functions QtFunctions.ResetFunctions(true, 0); // Draw a separator QtUtility.DrawPopupSeparator(); // Rotation // Set position functions QtFunctions.SetFunctions(true, true, 1); // Reset position functions QtFunctions.ResetFunctions(true, 1); // Draw a seperator QtUtility.DrawPopupSeparator(); // Scale // Set position functions QtFunctions.SetFunctions(true, true, 2); // Reset position functions QtFunctions.ResetFunctions(true, 2); }
private void Load() { xAxis = QtUtility.LoadBool("QT_Pos_xAxis"); yAxis = QtUtility.LoadBool("QT_Pos_yAxis"); zAxis = QtUtility.LoadBool("QT_Pos_zAxis"); //method = QTEditorTools.LoadInt("QT_SetPosMethod"); setPosOrigin = QtUtility.LoadInt("QT_SetPosOrigin"); axis = new Vector3(QtUtility.LoadFloat("QT_Pos_axis.x"), QtUtility.LoadFloat("QT_Pos_axis.y"), QtUtility.LoadFloat("QT_Pos_axis.z")); // Random Position MIN _randomMin = new Vector3(QtUtility.LoadFloat("QT_Pos_randomMin.x"), QtUtility.LoadFloat("QT_Pos_randomMin.y"), QtUtility.LoadFloat("QT_Pos_randomMin.z")); // Random Position MAX _randomMax = new Vector3(QtUtility.LoadFloat("QT_Pos_randomMax.x"), QtUtility.LoadFloat("QT_Pos_randomMax.y"), QtUtility.LoadFloat("QT_Pos_randomMax.z")); // If these are both Vector3.zero, we might have just started. lets initialize them to something // If these are both zero, lets change that. if (_randomMin == Vector3.zero && _randomMax == Vector3.zero) { _randomMin = new Vector3(-10f, -10f, -10f); _randomMax = new Vector3(10f, 10f, 10f); } translationType = QtUtility.LoadInt("QT_SetPosTranslationType"); isRelative = QtUtility.LoadInt("QT_SetPosIsRelative"); loaded = true; }
private void OnGUI() { if (!_mLoaded) { Load(); _mLoaded = true; } if (!_positionSet && _instance) { _rectangle = _instance.position = new Rect(Event.current.mousePosition.x - 5, Event.current.mousePosition.y - 5, PopupWidth, POPUP_HEIGHT); _positionSet = true; } QtUtility.DrawPopupBorder(PopupWidth, POPUP_HEIGHT); GUILayout.Label("QuickTools", _qtTitleBox); DrawButtons(); }
private void OnGUI() { oldGui = GUI.enabled; if (!loaded) { Load(); } minSize = new Vector2(300, 335); GUILayout.Label("Axis of rotation"); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); { xAxis = GUILayout.Toggle(xAxis, "X axis"); yAxis = GUILayout.Toggle(yAxis, "Y axis"); zAxis = GUILayout.Toggle(zAxis, "Z axis"); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.Label("Value Mode"); GUILayout.Space(5); translationType = GUILayout.Toolbar(translationType, translationTypes); GUILayout.Space(10); if (translationType == 0) { GUILayout.Label("Rotation"); axis = EditorGUILayout.Vector3Field("", axis); minSize = maxSize = new Vector2(300, 335); GUILayout.Space(15); } else { if (xAxis) { GUILayout.Label("X Axis"); EditorGUILayout.BeginHorizontal(); { _randomMin.x = EditorGUILayout.FloatField(_randomMin.x, GUILayout.Width(50f)); EditorGUILayout.MinMaxSlider(ref _randomMin.x, ref _randomMax.x, RAND_MIN, RAND_MAX); _randomMax.x = EditorGUILayout.FloatField(_randomMax.x, GUILayout.Width(50f)); } EditorGUILayout.EndHorizontal(); GUILayout.Space(15); } if (yAxis) { GUILayout.Label("Y Axis"); EditorGUILayout.BeginHorizontal(); { _randomMin.y = EditorGUILayout.FloatField(_randomMin.y, GUILayout.Width(50f)); EditorGUILayout.MinMaxSlider(ref _randomMin.y, ref _randomMax.y, RAND_MIN, RAND_MAX); _randomMax.y = EditorGUILayout.FloatField(_randomMax.y, GUILayout.Width(50f)); } EditorGUILayout.EndHorizontal(); GUILayout.Space(15); } if (zAxis) { GUILayout.Label("Z Axis"); EditorGUILayout.BeginHorizontal(); { _randomMin.z = EditorGUILayout.FloatField(_randomMin.z, GUILayout.Width(50f)); EditorGUILayout.MinMaxSlider(ref _randomMin.z, ref _randomMax.z, RAND_MIN, RAND_MAX); _randomMax.z = EditorGUILayout.FloatField(_randomMax.z, GUILayout.Width(50f)); } EditorGUILayout.EndHorizontal(); GUILayout.Space(15); } // Set dynamic window size var yMin = 282; yMin += (xAxis) ? 53 : 0; yMin += (yAxis) ? 53 : 0; yMin += (zAxis) ? 53 : 0; yMin = Mathf.Clamp(yMin, 335, (335 + (3 * 53))); minSize = maxSize = new Vector2(300, yMin); } GUILayout.Label("Operation Mode"); GUILayout.Space(5); isRelative = GUILayout.Toolbar(isRelative, relativeStrings); /* * GUILayout.Space(10); * GUILayout.Label("Transform orientation"); * orientation = GUILayout.Toolbar(orientation, orientationStrings); */ GUILayout.Space(10); GUILayout.Label("Space"); setRotOrigin = GUILayout.Toolbar(setRotOrigin, setRotStrings); if (QtUtility.GetSelection.Length == 0) { GUI.enabled = false; } else { GUI.enabled = true; } QtUtility.DrawSeparator(); GUILayout.Space(2); if (GUILayout.Button("Apply")) { Save(true); Close(); } GUI.enabled = oldGui; if (QtUtility.GetSelection.Length == 0) { EditorGUILayout.HelpBox("No Objects selected!", MessageType.Error); } else if (!xAxis && !yAxis && !zAxis) { EditorGUILayout.HelpBox("No axis of transform enabled!", MessageType.Error); } else { EditorGUILayout.HelpBox("Apply to all selected objects", MessageType.Info); } }
public static void RepeatScale() { // Booleans of axis we're manipulating var bAxisX = QtUtility.LoadBool("QT_Scale_xAxis"); var bAxisY = QtUtility.LoadBool("QT_Scale_yAxis"); var bAxisZ = QtUtility.LoadBool("QT_Scale_zAxis"); // values of axis var axisX = QtUtility.LoadFloat("QT_Scale_axis.x"); var axisY = QtUtility.LoadFloat("QT_Scale_axis.y"); var axisZ = QtUtility.LoadFloat("QT_Scale_axis.z"); // The Action origin. 0 == World | 1 == Parent | 2 == Local var setScaleOrigin = QtUtility.LoadInt("QT_SetScaleOrigin"); // Are we doing incremental? 0 == false | 1 == true var isRelative = QtUtility.LoadInt("QT_SetScaleIsRelative") != 0; // Random Scaleition MIN var randomMin = new Vector3(QtUtility.LoadFloat("QT_Scale_randomMin.x"), QtUtility.LoadFloat("QT_Scale_randomMin.y"), QtUtility.LoadFloat("QT_Scale_randomMin.z")); // Random Scaleition MAX var randomMax = new Vector3(QtUtility.LoadFloat("QT_Scale_randomMax.x"), QtUtility.LoadFloat("QT_Scale_randomMax.y"), QtUtility.LoadFloat("QT_Scale_randomMax.z")); // our translation type var scaleType = QtUtility.LoadInt("QT_SetScaleTranslationType"); foreach (var o in QtUtility.GetSelection) { // Are we using random scale? if (scaleType == 1) { // If that's the case, its time to randomize the values! axisX = Random.Range(randomMin.x, randomMax.x); axisY = Random.Range(randomMin.y, randomMax.y); axisZ = Random.Range(randomMin.z, randomMax.z); } // Register an undo state! Undo.RegisterFullObjectHierarchyUndo(o, "Set Scale"); var sel = (GameObject)o; // Set up parent info. var parentObj = sel.gameObject.transform.parent; var parent = (parentObj != null) ? parentObj.transform.localScale : Vector3.one; // Set up basic var scale = sel.gameObject.transform.localScale; var localScale = (setScaleOrigin == 0) ? Vector3.Scale(scale, parent) : scale; // If we're doing relative stuff, // we need to add to our current. if (isRelative) { axisX = (bAxisX) ? (localScale.x + axisX) : localScale.x; axisY = (bAxisY) ? (localScale.y + axisY) : localScale.y; axisZ = (bAxisZ) ? (localScale.z + axisZ) : localScale.z; } // add our changes! localScale.x = (bAxisX) ? axisX / parent.x : localScale.x / parent.x; localScale.y = (bAxisY) ? axisY / parent.y : localScale.y / parent.y; localScale.z = (bAxisZ) ? axisZ / parent.z : localScale.z / parent.z; // if we're based on the parent space, we need to scale it to match localScale = (setScaleOrigin == 1) ? Vector3.Scale(localScale, parent) : localScale; // Finally set the scale sel.gameObject.transform.localScale = localScale; } }
public static void RepeatRotation() { // Booleans of axis we're manipulating var bAxisX = QtUtility.LoadBool("QT_Rot_xAxis"); var bAxisY = QtUtility.LoadBool("QT_Rot_yAxis"); var bAxisZ = QtUtility.LoadBool("QT_Rot_zAxis"); // values of axis var axisX = QtUtility.LoadFloat("QT_Rot_axis.x"); var axisY = QtUtility.LoadFloat("QT_Rot_axis.y"); var axisZ = QtUtility.LoadFloat("QT_Rot_axis.z"); // The Action origin. 0 == World | 1 == Parent | 2 == Local var setRotOrigin = QtUtility.LoadInt("QT_SetRotOrigin"); // Are we doing incremental? 0 == false | 1 == true var isRelative = QtUtility.LoadInt("QT_SetRotIsRelative") != 0; // Random Rotition MIN var randomMin = new Vector3(QtUtility.LoadFloat("QT_Rot_randomMin.x"), QtUtility.LoadFloat("QT_Rot_randomMin.y"), QtUtility.LoadFloat("QT_Rot_randomMin.z")); // Random Rotition MAX var randomMax = new Vector3(QtUtility.LoadFloat("QT_Rot_randomMax.x"), QtUtility.LoadFloat("QT_Rot_randomMax.y"), QtUtility.LoadFloat("QT_Rot_randomMax.z")); // our translation type var rotationType = QtUtility.LoadInt("QT_SetRotTranslationType"); foreach (var o in QtUtility.GetSelection) { // Are we using random position? if (rotationType == 1) { // If that's the case, its time to randomize the values! axisX = Random.Range(randomMin.x, randomMax.x); axisY = Random.Range(randomMin.y, randomMax.y); axisZ = Random.Range(randomMin.z, randomMax.z); } // Register an undo state! Undo.RegisterFullObjectHierarchyUndo(o, "Set Rotation"); var sel = (GameObject)o; // Do we have a parent? If not, use vector3.zero as a "parent" var rotation = sel.transform.rotation.eulerAngles; // We're using local transforms instead! if (setRotOrigin == 1 || setRotOrigin == 2) { rotation = sel.gameObject.transform.localRotation.eulerAngles; } var x = rotation.x; var y = rotation.y; var z = rotation.z; //parentRot = sel.gameObject.transform.parent.localEulerAngles; // If we're doing relative, we're going off 0. if (isRelative) { x = bAxisX ? axisX : 0f; y = bAxisY ? axisY : 0f; z = bAxisZ ? axisZ : 0f; } else { x = bAxisX ? axisX : x; y = bAxisY ? axisY : y; z = bAxisZ ? axisZ : z; } // Finally add up and set! var setRotation = new Vector3(x, y, z); SetRotation(sel, setRotation, setRotOrigin, isRelative); } }
/// <summary> /// Perform the position set, /// based on parameters saved in the QTWizardSetPosition. /// </summary> public static void RepeatPosition() { // Booleans of axis we're manipulating var bAxisX = QtUtility.LoadBool("QT_Pos_xAxis"); var bAxisY = QtUtility.LoadBool("QT_Pos_yAxis"); var bAxisZ = QtUtility.LoadBool("QT_Pos_zAxis"); // values of axis var axisX = QtUtility.LoadFloat("QT_Pos_axis.x"); var axisY = QtUtility.LoadFloat("QT_Pos_axis.y"); var axisZ = QtUtility.LoadFloat("QT_Pos_axis.z"); // The Action origin. 0 == World | 1 == Parent | 2 == Local var setPosOrigin = QtUtility.LoadInt("QT_SetPosOrigin"); // Are we doing incremental? 0 == false | 1 == true var isRelative = QtUtility.LoadInt("QT_SetPosIsRelative"); // Random Position MIN var randomMin = new Vector3(QtUtility.LoadFloat("QT_Pos_randomMin.x"), QtUtility.LoadFloat("QT_Pos_randomMin.y"), QtUtility.LoadFloat("QT_Pos_randomMin.z")); // Random Position MAX var randomMax = new Vector3(QtUtility.LoadFloat("QT_Pos_randomMax.x"), QtUtility.LoadFloat("QT_Pos_randomMax.y"), QtUtility.LoadFloat("QT_Pos_randomMax.z")); // our translation type var translationType = QtUtility.LoadInt("QT_SetPosTranslationType"); foreach (var o in QtUtility.GetSelection) { // Are we using random position? if (translationType == 1) { // If that's the case, its time to randomize the values! axisX = Random.Range(randomMin.x, randomMax.x); axisY = Random.Range(randomMin.y, randomMax.y); axisZ = Random.Range(randomMin.z, randomMax.z); } // Register an undo state! Undo.RegisterFullObjectHierarchyUndo(o, "Set Position"); var sel = (GameObject)o; var parentScale = Vector3.one; GameObject localParent = null; GameObject localOldParent = null; // Set up parent parameters // based on the position origin. switch (setPosOrigin) { case 1: { if (sel.transform.parent != null) { var parent = sel.gameObject.transform.parent; parentScale = parent.localScale; } break; } case 2: { // We're creating a parent to be the object of our selection. // We're doing this to able to do the transform based on local space. // This might be a really dumb solution to the issue.. but hey, it works. localParent = new GameObject("QuickToolsTemp"); localParent.transform.position = sel.transform.position; localParent.transform.rotation = sel.transform.rotation; localParent.transform.localScale = sel.transform.localScale; // If we already have a parent, the new object needs to be a child of that as well! if (sel.transform.parent != null) { var parent1 = sel.transform.parent; localOldParent = parent1.gameObject; localParent.transform.parent = parent1; } // Finally, set our object to be the child of it. sel.transform.parent = localParent.transform; break; } } // Do we have a parent? If not, use vector3.zero as a "parent" var position = sel.transform.position; // We're using local transforms instead! // We we are doing local orientation if (setPosOrigin == 1 || setPosOrigin == 2) { position = sel.gameObject.transform.localPosition; } // This is basic? var x = position.x; var y = position.y; var z = position.z; // Are we in relative mode? // If that's the case, we add the axis to the current axis. if (isRelative == 1) { x = bAxisX ? axisX + position.x : x; y = bAxisY ? axisY + position.y : y; z = bAxisZ ? axisZ + position.z : z; } else { x = bAxisX ? axisX : position.x; y = bAxisY ? axisY : position.y; z = bAxisZ ? axisZ : position.z; } // If we're in World position // And we want to position the object in world space // We have to take into account the parents scale to get it correct. if (setPosOrigin == 0) { x = bAxisX ? parentScale.x * x : x; y = bAxisY ? parentScale.y * y : y; z = bAxisZ ? parentScale.z * z : z; } // Finally add up and set! var setPosition = new Vector3(x, y, z); SetPosition(sel, setPosition, setPosOrigin); // If we're doing it based on local // We have to make sure to reset the temp parent we set up! if (setPosOrigin != 2) { continue; } // Set parent back to the previous parent, or become batman. sel.transform.parent = localOldParent != null ? localOldParent.transform : null; DestroyImmediate(localParent); } }
private void OnGUI() { minSize = new Vector2(110, 100); if (!_mLoaded) { Load(); _mLoaded = true; } _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Width(position.width), GUILayout.Height(position.height)); // Position GUILayout.Space(22); _rect = GUILayoutUtility.GetLastRect(); _showPosition = EditorGUI.Foldout(new Rect(_rect.xMin + 3, _rect.yMin + 3, position.width - 6, 15), _showPosition, "Position", true, _foldOut); if (_showPosition) { // Set position functions QtFunctions.SetFunctions(false, false, 0); // Reset position functions QtFunctions.ResetFunctions(false, 0); } // Draw a seperator //QTEditorTools.DrawSeparator(); QtUtility.DrawMiniSeparator(); // Rotation GUILayout.Space(22); _rect = GUILayoutUtility.GetLastRect(); _showRotation = EditorGUI.Foldout(new Rect(_rect.xMin + 3, _rect.yMin + 3, position.width - 6, 15), _showRotation, "Rotation", true, _foldOut); if (_showRotation) { // Set position functions QtFunctions.SetFunctions(false, false, 1); // Reset position functions QtFunctions.ResetFunctions(false, 1); } // Draw a seperator //QTEditorTools.DrawSeparator(); QtUtility.DrawMiniSeparator(); // Scale GUILayout.Space(22); _rect = GUILayoutUtility.GetLastRect(); _showScale = EditorGUI.Foldout(new Rect(_rect.xMin + 3, _rect.yMin + 3, position.width - 6, 15), _showScale, "Scale", true, _foldOut); if (_showScale) { // Set position functions QtFunctions.SetFunctions(false, false, 2); // Reset position functions QtFunctions.ResetFunctions(false, 2); } // Draw a seperator //QTEditorTools.DrawSeparator(); //QTUtility.DrawMiniSeparator(); // Draw a seperator //QTEditorTools.DrawSeparator(); EditorGUILayout.EndScrollView(); }