using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Globalization; public class Gridding : MonoBehaviour { public static void SnapOn(string On) { //print("On====" + On); if(On!="" && On != null) { int nO = Get.GetObjectIndex(On); float X = addGrid(DOIT.ConvertStringToNumber(_G.OBJs[nO][15])); float Y = addGrid(DOIT.ConvertStringToNumber(_G.OBJs[nO][16])); float Z = addGrid(DOIT.ConvertStringToNumber(_G.OBJs[nO][17])); GameObject.Find(_G.OBJs[nO][0]).transform.position = new Vector3(X, Y, Z); _G.OBJs[nO][15] = X.ToString(); _G.OBJs[nO][16] = Y.ToString(); _G.OBJs[nO][17] = Z.ToString(); //print("x=2=" + _G.OBJs[nO][15] + " z==" + _G.OBJs[nO][16] + " z==" + _G.OBJs[nO][17]); } } public static float addGrid(float NS) { // print("grid NS=====ENTER===================================================" + NS); float fac = 1; if (NS < 0) {fac = -1;}; NS = Mathf.Abs(NS); float dec = 0; float ns = NS - Mathf.Floor(NS); //print("grid ns=====ENTER===================================================" + ns); if (_G.System == 1){ if (ns >= 0 && ns < 0.0625f) { dec = 0; } if (ns >= 0.0625f && ns < 0.125f) { dec = 0.0625f; }// 1/16 if (ns >= 0.125f && ns < 0.1875f) { dec = 0.125f; }// 2/16 if (ns >= 0.1875f && ns < 0.20f) { dec = 0.1875f; }// 3/16 if (ns >= 0.20f && ns < 0.3125f) { dec = 0.25f; }// 4/16 if (ns >= 0.3125f && ns < 0.375f) { dec = 0.3125f; }// 5/16 if (ns >= 0.375f && ns < 0.4375f) { dec = 0.375f; }// 6/16 if (ns >= 0.4375f && ns < 0.5f) { dec = 0.4375f; }// 7/16 if (ns >= 0.5f && ns < 0.5625f) { dec = 0.5f; }// 8/16 if (ns >= 0.5625f && ns < 0.625f) { dec = 0.5625f; }// 9/16 if (ns >= 0.625f && ns < 0.6875f) { dec = 0.625f; }// 10/16 if (ns >= 0.6875f && ns < 0.75f) { dec = 0.6875f; }// 11/16 if (ns >= 0.75f && ns < 0.8125f) { dec = 0.75f; }// 12/16 if (ns >= 0.8125f && ns < 0.875f) { dec = 0.8125f; }// 13/16 if (ns >= 0.875f && ns < 0.9375f) { dec = 0.875f; }// 14/16 if (ns >= 0.9375f && ns < 0.96f ) { dec = 0.9375f; }// 15/16 if (ns >= 0.96f && ns < 1f ) { dec = 1f; }// 15/16 NS = Mathf.Floor(NS) + dec; NS = Mathf.Round(NS*10000f)/10000f; } if (_G.System == 2){ NS=NS*2.54f; NS=Mathf.Round(NS*100)/100; //dec=Mathf.Round(ns*100)/100; //NS = Mathf.Floor(NS) + dec; NS=Mathf.Round(NS/2.54f*10000)/10000; } NS = NS * fac; //print("grid NS=====EXIT==" + NS); return NS; } public static Vector3 V(Vector3 V){ return new Vector3(addGrid(V.x),addGrid(V.y),addGrid(V.z)); } public static Vector2 v(Vector2 v){ return new Vector3(addGrid(v.x),addGrid(v.y)); } }