diff --git a/Assets/MapEditor.unity b/Assets/MapEditor.unity index 252370e1..c5b5ebe5 100644 --- a/Assets/MapEditor.unity +++ b/Assets/MapEditor.unity @@ -39733,7 +39733,7 @@ Camera: serializedVersion: 2 m_Bits: 2560 m_RenderingPath: 1 - m_TargetTexture: {fileID: 1650333357} + m_TargetTexture: {fileID: 1384490039} m_TargetDisplay: 0 m_TargetEye: 3 m_HDR: 0 @@ -50967,7 +50967,7 @@ MonoBehaviour: TerrainMaterial: {fileID: 2100000, guid: 869424636fdf59642bae55582eca31d9, type: 2} PropMaterial: {fileID: 2100000, guid: 7e0dcd483a119b0439d572104f720f3f, type: 2} UnitMaterial: {fileID: 2100000, guid: 45d596c0e62a2ba44b276b336c2b1a8b, type: 2} - NoPropMesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} + NoPropMesh: {fileID: 4300000, guid: cec6c7026bd5dab479ab7875f0fc87e0, type: 3} NoPropMaterial: {fileID: 2100000, guid: 9c1501c902f369f46af3de859e898238, type: 2} Invert: 0 LoadingProps: 0 @@ -84524,6 +84524,12 @@ MonoBehaviour: type: 2} m_PrefabInternal: {fileID: 1180596069} m_Script: {fileID: -2061169968, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} +--- !u!114 &1181951586 stripped +MonoBehaviour: + m_PrefabParentObject: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, + type: 2} + m_PrefabInternal: {fileID: 1597750314} + m_Script: {fileID: 2109663825, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} --- !u!1001 &1182109234 Prefab: m_ObjectHideFlags: 0 @@ -100627,6 +100633,37 @@ RectTransform: m_PrefabParentObject: {fileID: 224077777350642360, guid: ac95df46b11bff845bd7247ddbab7227, type: 2} m_PrefabInternal: {fileID: 1382992340} +--- !u!84 &1384490039 +RenderTexture: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: + m_ImageContentsHash: + serializedVersion: 2 + Hash: 00000000000000000000000000000000 + m_ForcedFallbackFormat: 4 + m_DownscaleFallback: 0 + m_Width: 256 + m_Height: 256 + m_AntiAliasing: 1 + m_DepthFormat: 1 + m_ColorFormat: 0 + m_MipMap: 0 + m_GenerateMips: 1 + m_SRGB: 0 + m_UseDynamicScale: 0 + m_BindMS: 0 + m_TextureSettings: + serializedVersion: 2 + m_FilterMode: 1 + m_Aniso: 0 + m_MipBias: 0 + m_WrapU: 1 + m_WrapV: 1 + m_WrapW: 1 + m_Dimension: 2 + m_VolumeDepth: 1 --- !u!1 &1385165962 GameObject: m_ObjectHideFlags: 0 @@ -103106,6 +103143,11 @@ MonoBehaviour: BrushListObject: {fileID: 156696, guid: cde0d706d2cdd694f9743c77040d0663, type: 2} BrushListPivot: {fileID: 796678062} TerrainMaterial: {fileID: 2100000, guid: 869424636fdf59642bae55582eca31d9, type: 2} + BrushTypes: + - {fileID: 1181951586} + - {fileID: 2116804369} + - {fileID: 2140200930} + - {fileID: 1538567026} TerrainMask: serializedVersion: 2 m_Bits: 256 @@ -110494,6 +110536,12 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1537465954} +--- !u!114 &1538567026 stripped +MonoBehaviour: + m_PrefabParentObject: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, + type: 2} + m_PrefabInternal: {fileID: 1085175420} + m_Script: {fileID: 2109663825, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} --- !u!1 &1539898745 GameObject: m_ObjectHideFlags: 0 @@ -119205,37 +119253,6 @@ MonoBehaviour: m_FlexibleWidth: -1 m_FlexibleHeight: -1 m_LayoutPriority: 1 ---- !u!84 &1650333357 -RenderTexture: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_Name: - m_ImageContentsHash: - serializedVersion: 2 - Hash: 00000000000000000000000000000000 - m_ForcedFallbackFormat: 4 - m_DownscaleFallback: 0 - m_Width: 256 - m_Height: 256 - m_AntiAliasing: 1 - m_DepthFormat: 1 - m_ColorFormat: 0 - m_MipMap: 0 - m_GenerateMips: 1 - m_SRGB: 0 - m_UseDynamicScale: 0 - m_BindMS: 0 - m_TextureSettings: - serializedVersion: 2 - m_FilterMode: 1 - m_Aniso: 0 - m_MipBias: 0 - m_WrapU: 1 - m_WrapV: 1 - m_WrapW: 1 - m_Dimension: 2 - m_VolumeDepth: 1 --- !u!1 &1652382937 GameObject: m_ObjectHideFlags: 0 @@ -148525,6 +148542,12 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 2113941614} +--- !u!114 &2116804369 stripped +MonoBehaviour: + m_PrefabParentObject: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, + type: 2} + m_PrefabInternal: {fileID: 679521753} + m_Script: {fileID: 2109663825, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} --- !u!1 &2117893653 GameObject: m_ObjectHideFlags: 0 @@ -150327,6 +150350,12 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 2139803068} +--- !u!114 &2140200930 stripped +MonoBehaviour: + m_PrefabParentObject: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, + type: 2} + m_PrefabInternal: {fileID: 145289807} + m_Script: {fileID: 2109663825, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} --- !u!1001 &2140658695 Prefab: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Input.meta b/Assets/Scripts/Input.meta new file mode 100644 index 00000000..e25f25f1 --- /dev/null +++ b/Assets/Scripts/Input.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ea7e74b02370a5d48ad4567ea21a1d4b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Input/KeyboardManager.cs b/Assets/Scripts/Input/KeyboardManager.cs new file mode 100644 index 00000000..e475ef6c --- /dev/null +++ b/Assets/Scripts/Input/KeyboardManager.cs @@ -0,0 +1,91 @@ +using UnityEngine; + +public class KeyboardManager { + + //public static KeyCode BrushStrength = KeyCode.V; + //public static KeyCode BrushSize = KeyCode.B; + + public static bool BrushStrengthDown(){ + return Input.GetKeyDown(KeyCode.V) || Input.GetKeyDown(KeyCode.S); + } + + public static bool BrushStrengthHold() + { + return Input.GetKey(KeyCode.V) || Input.GetKey(KeyCode.S); + } + + public static bool BrushSizeDown() + { + return Input.GetKeyDown(KeyCode.B) || Input.GetKeyDown(KeyCode.W); + } + + public static bool BrushSizeHold() + { + return Input.GetKey(KeyCode.B) || Input.GetKey(KeyCode.W); + } + + public static bool SwitchTypeNext() + { + return Input.GetKeyDown(KeyCode.Tab); + } + + public static bool SwitchType1() + { + return Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1); + } + + public static bool SwitchType2() + { + return Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2); + } + + public static bool SwitchType3() + { + return Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3); + } + + public static bool SwitchType4() + { + return Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4); + } + + const float ClickDownOffset = 0.5f; + const float ClickOffset = 0.1f; + + static float LastClickTime = 0; + public static bool IncreaseTarget() + { + if(Input.GetKeyDown(KeyCode.Q) || Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus)) + { + LastClickTime = Time.realtimeSinceStartup + ClickDownOffset; + return true; + } + else if(Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.Plus) || Input.GetKey(KeyCode.Equals) || Input.GetKey(KeyCode.KeypadPlus)) + { + if(Time.realtimeSinceStartup > LastClickTime) + { + LastClickTime = Time.realtimeSinceStartup + ClickOffset; + return true; + } + } + return false; + } + + public static bool DecreaseTarget() + { + if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus)) + { + LastClickTime = Time.realtimeSinceStartup + ClickDownOffset; + return true; + } + else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.Minus) || Input.GetKey(KeyCode.KeypadMinus)) + { + if (Time.realtimeSinceStartup > LastClickTime) + { + LastClickTime = Time.realtimeSinceStartup + ClickOffset; + return true; + } + } + return false; + } +} diff --git a/Assets/Scripts/Input/KeyboardManager.cs.meta b/Assets/Scripts/Input/KeyboardManager.cs.meta new file mode 100644 index 00000000..05983e55 --- /dev/null +++ b/Assets/Scripts/Input/KeyboardManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0c7a19d8ca8eccb409d07d39152da49d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Prop.cs b/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Prop.cs index 6eec8ed1..2cb608ad 100644 --- a/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Prop.cs +++ b/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Prop.cs @@ -19,6 +19,8 @@ public class PropObject public PropGameObject CreatePropGameObject(Vector3 position, Quaternion rotation, Vector3 scale, bool AllowFarLod = true) { + //Reset scale, because it's not supported anyway + scale = Vector3.one; PropGameObject NewProp = GameObject.Instantiate(PropsInfo.Current.PropObjectPrefab, PropsInfo.Current.PropsParent).GetComponent(); NewProp.gameObject.name = BP.Name; @@ -217,7 +219,7 @@ public static PropObject LoadProp(string scd, string LocalPath) } catch (NLua.Exceptions.LuaException e) { - Debug.LogError(LuaParser.Read.FormatException(e) + "\n" + LocalPath); + Debug.LogWarning(LuaParser.Read.FormatException(e) + "\n" + LocalPath); return ToReturn; } @@ -365,13 +367,14 @@ public static PropObject LoadProp(string scd, string LocalPath) } if(ToReturn.BP.LODs.Length <= 0){ ToReturn.BP.LODs = new BluePrintLoD[1]; + ToReturn.BP.LODs[0] = new BluePrintLoD(); ToReturn.BP.LODs[0].LODCutoff = 100; } if (ToReturn.BP.LODs[0].Mesh == null) { ToReturn.BP.LODs[0].Mesh = PropsInfo.Current.NoPropMesh; - ToReturn.BP.UniformScale = 0.5f; + ToReturn.BP.UniformScale = 2f; } if (ToReturn.BP.LODs[0].Mat == null) diff --git a/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Unit.cs b/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Unit.cs index 62b69764..d19e3f77 100644 --- a/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Unit.cs +++ b/Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile_Unit.cs @@ -16,6 +16,8 @@ public class UnitBluePrint public string Name = ""; public string HelpText = ""; + public int TypeId; + // Display public BluePrintLoD[] LODs = new BluePrintLoD[0]; @@ -105,6 +107,8 @@ public static UnitSource CreateEmptyUnit(string LocalPath, UnitSource ToReturn = ToReturn.BP.CodeName = ToReturn.BP.Name.Replace("_unit", ""); } + ToReturn.BP.TypeId = 0; + ToReturn.BP.Size = Vector3.one; ToReturn.BP.UniformScale = Vector3.one; ToReturn.BP.RenderScale = Vector3.one; @@ -156,6 +160,10 @@ public static UnitSource LoadUnit(string scd, string LocalPath) ToReturn.BP.Name = PathSplit[PathSplit.Length - 1].Replace(".bp", ""); ToReturn.BP.CodeName = ToReturn.BP.Name.Replace("_unit", ""); + + + ToReturn.BP.TypeId = ToReturn.BP.CodeName.GetHashCode(); + //Debug.Log("Load Unit : " + ToReturn.BP.CodeName); //Fix LUA diff --git a/Assets/Scripts/Placement/PlacementManager.cs b/Assets/Scripts/Placement/PlacementManager.cs index 6b8f02f8..4ae76634 100644 --- a/Assets/Scripts/Placement/PlacementManager.cs +++ b/Assets/Scripts/Placement/PlacementManager.cs @@ -207,7 +207,7 @@ void Update () { UpdateSymmetryObjects(); // Action - if (Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.B) || Input.GetKey(KeyCode.M)) + if (Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.R) || KeyboardManager.BrushSizeHold() || KeyboardManager.BrushStrengthHold()) { } else if (Input.GetMouseButtonDown(0)) diff --git a/Assets/Scripts/Selection/SelectionManager_Controls.cs b/Assets/Scripts/Selection/SelectionManager_Controls.cs index 3a5d17fe..7638d333 100644 --- a/Assets/Scripts/Selection/SelectionManager_Controls.cs +++ b/Assets/Scripts/Selection/SelectionManager_Controls.cs @@ -39,7 +39,7 @@ public void UpdateControler() ResetControlerPosition(); } -#endregion + #endregion #region Events @@ -159,11 +159,11 @@ public void DragUpdate() { ControlerDrag(); } - else if(DragType == DragTypes.RotateY) + else if (DragType == DragTypes.RotateY) { ControlerDragRotateY(); } - else if(DragType == DragTypes.ScaleX || DragType == DragTypes.ScaleZ || DragType == DragTypes.ScaleXYZ) + else if (DragType == DragTypes.ScaleX || DragType == DragTypes.ScaleZ || DragType == DragTypes.ScaleXYZ) { ControlerDragScale(); } @@ -180,7 +180,7 @@ public void DragEnd() UpdateSelectionBox(false); AddSelectionBoxObjects(); } - else if(DragType == DragTypes.MoveX || DragType == DragTypes.MoveZ || DragType == DragTypes.MoveXZ || DragType == DragTypes.RotateY) + else if (DragType == DragTypes.MoveX || DragType == DragTypes.MoveZ || DragType == DragTypes.MoveXZ || DragType == DragTypes.RotateY) { ControlerFinish(); } @@ -219,7 +219,7 @@ void ClickOnScreen() { SelectObject(hit.collider.gameObject); } - else if(Selection.Ids.Count > 0) + else if (Selection.Ids.Count > 0) { Undo.Current.RegisterSelectionChange(); Selection.Ids = new List(); @@ -228,24 +228,32 @@ void ClickOnScreen() } float LastClickTime = 0; - //GameObject LastSelectObject; + GameObject LastSelectObject; public void SelectObject(GameObject Obj) { int ObjectId = GetIdOfObject(Obj); bool contains = Selection.Ids.Contains(ObjectId); - - if( contains && !IsSelectionRemove() && !IsSelectionAdd()) + + if (contains && LastSelectObject == Obj) { - if(Time.time < LastClickTime + 0.2f) + if (Time.time < LastClickTime + 0.2f) + { + // Select all of same type + SelectAllOfType(AffectedTypes[ObjectId]); + return; + } + } + else if (contains && !IsSelectionRemove() && !IsSelectionAdd()) + { + if (Time.time < LastClickTime + 0.2f) CameraControler.FocusOnObject(Obj); LastClickTime = Time.time; return; } - //LastSelectObject = Obj; - + LastSelectObject = Obj; LastClickTime = Time.time; @@ -281,6 +289,31 @@ public void SelectObject(GameObject Obj) } } + public void SelectAllOfType(int SearchType) + { + List ToSelect = new List(); + for(int i = 0; i < AffectedGameObjects.Length; i++) + { + if(AffectedGameObjects[i] && AffectedTypes[i] == SearchType) + { + ToSelect.Add(AffectedGameObjects[i]); + } + } + + if (IsSelectionAdd()) + { + SelectObjects(ToSelect.ToArray()); + } + else if (IsSelectionRemove()) + { + SelectObjectsRemove(ToSelect.ToArray()); + } + else + { + CleanSelection(); + SelectObjects(ToSelect.ToArray()); + } + } public void SelectObjects(GameObject[] ToSelect) { @@ -299,6 +332,25 @@ public void SelectObjects(GameObject[] ToSelect) FinishSelectionChange(); } + + + public void SelectObjectsRemove(GameObject[] ToSelect) + { + bool AnyChanged = false; + for (int i = 0; i < ToSelect.Length; i++) + { + int ObjectId = GetIdOfObject(ToSelect[i]); + if (Selection.Ids.Contains(ObjectId)) + { + Selection.Ids.Remove(ObjectId); + AnyChanged = true; + } + } + + if (AnyChanged) + FinishSelectionChange(); + } + public void SelectObjectAdd(GameObject Obj) { int ObjectId = GetIdOfObject(Obj); diff --git a/Assets/Scripts/UI/Tools/PropsInfo.cs b/Assets/Scripts/UI/Tools/PropsInfo.cs index 769a84d1..0113664d 100644 --- a/Assets/Scripts/UI/Tools/PropsInfo.cs +++ b/Assets/Scripts/UI/Tools/PropsInfo.cs @@ -476,7 +476,7 @@ void BrushUpdate() if (Edit.MauseOnGameplay || ChangingStrength || ChangingSize) { - if (!ChangingSize && (Input.GetKey(KeyCode.M) || ChangingStrength)) + if (!ChangingSize && (KeyboardManager.BrushStrengthHold() || ChangingStrength)) { // Change Strength if (Input.GetMouseButtonDown(0)) @@ -497,7 +497,7 @@ void BrushUpdate() } } - else if (Input.GetKey(KeyCode.B) || ChangingSize) + else if (KeyboardManager.BrushSizeHold() || ChangingSize) { // Change Size if (Input.GetMouseButtonDown(0)) diff --git a/Assets/Scripts/UI/Tools/Stratum/StratumInfo.cs b/Assets/Scripts/UI/Tools/Stratum/StratumInfo.cs index d3f8dffe..188686c7 100644 --- a/Assets/Scripts/UI/Tools/Stratum/StratumInfo.cs +++ b/Assets/Scripts/UI/Tools/Stratum/StratumInfo.cs @@ -174,7 +174,7 @@ void Update() if (Edit.MauseOnGameplay || ChangingStrength || ChangingSize) { - if (!ChangingSize && (Input.GetKey(KeyCode.M) || ChangingStrength)) + if (!ChangingSize && (KeyboardManager.BrushStrengthHold() || ChangingStrength)) { // Change Strength if (Input.GetMouseButtonDown(0)) @@ -196,7 +196,7 @@ void Update() } } - else if (Input.GetKey(KeyCode.B) || ChangingSize) + else if (KeyboardManager.BrushSizeHold() || ChangingSize) { // Change Size if (Input.GetMouseButtonDown(0)) @@ -243,6 +243,33 @@ void Update() } } + if (Input.GetMouseButton(0)) + { + } + else if (KeyboardManager.SwitchTypeNext()) + { + LinearBrush.isOn = !LinearBrush.isOn; + } + else if (KeyboardManager.SwitchType1()) + { + LinearBrush.isOn = false; + } + else if (KeyboardManager.SwitchType2()) + { + LinearBrush.isOn = true; + } + + if (KeyboardManager.IncreaseTarget()) + { + if (TargetValue.value < 1) + TargetValue.SetValue(TargetValue.value + 0.05f); + } + else if (KeyboardManager.DecreaseTarget()) + { + if (TargetValue.value > 0) + TargetValue.SetValue(TargetValue.value - 0.05f); + } + if (Input.GetMouseButtonUp(0)) { if (Painting) @@ -651,7 +678,11 @@ void SymmetryPaint() float SizeProportion = (float)ScmapEditor.Current.map.TexturemapTex.width / (float)ScmapEditor.Current.map.Width; size = (int)(BrushSize.value * SizeProportion); ScatterValue = Scatter.value; - TargetPaintValue = Mathf.Clamp01((TargetValue.value + 1f) / 2f); + + if (LinearBrush.isOn) + TargetPaintValue = TargetValue.value; + else + TargetPaintValue = Mathf.Clamp01((TargetValue.value + 1f) / 2f); BrushGenerator.Current.GenerateSymmetry(BrushPos, 0, ScatterValue, size * 0.03f); @@ -868,6 +899,7 @@ static float ConvertToLinear(float value, float addValue) value += 1; value /= 2f; value = Mathf.Clamp01(value); + return value; //return Mathf.Clamp01((Mathf.Clamp01(value * 0.5f + 0.5f) + addValue) * 2f - 1f); //return Mathf.Pow(Mathf.Pow(value, 0.454545f) + addValue, 2.2f); diff --git a/Assets/Scripts/UI/Tools/TerrainInfo.cs b/Assets/Scripts/UI/Tools/TerrainInfo.cs index 203ef47a..53b568fd 100644 --- a/Assets/Scripts/UI/Tools/TerrainInfo.cs +++ b/Assets/Scripts/UI/Tools/TerrainInfo.cs @@ -44,6 +44,7 @@ public class TerrainInfo : MonoBehaviour public Transform BrushListPivot; public Material TerrainMaterial; + public Toggle[] BrushTypes; public LayerMask TerrainMask; public List BrushToggles; @@ -190,7 +191,7 @@ void Update() if (Edit.MauseOnGameplay || ChangingStrength || ChangingSize) { - if (!ChangingSize && (Input.GetKey(KeyCode.M) || ChangingStrength)) + if (!ChangingSize && (KeyboardManager.BrushStrengthHold() || ChangingStrength)) { // Change Strength if (Input.GetMouseButtonDown(0)) @@ -212,7 +213,7 @@ void Update() } } - else if (Input.GetKey(KeyCode.B) || ChangingSize) + else if (KeyboardManager.BrushSizeHold() || ChangingSize) { // Change Size if (Input.GetMouseButtonDown(0)) @@ -296,6 +297,55 @@ void Update() } } + if (Input.GetMouseButton(0)) + { + } + else if (KeyboardManager.SwitchTypeNext()) + { + int SelectedBrush = 0; + for(int i = 0; i < BrushTypes.Length; i++) + { + if (BrushTypes[i].isOn) + { + SelectedBrush = i; + //BrushTypes[i].isOn = false; + } + } + + SelectedBrush++; + if (SelectedBrush >= BrushTypes.Length) + SelectedBrush = 0; + + BrushTypes[SelectedBrush].isOn = true; + } + else if(KeyboardManager.SwitchType1()) + { + BrushTypes[0].isOn = true; + } + else if (KeyboardManager.SwitchType2()) + { + BrushTypes[1].isOn = true; + } + else if (KeyboardManager.SwitchType3()) + { + BrushTypes[2].isOn = true; + } + else if (KeyboardManager.SwitchType4()) + { + BrushTypes[3].isOn = true; + } + + if (KeyboardManager.IncreaseTarget()) + { + if (BrushTarget.value < 256) + BrushTarget.SetValue((int)BrushTarget.value + 1); + } + else if (KeyboardManager.DecreaseTarget()) + { + if (BrushTarget.value > 0) + BrushTarget.SetValue((int)BrushTarget.value - 1); + } + if (TerainChanged && Input.GetMouseButtonUp(0)) { Undo.RegisterUndo(new UndoHistory.HistoryTerrainHeight(), new UndoHistory.HistoryTerrainHeight.TerrainHeightHistoryParameter(beginHeights)); @@ -303,6 +353,7 @@ void Update() } + BrushGenerator.RegeneratePaintBrushIfNeeded(); } public float Min = 0; diff --git a/Assets/Scripts/UI/Tools/Units/UnitInstance.cs b/Assets/Scripts/UI/Tools/Units/UnitInstance.cs index 71cfd5f2..fe8ea010 100644 --- a/Assets/Scripts/UI/Tools/Units/UnitInstance.cs +++ b/Assets/Scripts/UI/Tools/Units/UnitInstance.cs @@ -28,6 +28,15 @@ public static GameObject[] GetAllUnitGo(out int[] Types) GameObject[] ToReturn = new GameObject[AllUnitInstances.Count]; Types = new int[ToReturn.Length]; AllUnitInstances.CopyTo(ToReturn); + + for (int i = 0; i < Types.Length; i++) + { + if (ToReturn[i] == null) + Types[i] = -1; + else + Types[i] = ToReturn[i].GetComponent().UnitRenderer.BP.TypeId; + } + return ToReturn; } @@ -88,12 +97,20 @@ public void SnapToTerrain(bool UpdateMatrixes = true) public bool UpdateAfterTerrainChange() { - Vector3 NewPos = GetSnapPosition(transform.localPosition); + Transform tr = transform; + + if (tr == null) + { + Debug.LogWarning("Transform component was null! Skip Unit"); + return false; + } + + Vector3 NewPos = GetSnapPosition(tr.localPosition); - if (NewPos.y == transform.localPosition.y) + if (NewPos.y == tr.localPosition.y) return false; - transform.localPosition = NewPos; + tr.localPosition = NewPos; UpdateMatrixTranslated(); return true;