Beispiel #1
0
 public static void AddObjectSnapping(LE_GUI3dObject p_gui3d, LE_Object p_newObject)
 {
     for (int j = 0; j < p_newObject.ObjectSnapPoints.Length; j++)
     {
         if (p_newObject.ObjectSnapPoints[j] != null)
         {
             Material matLine = null;
             Material matFill = null;
             if (p_newObject.IsDrawSnapToObjectUI)
             {
                 matLine = (Material)Resources.Load("SnapToObjectUIMaterial_Line");
                 matFill = (Material)Resources.Load("SnapToObjectUIMaterial_Fill");
             }
             S_SnapToObject snapInstance = p_newObject.ObjectSnapPoints[j].InstatiateSnapSystem((GameObject)GameObject.Instantiate(Resources.Load("ObjectSnapButtonVisuals")), p_newObject.IsDrawSnapToObjectUI, matLine, matFill);
             if (snapInstance != null)
             {
                 string snapPointUID = GetSnapPointUID(p_newObject.UID, j);
                 p_gui3d.AddSnapPoint(snapPointUID, snapInstance);
                 // deactivate if snap UI is hidden right now
                 if (!p_gui3d.IsSnapToObjectActive)
                 {
                     snapInstance.gameObject.SetActive(false);
                 }
                 // restore the already snapped object states
                 p_gui3d.LoadSnapCounter(snapPointUID, snapInstance);
             }
         }
         else
         {
             Debug.LogError("LE_GUI3dObject: AddObjectSnapping: object '" + p_newObject.name + "' has a nullpointer in the ObjectSnapPoints array at index '" + j + "'!");
         }
     }
 }
Beispiel #2
0
        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;
            };
        }
Beispiel #3
0
 public static void AddSnappingScripts(LE_GUI3dObject p_gui3d, LE_Object p_newObject)
 {
     if (p_newObject != null)
     {
         // handle snapping
         if (p_newObject.SnapType == LE_Object.ESnapType.SNAP_TO_OBJECT)                 // object snapping
         {
             AddObjectSnapping(p_gui3d, p_newObject);
         }
         else if (p_newObject.SnapType == LE_Object.ESnapType.SNAP_TO_TERRAIN)                 // terrain snapping
         {
             AddTerrainSnapping(p_gui3d, p_newObject);
         }
         else
         {
             if (p_newObject.SnapType == LE_Object.ESnapType.SNAP_TO_3D_GRID || p_newObject.SnapType == LE_Object.ESnapType.SNAP_TO_2D_GRID_AND_TERRAIN)
             {
                 // add grid snapping
                 AddGridSnapping(p_gui3d, p_newObject, false);
             }
         }
     }
     else
     {
         Debug.LogError("LE_GUI3dObject: AddSnappingScripts: passed object is null!");
     }
 }
Beispiel #4
0
 public LE_CmdSnapObjectToObject(LE_GUI3dObject p_gui3d, int p_sourceObjUID, int p_sourceSnapPointIndex, S_SnapToObjectPrefab p_snapPrefab)
 {
     m_gui3d                = p_gui3d;
     m_sourceObj            = new LE_CmdObjectLink(p_sourceObjUID);
     m_sourceSnapPointIndex = p_sourceSnapPointIndex;
     m_snapPrefab           = p_snapPrefab;
 }
Beispiel #5
0
 public static void OnNewObjectPlaced(LE_GUI3dObject p_gui3d, LE_Object p_newInstance)
 {
     ApplyRandomity(p_newInstance);
     ApplyColor(p_newInstance, p_newInstance.ColorProperty);
     ApplyVariation(p_newInstance, p_newInstance.VariationsDefaultIndex);
     p_newInstance.SolveCollisionAndDeactivateRigidbody();             // solve placement of rigidbodies
     AddSnappingScripts(p_gui3d, p_newInstance);
     SelectNewObjectAndNotifyListeners(p_gui3d, p_newInstance);
 }
Beispiel #6
0
 public LE_CmdPlaceObject(LE_GUI3dObject p_gui3d, LE_Object p_prefab, Transform p_copyTransform, string p_objectResourcePath)
 {
     m_gui3d              = p_gui3d;
     m_prefab             = p_prefab;
     m_position           = p_copyTransform.position;
     m_rotation           = p_copyTransform.rotation;
     m_scale              = p_copyTransform.localScale;
     m_objectResourcePath = p_objectResourcePath;
 }
