public static void AddTerrainSnapping(LE_GUI3dObject p_gui3d, LE_Object p_newObject) { // add and configurate world snapper S_SnapToWorld worldSnap = p_newObject.gameObject.AddComponent <S_SnapToWorld>(); worldSnap.SnapToLayers = 1 << p_gui3d.TERRAIN_LAYER; worldSnap.SnapFrameRate = -1; worldSnap.IsRotationSnap = p_newObject.IsPlacementRotationByNormal; // snap after create worldSnap.DoSnap(); // update snapper every time the terrain is changed or the object is moved System.EventHandler <LE_LevelDataChangedEvent> snapUpdateFunct = (object p_object, LE_LevelDataChangedEvent p_args) => { if (p_args.ChangeType == LE_ELevelDataChangeType.TERRAIN_HEIGHTS || (p_object is LE_ObjectEditHandle && (((LE_ObjectEditHandle)p_object).Target == p_newObject.transform || ((LE_ObjectEditHandle)p_object).transform.IsChildOf(p_newObject.transform)))) { worldSnap.DoSnap(); } }; LE_EventInterface.OnChangeLevelData += snapUpdateFunct; p_newObject.gameObject.AddComponent <UtilityOnDestroyHandler>().m_onDestroy = () => { LE_EventInterface.OnChangeLevelData -= snapUpdateFunct; }; }
public static LE_Object PlaceObject(LE_GUI3dObject p_gui3d, LE_Object p_prefab, Vector3 p_position, Quaternion p_rotation, Vector3 p_scale, string p_objectResourcePath, bool p_isDestroyClonedScripts, int p_customUID) { LE_Object instance = InstantiateObject(p_prefab, p_position, p_rotation, p_scale, p_objectResourcePath); if (p_customUID > 0) { instance.UID = p_customUID; } if (p_isDestroyClonedScripts) { // remove cloned LE_ObjectEditHandle LE_ObjectEditHandle handle = instance.GetComponentInChildren <LE_ObjectEditHandle>(); if (handle != null) { GameObject.Destroy(handle.gameObject); } // remove cloned S_SnapToWorld S_SnapToWorld worldSnap = instance.GetComponent <S_SnapToWorld>(); if (worldSnap != null) { GameObject.Destroy(worldSnap); } // remove cloned S_SnapToGrid S_SnapToGrid gridSnap = instance.GetComponent <S_SnapToGrid>(); if (gridSnap != null) { GameObject.Destroy(gridSnap); } // remove cloned S_SnapToObject S_SnapToObject[] objectSnapArray = instance.GetComponentsInChildren <S_SnapToObject>(true); for (int i = 0; i < objectSnapArray.Length; i++) { LE_ObjectSnapPoint.DestroySnapSystem(objectSnapArray[i]); } // remove cloned UtilityOnDestroyHandler UtilityOnDestroyHandler destroyHandler = instance.GetComponent <UtilityOnDestroyHandler>(); if (destroyHandler != null) { destroyHandler.DestroyWithoutHandling(); } } OnNewObjectPlaced(p_gui3d, instance); return(instance); }