using UnityEngine; using System.Globalization; public class Push : MonoBehaviour { static int hitObjectNumber; static int selectedObjectNumber; static float rtx; static float rty; static float rtz; static Vector3 tPOS; static Vector3 sPOS; static float selectedObjectDepth; static float selectedObjectHeight; static float Tw; static float Td; static float Th; static float dis; public static void It(/*Vector3 direction*/)//item target hit = wall or mesh { //print("_G.HIT =====================it============================================" + _G.HIT); if (_G.HIT.Substring(0, 1) != "w" && _G.HIT.Substring(0, 1) != "m" && _G.HIT.Length > 4 && SceneModeManager.SelectedName.Length > 4 && _G.HIT != "sceil") { Ito(/*direction*/); } else { for (int i = 1; i < _G.NW + 1; i++) { if (_G.HIT == "w" + i.ToString(CultureInfo.InvariantCulture) || _G.HIT == "m" + i.ToString(CultureInfo.InvariantCulture)) { //int nA = int.Parse(_G.HIT.Substring(1, _G.HIT.Length - 1)); Itm(/*direction*/); } } } _G.HIT = ""; } public static void Ito(/*Vector3 direction*/)//item target hit = object { if (_G.HIT != "" && SceneModeManager.SelectedName != "") { GameObject hitObject = GameObject.Find(_G.HIT).gameObject; GameObject selectedObject = GameObject.Find(SceneModeManager.SelectedName).gameObject; hitObjectNumber = Get.GetObjectIndex(_G.HIT); selectedObjectNumber = Get.GetObjectIndex(SceneModeManager.SelectedName); //Get position rty = DOIT.ConvertStringToNumber(_G.OBJs[hitObjectNumber][19]); //Rotate to O angle selectedObject.transform.parent = hitObject.transform; hitObject.transform.localRotation = Quaternion.Euler(0, 0, 0); //Get mesure Vector3 selectedObjectColliderSize = selectedObject.GetComponent().bounds.size; float selectedObjectWide = selectedObjectColliderSize.x - 0.5f;// DOIT.ConvertStringToNumber(_G.OBJs[nsO][6]); selectedObjectHeight = selectedObjectColliderSize.y - 0.5f; selectedObjectDepth = selectedObjectColliderSize.z - 0.5f;//Object depth Tw = hitObject.transform.localScale.x - 0.5f; Th = hitObject.transform.localScale.y - 0.5f; Td = hitObject.transform.localScale.z - 0.5f; sPOS = selectedObject.transform.position; tPOS = hitObject.transform.position; //Distance center float Mx = Mathf.Abs(sPOS.x - tPOS.x); float Mz = Mathf.Abs(sPOS.z - tPOS.z); float My = Mathf.Abs(sPOS.y - tPOS.y); float disW = Tw / 2 + selectedObjectWide / 2; float disH = Th / 2 + selectedObjectHeight / 2; float disD = Td / 2 + selectedObjectDepth / 2; float dirCx = sPOS.x - tPOS.x; float dirCy = sPOS.y - tPOS.y; float dirCz = sPOS.z - tPOS.z; Vector3 newPosition = selectedObject.transform.position; //Push to right if (Mx < disW + 0 && dirCx > 0 && My <= disH - 2 && Mz <= disD + 0.5) { newPosition = new Vector3(tPOS.x + disW, sPOS.y, sPOS.z); //print("-----------Push to right-----------"); } //Push to left if (Mx < disW + 0 && dirCx < 0 && My <= disH - 2 && Mz <= disD + 0.5) { newPosition = new Vector3(tPOS.x - disW, sPOS.y, sPOS.z); //print("-----------Push to left-----------"); } //Push to Top if (My < disH - 4 && My > disH - 4 && dirCy < 0 && Mx <= disW - 4 && Mz <= disD - 2) { newPosition = new Vector3(sPOS.x, tPOS.y - disH, sPOS.z); //print("-----------Push to under -----------"); } //Push to under if (My < disH - 4 && My > disH - 4 && dirCy > 0 && Mx <= disW - 4 && Mz <= disD - 2) { newPosition = new Vector3(sPOS.x, tPOS.y + disH, sPOS.z); //print("-----------Push totop-----------"); } //Push to front if (Mz < disD + 4 && Mz > disD - 4 && dirCz < 0 && Mx <= disW - 2 && My <= disH - 2) { newPosition = new Vector3(sPOS.x, sPOS.y, tPOS.z - disD); //print("-----------Push to front -----------"); } //Push to back if (Mz < disD + 4 && Mz > disD - 4 && dirCz > 0 && Mx <= disW - 2 && My <= disH - 2) { newPosition = new Vector3(sPOS.x, sPOS.y, tPOS.z + disD); // print("-----------Push to back-----------"); } selectedObject.transform.position = newPosition; hitObject.transform.localRotation = Quaternion.Euler(0, rty, 0); selectedObject.transform.parent = GameObject.Find("SCENE").transform; DOIT.SaveObjectPositionInData(SceneModeManager.Selected); //ASH.REFRESH(); } } public static void Itm(/*Vector3 direction,*/bool useNewVersion = false) { //print("PUSH BY HIT NAME ===================m=================="+ wi+"============================" + _G.HIT); //Selection GameObject selected = GameObject.Find(SceneModeManager.SelectedName).gameObject; int objectNumberSelected = Get.GetObjectIndex(SceneModeManager.SelectedName); Transform currentParent = selected.transform.parent; if (useNewVersion) { //Target //_G.HIT = _G.HIT.Replace("m", "w"); GameObject hitObject = GameObject.Find(_G.HIT).gameObject; // Calculate overlap amount float hitBoundMaxX = hitObject.GetComponent().bounds.max.x; float selectedBoundMinX = selected.GetComponent().bounds.min.x; float overlap = hitBoundMaxX - selectedBoundMinX; selected.transform.position += new Vector3(overlap, 0, 0); } else { if (_G.OBJs[objectNumberSelected][22] != "floor" && _G.OBJs[objectNumberSelected][22] != "ceil") { float objectHeight = DOIT.ConvertStringToNumber(_G.OBJs[objectNumberSelected][16]); float objectDepth = selected.transform.localScale.z - 0.5f; float objectWide = selected.transform.localScale.x - 0.5f; //Wall GameObject wallAttachedToSelected = GameObject.Find(_G.OBJs[objectNumberSelected][22]).gameObject; int wallNumber = int.Parse(_G.OBJs[objectNumberSelected][22].Substring(1, _G.OBJs[objectNumberSelected][22].Length - 1)) - 1; Vector3 wallRotation = wallAttachedToSelected.transform.localRotation.eulerAngles; //Target _G.HIT = _G.HIT.Replace("m", "w"); selected.transform.SetParent(wallAttachedToSelected.transform); wallAttachedToSelected.transform.localRotation = Quaternion.Euler(0, 0, 0); Vector3 wallPosition = wallAttachedToSelected.transform.position; Vector3 selectedPosition = selected.transform.position; float X = wallPosition.x - _G. WallsWidth[wallNumber] / 2 + objectWide / 2; if (wallPosition.x < selectedPosition.x) X = wallPosition.x + _G. WallsWidth[wallNumber] / 2 - objectWide / 2; selected.transform.position = new Vector3(X, objectHeight, wallPosition.z - objectDepth / 2); wallAttachedToSelected.transform.localRotation = Quaternion.Euler(wallRotation.x, wallRotation.y, wallRotation.z); selected.transform.SetParent(currentParent); DOIT.SaveObjectPositionInData(SceneModeManager.Selected); } } } }