Example #1
0
        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);
        }
Example #2
0
        public static void AddGridSnapping(LE_GUI3dObject p_gui3d, LE_Object p_newObject, bool p_isPreview)
        {
            S_SnapToGrid gridSnap = p_newObject.gameObject.AddComponent <S_SnapToGrid>();

            gridSnap.GridOffset          = p_newObject.SnapGridOffset;
            gridSnap.GridCellSize        = p_newObject.SnapGridCellSize;
            gridSnap.SnapCondition       = p_isPreview ? S_SnapToGrid.ESnapCondition.ON_UPDATE : S_SnapToGrid.ESnapCondition.WHEN_STILL;
            gridSnap.IsInstantSnap       = p_isPreview;
            gridSnap.IsSnapAxisXRotation = gridSnap.IsSnapAxisYRotation = gridSnap.IsSnapAxisZRotation = false;             // under construction
            if (p_newObject.SnapType == LE_Object.ESnapType.SNAP_TO_2D_GRID_AND_TERRAIN)
            {
                // disable y axis snapping and activate terrain snapping
                gridSnap.IsSnapAxisY = false;
                if (!p_isPreview)
                {
                    AddTerrainSnapping(p_gui3d, p_newObject);
                }
            }
        }