Beispiel #7
0
        public LE_CmdDeleteObject(LE_GUI3dObject p_gui3d, LE_Object p_selectedObject)
        {
            m_gui3d = p_gui3d;
            m_objectInstance.Obj = p_selectedObject;
            m_prefab             = Resources.Load <LE_Object>(p_selectedObject.name);
            m_objectResourcePath = p_selectedObject.name;
            m_UID = p_selectedObject.UID;

            if (m_prefab == null)
            {
                Debug.LogWarning("LE_CmdDeleteObject: '" + p_selectedObject.name + "' is not a valid resource path! Command will fail on execution!");
            }
        }
Beispiel #8
0
 public LE_LogicLevel(
     LE_ConfigLevel p_confL, LE_GUI3dTerrain p_GUI3dTerrain, LE_GUI3dObject p_GUI3dObject, bool p_isObliqueFocusCentering,
     Texture2D[] p_configTextures, Vector2[] p_configTextureSizes, Vector2[] p_configTextureOffsets)
 {
     m_confL                   = p_confL;
     m_GUI3dTerrain            = p_GUI3dTerrain;
     m_GUI3dObject             = p_GUI3dObject;
     m_isObliqueFocusCentering = p_isObliqueFocusCentering;
     m_configTextures          = p_configTextures;
     m_configTextureSizes      = p_configTextureSizes;
     m_configTextureOffsets    = p_configTextureOffsets;
     // register to events
     LE_GUIInterface.Instance.events.OnLevelSaveBtn       += OnLevelSaveBtn;
     LE_GUIInterface.Instance.events.OnLevelLoadBtn       += OnLevelLoadBtn;
     LE_GUIInterface.Instance.events.OnLevelRenderIconBtn += OnLevelRenderIconBtn;
 }
Beispiel #9
0
// STATIC LOGIC -------------------------------------------------------------------------------------------------------------------

        public static void OnNewObjectSnapped(LE_GUI3dObject p_gui3d, LE_Object p_newObject, S_SnapToObjectEventArgs p_args)
        {
            if (p_newObject != null)
            {
                LE_Object sourceObj      = p_args.Source.GetComponentInParent <LE_Object>();
                LE_Object destinationObj = p_args.NewInstance.GetComponent <LE_Object>();
                // mark source snap point as used
                p_gui3d.MarkSnapPointAsUsed(sourceObj, destinationObj, p_args.Source);
                // mark destination snap point as used
                if (destinationObj.RootSnapPointIndex != -1)
                {
                    p_gui3d.MarkSnapPointAsUsed(destinationObj, sourceObj, destinationObj.RootSnapPointIndex);
                }
                // setup new object
                OnNewObjectPlaced(p_gui3d, p_newObject);
            }
        }
Beispiel #10
0
 public static void SelectNewObjectAndNotifyListeners(LE_GUI3dObject p_gui3d, LE_Object p_newInstance)
 {
     // select new object
     p_gui3d.SelectObject(p_newInstance);
     // check if more objects of this kind can be placed
     p_gui3d.UpdateIsObjectPlaceable();
     // notify listeners that the level data was changed
     if (LE_EventInterface.OnChangeLevelData != null)
     {
         LE_EventInterface.OnChangeLevelData(p_newInstance, new LE_LevelDataChangedEvent(LE_ELevelDataChangeType.OBJECT_PLACE));
     }
     // notify listeners that an object has been placed
     if (LE_EventInterface.OnObjectPlaced != null)
     {
         LE_EventInterface.OnObjectPlaced(p_gui3d, new LE_ObjectPlacedEvent(p_newInstance));
     }
 }
Beispiel #11
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);
        }
Beispiel #12
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);
                }
            }
        }
Beispiel #13
0
 public static void DeleteObject(LE_GUI3dObject p_gui3d, LE_Object p_selectedObject)
 {
     if (p_selectedObject != null)
     {
         // if this object was snapped to any other object then reactivate the snap point to which this object was attached
         p_gui3d.ReactivateSnapPoints(p_selectedObject.UID, p_selectedObject.ObjectSnapPoints.Length);
         // destroy game object
         GameObject.Destroy(p_selectedObject.gameObject);
         // some script could search this kind of objects -> mark as deleted
         p_selectedObject.name = "deleted";
         // IsObjectPlaceable could have changed
         p_gui3d.UpdateIsObjectPlaceable();
         // notify listeners that the level data was changed
         if (LE_EventInterface.OnChangeLevelData != null)
         {
             LE_EventInterface.OnChangeLevelData(p_selectedObject.gameObject, new LE_LevelDataChangedEvent(LE_ELevelDataChangeType.OBJECT_DELETE));
         }
     }
 }
