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 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; }
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); } }