Ejemplo n.º 1
0
        public void Focus()
        {
            if (m_selectedObject != null)
            {
                // calculate objects size
                Renderer[] renderers = m_selectedObject.GetComponentsInChildren <Renderer>();
                Vector3    center    = Vector3.zero;
                Vector3    size      = Vector3.zero;
                float      counter   = 0;
                foreach (Renderer r in renderers)
                {
                    if (r.GetComponentInParent <LE_ObjectEditHandle>() == null)
                    {
                        center += r.bounds.center;
                        size   += r.bounds.size;
                        counter++;
                    }
                }
                if (counter != 0)
                {
                    center *= 1f / counter;
                    size   *= 1f / counter;
                }
                else
                {
                    center = m_selectedObject.transform.position;
                    size   = Vector3.one * MIN_FOCUS_DISTANCE;
                }

                Vector3 dir      = Camera.main.transform.position - center;
                float   distance = Mathf.Max(size.x, size.y, size.z) * 3f;
                Camera.main.transform.position = center + dir.normalized * distance;
                if (Camera.main.transform.position.y < center.y)
                {
                    Vector3 pos = Camera.main.transform.position;
                    pos.y = center.y;
                    Camera.main.transform.position = pos;
                }
                Camera.main.transform.LookAt(center, Vector3.up);
                if (OnFocused != null)
                {
                    OnFocused(center, distance);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 private bool GetMinMaxBounds(LE_Object p_object, out Vector3 o_min, out Vector3 o_max)
 {
     o_min = Vector3.one * 9999999;
     o_max = -Vector3.one * 9999999;
     Collider[] colliders = p_object.GetComponentsInChildren <Collider>();
     if (colliders.Length > 0)
     {
         bool isColliderFound = false;
         for (int j = 0; j < colliders.Length; j++)
         {
             if (colliders[j].GetComponent <LE_ObjectEditHandleCollider>() == null)
             {
                 isColliderFound = true;
                 Bounds bounds = colliders[j].bounds;
                 o_min = Vector3.Min(o_min, bounds.min);
                 o_max = Vector3.Max(o_max, bounds.max);
             }
         }
         return(isColliderFound);
     }
     return(false);
 }
Ejemplo n.º 4
0
 private void UpdateNewObjectDragAndDrop()
 {
     // drag and drop
     if (m_object != null && m_objectResourcePath != null)
     {
         // reset drag icon text it could have been changed with
         // custom is placeable text
         SetDragMessageInUI();
         // hide preview if cursor is over 2d GUI
         if (!IsInteractable)
         {
             if (m_previewInstance != null)
             {
                 Destroy(m_previewInstance.gameObject);
             }
         }
         // check if the icon is being dragged and the cursor is over something
         else if (IsCursorOverSomething)
         {
             // make a preview of the dragged object
             if (IsObjectDraggedInUI())
             {
                 // object can be dragged
                 if (OnObjectDrag() &&
                     // object is not snapped to terrain OR
                     ((m_object.SnapType != LE_Object.ESnapType.SNAP_TO_TERRAIN && m_object.SnapType != LE_Object.ESnapType.SNAP_TO_2D_GRID_AND_TERRAIN) ||
                      // hit point is on terrain
                      (m_cursorHitInfo.collider != null && m_cursorHitInfo.collider.gameObject.layer == TERRAIN_LAYER)))
                 {
                     // instatiate the 3d representation
                     if (m_previewInstance == null)
                     {
                         m_previewInstance      = (LE_Object)Instantiate(m_object);
                         m_previewInstance.name = "LE_GUI3dObject Preview Instance";
                         MoveToLayer(m_previewInstance.transform, LayerMask.NameToLayer("Ignore Raycast"));
                         // destroy all rigidbodies
                         Rigidbody[] rigidbodies = m_previewInstance.GetComponentsInChildren <Rigidbody>();
                         for (int i = 0; i < rigidbodies.Length; i++)
                         {
                             Destroy(rigidbodies[i]);
                         }
                         // add grid snapping to preview if needed
                         if (m_previewInstance.SnapType == LE_Object.ESnapType.SNAP_TO_3D_GRID || m_previewInstance.SnapType == LE_Object.ESnapType.SNAP_TO_2D_GRID_AND_TERRAIN)
                         {
                             LE_LogicObjects.AddGridSnapping(this, m_previewInstance, true);
                         }
                     }
                     SmartMove(m_previewInstance);
                 }
             }
             // place object if cursor was released while the object was over something
             else if (m_isObjectPlaceable)
             {
                 PlaceObject();
             }
             else
             {
                 if (m_previewInstance != null)
                 {
                     Destroy(m_previewInstance.gameObject);
                 }
             }
         }
         else if (m_previewInstance != null)
         {
             Destroy(m_previewInstance.gameObject);
         }
         if (LE_GUIInterface.Instance.delegates.SetDraggableObjectState != null)
         {
             // icon hiding and coloring
             if (!IsInteractable || !IsObjectDraggedInUI())
             {
                 // keep icon color if icon is over 2d GUI
                 LE_GUIInterface.Instance.delegates.SetDraggableObjectState(LE_GUIInterface.Delegates.EDraggedObjectState.NONE);
             }
             else if (m_previewInstance != null)
             {
                 // hide icon if a 3d preview is drawn
                 LE_GUIInterface.Instance.delegates.SetDraggableObjectState(LE_GUIInterface.Delegates.EDraggedObjectState.IN_3D_PREVIEW);
             }
             else
             {
                 // show icon in red since it cannot be placed here
                 LE_GUIInterface.Instance.delegates.SetDraggableObjectState(LE_GUIInterface.Delegates.EDraggedObjectState.NOT_PLACEABLE);
             }
         }
     }
 }