public void ImportMarkers() { var extensions = new[] { new ExtensionFilter("Faf Markers", "fafmapmarkers") }; var paths = StandaloneFileBrowser.OpenFilePanel("Import markers", DefaultPath, extensions, false); if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0])) { ExportMarkers ImpMarkers = JsonUtility.FromJson <ExportMarkers>(System.IO.File.ReadAllText(paths[0])); bool AnyCreated = false; int mc = 0; MapLua.SaveLua.Marker[] CreatedMarkers = new MapLua.SaveLua.Marker[ImpMarkers.Markers.Length]; for (int m = 0; m < ImpMarkers.Markers.Length; m++) { if (!AnyCreated) { Undo.Current.RegisterMarkersAdd(); } AnyCreated = true; if (SelectionManager.Current.SnapToGrid) { ImpMarkers.Markers[m].Pos = ScmapEditor.SnapToGridCenter(ImpMarkers.Markers[m].Pos, true, SelectionManager.Current.SnapToWater); } MapLua.SaveLua.Marker NewMarker = new MapLua.SaveLua.Marker(ImpMarkers.Markers[m].MarkerType); CreatedMarkers[m] = NewMarker; NewMarker.position = ScmapEditor.WorldPosToScmap(ImpMarkers.Markers[m].Pos); NewMarker.orientation = ImpMarkers.Markers[m].Rot.eulerAngles; MarkersControler.CreateMarker(NewMarker, mc); ChainsList.AddToCurrentChain(NewMarker); MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Add(NewMarker); } for (int m = 0; m < ImpMarkers.Markers.Length; m++) { CreatedMarkers[m].AdjacentToMarker = new List <MapLua.SaveLua.Marker>(); for (int c = 0; c < ImpMarkers.Markers[m].Connected.Length; c++) { CreatedMarkers[m].AdjacentToMarker.Add(CreatedMarkers[ImpMarkers.Markers[m].Connected[c]]); } } RenderMarkersConnections.Current.UpdateConnections(); EnvPaths.SetLastPath(ExportPathKey, System.IO.Path.GetDirectoryName(paths[0])); GenericInfoPopup.ShowInfo("Markers imported"); } }
public void Place(Vector3[] Positions, Quaternion[] Rotations, Vector3[] Scales) { //List<MapLua.SaveLua.Marker> NewMarkers = new List<MapLua.SaveLua.Marker>(); int mc = 0; // MasterChainID LastAddedMarkers = new List <int>(); int TotalMarkersCount = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Count; bool AnyCreated = false; if (CreationId == 5) { Vector3 NewPos; MarkerPreset Mpreset = MarkerPresets[SpawnPressetDropdown.value].GetComponent <MarkerPreset>(); for (int i = 0; i < Positions.Length; i++) { for (int m = 0; m < Mpreset.Markers.Length; m++) { if (!AnyCreated) { Undo.Current.RegisterMarkersAdd(); } AnyCreated = true; //Debug.Log(Mpreset.Markers[m].Tr.localPosition); NewPos = Positions[i] + Rotations[i] * Mpreset.Markers[m].Tr.localPosition; if (SelectionManager.Current.SnapToGrid) { NewPos = ScmapEditor.SnapToGridCenter(NewPos, true, SelectionManager.Current.SnapToWater); } //NewPos.y = ScmapEditor.Current.Teren.SampleHeight(NewPos); MapLua.SaveLua.Marker NewMarker = new MapLua.SaveLua.Marker(Mpreset.Markers[m].MarkerType); NewMarker.position = ScmapEditor.WorldPosToScmap(NewPos); //NewMarker.orientation = MarkersControler.CreateMarker(NewMarker, mc); ChainsList.AddToCurrentChain(NewMarker); LastAddedMarkers.Add(TotalMarkersCount); TotalMarkersCount++; MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Add(NewMarker); } } } else { for (int i = 0; i < Positions.Length; i++) { if (!AnyCreated) { Undo.Current.RegisterMarkersAdd(); } AnyCreated = true; MapLua.SaveLua.Marker NewMarker = new MapLua.SaveLua.Marker(LastCreationType); bool snapToWater = SelectionManager.Current.SnapToWater; if (LastCreationType == MapLua.SaveLua.Marker.MarkerTypes.Mass || LastCreationType == MapLua.SaveLua.Marker.MarkerTypes.Hydrocarbon) { snapToWater = false; } if (SelectionManager.Current.SnapToGrid) { Positions[i] = ScmapEditor.SnapToGridCenter(Positions[i], true, snapToWater); } //Positions[i].y = ScmapEditor.Current.Teren.SampleHeight(Positions[i]); ChainsList.AddToCurrentChain(NewMarker); NewMarker.position = ScmapEditor.WorldPosToScmap(Positions[i]); if (CreationId == 3) { NewMarker.orientation = Rotations[i].eulerAngles; } else { NewMarker.orientation = Vector3.zero; } MarkersControler.CreateMarker(NewMarker, mc); LastAddedMarkers.Add(TotalMarkersCount); TotalMarkersCount++; MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Add(NewMarker); } } if (AnyCreated) { //MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Concat<MapLua.SaveLua.Marker>(NewMarkers.ToArray()); MarkerSelectionOptions.UpdateOptions(); MarkersControler.UpdateBlankMarkersGraphics(); RenderMarkersWarnings.Generate(); } }
public void OffsetPosition(Vector3 Offset) { Offset = SymmetryMatrix.MultiplyPoint(Offset); int count = Ids.Count; if (Current.SnapToGrid) { for (int i = 0; i < Positions.Length; i++) { /* * if (i >= count) * { * SelectionRings[i].transform.localPosition = ScmapEditor.SnapToGridCenter(Positions[i] + Offset, true, Current.SnapToWater); * } * else * { * Current.AffectedGameObjects[Ids[i]].transform.localPosition = ScmapEditor.SnapToGridCenter(Positions[i] + Offset, true, Current.SnapToWater); * SelectionRings[i].transform.localPosition = Current.AffectedGameObjects[Ids[i]].transform.localPosition; * }*/ Vector3 NewPos = Vector3.zero; if (Current.LastControlType == SelectionControlTypes.Marker) { if (i >= count) { NewPos = ScmapEditor.SnapToGridCenter(Positions[i] + Offset, true, Current.SnapToWater); } else { NewPos = ScmapEditor.SnapMarker(Positions[i] + Offset, Current.AffectedTypes[Ids[i]]); } } else { NewPos = ScmapEditor.SnapToGridCenter(Positions[i] + Offset, true, Current.SnapToWater); } SelectionRings[i].transform.localPosition = NewPos; if (CustomSnapAction != null) { CustomSnapAction(SelectionRings[i].transform, GetAffected(i)); NewPos = SelectionRings[i].transform.localPosition; } if (i < count) { Current.AffectedGameObjects[Ids[i]].transform.localPosition = NewPos; } } } else { for (int i = 0; i < Positions.Length; i++) { Vector3 NewPos = Positions[i] + Offset; SelectionRings[i].transform.localPosition = NewPos; if (CustomSnapAction != null) { CustomSnapAction(SelectionRings[i].transform, GetAffected(i)); NewPos = SelectionRings[i].transform.localPosition; } if (i < count) { Current.AffectedGameObjects[Ids[i]].transform.localPosition = NewPos; } } } }
void Update() { if (!PlacementObject) { enabled = false; return; } if (!SelectionManager.Current.IsPointerOnGameplay()) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, RaycastMask)) { if (LastSym != SymmetryWindow.GetSymmetryType()) { GenerateSymmetry(); } if (!PlacementObject.activeSelf) { PlacementObject.SetActive(true); for (int i = 0; i < PlacementSymmetry.Length; i++) { PlacementSymmetry[i].SetActive(true); } } // Rotate bool Rotating = false; if (SelectionManager.AllowRotation) { if (Input.GetKeyDown(KeyCode.E)) { /*if (MinRotAngle > 1) * { * PlaceAngle += MinRotAngle; * if (PlaceAngle >= 360) * PlaceAngle = 0; * PlacementObject.transform.rotation = Quaternion.Euler(Vector3.up * PlaceAngle); * } * else*/ { RotationStartMousePos = Input.mousePosition; StartRotation = PlacementObject.transform.eulerAngles; } } else if (Input.GetKeyUp(KeyCode.E)) { ChangeControlerType.ChangeCurrentControler(0); } else if (Input.GetKey(KeyCode.E)) { Rotating = true; Vector3 NewRot = StartRotation + Vector3.down * ((Input.mousePosition.x - RotationStartMousePos.x) * 0.5f); if (MinRotAngle > 1) { int ClampedRot = (int)(NewRot.y / MinRotAngle); NewRot.y = MinRotAngle * ClampedRot; } PlacementObject.transform.eulerAngles = NewRot; } } //Scale bool Scaling = false; if (!Rotating && SelectionManager.AllowScale) { if (Input.GetKeyDown(KeyCode.R)) { RotationStartMousePos = Input.mousePosition; StartScale = PlacementObject.transform.localScale; LastHitPoint = hit.point; } else if (Input.GetKeyUp(KeyCode.R)) { ChangeControlerType.ChangeCurrentControler(0); } else if (Input.GetKey(KeyCode.R)) { Scaling = true; Vector3 Scale = StartScale; float ScalingScale = (Scale.x + Scale.y + Scale.z) / 3f; float ScalePower = (Input.mousePosition.x - RotationStartMousePos.x) * 0.003f * ScalingScale; Scale.x = Mathf.Clamp(Scale.x + ScalePower, 0.005f, 100); Scale.y = Mathf.Clamp(Scale.y + ScalePower, 0.005f, 100); Scale.z = Mathf.Clamp(Scale.z + ScalePower, 0.005f, 100); PlacementObject.transform.localScale = Scale; } } if (!Rotating) { Vector3 Point = hit.point; if (Scaling) { Point = LastHitPoint; } if (SelectionManager.Current.SnapToGrid) { PlacementObject.transform.position = ScmapEditor.SnapToGridCenter(Point, true, SnapToWater); } else if (SnapToWater) { PlacementObject.transform.position = ScmapEditor.ClampToWater(Point); } else { PlacementObject.transform.position = Point; } } UpdateSymmetryObjects(); // Action if (Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.B) || Input.GetKey(KeyCode.M)) { } else if (Input.GetMouseButtonDown(0)) { Place(); } } else if (PlacementObject.activeSelf) { PlacementObject.SetActive(false); for (int i = 0; i < PlacementSymmetry.Length; i++) { PlacementSymmetry[i].SetActive(false); } } }
public void ImportMarkers() { var extensions = new[] { new ExtensionFilter("Faf Markers", "fafmapmarkers") }; var paths = StandaloneFileBrowser.OpenFilePanel("Import markers", EnvPaths.GetMapsPath(), extensions, false); /* * OpenFileDialog FileDialog = new OpenFileDialog(); * FileDialog.Title = "Import markers"; * FileDialog.AddExtension = true; * FileDialog.DefaultExt = ".fafmapmarkers"; * FileDialog.Filter = "Faf Markers (*.fafmapmarkers)|*.fafmapmarkers"; * FileDialog.CheckFileExists = true; */ if (paths.Length > 0 && !string.IsNullOrEmpty(paths[0])) { ExportMarkers ImpMarkers = JsonUtility.FromJson <ExportMarkers>(System.IO.File.ReadAllText(paths[0])); bool AnyCreated = false; int mc = 0; MapLua.SaveLua.Marker[] CreatedMarkers = new MapLua.SaveLua.Marker[ImpMarkers.Markers.Length]; for (int m = 0; m < ImpMarkers.Markers.Length; m++) { if (!AnyCreated) { Undo.Current.RegisterMarkersAdd(); } AnyCreated = true; if (SelectionManager.Current.SnapToGrid) { ImpMarkers.Markers[m].Pos = ScmapEditor.SnapToGridCenter(ImpMarkers.Markers[m].Pos, true, SelectionManager.Current.SnapToWater); } MapLua.SaveLua.Marker NewMarker = new MapLua.SaveLua.Marker(ImpMarkers.Markers[m].MarkerType); CreatedMarkers[m] = NewMarker; NewMarker.position = ScmapEditor.WorldPosToScmap(ImpMarkers.Markers[m].Pos); NewMarker.orientation = ImpMarkers.Markers[m].Rot.eulerAngles; MarkersControler.CreateMarker(NewMarker, mc); ChainsList.AddToCurrentChain(NewMarker); MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Add(NewMarker); } for (int m = 0; m < ImpMarkers.Markers.Length; m++) { CreatedMarkers[m].AdjacentToMarker = new List <MapLua.SaveLua.Marker>(); for (int c = 0; c < ImpMarkers.Markers[m].Connected.Length; c++) { CreatedMarkers[m].AdjacentToMarker.Add(CreatedMarkers[ImpMarkers.Markers[m].Connected[c]]); } } RenderMarkersConnections.Current.UpdateConnections(); } }