Beispiel #14
0
 public LE_CmdCloneObject(LE_GUI3dObject p_gui3d, int p_instanceToCloneUID, Transform p_copyTransform, string p_objectResourcePath)
     : base(p_gui3d, null, p_copyTransform, p_objectResourcePath)
 {
     m_instanceToClone        = new LE_CmdObjectLink(p_instanceToCloneUID);
     m_isDestroyClonedScripts = true;
 }
Beispiel #15
0
        private void Start()
        {
            // check if there is an instance of the LE_GUIInterface, which is required for the editor to work
            if (LE_GUIInterface.Instance == null)
            {
                Debug.LogError("LE_LevelEditorMain: a LE_GUIInterface object must be added to the scene!");
            }

            // search or create a default(will be not functional!) config
            LE_ConfigTerrain LEConfTerrain = GetComponentInChildren <LE_ConfigTerrain>();

            if (LEConfTerrain == null)
            {
                Debug.LogError("LE_LevelEditorMain: a LE_ConfigTerrain component must be added to the game object with the LE_LevelEditorMain script!");
                LEConfTerrain = gameObject.AddComponent <LE_ConfigTerrain>();
            }
            // check if everything is setup right
            if (LEConfTerrain.TerrainTextureConfig == null)
            {
                Debug.LogError("LE_LevelEditorMain: TerrainTextureConfig was not initialized! You need to set it in the inspector of LE_ConfigTerrain. Provide an empty terrain texture config if you do not want to use the terrain editor.");
            }
            if (!IS_TERRAIN_EDITOR)
            {
                if (LEConfTerrain.Brushes.Length > 0)
                {
                    Debug.LogWarning("LE_LevelEditorMain: IS_TERRAIN_EDITOR is set to 'false', but you have provided a non empty array for LE_ConfigTerrain.Brushes! This is performance waist and will increase loading time! Remove brushes or reenable terrain editing.");
                }
                if (LEConfTerrain.BrushProjector != null)
                {
                    Debug.LogWarning("LE_LevelEditorMain: IS_TERRAIN_EDITOR is set to 'false', but you have provided a value for LE_ConfigTerrain.BrushProjector! This is performance waist and will increase loading time! Remove brush projector from scene or reenable terrain editing.");
                }
            }

            Camera cam = Cam;

            if (cam == null)
            {
                Debug.LogError("LE_LevelEditorMain: Start: could not find main camera!");
            }

            // initialize command manager (undo/redo)
            InitializeCommandManager();

            // initialize object 3d GUI
            if (IS_OBJECT_EDITOR)
            {
                m_GUI3dObject = gameObject.AddComponent <LE_GUI3dObject>();
                m_GUI3dObject.TERRAIN_LAYER       = LEConfTerrain.TerrainLayer;
                m_GUI3dObject.OnFocused          += OnGUI3dObjectFocused;
                m_GUI3dObject.IsKeyComboFocus     = (ACTIVE_KEY_COMBOS & LE_EKeyCombo.FOCUS) != 0;
                m_GUI3dObject.IsKeyComboDuplicate = (ACTIVE_KEY_COMBOS & LE_EKeyCombo.DUPLICATE) != 0;
                m_GUI3d.Add(m_GUI3dObject);
            }

            // initialize input
            m_input = new LE_Input(this);

            // set pivot point
            m_camPivot = cam.transform.position + cam.transform.forward * 100f;

            // to monitor the last change frame number register to the OnChangeLevelData event
            LE_EventInterface.OnChangeLevelData += OnChangeLevelData;

            // register to UI events
            LE_GUIInterface.Instance.events.OnEditModeBtn += OnEditModeBtn;
            LE_GUIInterface.Instance.events.OnUndoBtn     += OnUndoBtn;
            LE_GUIInterface.Instance.events.OnRedoBtn     += OnRedoBtn;
        }
