Beispiel #1
0
    static void Initialize()
    {
        T4MMainEditor window = (T4MMainEditor)EditorWindow.GetWindowWithRect(typeof(T4MMainEditor), new Rect(0, 0, 386, 582), false, "iT4M");

        Instance = window;
        //window.initlize();
        window.Show();
    }
Beispiel #2
0
    void Painter()
    {
        if (State != 1)
        {
            State = 1;
        }
        Event e = Event.current;

        if (e.type == EventType.KeyDown && e.keyCode == KeyCode.T)
        {
            if (T4MMainEditor.T4MActived != "Activated")
            {
                T4MMainEditor.T4MActived = "Activated";
            }
            else
            {
                T4MMainEditor.T4MActived = "Deactivated";
            }
        }

        if (T4MConfig.T4MPreview && T4MMainEditor.T4MActived == "Activated" && T4MConfig.T4MPreview.enabled == false || T4MConfig.T4MPreview.enabled == false)
        {
            if (
                T4MCache.PaintPrev != PaintHandle.Follow_Normal_Circle &&
                T4MCache.PaintPrev != PaintHandle.Follow_Normal_WireCircle &&
                T4MCache.PaintPrev != PaintHandle.Hide_preview
                )
            {
                T4MConfig.T4MPreview.enabled = true;
            }
        }
        else if (T4MConfig.T4MPreview && T4MMainEditor.T4MActived == "Deactivated" && T4MConfig.T4MPreview.enabled == true || T4MConfig.T4MPreview.enabled == true)
        {
            if (T4MCache.PaintPrev != PaintHandle.Classic)
            {
                T4MConfig.T4MPreview.enabled = false;
            }
        }

        if (T4MMainEditor.T4MActived == "Activated")
        {
            HandleUtility.AddDefaultControl(0);
            RaycastHit raycastHit = new RaycastHit();
            Ray        terrain    = HandleUtility.GUIPointToWorldRay(e.mousePosition);
            if (e.type == EventType.KeyDown && e.keyCode == KeyCode.KeypadPlus)
            {
                T4MConfig.brushSize += 1;
            }
            else if (e.type == EventType.KeyDown && e.keyCode == KeyCode.KeypadMinus)
            {
                T4MConfig.brushSize -= 1;
            }

            if (Physics.Raycast(terrain, out raycastHit, Mathf.Infinity, layerMask))
            {
                if (T4MMainEditor.CurrentSelect.gameObject.GetComponent <T4MMainObj>().ConvertType != "UT")
                {
                    T4MConfig.T4MPreview.transform.localEulerAngles = new Vector3(90, 180 + T4MMainEditor.CurrentSelect.localEulerAngles.y, 0);
                }
                else
                {
                    T4MConfig.T4MPreview.transform.localEulerAngles = new Vector3(90, T4MMainEditor.CurrentSelect.localEulerAngles.y, 0);
                }
                T4MConfig.T4MPreview.transform.position = raycastHit.point;

                if (T4MCache.PaintPrev != PaintHandle.Classic && T4MCache.PaintPrev != PaintHandle.Hide_preview && T4MCache.PaintPrev != PaintHandle.Follow_Normal_WireCircle)
                {
                    Handles.color = new Color(1f, 1f, 0f, 0.05f);
                    Handles.DrawSolidDisc(raycastHit.point, raycastHit.normal, T4MConfig.T4MPreview.orthographicSize * 0.9f);
                }
                else if (T4MCache.PaintPrev != PaintHandle.Classic && T4MCache.PaintPrev != PaintHandle.Hide_preview && T4MCache.PaintPrev != PaintHandle.Follow_Normal_Circle)
                {
                    Handles.color = new Color(1f, 1f, 0f, 1f);
                    Handles.DrawWireDisc(raycastHit.point, raycastHit.normal, T4MConfig.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 * T4MConfig.T4MMaskTexUVCoord;                //0.14f;
                    int     PuX        = Mathf.FloorToInt(pixelUV.x * T4MCache.T4MMaskTex.width);
                    int     PuY        = Mathf.FloorToInt(pixelUV.y * T4MCache.T4MMaskTex.height);
                    int     x          = Mathf.Clamp(PuX - T4MCache.T4MBrushSizeInPourcent / 2, 0, T4MCache.T4MMaskTex.width - 1);
                    int     y          = Mathf.Clamp(PuY - T4MCache.T4MBrushSizeInPourcent / 2, 0, T4MCache.T4MMaskTex.height - 1);
                    int     width      = Mathf.Clamp((PuX + T4MCache.T4MBrushSizeInPourcent / 2), 0, T4MCache.T4MMaskTex.width) - x;
                    int     height     = Mathf.Clamp((PuY + T4MCache.T4MBrushSizeInPourcent / 2), 0, T4MCache.T4MMaskTex.height) - y;
                    Color[] terrainBay = T4MCache.T4MMaskTex.GetPixels(x, y, width, height, 0);
                    if (T4MCache.T4MMaskTex2)
                    {
                        terrainBay2 = T4MCache.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 = T4MCache.T4MBrushAlpha[Mathf.Clamp((y + i) - (PuY - T4MCache.T4MBrushSizeInPourcent / 2), 0, T4MCache.T4MBrushSizeInPourcent - 1) * T4MCache.T4MBrushSizeInPourcent + Mathf.Clamp((x + j) - (PuX - T4MCache.T4MBrushSizeInPourcent / 2), 0, T4MCache.T4MBrushSizeInPourcent - 1)] * T4MConfig.T4MStronger;

                            if (T4MConfig.T4MselTexture < 3)
                            {
                                terrainBay[index] = Color.Lerp(terrainBay[index], T4MCache.T4MtargetColor, Stronger);
                            }
                            else
                            {
                                terrainBay[index] = Color.Lerp(terrainBay[index], T4MCache.T4MtargetColor, Stronger);                               //*0.3f);
                                if (T4MCache.T4MMaskTex2)
                                {
                                    terrainBay2[index] = Color.Lerp(terrainBay2[index], T4MCache.T4MtargetColor2, Stronger);                                   ///0.3f);
                                }
                            }
                        }
                    }
                    T4MCache.T4MMaskTex.SetPixels(x, y, width, height, terrainBay, 0);
                    T4MCache.T4MMaskTex.Apply();
                    if (T4MCache.T4MMaskTex2)
                    {
                        T4MCache.T4MMaskTex2.SetPixels(x, y, width, height, terrainBay2, 0);
                        T4MCache.T4MMaskTex2.Apply();
                        UndoObj    = new Texture2D[2];
                        UndoObj[0] = T4MCache.T4MMaskTex;
                        UndoObj[1] = T4MCache.T4MMaskTex2;
                    }
                    else
                    {
                        UndoObj    = new Texture2D[1];
                        UndoObj[0] = T4MCache.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)
                {
                    T4MMainEditor.SaveTexture();
                    ToggleF = false;
                }
            }
        }
    }