public static void ConvToOneGUI(Transform CurrentSelect) { GUILayout.BeginVertical(); GUILayout.Label("Already T4M Object", EditorStyles.boldLabel); if (GUILayout.Button("合并到一张图(远景用)")) { T4MObjSC _T4MObjSC = CurrentSelect.GetComponent <T4MObjSC>(); if (null != _T4MObjSC.T4MMaterial) { T4MTool.ConvT4MObj4Tex(_T4MObjSC.T4MMaterial, CurrentSelect); } } if (GUILayout.Button("合并控制图(4层)")) { T4MObjSC _T4MObjSC = CurrentSelect.GetComponent <T4MObjSC>(); if (null != _T4MObjSC.T4MMaterial) { T4MTool.ConvT4MObj4CtrlTex4(_T4MObjSC.T4MMaterial, CurrentSelect); } } if (GUILayout.Button("合并控制图(6)层)")) { T4MObjSC _T4MObjSC = CurrentSelect.GetComponent <T4MObjSC>(); if (null != _T4MObjSC.T4MMaterial) { T4MTool.ConvT4MObj4CtrlTex6(_T4MObjSC.T4MMaterial, CurrentSelect); } } GUILayout.EndVertical(); }
// 设置压平区域的数据 private bool SetZeroAreaData() { if (!bFixHeight) { return(true); } T4MObjSC t4mObj = GameObject.FindObjectOfType <T4MObjSC>(); if (t4mObj == null) { Debug.LogError("can not find T4MObjSC"); return(false); } Vector3 mapPos = t4mObj.transform.position; zeroAreaHeight = -mapPos.y; string texPath = "Assets" + TerrainModelPath + MapName + "/terrainZeroArea.tga"; Texture2D terrainZeroAreaTex = AssetDatabase.LoadAssetAtPath <Texture2D>(texPath); if (terrainZeroAreaTex == null) { Debug.LogError("terrainZeroArea.tga == null where " + texPath + "not found"); return(false); } zeroAreaCols = terrainZeroAreaTex.GetPixels(); zeroAreaSize = (int)Mathf.Sqrt(zeroAreaCols.Length); return(true); }
public static void T4MComponentDisablemethod(IEnumerable <T4MObjSC> cs) { EditorUtility.DisplayProgressBar("T4MComponentDisable", "Collecting T4MObjSC Components", 0); int total = 0; { // foreach(var c in cs) var __enumerator2 = (cs).GetEnumerator(); while (__enumerator2.MoveNext()) { var c = __enumerator2.Current; { total++; } } } string str = ""; int i = 0; int processed = 0; { // foreach(var go in cs) var __enumerator3 = (cs).GetEnumerator(); while (__enumerator3.MoveNext()) { var go = __enumerator3.Current; { EditorUtility.DisplayProgressBar("T4MComponentDisable", go.gameObject.name, i * 1.0f / total); var g = go.gameObject; Debug.Log(g.name + "T4MComponentDisable"); T4MObjSC mObjSc = g.GetComponent <T4MObjSC>(); mObjSc.enabled = false; } } } EditorUtility.ClearProgressBar(); Debug.Log("T4MComponentDisable----------------------------begin"); if (!string.IsNullOrEmpty(str)) { Debug.Log(str); } Debug.Log("T4MComponentDisable----------------------------end-total=[" + processed.ToString() + "]"); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
//关闭T4m插件 public static void T4MComponentDisablemethod() { { // foreach(var go in EnumAssets.EnumComponentRecursiveInCurrentSelection<T4MObjSC>()) var __enumerator1 = (EnumAssets.EnumComponentRecursiveInCurrentSelection <T4MObjSC>()).GetEnumerator(); while (__enumerator1.MoveNext()) { var go = __enumerator1.Current; { var g = go.gameObject; Debug.Log(g.name + "T4MComponentDisable"); T4MObjSC mObjSc = g.GetComponent <T4MObjSC>(); mObjSc.enabled = false; } } } AssetDatabase.Refresh(); }
void Painter() { if (State != 1) { State = 1; } Event e = Event.current; if (e.type == EventType.KeyDown && e.keyCode == KeyCode.T) { if (T4MSC.T4MActived != "Activated") { T4MSC.T4MActived = "Activated"; } else { T4MSC.T4MActived = "Deactivated"; } } if (T4MSC.T4MPreview && T4MSC.T4MActived == "Activated" && T4MSC.T4MPreview.enabled == false || T4MSC.T4MPreview.enabled == false) { if ( T4MSC.PaintPrev != T4MSC.PaintHandle.Follow_Normal_Circle && T4MSC.PaintPrev != T4MSC.PaintHandle.Follow_Normal_WireCircle && T4MSC.PaintPrev != T4MSC.PaintHandle.Hide_preview ) { T4MSC.T4MPreview.enabled = true; } } else if (T4MSC.T4MPreview && T4MSC.T4MActived == "Deactivated" && T4MSC.T4MPreview.enabled == true || T4MSC.T4MPreview.enabled == true) { if (T4MSC.PaintPrev != T4MSC.PaintHandle.Classic) { T4MSC.T4MPreview.enabled = false; } } if (T4MSC.T4MActived == "Activated") { HandleUtility.AddDefaultControl(0); RaycastHit raycastHit = new RaycastHit(); Ray terrain = HandleUtility.GUIPointToWorldRay(e.mousePosition); if (e.type == EventType.KeyDown && e.keyCode == KeyCode.KeypadPlus) { T4MSC.brushSize += 1; } else if (e.type == EventType.KeyDown && e.keyCode == KeyCode.KeypadMinus) { T4MSC.brushSize -= 1; } if (Physics.Raycast(terrain, out raycastHit, Mathf.Infinity, layerMask)) { T4MObjSC t4msc = T4MSC.CurrentSelect.gameObject.GetComponent <T4MObjSC>(); if (t4msc && t4msc.ConvertType != "UT") { T4MSC.T4MPreview.transform.localEulerAngles = new Vector3(90, 180 + T4MSC.CurrentSelect.localEulerAngles.y, 0); } else { T4MSC.T4MPreview.transform.localEulerAngles = new Vector3(90, T4MSC.CurrentSelect.localEulerAngles.y, 0); } T4MSC.T4MPreview.transform.position = raycastHit.point; if (T4MSC.PaintPrev != T4MSC.PaintHandle.Classic && T4MSC.PaintPrev != T4MSC.PaintHandle.Hide_preview && T4MSC.PaintPrev != T4MSC.PaintHandle.Follow_Normal_WireCircle) { Handles.color = new Color(1f, 1f, 0f, 0.05f); Handles.DrawSolidDisc(raycastHit.point, raycastHit.normal, T4MSC.T4MPreview.orthographicSize * 0.9f); } else if (T4MSC.PaintPrev != T4MSC.PaintHandle.Classic && T4MSC.PaintPrev != T4MSC.PaintHandle.Hide_preview && T4MSC.PaintPrev != T4MSC.PaintHandle.Follow_Normal_Circle) { Handles.color = new Color(1f, 1f, 0f, 1f); Handles.DrawWireDisc(raycastHit.point, raycastHit.normal, T4MSC.T4MPreview.orthographicSize * 0.9f); } if ((e.type == EventType.mouseDrag && e.alt == false && e.shift == false && e.button == 0) || (e.shift == false && e.alt == false && e.button == 0 && ToggleF == false)) { Vector2 pixelUV = raycastHit.textureCoord * T4MSC.T4MMaskTexUVCoord; //0.14f; int PuX = Mathf.FloorToInt(pixelUV.x * T4MSC.T4MMaskTex.width); int PuY = Mathf.FloorToInt(pixelUV.y * T4MSC.T4MMaskTex.height); int x = Mathf.Clamp(PuX - T4MSC.T4MBrushSizeInPourcent / 2, 0, T4MSC.T4MMaskTex.width - 1); int y = Mathf.Clamp(PuY - T4MSC.T4MBrushSizeInPourcent / 2, 0, T4MSC.T4MMaskTex.height - 1); int width = Mathf.Clamp((PuX + T4MSC.T4MBrushSizeInPourcent / 2), 0, T4MSC.T4MMaskTex.width) - x; int height = Mathf.Clamp((PuY + T4MSC.T4MBrushSizeInPourcent / 2), 0, T4MSC.T4MMaskTex.height) - y; Color[] terrainBay = T4MSC.T4MMaskTex.GetPixels(x, y, width, height, 0); if (T4MSC.T4MMaskTex2) { terrainBay2 = T4MSC.T4MMaskTex2.GetPixels(x, y, width, height, 0); } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int index = (i * width) + j; float Stronger = T4MSC.T4MBrushAlpha[Mathf.Clamp((y + i) - (PuY - T4MSC.T4MBrushSizeInPourcent / 2), 0, T4MSC.T4MBrushSizeInPourcent - 1) * T4MSC.T4MBrushSizeInPourcent + Mathf.Clamp((x + j) - (PuX - T4MSC.T4MBrushSizeInPourcent / 2), 0, T4MSC.T4MBrushSizeInPourcent - 1)] * T4MSC.T4MStronger; if (T4MSC.T4MselTexture < 3) { terrainBay[index] = Color.Lerp(terrainBay[index], T4MSC.T4MtargetColor, Stronger); } else { terrainBay[index] = Color.Lerp(terrainBay[index], T4MSC.T4MtargetColor, Stronger); //*0.3f); if (T4MSC.T4MMaskTex2) { terrainBay2[index] = Color.Lerp(terrainBay2[index], T4MSC.T4MtargetColor2, Stronger); ///0.3f); } } } } T4MSC.T4MMaskTex.SetPixels(x, y, width, height, terrainBay, 0); T4MSC.T4MMaskTex.Apply(); if (T4MSC.T4MMaskTex2) { T4MSC.T4MMaskTex2.SetPixels(x, y, width, height, terrainBay2, 0); T4MSC.T4MMaskTex2.Apply(); UndoObj = new Texture2D[2]; UndoObj[0] = T4MSC.T4MMaskTex; UndoObj[1] = T4MSC.T4MMaskTex2; } else { UndoObj = new Texture2D[1]; UndoObj[0] = T4MSC.T4MMaskTex; } //Undo.RecordObjects(UndoObj, "T4MMask"); //Unity don't work correctly with this for now ToggleF = true; } else if (e.type == EventType.mouseUp && e.alt == false && e.button == 0 && ToggleF == true) { T4MSC.SaveTexture(); ToggleF = false; } } } }