public UnitInstance CreateUnitObject(MapLua.SaveLua.Army.Unit Source, MapLua.SaveLua.Army.UnitsGroup Group) { Vector3 position = ScmapEditor.ScmapPosToWorld(Source.Position); Vector3 RadianOrientation = Vector3.zero; Quaternion rotation = Quaternion.Euler(Source.Orientation * Mathf.Rad2Deg); GameObject Obj = Instantiate(UnitsInfo.Current.UnitInstancePrefab, transform) as GameObject; Obj.name = Source.Name; UnitInstance UInst = Obj.GetComponent <UnitInstance>(); //UInst.Owner = Owner; UInst.Group = Group; Group.UnitInstances.Add(UInst); UInst.orders = Source.orders; UInst.platoon = Source.platoon; UInst.UnitRenderer = this; UInst.SetMatrix(ScmapEditor.SnapToTerrain(position), rotation); if (BP.Footprint.x > 0 && BP.Footprint.y > 0) { UInst.Col.size = new Vector3(BP.Footprint.x * 0.1f, BP.Size.y * 0.1f, BP.Footprint.y * 0.1f); } else { UInst.Col.size = BP.Size * 0.1f; } UInst.Col.center = Vector3.up * (BP.Size.y * 0.05f); AddInstance(UInst); return(UInst); }
public static void CreateMarker(SaveLua.Marker Owner, int mc) { GameObject NewMarker = Instantiate(Current.MarkerPrefab, Current.MasterChains[mc]); NewMarker.name = Owner.Name; MarkerObject NewObj = NewMarker.GetComponent <MarkerObject>(); NewObj.Owner = Owner; Owner.MarkerObj = NewObj; MarkerPropGraphic PropGraphic; if (Owner.MarkerType == SaveLua.Marker.MarkerTypes.BlankMarker && ArmyInfo.ArmyExist(Owner.Name)) { PropGraphic = Current.SpawnGraphic; } else { PropGraphic = GetPropByType(Owner.MarkerType); } NewObj.Mf.sharedMesh = PropGraphic.SharedMesh; NewObj.Mr.sharedMaterial = PropGraphic.SharedMaterial; NewObj.Bc.size = PropGraphic.SharedMesh.bounds.size; NewObj.Bc.center = PropGraphic.SharedMesh.bounds.center; NewObj.Tr.localPosition = ScmapEditor.ScmapPosToWorld(Owner.position); NewObj.Tr.localRotation = MarkerObject.ScmapRotToMarkerRot(Owner.orientation, Owner.MarkerType); NewMarker.SetActive(Current.MarkerLayersSettings.ActiveByType(Owner.MarkerType)); }
public static void CreateRanges() { //SelectionManager.Current.AffectedGameObjects[SelectionManager.Current.Selection.Ids[0]].GetComponent<UnitInstance>() Count = SelectionManager.Current.Selection.Ids.Count; if (Count > MaxUnitRanges) { Count = MaxUnitRanges; } for (int i = 0; i < Count; i++) { GameObject UIobj = SelectionManager.Current.AffectedGameObjects[SelectionManager.Current.Selection.Ids[i]]; if (UIobj == null) { continue; } UnitInstance UI = UIobj.GetComponent <UnitInstance>(); if (UI == null) { UnitRanges[i].UnitTr = null; UnitRanges[i].Radius = 0; } else { UnitRanges[i].UnitTr = UI.transform; UnitRanges[i].Radius = ScmapEditor.ScmapPosToWorld(UI.UnitRenderer.BP.MaxRange); UnitRanges[i].MinRadius = ScmapEditor.ScmapPosToWorld(UI.UnitRenderer.BP.MinRange); } } }
public void CreateObject(bool AllowFarLod = true) { Obj = Group.PropObject.CreatePropGameObject( ScmapEditor.ScmapPosToWorld(Position), MassMath.QuaternionFromRotationMatrix(RotationX, RotationY, RotationZ), Scale, AllowFarLod ); Obj.Connected = this; }
public UnitInstance CreateUnitObject(MapLua.SaveLua.Army.Unit Source, MapLua.SaveLua.Army.UnitsGroup Group) { Vector3 position = ScmapEditor.ScmapPosToWorld(Source.Position); Vector3 RadianOrientation = Vector3.zero; Quaternion rotation = UnitInstance.RotationFromScmapRotation(Source.Orientation); GameObject Obj = Instantiate(UnitsInfo.Current.UnitInstancePrefab, transform) as GameObject; return(FillGameObjectValues(Obj, Source, Group, position, rotation)); }
public void LoadSkybox() { SkyData = ScmapEditor.Current.map.AdditionalSkyboxData; CreateMesh(); transform.position = ScmapEditor.ScmapPosToWorld(SkyData.Data.Position) + Vector3.up * (SkyData.Data.HorizonHeight * 0.1f); transform.localScale = Vector3.one * (SkyData.Data.Scale * 0.1f); Mat.SetFloat("_HorizonHeight", SkyData.Data.HorizonHeight * 0.1f); Mat.SetColor("_HorizonColor", SkyData.Data.HorizonColor); Mat.SetFloat("_ZenithHeight", SkyData.Data.ZenithHeight * 0.1f); Mat.SetColor("_ZenithColor", SkyData.Data.ZenithColor); }
public static void CreateGameObjectFromDecal(Decal Component) { GameObject NewDecalObject = Instantiate(Current.DecalPrefab, Current.DecalPivot); OzoneDecal Obj = NewDecalObject.GetComponent <OzoneDecal>(); Component.Obj = Obj; Obj.Dec = Component; Obj.tr = NewDecalObject.transform; Obj.tr.localRotation = Quaternion.Euler(Component.Rotation * Mathf.Rad2Deg); Obj.tr.localScale = new Vector3(Component.Scale.x * 0.1f, Component.Scale.x * 0.1f, Component.Scale.z * 0.1f); Obj.CutOffLOD = Component.CutOffLOD; Obj.NearCutOffLOD = Component.NearCutOffLOD; Obj.MovePivotPoint(ScmapEditor.ScmapPosToWorld(Component.Position)); Obj.Material = Component.Shared.SharedMaterial; Component.Shared.OnVisibilityChanged += Component.UpdateVisibility; }
public void AddInstance(WaveGenerator wave) { if (instancesCount >= MAX_MEMORY_ALLOCATION) { return; } Vector3 position = ScmapEditor.ScmapPosToWorld(wave.Position); Quaternion rotation = Quaternion.Euler(0f, wave.Rotation * Mathf.Rad2Deg, 0f); //Vector3 scale = Vector3.one * Mathf.Max(wave.ScaleFirst, wave.ScaleSecond) * 0.1f; instances[instancesCount] = Matrix4x4.TRS(position, rotation, Vector3.one); // + rotation * Vector3.back * Random.Range(0.1f, 0.4f) Offset them for debuging velocity[instancesCount] = new Vector4(wave.Velocity.x * -10f, wave.Velocity.y * 10f, wave.Velocity.z * 10f); first[instancesCount] = new Vector4(wave.LifetimeFirst, wave.PeriodFirst, wave.ScaleFirst, wave.FrameRateFirst); second[instancesCount] = new Vector4(wave.LifetimeSecond, wave.PeriodSecond, wave.ScaleSecond, wave.FrameRateSecond); frames[instancesCount] = new Vector4(wave.FrameCount, wave.StripCount, Random.Range(0, Mathf.Max(wave.PeriodFirst, wave.ScaleSecond)), 0); //lifetime[instancesCount] = 0; spheres[instancesCount] = new BoundingSphere(position, 2f); instancesCount++; }
public static void Generate() { Clear(); if (!MapLuaParser.IsMapLoaded) { return; } if (MapLuaParser.LoadingMapProcess || MapLuaParser.SavingMapProcess) { return; } if (MapLuaParser.Current.ScenarioLuaFile.Data != null && MapLuaParser.Current.ScenarioLuaFile.Data.Size != null && MapLuaParser.Current.ScenarioLuaFile.Data.Size.Length >= 2) { } else { return; } if (MapLuaParser.Current.SaveLuaFile.Data.MasterChains == null || MapLuaParser.Current.SaveLuaFile.Data.MasterChains.Length <= 0 || MapLuaParser.Current.SaveLuaFile.Data.MasterChains[0].Markers == null || MapLuaParser.Current.SaveLuaFile.Data.MasterChains[0].Markers.Count == 0) { return; } Vector3 MapMaxPoint = ScmapEditor.ScmapPosToWorld( new Vector3(MapLuaParser.Current.ScenarioLuaFile.Data.Size[0], 0, MapLuaParser.Current.ScenarioLuaFile.Data.Size[1]) ); int mc = 0; int Mcount = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Count; MapLua.SaveLua.Marker Current; for (int m = 0; m < Mcount; m++) { Current = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m]; if (Current.MarkerObj == null) { continue; } if (Current.MarkerType != MapLua.SaveLua.Marker.MarkerTypes.Mass && Current.MarkerType != MapLua.SaveLua.Marker.MarkerTypes.Hydrocarbon) { continue; } Vector3 LocalPos = Current.MarkerObj.Tr.localPosition; if (LocalPos.x < BorderOffset || LocalPos.z > -BorderOffset || LocalPos.x > MapMaxPoint.x - BorderOffset || LocalPos.z < MapMaxPoint.z + BorderOffset ) { WarningPosition.Add(new MarkerWarning(Current.MarkerObj.Tr, AiWarning)); } } RenderEnabled = WarningPosition.Count > 0; }
public void OnRenderObject() { if (PreviewTex.IsPreview) { return; } if (Camera.current != RenderCamera || ScmapEditor.Current == null || ScmapEditor.Current.Teren == null) { return; } if (MapLuaParser.Current.SaveLuaFile.Data.areas.Length == 0) { return; } float Height = ScmapEditor.GetWaterLevel(); GL.PushMatrix(); // Set transformation matrix for drawing to // match our transform GL.MultMatrix(transform.localToWorldMatrix); Mat.SetPass(0); for (int a = 0; a < MapLuaParser.Current.SaveLuaFile.Data.areas.Length; a++) { if (MapLuaParser.Current.SaveLuaFile.Data.areas[a] == AreaInfo.SelectedArea) { continue; } GL.Begin(GL.LINES); Vector3 Pos0 = ScmapEditor.ScmapPosToWorld(new Vector3(MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.x, 0, MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.y)); Pos0.y = ScmapEditor.Current.Teren.SampleHeight(Pos0); Vector3 Pos1 = ScmapEditor.ScmapPosToWorld(new Vector3(MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.width, 10, MapLuaParser.Current.SaveLuaFile.Data.areas[a].rectangle.height)); Pos1.y = ScmapEditor.Current.Teren.SampleHeight(Pos1); Pos0.y = Mathf.Lerp(Pos0.y, Pos1.y, 0.5f); if (Pos0.y < Height) { Pos0.y = Height; } Pos1.y = Pos0.y; GL.Vertex(Pos0); GL.Vertex3(Pos0.x, Pos0.y, Pos1.z); GL.Vertex3(Pos0.x, Pos0.y, Pos1.z); GL.Vertex(Pos1); GL.Vertex(Pos1); GL.Vertex3(Pos1.x, Pos0.y, Pos0.z); GL.Vertex3(Pos1.x, Pos0.y, Pos0.z); GL.Vertex(Pos0); GL.End(); } GL.PopMatrix(); }
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 OnGUI() { RenderAdaptiveMarkers.DrawGUIStatic(); if (BP.Footprint.x == 0 && BP.Footprint.y == 0) { return; } if (PreviewTex.IsPreview) { return; } if (MapLuaParser.LoadingMapProcess || MapLuaParser.SavingMapProcess) { return; } 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 MapMaxPoint = ScmapEditor.ScmapPosToWorld( new Vector3(MapLuaParser.Current.ScenarioLuaFile.Data.Size[0], 0, MapLuaParser.Current.ScenarioLuaFile.Data.Size[1]) ); Vector2 BorderOffsetFootprint = new Vector2(BorderOffset + BP.Footprint.x * 0.05f, BorderOffset + BP.Footprint.y * 0.05f); //GUI.Label(new Rect(500, 500, 100, 50), "Test"); //Color LastColor = GUI.contentColor; //GUI.contentColor = LabelColor; var ListEnum = Instances.GetEnumerator(); while (ListEnum.MoveNext()) { Vector3 LocalPos = ListEnum.Current.LocalToWorldMatrix.GetColumn(3); if (LocalPos.x < BorderOffsetFootprint.x) { LocalPos.x -= BP.Footprint.x * 0.05f; DrawGuiLabel(MainCam, CamRect, LocalPos, BuildingEdgeWarning, RenderMarkersWarnings.Instance.LabelStyle); } else if (LocalPos.z > -BorderOffsetFootprint.y) { LocalPos.z += BP.Footprint.y * 0.05f; DrawGuiLabel(MainCam, CamRect, LocalPos, BuildingEdgeWarning, RenderMarkersWarnings.Instance.LabelStyle); } else if (LocalPos.x > MapMaxPoint.x - BorderOffsetFootprint.x) { LocalPos.x += BP.Footprint.x * 0.05f; DrawGuiLabel(MainCam, CamRect, LocalPos, BuildingEdgeWarning, RenderMarkersWarnings.Instance.LabelStyle); } else if (LocalPos.z < MapMaxPoint.z + BorderOffsetFootprint.y) { LocalPos.z -= BP.Footprint.y * 0.05f; DrawGuiLabel(MainCam, CamRect, LocalPos, BuildingEdgeWarning, RenderMarkersWarnings.Instance.LabelStyle); } } ListEnum.Dispose(); GUI.EndScrollView(); }