Beispiel #16
0
        public LE_LogicObjects(LE_GUI3dObject p_GUI3dObject, LE_ObjectMap p_objectMap)
        {
            m_GUI3dObject = p_GUI3dObject;

            // register to events
            LE_GUIInterface.Instance.events.OnObjectEditSpaceBtn                  += OnObjectEditSpaceBtn;
            LE_GUIInterface.Instance.events.OnObjectEditModeBtn                   += OnObjectEditModeBtn;
            LE_GUIInterface.Instance.events.OnObjectSelectDraggable               += OnObjectSelectDraggable;
            LE_GUIInterface.Instance.events.OnSelectedObjectFocusBtn              += OnSelectedObjectFocusBtn;
            LE_GUIInterface.Instance.events.OnSelectedObjectDuplicateBtn          += OnSelectedObjectDuplicateBtn;
            LE_GUIInterface.Instance.events.OnSelectedPrefabFindBtn               += OnSelectedPrefabFindBtn;
            LE_GUIInterface.Instance.events.OnSelectedObjectDeleteBtn             += OnSelectedObjectDeleteBtn;
            LE_GUIInterface.Instance.events.OnSelectedObjectIsSleepOnStartChanged += OnSelectedObjectIsSleepOnStartChanged;
            LE_GUIInterface.Instance.events.OnSelectedObjectColorChanged          += OnSelectedObjectColorChanged;
            LE_GUIInterface.Instance.events.OnSelectedObjectVariationIndexChanged += OnSelectedObjectVariationIndexChanged;

            // initialize UI
            if (p_objectMap != null)
            {
                if (p_objectMap.ObjectPrefabs.Length > 0 || p_objectMap.ObjectPrefabResourcePaths.Length > 0 || p_objectMap.SubObjectMaps.Length > 0)
                {
                    if (LE_GUIInterface.Instance.delegates.SetObjects != null)
                    {
                        LE_GUIInterface.Instance.delegates.SetObjects(p_objectMap);
                    }
                    else
                    {
                        Debug.LogError("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetObjects, but the provided object map is not empty. You have to set this delegate to update your object UI.");
                    }
                }
            }
            else
            {
                Debug.LogError("LE_LogicObjects: ROOT_OBJECT_MAP was not initialized! You need to set it in the inspector of LE_LevelEditorMain.");
            }

            m_GUI3dObject.ObjectEditMode = LE_EObjectEditMode.MOVE;

            // generate some warnings if needed
            if (LE_GUIInterface.Instance.delegates.SetIsSelectedObjectFocusBtnInteractable == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetIsSelectedObjectFocusBtnInteractable delegate! It might confuse players if you have a focus button, which is always clickable, but works only when an object is selected. Set this delegate to disable the focus button when no object is selected.");
            }
            if (LE_GUIInterface.Instance.delegates.SetIsSelectedObjectDuplicateBtnInteractable == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetIsSelectedObjectDuplicateBtnInteractable delegate! It might confuse players if you have a duplicate button, which is always clickable, but works only when an object can be duplicated. Set this delegate to disable the duplicate button when no object is selected or this object cannot be created (e.g. max. count reached in this level).");
            }
            if (LE_GUIInterface.Instance.delegates.SetIsSelectedObjectDeleteBtnInteractable == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetIsSelectedObjectDeleteBtnInteractable delegate! It might confuse players if you have a delete button, which is always clickable, but works only when an object is selected. Set this delegate to disable the delete button when no object is selected.");
            }
            if (LE_GUIInterface.Instance.delegates.SetIsSelectedObjectSleepPropertyInteractable == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetIsSelectedObjectSleepPropertyInteractable delegate! It might confuse players if you have a property menu, which is always editable, but applied only to some objects. Set this delegate to disable the 'Is Sleep On Start' property menu when the selected object does not support it.");
            }
            if (LE_GUIInterface.Instance.delegates.SetSelectedObjectIsSleepOnStartPropertyValue == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetIsSelectedObjectSleepPropertyValue delegate! The value of this property can change every time when an object is selected. Set this delegate to get updates for this property.");
            }
            if (LE_GUIInterface.Instance.delegates.SetIsSelectedObjectColorPropertyInteractable == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetIsSelectedObjectColorPropertyInteractable delegate! It might confuse players if you have a property menu, which is always editable, but applied only to some objects. Set this delegate to disable the 'Color' property menu when the selected object does not support it.");
            }
            if (LE_GUIInterface.Instance.delegates.SetSelectedObjectColorPropertyValue == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetSelectedObjectColorPropertyValue delegate! The value of this property can change every time when an object is selected. Set this delegate to get updates for this property.");
            }
            if (LE_GUIInterface.Instance.delegates.SetSelectedObjectVariationPropertyValue == null)
            {
                Debug.LogWarning("LE_LogicObjects: you have not set the LE_GUIInterface.delegates.SetSelectedObjectVariationPropertyValue delegate! The value of this property can change every time when an object is selected. Set this delegate to get updates for this property.");
            }
        }
Beispiel #17
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)
 {
     return(PlaceObject(p_gui3d, p_prefab, p_position, p_rotation, p_scale, p_objectResourcePath, p_isDestroyClonedScripts, -1));
 }