public void Place(Vector3[] Positions, Quaternion[] Rotations, Vector3[] Scales, bool RegisterUndo) { if (FirstSelected == null) { ShowGroupError(); return; } if (Positions.Length > 0 && RegisterUndo) { Undo.RegisterUndo(new UndoHistory.HistoryUnitsRemove(), new UndoHistory.HistoryUnitsRemove.UnitsRemoveParam(new SaveLua.Army.UnitsGroup[] { FirstSelected.Source })); } for (int i = 0; i < Positions.Length; i++) { if (RandomRotation.isOn) { Rotations[i] = GetRandomRotation; } SaveLua.Army.Unit NewUnit = new SaveLua.Army.Unit(); NewUnit.Name = SaveLua.Army.Unit.GetFreeName("UNIT_"); NewUnit.type = SelectedUnit.CodeName; NewUnit.orders = ""; NewUnit.platoon = ""; NewUnit.Position = ScmapEditor.WorldPosToScmap(Positions[i]); NewUnit.Orientation = Rotations[i].eulerAngles * Mathf.Deg2Rad; FirstSelected.Source.AddUnit(NewUnit); NewUnit.Instantiate(); FirstSelected.Refresh(); } }
void OnGUI() { if (!Started) { return; } // Label Camera MainCam = CameraControler.Current.Cam; Rect CamRect = MainCam.pixelRect; Rect UiRect = new Rect(CamRect.x, CamRect.y + (Screen.height - CamRect.height), CamRect.width, CamRect.height); GUI.BeginScrollView(UiRect, Vector2.zero, new Rect(0, (Screen.height - CamRect.height), CamRect.width, CamRect.height), false, false); Vector3 Center = (Begin + End) / 2f; Vector3 ScBegin = ScmapEditor.WorldPosToScmap(Begin); Vector3 ScEnd = ScmapEditor.WorldPosToScmap(End); ScBegin.y = 0; ScEnd.y = 0; float Distance = Vector3.Distance(ScBegin, ScEnd); DrawGuiLabel(MainCam, CamRect, Center, Distance.ToString("N2"), LabelStyle); GUI.EndScrollView(); }
public void Bake() { //Group.Blueprint = GetGamedataFile.FixMapsPath(Group.Blueprint.Replace("\\", "/")); BlueprintPath = Group.Blueprint.Replace("\\", "/"); if (!BlueprintPath.StartsWith("/")) { BlueprintPath = "/" + BlueprintPath; } BlueprintPath = GetGamedataFile.FixMapsPath(BlueprintPath); Position = ScmapEditor.WorldPosToScmap(Obj.Tr.position); RotationX = Vector3.zero; RotationY = Vector3.zero; RotationZ = Vector3.zero; MassMath.QuaternionToRotationMatrix(Obj.Tr.localRotation, ref RotationX, ref RotationY, ref RotationZ); Scale = Obj.Tr.localScale; if (Group.PropObject.BP != null) { Scale.x /= Group.PropObject.BP.LocalScale.x; Scale.y /= Group.PropObject.BP.LocalScale.y; Scale.z /= Group.PropObject.BP.LocalScale.z; } }
void CursorUiPos() { Ray ray = Cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, MaxRaycastDistance, MaskCursor)) { GameplayCursorPos = hit.point; GameplayCursorPosScm = ScmapEditor.WorldPosToScmap(GameplayCursorPos); if (GameplayCursorPosScm.x == LastCursorPos.x && GameplayCursorPosScm.z == LastCursorPos.z) { return; } GameplayCursorPosScm.y = hit.point.y * 10; //GameplayCursorPosScm.z = ScmapEditor.Current.map.Height - GameplayCursorPosScm.z; string X = GameplayCursorPosScm.x.ToString("N2"); string Y = GameplayCursorPosScm.y.ToString("N2"); string Z = GameplayCursorPosScm.z.ToString("N2"); X = X.PadRight(8); Y = Y.PadRight(8); Z = Z.PadRight(8); CursorInfo.text = "x: " + X + "\ty: " + Y + "\tz: " + Z; SetToEmptyPos = false; } else if (!SetToEmptyPos) { SetToEmptyPos = true; CursorInfo.text = "x: -------- \ty: -------- \tz: -------- "; } }
GameObject[] ReadUnitsStorage(UnitsStorage Data) { List <GameObject> CreatedUnits = new List <GameObject>(); if (Data != null && Data.Units != null) { for (int i = 0; i < Data.Units.Length; i++) { SaveLua.Army.Unit NewUnit = new SaveLua.Army.Unit(); NewUnit.Name = SaveLua.Army.Unit.GetFreeName("UNIT_"); NewUnit.type = Data.Units[i].ID; NewUnit.orders = Data.Units[i].orders; NewUnit.platoon = Data.Units[i].platoon; if (!ScmapEditor.Current.Teren.terrainData.bounds.Contains(ScmapEditor.Current.Teren.transform.InverseTransformPoint(Data.Units[i].pos))) { Vector3 Offset = ScmapEditor.Current.Teren.transform.TransformPoint(ScmapEditor.Current.Teren.terrainData.bounds.center) - Data.Center; Offset.y = 0; Data.Units[i].pos += Offset; } NewUnit.Position = ScmapEditor.WorldPosToScmap(Data.Units[i].pos); NewUnit.Orientation = UnitInstance.ScmapRotationFromRotation(Data.Units[i].rot); FirstSelected.Source.AddUnit(NewUnit); NewUnit.Instantiate(); SnapAction(NewUnit.Instance.transform, NewUnit.Instance.gameObject); CreatedUnits.Add(NewUnit.Instance.gameObject); } } return(CreatedUnits.ToArray()); }
public void UpdateSize() { Position = ScmapEditor.WorldPosToScmap(MapLuaParser.Current.MapCenterPoint); Scale = Mathf.Max(ScmapEditor.Current.map.Width, ScmapEditor.Current.map.Height) * 2.288245f; ScmapEditor.Current.Skybox.LoadSkybox(); }
public Marker(Marker CopyMarker, string NewName = "") { ConnectedToChains = new List <Chain>(); AdjacentToMarker = new List <Marker>(); for (int i = 0; i < CopyMarker.ConnectedToChains.Count; i++) { ConnectedToChains.Add(CopyMarker.ConnectedToChains[i]); } for (int i = 0; i < CopyMarker.AdjacentToMarker.Count; i++) { AdjacentToMarker.Add(CopyMarker.AdjacentToMarker[i]); } if (string.IsNullOrEmpty(NewName)) { Name = GetLowestName(CopyMarker.MarkerType); } else { Name = NewName; } AddNewMarker(this); size = CopyMarker.size; amount = CopyMarker.amount; position = ScmapEditor.WorldPosToScmap(CopyMarker.MarkerObj.transform.position); orientation = Markers.MarkerObject.MarkerRotToScmapRot(CopyMarker.MarkerObj.Tr.localRotation, CopyMarker.MarkerType); prop = "/env/common/props/markers/M_Blank_prop.bp"; MarkerType = CopyMarker.MarkerType; type = MarkerTypeToString(CopyMarker.MarkerType); if (MarkerType == MarkerTypes.Mass) { resource = true; //amount = 100; prop = "/env/common/props/markers/M_Mass_prop.bp"; color = "ff808080"; } else if (MarkerType == MarkerTypes.Hydrocarbon) { //size = 3; resource = true; //amount = 100; prop = "/env/common/props/markers/M_Hydrocarbon_prop.bp"; color = "ff808080"; } else if (MarkerType == MarkerTypes.CameraInfo) { canSyncCamera = CopyMarker.canSyncCamera; canSetCamera = CopyMarker.canSetCamera; zoom = CopyMarker.zoom; } }
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 Bake() { _Dec.Type = _Dec.Shared.Type; _Dec.Position = ScmapEditor.WorldPosToScmap(GetPivotPoint()); _Dec.Scale = tr.localScale * 10f; _Dec.Rotation = tr.localEulerAngles * Mathf.Deg2Rad; _Dec.CutOffLOD = CutOffLOD; _Dec.NearCutOffLOD = NearCutOffLOD; _Dec.TexPathes = new string[2]; _Dec.Shared.FixPaths(); _Dec.TexPathes[0] = _Dec.Shared.Tex1Path; _Dec.TexPathes[1] = _Dec.Shared.Tex2Path; _Dec.Obj = this; }
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(); } }
IEnumerator CreateFiles() { ScmapEditor.Current.UnloadMap(); MapLuaParser.Current.ResetUI(); MapLuaParser.Current.SaveLuaFile.Unload(); string FileName = Name.text.Replace(" ", "_"); Debug.Log("Create new map: " + FolderName); MapLuaParser.Current.FolderName = FolderName; MapLuaParser.Current.ScenarioFileName = FileName + "_scenario"; MapLuaParser.Current.FolderParentPath = MapPath; Directory.CreateDirectory(MapPath + MapLuaParser.Current.FolderName); int NewMapWidth = SizeByValue(Width.value); int NewMapHeight = SizeByValue(Height.value); int NewMapSize = NewMapWidth; if (NewMapHeight > NewMapSize) { NewMapSize = NewMapHeight; } // Scenario - Basic MapLuaParser.Current.ScenarioLuaFile.Data = new MapLua.ScenarioLua.ScenarioInfo(); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations = new MapLua.ScenarioLua.Configuration[1]; MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0] = new MapLua.ScenarioLua.Configuration(); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].name = "standard"; MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams = new MapLua.ScenarioLua.Team[1]; MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams[0] = new MapLua.ScenarioLua.Team(); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams[0].name = "FFA"; MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams[0].Armys = new List <MapLua.ScenarioLua.Army>(); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].ExtraArmys = new List <MapLua.ScenarioLua.Army>(); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].ExtraArmys.Add(new MapLua.ScenarioLua.Army("ARMY_17")); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].ExtraArmys.Add(new MapLua.ScenarioLua.Army("NEUTRAL_CIVILIAN")); MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].factions = new MapLua.ScenarioLua.Factions[0]; MapLuaParser.Current.ScenarioLuaFile.Data.starts = true; // Scenario - User settings MapLuaParser.Current.ScenarioLuaFile.Data.name = Name.text; MapLuaParser.Current.ScenarioLuaFile.Data.description = Desc.text; MapLuaParser.Current.ScenarioLuaFile.Data.Size = new int[2]; MapLuaParser.Current.ScenarioLuaFile.Data.type = MapType.options[MapType.value].text.ToLower(); MapLuaParser.Current.ScenarioLuaFile.Data.Size[0] = NewMapSize; MapLuaParser.Current.ScenarioLuaFile.Data.Size[1] = NewMapSize; MapLuaParser.Current.ScenarioLuaFile.Data.save = "/maps/" + FolderName + "/" + FileName + "_save.lua"; MapLuaParser.Current.ScenarioLuaFile.Data.script = "/maps/" + FolderName + "/" + FileName + "_script.lua"; MapLuaParser.Current.ScenarioLuaFile.Data.map = "/maps/" + FolderName + "/" + FileName + ".scmap"; MapLuaParser.Current.ScenarioLuaFile.Data.map_version = 1; MapLuaParser.Current.SaveLuaFile.Data = new MapLua.SaveLua.Scenario(); MapLuaParser.Current.SaveLuaFile.Data.MasterChains[0].Markers = new List <MapLua.SaveLua.Marker>(); // Armies int Armies = ArmyCount.value + 1; float MapArmyDistance = NewMapWidth * 0.2f; for (int i = 0; i < Armies; i++) { MapLuaParser.Current.ScenarioLuaFile.Data.Configurations[0].Teams[0].Armys.Add(new MapLua.ScenarioLua.Army("ARMY_" + (i + 1))); MapLua.SaveLua.Marker A1marker = new MapLua.SaveLua.Marker(MapLua.SaveLua.Marker.MarkerTypes.BlankMarker, "ARMY_" + (i + 1)); Vector3 ArmyPosition = new Vector3((int)(NewMapWidth * 0.5f), InitialHeight.intValue, (int)(NewMapWidth * 0.5f)); ArmyPosition += Quaternion.Euler(Vector3.up * 360 * (i / (float)Armies)) * Vector3.forward * MapArmyDistance; A1marker.position = ScmapEditor.WorldPosToScmap(ScmapEditor.SnapToGrid(ScmapEditor.ScmapPosToWorld(ArmyPosition))); MapLuaParser.Current.SaveLuaFile.Data.MasterChains[0].Markers.Add(A1marker); } Markers.MarkersControler.LoadMarkers(); //Save lua MapLuaParser.Current.SaveLuaFile.Data.areas = new MapLua.SaveLua.Areas[1]; MapLuaParser.Current.SaveLuaFile.Data.areas[0] = new MapLua.SaveLua.Areas(); MapLuaParser.Current.SaveLuaFile.Data.areas[0].Name = "AREA_1"; if (NewMapWidth == NewMapHeight) { MapLuaParser.Current.SaveLuaFile.Data.areas[0].rectangle = new Rect(0, 0, NewMapWidth, NewMapHeight); } else { if (NewMapWidth > NewMapHeight) // Horizontal { int Offset = (NewMapWidth - NewMapHeight) / 2; MapLuaParser.Current.SaveLuaFile.Data.areas[0].rectangle = new Rect(0, Offset, NewMapWidth, NewMapHeight + Offset); } else // Vertical { int Offset = (NewMapHeight - NewMapWidth) / 2; MapLuaParser.Current.SaveLuaFile.Data.areas[0].rectangle = new Rect(Offset, 0, NewMapWidth + Offset, NewMapHeight); } } ScmapEditor.Current.map = new Map(MapLuaParser.Current.ScenarioLuaFile.Data.Size[0], MapLuaParser.Current.ScenarioLuaFile.Data.Size[1], InitialHeight.intValue, Water.isOn, WaterElv.intValue, DepthElevation.intValue, AbyssElevation.intValue); //GenerateControlTex.GenerateWater(); ScmapEditor.Current.LoadHeights(); yield return(null); yield return(null); MapLuaParser.Current.SaveMap(false); MapLuaParser.Current.SaveScriptLua(0); yield return(null); yield return(null); MapLuaParser.Current.LoadFile(); }
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(); } }
public IEnumerator UpdatingMarkersHeights() { const int BreakEvery = 50; int UpdateCount = 0; for (int mc = 0; mc < MapLuaParser.Current.SaveLuaFile.Data.MasterChains.Length; mc++) { int Mcount = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Count; for (int m = 0; m < Mcount; m++) { if (!MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj) { continue; } Vector3 CurrPos = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.Tr.localPosition; CurrPos.y = ScmapEditor.Current.Teren.SampleHeight(CurrPos); MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.Tr.localPosition = CurrPos; MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].position = ScmapEditor.WorldPosToScmap(CurrPos); UpdateCount++; if (UpdateCount > BreakEvery) { UpdateCount = 0; yield return(null); } } } yield return(null); UpdateProcess = null; Updating = false; if (BufforUpdate) { BufforUpdate = false; UpdateMarkersHeights(); } }
public static void SaveUnit(LuaParser.Creator LuaFile, UnitInstance Instance) { LuaFile.OpenTab(LuaParser.Write.PropertieToLua(Instance.gameObject.name) + LuaParser.Write.OpenBracketValue); LuaFile.AddLine(LuaParser.Write.StringToLua(UnitsGroup.KEY_TYPE, Instance.UnitRenderer.BP.CodeName)); LuaFile.AddLine(LuaParser.Write.StringToLua(UnitsGroup.KEY_ORDERS, Instance.orders)); LuaFile.AddLine(LuaParser.Write.StringToLua(UnitsGroup.KEY_PLATOON, Instance.platoon)); LuaFile.AddLine(LuaParser.Write.Vector3ToLua(UnitsGroup.KEY_POSITION, ScmapEditor.WorldPosToScmap(Instance.transform.localPosition))); LuaFile.AddLine(LuaParser.Write.Vector3ToLua(UnitsGroup.KEY_ORIENTATION, Instance.GetScmapRotation())); LuaFile.CloseTab(LuaParser.Write.EndBracketNext); }
public void SaveMarkerValues(LuaParser.Creator LuaFile) { if (MarkerType == MarkerTypes.AutoPathNode) { // Convert to Land/Amphibious/Naval markers if (IsOnWater()) { // Water for (int i = 0; i < AutoMarker_Water.AdjacentToMarker.Count; i++) { if (AutoMarker_Water.AdjacentToMarker[i].MarkerType == MarkerTypes.AutoPathNode) { if (AutoMarker_Water.AdjacentToMarker[i].AutoMarker_Water != null) { AutoMarker_Water.AdjacentToMarker[i] = AutoMarker_Water.AdjacentToMarker[i].AutoMarker_Water; } else { AutoMarker_Water.AdjacentToMarker.RemoveAt(i); i--; } } } AutoMarker_Water.SaveMarkerValues(LuaFile); } else { // Land for (int i = 0; i < AutoMarker_Land.AdjacentToMarker.Count; i++) { if (AutoMarker_Land.AdjacentToMarker[i].MarkerType == MarkerTypes.AutoPathNode) { if (AutoMarker_Land.AdjacentToMarker[i].AutoMarker_Land != null) { AutoMarker_Land.AdjacentToMarker[i] = AutoMarker_Land.AdjacentToMarker[i].AutoMarker_Land; } else { AutoMarker_Land.AdjacentToMarker.RemoveAt(i); i--; } } } AutoMarker_Land.SaveMarkerValues(LuaFile); } // Amphibious for (int i = 0; i < AutoMarker_Amphibious.AdjacentToMarker.Count; i++) { if (AutoMarker_Amphibious.AdjacentToMarker[i].MarkerType == MarkerTypes.AutoPathNode) { if (AutoMarker_Amphibious.AdjacentToMarker[i].AutoMarker_Amphibious != null) { AutoMarker_Amphibious.AdjacentToMarker[i] = AutoMarker_Amphibious.AdjacentToMarker[i].AutoMarker_Amphibious; } else { AutoMarker_Amphibious.AdjacentToMarker.RemoveAt(i); i--; } } } AutoMarker_Amphibious.SaveMarkerValues(LuaFile); } else { if (MarkerObj != null) { position = ScmapEditor.WorldPosToScmap(MarkerObj.transform.position); if (MarkerType != MarkerTypes.CameraInfo) { MarkerObj.transform.localRotation = Quaternion.identity; } orientation = Markers.MarkerObject.MarkerRotToScmapRot(MarkerObj.transform.localRotation, MarkerObj.Owner.MarkerType); } ForceDefaultValues(); LuaFile.OpenTab(LuaParser.Write.PropertieToLua(Name) + LuaParser.Write.OpenBracketValue); if (AllowByType(KEY_SIZE)) { LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_SIZE), size)); } if (AllowByType(KEY_RESOURCE)) { LuaFile.AddLine(LuaParser.Write.BoolToLuaFunction(LuaParser.Write.PropertieToLua(KEY_RESOURCE), resource)); } if (AllowByType(KEY_AMOUNT)) { LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_AMOUNT), amount)); } LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_COLOR), color)); if (AllowByType(KEY_EDITORICON)) { LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_EDITORICON), editorIcon)); } if (AllowByType(KEY_HINT)) { LuaFile.AddLine(LuaParser.Write.BoolToLuaFunction(LuaParser.Write.PropertieToLua(KEY_HINT), hint)); } if (AllowByType(KEY_ADJACENTTO)) { if (string.IsNullOrEmpty(graph)) { switch (MarkerType) { case MarkerTypes.LandPathNode: graph = "DefaultLand"; break; case MarkerTypes.AmphibiousPathNode: graph = "DefaultAmphibious"; break; case MarkerTypes.WaterPathNode: graph = "DefaultWater"; break; case MarkerTypes.AirPathNode: graph = "DefaultAir"; break; } } LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_GRAPH), graph)); adjacentTo = ""; for (int i = 0; i < AdjacentToMarker.Count; i++) { if (i > 0) { adjacentTo += " "; } adjacentTo += AdjacentToMarker[i].Name; } LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_ADJACENTTO), adjacentTo)); } //Type LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_TYPE), MarkerTypeToString(MarkerType))); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_PROP), prop)); if (AllowByType(KEY_ZOOM)) { LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_ZOOM), zoom)); } if (AllowByType(KEY_CANSETCAMERA)) { LuaFile.AddLine(LuaParser.Write.BoolToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CANSETCAMERA), canSetCamera)); } if (AllowByType(KEY_CANSYNCCAMERA)) { LuaFile.AddLine(LuaParser.Write.BoolToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CANSYNCCAMERA), canSyncCamera)); } if (AllowByType(KEY_OFFSET)) { LuaFile.AddLine(LuaParser.Write.Vector3ToLuaFunction(LuaParser.Write.PropertieToLua(KEY_OFFSET), offset)); } if (AllowByType(KEY_EFFECTTEMPLATE)) { LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_EFFECTTEMPLATE), EffectTemplate)); } if (AllowByType(KEY_SCALE)) { LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_SCALE), scale)); } if (MarkerType == MarkerTypes.WeatherGenerator) { LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDCOUNT), cloudCount)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDCOUNTRANGE), cloudCountRange)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDEMITTERSCALE), cloudEmitterScale)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDEMITTERSCALERANGE), cloudEmitterScaleRange)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDHEIGHT), cloudHeight)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDHEIGHTRANGE), cloudHeightRange)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_CLOUDSPREAD), cloudSpread)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_SPAWNCHANCE), spawnChance)); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_FORCETYPE), ForceType)); } else if (MarkerType == MarkerTypes.WeatherDefinition) { LuaFile.AddLine(LuaParser.Write.Vector3ToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERDRIFTDIRECTION), WeatherDriftDirection)); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_MAPSTYLE), MapStyle)); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE01), WeatherType01)); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE02), WeatherType02)); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE03), WeatherType03)); LuaFile.AddLine(LuaParser.Write.StringToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE04), WeatherType04)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE01CHANCE), WeatherType01Chance)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE02CHANCE), WeatherType02Chance)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE03CHANCE), WeatherType03Chance)); LuaFile.AddLine(LuaParser.Write.FloatToLuaFunction(LuaParser.Write.PropertieToLua(KEY_WEATHERTYPE04CHANCE), WeatherType04Chance)); } //Transform if (MarkerType == MarkerTypes.CameraInfo) { LuaFile.AddLine(LuaParser.Write.Vector3ToLuaFunctionPrecision(LuaParser.Write.PropertieToLua(KEY_ORIENTATION), orientation, true, 6)); } else { LuaFile.AddLine(LuaParser.Write.Vector3ToLuaFunction(LuaParser.Write.PropertieToLua(KEY_ORIENTATION), orientation)); } LuaFile.AddLine(LuaParser.Write.Vector3ToLuaFunction(LuaParser.Write.PropertieToLua(KEY_POSITION), position)); LuaFile.CloseTab(LuaParser.Write.EndBracketNext); } }
public IEnumerator UpdatingMarkersHeights() { //const int BreakEvery = 50; //int UpdateCount = 0; float Realtime = Time.realtimeSinceStartup; for (int mc = 0; mc < MapLuaParser.Current.SaveLuaFile.Data.MasterChains.Length; mc++) { int Mcount = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Count; for (int m = 0; m < Mcount; m++) { if (!MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj) { continue; } Vector3 CurrPos = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.Tr.localPosition; CurrPos.y = ScmapEditor.Current.Teren.SampleHeight(CurrPos); MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.Tr.localPosition = CurrPos; MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].position = ScmapEditor.WorldPosToScmap(CurrPos); /*UpdateCount++; * if (UpdateCount > BreakEvery) * { * UpdateCount = 0; * yield return null; * }*/ if (Time.realtimeSinceStartup - Realtime > MaxAllowedOverhead) { yield return(null); Realtime = Time.realtimeSinceStartup; } } } yield return(null); UpdateProcess = null; Updating = false; if (BufforUpdate) { BufforUpdate = false; UpdateMarkersHeights(); } }
public void GenerateWaves() { WavesRenderer.WavePattern pattern = WavesRenderer.Instance.WavePatterns[WavesDropdown.value]; int patternPropertyId = Shader.PropertyToID(pattern.parameters[0].texture + pattern.parameters[0].ramp); Vector2 angleRange = Vector2.zero; angleRange.x = MinWaveAngle.value; while (angleRange.x < 0f) { angleRange.x += 360f; } while (angleRange.x > 360f) { angleRange.x -= 360f; } MinWaveAngle.SetValue(angleRange.x); angleRange.y = Mathf.Clamp(MaxWaveAngle.value, 0f, 180f); MaxWaveAngle.SetValue(angleRange.y); var waveShorePoints = WavesRenderer.GetShoreDepthPoints(ShoreDepth.value * 0.1f, angleRange); Debug.Log(waveShorePoints.Count); List <WavesRenderer.ShoreDepthPoint> waveShoreUsedPoints; int spawnedCount = 0; float density = ShoreDensity.value * 0.01f; if (density < 1) { int targetSpawnCount = Mathf.RoundToInt(waveShorePoints.Count * density); HashSet <Vector3> usedPoints = new HashSet <Vector3>(); waveShoreUsedPoints = new List <WavesRenderer.ShoreDepthPoint>(targetSpawnCount); int MaxSearchStepDensity = Mathf.RoundToInt(Mathf.Lerp(600, 10, density + Mathf.Clamp01((waveShorePoints.Count - 500) / 2000f))); if (!PreventCloseWaves.isOn) { MaxSearchStepDensity = 0; } while (spawnedCount < targetSpawnCount) { int MaxStepCount = MaxSearchStepDensity; while (true) { int newId = Random.Range(0, waveShorePoints.Count); Vector3 searchPoint = waveShorePoints[newId].point; bool toCloseToUsedPoint = false; foreach (Vector3 point in usedPoints) { if ((point - searchPoint).sqrMagnitude <= 0.1f) { toCloseToUsedPoint = true; break; } } MaxStepCount--; if (!toCloseToUsedPoint || MaxStepCount < 0) { usedPoints.Add(searchPoint); waveShoreUsedPoints.Add(waveShorePoints[newId]); waveShorePoints.RemoveAt(newId); break; } } spawnedCount++; } } else { waveShoreUsedPoints = waveShorePoints; spawnedCount = waveShorePoints.Count; } if (waveShoreUsedPoints.Count == 0) { return; } Debug.Log("Spawned " + pattern.name + " waves, count: " + spawnedCount); Undo.RegisterUndo(new UndoHistory.HistoryWaterWaves()); for (int i = 0; i < waveShoreUsedPoints.Count; i++) { Vector3 forward = Quaternion.Euler(0f, waveShoreUsedPoints[i].angle, 0f) * Vector3.forward; #if UNITY_EDITOR Vector3 right = Vector3.Cross(forward, Vector3.up); Debug.DrawLine(waveShoreUsedPoints[i].point, waveShoreUsedPoints[i].point + forward * 0.2f, Color.cyan, 10f); Debug.DrawLine(waveShoreUsedPoints[i].point - right * 0.05f, waveShoreUsedPoints[i].point + right * 0.05f, Color.cyan, 10f); #endif WaveGenerator newWave = new WaveGenerator(); newWave.Position = ScmapEditor.WorldPosToScmap(waveShoreUsedPoints[i].point); newWave.Rotation = waveShoreUsedPoints[i].angle * Mathf.Deg2Rad; newWave.TextureName = pattern.parameters[0].texture; newWave.RampName = pattern.parameters[0].ramp; newWave.propertyID = patternPropertyId; newWave.PeriodFirst = pattern.parameters[0].period - pattern.parameters[0].periodVariance; newWave.PeriodSecond = pattern.parameters[0].period + pattern.parameters[0].periodVariance; newWave.LifetimeFirst = pattern.parameters[0].lifetime - pattern.parameters[0].lifetimeVariance; newWave.LifetimeSecond = pattern.parameters[0].lifetime + pattern.parameters[0].lifetimeVariance; newWave.ScaleFirst = pattern.parameters[0].scale.x + Random.Range(-pattern.parameters[0].scaleVariance, pattern.parameters[0].scaleVariance); newWave.ScaleSecond = pattern.parameters[0].scale.y + Random.Range(-pattern.parameters[0].scaleVariance, pattern.parameters[0].scaleVariance); newWave.Velocity = -forward * (pattern.parameters[0].speed + Random.Range(-pattern.parameters[0].speedVariance, pattern.parameters[0].speedVariance)); // ?? TODO Check if it really works newWave.Velocity = new Vector3(newWave.Velocity.x * -1f, newWave.Velocity.y * 1, newWave.Velocity.z * 1); newWave.FrameCount = pattern.parameters[0].frameCount; newWave.FrameRateFirst = pattern.parameters[0].frameRate - pattern.parameters[0].frameRateVariance; newWave.FrameRateSecond = pattern.parameters[0].frameRate + pattern.parameters[0].frameRateVariance; newWave.StripCount = pattern.parameters[0].stripCount; ScmapEditor.Current.map.WaveGenerators.Add(newWave); } WavesRenderer.ReloadWaves(); }