public override bool Rollback() { if (!base.Rollback()) { return(false); } if (m_prefab == null) { Debug.LogError("LE_CmdDeleteObject: Rollback: could not rollback, m_prefab is null!"); return(false); } if (m_gui3d == null) { Debug.LogError("LE_CmdDeleteObject: Rollback: could not rollback, m_gui3d is null!"); return(false); } m_objectInstance.Obj = LE_LogicObjects.InstantiateObject(m_prefab, m_position, m_rotation, m_scale, m_objectResourcePath); m_objectInstance.UID = m_UID; m_objectInstance.Obj.IsRigidbodySleepingStart = m_isRigidbodySleepingStart; m_objectInstance.Obj.DeactivateRigidbody(); // no collision solving needed LE_LogicObjects.ApplyColor(m_objectInstance.Obj, m_color); LE_LogicObjects.ApplyVariation(m_objectInstance.Obj, m_variationIndex); // load snap points that were connected before deleting m_gui3d.SetSnapPointUIDsToObjUIDsAndApplyChanges(m_snapPointLinks); LE_LogicObjects.AddSnappingScripts(m_gui3d, m_objectInstance.Obj); LE_LogicObjects.SelectNewObjectAndNotifyListeners(m_gui3d, m_objectInstance.Obj); return(true); }
private bool Apply(float p_direction) { if (m_object.Obj == null) { Debug.LogError("LE_CmdChangeColorObject: Execute: could not execute, m_object is null!"); return(false); } Color targetColor = m_object.Obj.ColorProperty + p_direction * m_deltaColor; LE_LogicObjects.ApplyColor(m_object.Obj, targetColor); return(true); }
private bool Apply(int p_variationIndex) { if (m_object.Obj == null) { Debug.LogError("LE_CmdChangeObjectVariation: Execute: could not execute, m_object is null!"); return(false); } if (m_variationIndexBefore == -10) { m_variationIndexBefore = m_object.Obj.VariationsDefaultIndex; } LE_LogicObjects.ApplyVariation(m_object.Obj, p_variationIndex); return(true); }
public override bool Rollback() { if (!base.Rollback()) { return(false); } if (m_objectInstance.Obj == null) { Debug.LogError("LE_CmdPlaceObject: Rollback: could not rollback, m_objectInstance is null!"); return(false); } if (m_gui3d == null) { Debug.LogError("LE_CmdPlaceObject: Rollback: could not rollback, m_gui3d is null!"); return(false); } LE_LogicObjects.DeleteObject(m_gui3d, m_objectInstance.Obj); return(true); }
public override bool Rollback() { if (!base.Rollback()) { return(false); } if (m_snappedObj.Obj == null) { Debug.LogError("LE_CmdSnapObjectToObject: Rollback: could not rollback, m_snappedObj is null!"); return(false); } if (m_gui3d == null) { Debug.LogError("LE_CmdSnapObjectToObject: Rollback: could not rollback, m_gui3d is null!"); return(false); } LE_LogicObjects.DeleteObject(m_gui3d, m_snappedObj.Obj); return(true); }
public override bool Execute() { if (!base.Execute()) { return(false); } if (m_prefab == null) { Debug.LogError("LE_CmdPlaceObject: Execute: could not execute, m_prefab is null!"); return(false); } if (m_gui3d == null) { Debug.LogError("LE_CmdPlaceObject: Execute: could not execute, m_gui3d is null!"); return(false); } int priorUID = m_objectInstance.UID; m_objectInstance.Obj = LE_LogicObjects.PlaceObject(m_gui3d, m_prefab, m_position, m_rotation, m_scale, m_objectResourcePath, m_isDestroyClonedScripts, priorUID); if (priorUID == -1) { // save randomity result in the first run m_position = m_objectInstance.Obj.transform.position; m_rotation = m_objectInstance.Obj.transform.rotation; m_scale = m_objectInstance.Obj.transform.localScale; } else { // restore randomity result of the first run m_objectInstance.Obj.transform.position = m_position; m_objectInstance.Obj.transform.rotation = m_rotation; m_objectInstance.Obj.transform.localScale = m_scale; } return(true); }
public List <KeyValuePair <string, int> > GetSnapPointsToReactivate(int p_deletedObjectUID, int p_deletedObjectSnapPointCount) { List <KeyValuePair <string, int> > reactivatedSnapPointUIDsToObjectUIDs = new List <KeyValuePair <string, int> >(); // find all connections from the object that is going to be deleted to other objects for (int i = 0; i < p_deletedObjectSnapPointCount; i++) { string snapPointUID = LE_LogicObjects.GetSnapPointUID(p_deletedObjectUID, i); if (m_snapPointUIDsToObjUIDs.ContainsKey(snapPointUID)) { reactivatedSnapPointUIDsToObjectUIDs.Add(new KeyValuePair <string, int>(snapPointUID, m_snapPointUIDsToObjUIDs[snapPointUID])); } } // find all connections from other objects to the object that is going to be deleted foreach (KeyValuePair <string, int> reference in m_snapPointUIDsToObjUIDs) { if (reference.Value == p_deletedObjectUID) { reactivatedSnapPointUIDsToObjectUIDs.Add(new KeyValuePair <string, int>(reference.Key, p_deletedObjectUID)); } } return(reactivatedSnapPointUIDsToObjectUIDs); }
public override bool Execute() { if (!base.Execute()) { return(false); } if (m_objectInstance.Obj == null) { Debug.LogError("LE_CmdDeleteObject: Execute: could not execute, m_objectInstance is null!"); return(false); } if (m_gui3d == null) { Debug.LogError("LE_CmdDeleteObject: Execute: could not execute, m_gui3d is null!"); return(false); } // save objects state for rollback m_position = m_objectInstance.Obj.transform.position; m_rotation = m_objectInstance.Obj.transform.rotation; m_scale = m_objectInstance.Obj.transform.localScale; m_isRigidbodySleepingStart = m_objectInstance.Obj.IsRigidbodySleepingStart; m_color = m_objectInstance.Obj.ColorProperty; m_variationIndex = m_objectInstance.Obj.VariationsDefaultIndex; m_snapPointLinks.Clear(); List <KeyValuePair <string, int> > snapPointLinks = m_gui3d.GetSnapPointsToReactivate(m_UID, m_objectInstance.Obj.ObjectSnapPoints.Length); foreach (KeyValuePair <string, int> link in snapPointLinks) { m_snapPointLinks.Add(link.Key, link.Value); } // delete object LE_LogicObjects.DeleteObject(m_gui3d, m_objectInstance.Obj); return(true); }
private void OnAfterObjectSnapped(object p_sender, S_SnapToObjectEventArgs p_args) { if (m_gui3d == null) { Debug.LogError("LE_CmdSnapObjectToObject: OnAfterObjectSnapped: m_gui3d is null!"); return; } LE_Object newObj = p_args.NewInstance.GetComponent <LE_Object>(); if (newObj != null) { if (m_snappedObj.UID > 0) { newObj.UID = m_snappedObj.UID; // reuse snap object UID of the first creation } m_snappedObj.Obj = newObj; LE_LogicObjects.OnNewObjectSnapped(m_gui3d, newObj, p_args); } else { Debug.LogError("LE_CmdSnapObjectToObject: OnAfterObjectSnapped: LE_Object is not attached to the root of the new object! This object will not be saved if it has no LE_Object attached!"); } }
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); } } } }