private void OnGUI()
 {
   if (SnapSettings.ms_Styles == null)
     SnapSettings.ms_Styles = new SnapSettings.Styles();
   GUILayout.Space(5f);
   EditorGUI.BeginChangeCheck();
   Vector3 move = SnapSettings.move;
   move.x = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveX, move.x, new GUILayoutOption[0]);
   move.y = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveY, move.y, new GUILayoutOption[0]);
   move.z = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveZ, move.z, new GUILayoutOption[0]);
   if (EditorGUI.EndChangeCheck())
   {
     if ((double) move.x <= 0.0)
       move.x = SnapSettings.move.x;
     if ((double) move.y <= 0.0)
       move.y = SnapSettings.move.y;
     if ((double) move.z <= 0.0)
       move.z = SnapSettings.move.z;
     SnapSettings.move = move;
   }
   SnapSettings.scale = EditorGUILayout.FloatField(SnapSettings.ms_Styles.scale, SnapSettings.scale, new GUILayoutOption[0]);
   SnapSettings.rotation = EditorGUILayout.FloatField(SnapSettings.ms_Styles.rotation, SnapSettings.rotation, new GUILayoutOption[0]);
   GUILayout.Space(5f);
   bool flag1 = false;
   bool flag2 = false;
   bool flag3 = false;
   GUILayout.BeginHorizontal();
   if (GUILayout.Button(SnapSettings.ms_Styles.snapAllAxes, SnapSettings.ms_Styles.buttonLeft, new GUILayoutOption[0]))
   {
     flag1 = true;
     flag2 = true;
     flag3 = true;
   }
   if (GUILayout.Button(SnapSettings.ms_Styles.snapX, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
     flag1 = true;
   if (GUILayout.Button(SnapSettings.ms_Styles.snapY, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
     flag2 = true;
   if (GUILayout.Button(SnapSettings.ms_Styles.snapZ, SnapSettings.ms_Styles.buttonRight, new GUILayoutOption[0]))
     flag3 = true;
   GUILayout.EndHorizontal();
   if (!(flag1 | flag2 | flag3))
     return;
   Vector3 vector3 = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z);
   Undo.RecordObjects((Object[]) Selection.transforms, "Snap " + (Selection.transforms.Length != 1 ? " selection" : Selection.activeGameObject.name) + " to grid");
   foreach (Transform transform in Selection.transforms)
   {
     Vector3 position = transform.position;
     if (flag1)
       position.x = Mathf.Round(position.x * vector3.x) / vector3.x;
     if (flag2)
       position.y = Mathf.Round(position.y * vector3.y) / vector3.y;
     if (flag3)
       position.z = Mathf.Round(position.z * vector3.z) / vector3.z;
     transform.position = position;
   }
 }
Beispiel #2
0
        private void OnGUI()
        {
            if (SnapSettings.ms_Styles == null)
            {
                SnapSettings.ms_Styles = new SnapSettings.Styles();
            }
            GUILayout.Space(5f);
            EditorGUI.BeginChangeCheck();
            Vector3 move = SnapSettings.move;

            move.x = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveX, move.x, new GUILayoutOption[0]);
            move.y = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveY, move.y, new GUILayoutOption[0]);
            move.z = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveZ, move.z, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                if (move.x <= 0f)
                {
                    move.x = SnapSettings.move.x;
                }
                if (move.y <= 0f)
                {
                    move.y = SnapSettings.move.y;
                }
                if (move.z <= 0f)
                {
                    move.z = SnapSettings.move.z;
                }
                SnapSettings.move = move;
            }
            SnapSettings.scale    = EditorGUILayout.FloatField(SnapSettings.ms_Styles.scale, SnapSettings.scale, new GUILayoutOption[0]);
            SnapSettings.rotation = EditorGUILayout.FloatField(SnapSettings.ms_Styles.rotation, SnapSettings.rotation, new GUILayoutOption[0]);
            GUILayout.Space(5f);
            bool flag  = false;
            bool flag2 = false;
            bool flag3 = false;

            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            if (GUILayout.Button(SnapSettings.ms_Styles.snapAllAxes, SnapSettings.ms_Styles.buttonLeft, new GUILayoutOption[0]))
            {
                flag  = true;
                flag2 = true;
                flag3 = true;
            }
            if (GUILayout.Button(SnapSettings.ms_Styles.snapX, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
            {
                flag = true;
            }
            if (GUILayout.Button(SnapSettings.ms_Styles.snapY, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
            {
                flag2 = true;
            }
            if (GUILayout.Button(SnapSettings.ms_Styles.snapZ, SnapSettings.ms_Styles.buttonRight, new GUILayoutOption[0]))
            {
                flag3 = true;
            }
            GUILayout.EndHorizontal();
            if (flag | flag2 | flag3)
            {
                Vector3 vector = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z);
                Undo.RecordObjects(Selection.transforms, "Snap " + ((Selection.transforms.Length != 1) ? " selection" : Selection.activeGameObject.name) + " to grid");
                Transform[] transforms = Selection.transforms;
                for (int i = 0; i < transforms.Length; i++)
                {
                    Transform transform = transforms[i];
                    Vector3   position  = transform.position;
                    if (flag)
                    {
                        position.x = Mathf.Round(position.x * vector.x) / vector.x;
                    }
                    if (flag2)
                    {
                        position.y = Mathf.Round(position.y * vector.y) / vector.y;
                    }
                    if (flag3)
                    {
                        position.z = Mathf.Round(position.z * vector.z) / vector.z;
                    }
                    transform.position = position;
                }
            }
        }
		private void OnGUI()
		{
			if (SnapSettings.ms_Styles == null)
			{
				SnapSettings.ms_Styles = new SnapSettings.Styles();
			}
			GUILayout.Space(5f);
			EditorGUI.BeginChangeCheck();
			Vector3 move = SnapSettings.move;
			move.x = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveX, move.x, new GUILayoutOption[0]);
			move.y = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveY, move.y, new GUILayoutOption[0]);
			move.z = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveZ, move.z, new GUILayoutOption[0]);
			if (EditorGUI.EndChangeCheck())
			{
				if (move.x <= 0f)
				{
					move.x = SnapSettings.move.x;
				}
				if (move.y <= 0f)
				{
					move.y = SnapSettings.move.y;
				}
				if (move.z <= 0f)
				{
					move.z = SnapSettings.move.z;
				}
				SnapSettings.move = move;
			}
			SnapSettings.scale = EditorGUILayout.FloatField(SnapSettings.ms_Styles.scale, SnapSettings.scale, new GUILayoutOption[0]);
			SnapSettings.rotation = EditorGUILayout.FloatField(SnapSettings.ms_Styles.rotation, SnapSettings.rotation, new GUILayoutOption[0]);
			GUILayout.Space(5f);
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			GUILayout.BeginHorizontal(new GUILayoutOption[0]);
			if (GUILayout.Button(SnapSettings.ms_Styles.snapAllAxes, SnapSettings.ms_Styles.buttonLeft, new GUILayoutOption[0]))
			{
				flag = true;
				flag2 = true;
				flag3 = true;
			}
			if (GUILayout.Button(SnapSettings.ms_Styles.snapX, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
			{
				flag = true;
			}
			if (GUILayout.Button(SnapSettings.ms_Styles.snapY, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
			{
				flag2 = true;
			}
			if (GUILayout.Button(SnapSettings.ms_Styles.snapZ, SnapSettings.ms_Styles.buttonRight, new GUILayoutOption[0]))
			{
				flag3 = true;
			}
			GUILayout.EndHorizontal();
			if (flag | flag2 | flag3)
			{
				Vector3 vector = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z);
				Undo.RecordObjects(Selection.transforms, "Snap " + ((Selection.transforms.Length != 1) ? " selection" : Selection.activeGameObject.name) + " to grid");
				Transform[] transforms = Selection.transforms;
				for (int i = 0; i < transforms.Length; i++)
				{
					Transform transform = transforms[i];
					Vector3 position = transform.position;
					if (flag)
					{
						position.x = Mathf.Round(position.x * vector.x) / vector.x;
					}
					if (flag2)
					{
						position.y = Mathf.Round(position.y * vector.y) / vector.y;
					}
					if (flag3)
					{
						position.z = Mathf.Round(position.z * vector.z) / vector.z;
					}
					transform.position = position;
				}
			}
		}
        private void OnGUI()
        {
            if (SnapSettings.ms_Styles == null)
            {
                SnapSettings.ms_Styles = new SnapSettings.Styles();
            }
            GUILayout.Space(5f);
            EditorGUI.BeginChangeCheck();
            Vector3 move = SnapSettings.move;

            move.x = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveX, move.x, new GUILayoutOption[0]);
            move.y = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveY, move.y, new GUILayoutOption[0]);
            move.z = EditorGUILayout.FloatField(SnapSettings.ms_Styles.moveZ, move.z, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                if ((double)move.x <= 0.0)
                {
                    move.x = SnapSettings.move.x;
                }
                if ((double)move.y <= 0.0)
                {
                    move.y = SnapSettings.move.y;
                }
                if ((double)move.z <= 0.0)
                {
                    move.z = SnapSettings.move.z;
                }
                SnapSettings.move = move;
            }
            SnapSettings.scale    = EditorGUILayout.FloatField(SnapSettings.ms_Styles.scale, SnapSettings.scale, new GUILayoutOption[0]);
            SnapSettings.rotation = EditorGUILayout.FloatField(SnapSettings.ms_Styles.rotation, SnapSettings.rotation, new GUILayoutOption[0]);
            GUILayout.Space(5f);
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(SnapSettings.ms_Styles.snapAllAxes, SnapSettings.ms_Styles.buttonLeft, new GUILayoutOption[0]))
            {
                flag1 = true;
                flag2 = true;
                flag3 = true;
            }
            if (GUILayout.Button(SnapSettings.ms_Styles.snapX, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
            {
                flag1 = true;
            }
            if (GUILayout.Button(SnapSettings.ms_Styles.snapY, SnapSettings.ms_Styles.buttonMid, new GUILayoutOption[0]))
            {
                flag2 = true;
            }
            if (GUILayout.Button(SnapSettings.ms_Styles.snapZ, SnapSettings.ms_Styles.buttonRight, new GUILayoutOption[0]))
            {
                flag3 = true;
            }
            GUILayout.EndHorizontal();
            if (!(flag1 | flag2 | flag3))
            {
                return;
            }
            Vector3 vector3 = new Vector3(1f / SnapSettings.move.x, 1f / SnapSettings.move.y, 1f / SnapSettings.move.z);

            Undo.RecordObjects((Object[])Selection.transforms, "Snap " + (Selection.transforms.Length != 1 ? " selection" : Selection.activeGameObject.name) + " to grid");
            foreach (Transform transform in Selection.transforms)
            {
                Vector3 position = transform.position;
                if (flag1)
                {
                    position.x = Mathf.Round(position.x * vector3.x) / vector3.x;
                }
                if (flag2)
                {
                    position.y = Mathf.Round(position.y * vector3.y) / vector3.y;
                }
                if (flag3)
                {
                    position.z = Mathf.Round(position.z * vector3.z) / vector3.z;
                }
                transform.position = position;
            }
        }