Пример #1
0
    public static void SelectCovers(string title, System.Predicate <Cover> match = null)
    {
        GUIEditorUtils.RegisterSceneUndo("Covers : " + title);

        List <Cover> coverList = new List <Cover>();

        Cover[] covers = Resources.FindObjectsOfTypeAll(typeof(Cover)) as Cover[];

        if (null != covers)
        {
            coverList.AddRange(covers);

            coverList = coverList.FindAll(cover => !EditorUtility.IsPersistent(cover.gameObject));
        }

        if (null != match)
        {
            coverList = coverList.FindAll(match);
        }

        List <GameObject> gameObjectList = new List <GameObject>();

        foreach (Cover cover in coverList)
        {
            gameObjectList.Add(cover.gameObject);
        }

        Selection.objects = gameObjectList.ToArray();
    }
Пример #2
0
    //---------------------------------------------------------------------------------------------
    //
    // ShowZoom
    //	Show current Zoom and also buttons for changing it
    //
    //---------------------------------------------------------------------------------------------
    void ShowZoom()
    {
        GUIEditorUtils.LookLikeControls(40);
        EditorGUILayout.BeginHorizontal();

        m_ZoomFactor = EditorGUILayout.IntField("Zoom", Mathf.RoundToInt(m_ZoomFactor * 100.0f), GUILayout.Width(75)) / 100.0f;

        GUI.SetNextControlName("ZoomButtons");
        switch (GUILayout.Toolbar(-1, m_ZoomButtonsSelStrings, GUILayout.Width(50)))
        {
        case 0:
            m_ZoomFactor += 0.01f;
            GUI.FocusControl("ZoomButtons");
            break;

        case 1:
            m_ZoomFactor -= 0.01f;
            GUI.FocusControl("ZoomButtons");
            break;
        }

        m_ZoomFactor = Mathf.Clamp(m_ZoomFactor, GUIEditorUtils.MIN_SCALE_FACTOR, GUIEditorUtils.MAX_SCALE_FACTOR);

        EditorGUILayout.EndHorizontal();
        GUIEditorUtils.LookLikeControls(m_DefaultLabelWidth);
    }
Пример #3
0
    void OnGUI()
    {
        GUIEditorUtils.LookLikeControls();

        EditorGUI.BeginChangeCheck();

        m_ImageType = (ImageType)EditorGUILayout.EnumPopup("Choose file format : ", m_ImageType);


        switch (m_ImageType)
        {
        case ImageType.JPG:
            m_JPEGQuality = EditorGUILayout.IntField("JPEG quality (25-100) %", m_JPEGQuality);
            m_JPEGQuality = Mathf.Clamp(m_JPEGQuality, 25, 100);
            break;

        case ImageType.SUPERSIZED_PNG:
            m_Supersize = EditorGUILayout.IntField("Supersize (1-100) ", m_Supersize);
            m_Supersize = Mathf.Clamp(m_Supersize, 1, 100);
            break;
        }

        if (EditorGUI.EndChangeCheck())
        {
            SaveInEditorPrefs();
        }

        //GUIEditorUtils.LookLikeInspector();

        GUILayout.FlexibleSpace();

        GUILayout.Label("Note : for taking screenshot out of game mode\nplease use 'SUPERSIZED_PNG' mode.");

        GUILayout.Space(10);
    }
Пример #4
0
    //
    // Draw handler for Rotate mode
    //
    void DrawRotHandler(Color c, Vector2 pos0, float angle, float length)
    {
        Handles.color = c;

        Vector2 pos1 = new Vector2(m_Pos.x + Mathf.Cos(angle) * length, m_Pos.y + Mathf.Sin(angle) * length);

        GUIEditorUtils.DrawClippedLine(pos0, pos1);
    }
Пример #5
0
    //
    // Draw handler for Scale mode
    //
    void DrawScaleHandler(Color c, Vector2 pos0, float angle, float length)
    {
        Handles.color = c;

        Vector2 pos1 = new Vector2(m_Pos.x + Mathf.Cos(angle) * length, m_Pos.y + Mathf.Sin(angle) * length);

        GUIEditorUtils.DrawClippedLine(pos0, pos1);

        DrawPoint(c, pos1, DEFAULT_SCALEHANDLER_RADIUS, m_Rot);
    }
Пример #6
0
    void RenderTopPanel()
    {
        GUIEditorUtils.LookLikeControls();

        EditorGUILayout.BeginHorizontal(GUILayout.Height(28));
        GUILayout.FlexibleSpace();
        ShowZoom();
        EditorGUILayout.Separator();
        EditorGUILayout.EndVertical();
    }
Пример #7
0
    void CheckObjects <T>(string name, CheckObject <T> checkDelegate, T[] allObjects) where T : MonoBehaviour
    {
        List <GameObject> problematicObjects = new List <GameObject>();

        //T[] allObjects = Resources.FindObjectsOfTypeAll( typeof( T ) ) as T[];

        if (null != allObjects)
        {
            foreach (T obj in allObjects)
            {
                if (EditorUtility.IsPersistent(obj.gameObject))
                {
                    continue;
                }

                if (!checkDelegate(obj, allObjects))
                {
                    problematicObjects.Add(obj.gameObject);
                }
            }
        }

        if (problematicObjects.Count > 0)
        {
            string output = problematicObjects.Count + " problematic " + name + "s found ! See selection for more details. ( " + name + "s ";

            bool first = true;

            foreach (GameObject go in problematicObjects)
            {
                if (!first)
                {
                    output += ", ";
                }
                else
                {
                    first = false;
                }
                output += go.name;
            }
            output += ")";

            Debug.LogError(output);

            GUIEditorUtils.RegisterSceneUndo("Checking " + name + "s : selection of problematic " + name + "s");
        }
        else
        {
            Debug.Log("No  problematic " + name + "s found.");
        }

        Selection.objects = problematicObjects.ToArray();
    }
Пример #8
0
    void OnWizardCreate()
    {
        if (replacement == null)
        {
            return;
        }

        GUIEditorUtils.RegisterSceneUndo("Replace Selection");

        Transform[] transforms = Selection.GetTransforms(
            SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable);

        foreach (Transform t in transforms)
        {
            GameObject g;
            PrefabType pref = PrefabUtility.GetPrefabType(replacement);

            if (pref == PrefabType.Prefab || pref == PrefabType.ModelPrefab)
            {
                g = (GameObject)PrefabUtility.InstantiatePrefab(replacement);
            }
            else
            {
                g = (GameObject)Editor.Instantiate(replacement);
            }
            g.transform.parent = t.parent;
            g.name             = (inheritName)? t.gameObject.name : replacement.name;
            if (inheritTag)
            {
                g.tag = t.gameObject.tag;
            }
            if (inheritLayer)
            {
                g.layer = t.gameObject.layer;
            }
            if (inheritStatic)
            {
                g.isStatic = t.gameObject.isStatic;
            }
            g.transform.localPosition = t.localPosition;
            g.transform.localScale    = t.localScale;
            g.transform.localRotation = t.localRotation;
        }

        if (!keep)
        {
            foreach (GameObject g in Selection.gameObjects)
            {
                GameObject.DestroyImmediate(g);
            }
        }
    }
Пример #9
0
    private static void ExecuteCommandOnSelectedCovers(CoverCommand command, float param, string undoName)
    {
        List <Cover> covers = CoverUtils.GrabSelectedCovers();

        if (covers.Count > 0)
        {
            GUIEditorUtils.RegisterSceneUndo(undoName);

            foreach (Cover cover in covers)
            {
                command(cover, param);
            }
        }
    }
Пример #10
0
    //
    // Draw Point
    //
    void DrawPoint(Color c, Vector2 pos, float radius, float angle)
    {
        Handles.color = c;

        Vector2 p0 = new Vector2(pos.x + (Mathf.Cos(angle + HALF_PI * 0.5f) * radius), pos.y + (Mathf.Sin(angle + HALF_PI * 0.5f) * radius));
        Vector2 p1 = new Vector2(pos.x + (Mathf.Cos(angle + HALF_PI * 1.5f) * radius), pos.y + (Mathf.Sin(angle + HALF_PI * 1.5f) * radius));
        Vector2 p2 = new Vector2(pos.x + (Mathf.Cos(angle + HALF_PI * 2.5f) * radius), pos.y + (Mathf.Sin(angle + HALF_PI * 2.5f) * radius));
        Vector2 p3 = new Vector2(pos.x + (Mathf.Cos(angle + HALF_PI * 3.5f) * radius), pos.y + (Mathf.Sin(angle + HALF_PI * 3.5f) * radius));

        GUIEditorUtils.DrawClippedLine(p0, p1);
        GUIEditorUtils.DrawClippedLine(p1, p2);
        GUIEditorUtils.DrawClippedLine(p2, p3);
        GUIEditorUtils.DrawClippedLine(p3, p0);
    }
Пример #11
0
    //
    // Draw Arrow
    //
    void DrawArrow(Color c, Vector2 pos0, float angle, float length)
    {
        Handles.color = c;

        Vector2 pos1 = new Vector2(pos0.x + Mathf.Cos(angle) * length, pos0.y + Mathf.Sin(angle) * length);

        GUIEditorUtils.DrawClippedLine(pos0, pos1);

        Vector2 tmpPos = new Vector2(pos1.x + Mathf.Cos(angle + DEFAULT_ARROWHEAD_ANGLE) * DEFAULT_ARROWHEAD_LENGTH, pos1.y + Mathf.Sin(angle + DEFAULT_ARROWHEAD_ANGLE) * DEFAULT_ARROWHEAD_LENGTH);

        GUIEditorUtils.DrawClippedLine(pos1, tmpPos);

        tmpPos = new Vector2(pos1.x + Mathf.Cos(angle - DEFAULT_ARROWHEAD_ANGLE) * DEFAULT_ARROWHEAD_LENGTH, pos1.y + Mathf.Sin(angle - DEFAULT_ARROWHEAD_ANGLE) * DEFAULT_ARROWHEAD_LENGTH);
        GUIEditorUtils.DrawClippedLine(pos1, tmpPos);
    }
Пример #12
0
    // Implement your own editor GUI here.
    void OnGUI()
    {
        GUIEditorUtils.LookLikeControls();

        //base ragdoll field
        GUILayout.Space(20);
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Base Ragdoll:", GUILayout.Width(95), GUILayout.ExpandWidth(false));

        BaseRagdoll = (GameObject)EditorGUILayout.ObjectField(BaseRagdoll, typeof(GameObject), true, GUILayout.Width(220), GUILayout.ExpandWidth(false));

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10);

        //clone button
        EditorGUILayout.BeginHorizontal("box");
        GUILayout.Label("", GUILayout.Width(90), GUILayout.ExpandWidth(false));

        UnityEngine.Object[] activeGOs = Selection.GetFiltered(typeof(AgentHuman), SelectionMode.Editable | SelectionMode.TopLevel);
        string caption = ("Clone To Selection: " + activeGOs.Length + (activeGOs.Length == 1 ? " object" : " objects"));

        if (GUILayout.Button(caption, GUILayout.Width(200)))                                    //beny: possible to use also GUILayout.ExpandWidth(false), but absolute width is better for this
        {
            CloneToSelection();
        }

        GUILayout.Label("", GUILayout.Width(100), GUILayout.ExpandWidth(false));
        GUILayout.Space(20);
        EditorGUILayout.EndHorizontal();

        GUI.changed = false;


//		if (GUI.changed)
        {
            //check the base ragdoll
            if (BaseRagdoll)
            {
                AgentHuman agent = BaseRagdoll.GetComponent <AgentHuman>();

                if (!agent || !agent.RagdollRoot)                                       //do not allow other objects to be picked in
                {
                    BaseRagdoll = null;
                    this.Repaint();
                }
            }
        }
    }
Пример #13
0
    public static float Axis(Rect pos, SerializedProperty prop, string label)
    {
        GUIEditorUtils.LookLikeControls(20);

        EditorGUI.BeginChangeCheck();
        float result = EditorGUI.FloatField(pos, label, prop.floatValue);

        if (EditorGUI.EndChangeCheck() == true)
        {
            prop.floatValue = result;
        }

        GUIEditorUtils.LookLikeInspector();

        return(result);
    }
Пример #14
0
    //---------------------------------------------------------------------------------------------
    //
    // ShowWidgetParams
    //  Show UV and size of selected widget
    //
    //---------------------------------------------------------------------------------------------
    void ShowWidgetParams()
    {
        //
        // Enable modification of U,V,Width,Height
        //
        int u = Mathf.RoundToInt(m_EditedArea.Area.x);
        int v = Mathf.RoundToInt(m_EditedArea.Area.y);
        int w = Mathf.RoundToInt((m_EditedArea.Area.x + m_EditedArea.Area.width) - u);
        int h = Mathf.RoundToInt((m_EditedArea.Area.y + m_EditedArea.Area.height) - v);

        int oldU = u;
        int oldV = v;
        int oldW = w;
        int oldH = h;

        Texture texture   = m_SelectedWidget ? m_SelectedWidget.GetTexture() : null;
        int     texWidth  = texture ? texture.width  : 1024;
        int     texHeight = texture ? texture.height : 1024;

        EditorGUILayout.BeginVertical();
        GUIEditorUtils.LookLikeControls(20);
        EditorGUILayout.LabelField("Mapping", EditorStyles.boldLabel);
        u = EditorGUILayout.IntSlider("U", u, -texWidth, texWidth * 2);
        v = EditorGUILayout.IntSlider("V", v, -texHeight, texHeight * 2);
        w = EditorGUILayout.IntSlider("W", w, -texWidth, texWidth);
        h = EditorGUILayout.IntSlider("H", h, -texHeight, texHeight);
        GUIEditorUtils.LookLikeControls(m_DefaultLabelWidth);
        EditorGUILayout.EndVertical();

        if (m_SelectedWidget)
        {
            m_EditedArea.Area.x      = u;
            m_EditedArea.Area.y      = v;
            m_EditedArea.Area.width  = w;
            m_EditedArea.Area.height = h;

            bool dirtyFlag = (oldU != u) || (oldV != v) || (oldW != w) || (oldH != h);

            UpdateWidgetByArea(m_SelectedWidget, m_EditedArea, dirtyFlag);
        }
    }
Пример #15
0
    //---------------------------------------------------------------------------------------------
    //
    // Show Left Panel
    //		- parameters of selected widget
    //		- zoom buttons
    //		- etc.
    //
    //---------------------------------------------------------------------------------------------
    void RenderLeftPanel()
    {
        GUIEditorUtils.LookLikeControls(m_DefaultLabelWidth);

        // Show left panel with params
        m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos, GUILayout.Width(290));
        EditorGUILayout.BeginVertical();
        GUI.enabled = m_SelectedWidget ? true : false;

        // Edit widget params
        ShowWidgetParams();
        EditorGUILayout.Separator();

        ShowGrid9Params();
        EditorGUILayout.Separator();

        ShowCopyPaste();
        EditorGUILayout.Separator();

        GUI.enabled = true;
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndScrollView();
    }
Пример #16
0
    // Implement your own editor GUI here.
    void OnGUI()
    {
        GUIEditorUtils.LookLikeControls();

        if (m_EditableObjects == null)
        {
            GUILayout.Space(30);
            EditorGUILayout.BeginHorizontal("box");
            GUILayout.Label("Select object(s) that you want to see animated first...");
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Refresh", GUILayout.Width(78)))
            {
                RefreshContent();
            }
            EditorGUILayout.EndHorizontal();
            return;
        }

        //update the slider time...
        m_MaxSliderTime = 0;

        EditorGUILayout.BeginHorizontal();
        bool OldGUI = GUI.enabled;

        GUI.enabled = false;
        GUILayout.Label("Target", GUILayout.Width(150), GUILayout.ExpandWidth(false));
        GUILayout.Label("Animation", GUILayout.Width(200), GUILayout.ExpandWidth(false));
        GUILayout.Label("Length", GUILayout.Width(75), GUILayout.ExpandWidth(false));
        GUILayout.Label("Speed", GUILayout.Width(75), GUILayout.ExpandWidth(false));

        //GUILayout.Space(2*kPlsuMinusWidth);
        //GUILayout.Space(kPlsuMinusWidth);
        //GUILayout.Space(kPlsuMinusWidth);

        GUI.enabled = OldGUI;
        EditorGUILayout.EndHorizontal();

        //display tracks per object and update m_MaxSliderTime
        foreach (AnimTrack track in m_EditableObjects)
        {
            if (track != null && track.m_GameObject != null)
            {
                EditorGUILayout.BeginHorizontal("", GUILayout.MaxHeight(11));

                GUILayout.Label(track.m_GameObject.name, GUILayout.Width(150), GUILayout.ExpandWidth(false));

                track.m_Animation = (AnimationClip)EditorGUILayout.ObjectField(track.m_Animation, typeof(AnimationClip), false, GUILayout.Width(200), GUILayout.ExpandWidth(false));

                string animLength = (track.m_Animation != null) ? track.m_Animation.length.ToString("F3") : " -- ";
                GUILayout.Label(animLength, GUILayout.Width(75), GUILayout.ExpandWidth(false));

                track.m_Speed = EditorGUILayout.FloatField(track.m_Speed, GUILayout.Width(75), GUILayout.ExpandWidth(false));

                float trackSpeed = (track.m_Animation == null || track.m_Speed <= 0.001) ? 0.0f : track.m_Animation.length / track.m_Speed;
                m_MaxSliderTime = Mathf.Max(m_MaxSliderTime, trackSpeed);

                track.m_Delay   = EditorGUILayout.FloatField(track.m_Delay, GUILayout.Width(75), GUILayout.ExpandWidth(false));
                m_MaxSliderTime = Mathf.Max(m_MaxSliderTime, m_MaxSliderTime + track.m_Delay);

                EditorGUILayout.EndHorizontal();
            }
        }

        GUILayout.Space(10);

        EditorGUILayout.BeginHorizontal("box");
        if (GUILayout.Button("Play", GUILayout.Width(78)))                                      //beny: possible to use also GUILayout.ExpandWidth(false), but absolute width is better for this
        {
            m_AnimTime       = 0;
            m_LastUpdateTime = Time.realtimeSinceStartup;
            m_IsPlaying      = true;
        }

        if (GUILayout.Button("Stop", GUILayout.Width(78)))
        {
            m_AnimTime       = 0;
            m_LastUpdateTime = 0;
            m_IsPlaying      = false;
        }

        if (GUILayout.Button("Pause", GUILayout.Width(78)))
        {
            m_IsPlaying      = !m_IsPlaying;
            m_LastUpdateTime = Time.realtimeSinceStartup;
        }

        GUILayout.Space(20);
        GUILayout.Label("Time: " + m_AnimTime.ToString("F3"), GUILayout.Width(95));                     //do not allow the string to resize the label (and format it to .3 digits)
//			GUILayout.Space(10);

        if (GUILayout.Button("Refresh", GUILayout.Width(78)))
        {
            RefreshContent();
        }

        EditorGUILayout.EndHorizontal();

        GUI.changed = false;

        bool oldEnabled = GUI.enabled;

        GUI.enabled = (m_MaxSliderTime > 0);
        m_AnimTime  = GUILayout.HorizontalSlider(m_AnimTime, 0, m_MaxSliderTime, GUILayout.Width(450));
        GUI.enabled = oldEnabled;

        if (GUI.changed)
        {
            UpdateAnimationsByTime(m_AnimTime);
        }

        //EditorGUILayout.CurveField("Test", testCurve);
    }
Пример #17
0
 private static void TransformDisplay(int Index, ref Transform T)
 {
     GUIEditorUtils.LookLikeInspector();
     T = (Transform)EditorGUILayout.ObjectField("Part #" + Index, T, typeof(Transform), true);
     GUIEditorUtils.LookLikeControls();
 }
Пример #18
0
    //---------------------------------------------------------------------------------------------
    //
    // Process Input
    //
    // check witch point of selected widget will be dragged etc.
    //
    //---------------------------------------------------------------------------------------------
    void ProcessInput()
    {
        Event e = Event.current;

        if (e.type == EventType.ScrollWheel)
        {
            // Zoom

            if (e.delta.y > 0.0f)
            {
                m_ZoomFactor -= 0.1f;
            }
            else if (e.delta.y < 0.0f)
            {
                m_ZoomFactor += 0.1f;
            }

            m_ZoomFactor = Mathf.Clamp(m_ZoomFactor, GUIEditorUtils.MIN_SCALE_FACTOR, GUIEditorUtils.MAX_SCALE_FACTOR);

            // Pan with "horizontal" wheel

            float pan = e.delta.x * GUIEditorUtils.WHEEL_PAN_MULTIPLICATOR / m_ZoomFactor;

            SetPlatformShift(new Vector2(m_PlatformShift.x + pan, m_PlatformShift.y));
        }
        else if (e.type == EventType.MouseDown && SecondaryButtons.Contains(e.button))
        {
            // pan
            m_Pan       = true;
            m_DragOrig  = m_PlatformShift;
            m_DragMouse = Event.current.mousePosition;
        }
        else if (e.type == EventType.MouseUp && SecondaryButtons.Contains(e.button))
        {
            m_Pan = false;
        }
        // Pan ?
        else if (m_Pan && (e.type == EventType.MouseDrag) && SecondaryButtons.Contains(e.button))
        {
            if (m_TexturePosPrepared)
            {
                Vector2 mouseDelta = new Vector2();

                mouseDelta  = Event.current.mousePosition - m_DragMouse;
                mouseDelta /= m_ZoomFactor;

                mouseDelta.x /= m_TextureSize.x;
                mouseDelta.y /= m_TextureSize.y;

                SetPlatformShift(m_DragOrig + mouseDelta);
            }
        }
        else if (e.type == EventType.MouseDown && e.button == PrimaryButton)
        {
            m_MouseDown = true;

            // Select vertex of edited rectangle?

            if (m_TexturePosPrepared)
            {
                Vector2 mousePos = Event.current.mousePosition;

                if (mousePos.x >= m_TexturePos.x && mousePos.y >= m_TexturePos.y)
                {
                    Vector2 pos = new Vector2(m_TexturePos.x + m_EditedArea.Area.x * m_ZoomFactor, m_TexturePos.y + m_EditedArea.Area.y * m_ZoomFactor);

                    pos.x += m_TextureSize.x * m_ZoomFactor * m_PlatformShift.x;
                    pos.y += m_TextureSize.y * m_ZoomFactor * m_PlatformShift.y;

                    if (GUIEditorUtils.IsPointTouched(mousePos, pos, 0, 0, m_PointSize * 0.5f))
                    {
                        m_SelectedPointIdx = 0;

                        Undo.RecordObject(m_SelectedWidget, "Edit UV");
                    }
                    else if (GUIEditorUtils.IsPointTouched(mousePos, pos, m_EditedArea.Area.width * m_ZoomFactor, 0, m_PointSize * 0.5f))
                    {
                        m_SelectedPointIdx = 1;

                        Undo.RecordObject(m_SelectedWidget, "Edit UV");
                    }
                    else if (GUIEditorUtils.IsPointTouched(mousePos, pos, m_EditedArea.Area.width * m_ZoomFactor, m_EditedArea.Area.height * m_ZoomFactor, m_PointSize * 0.5f))
                    {
                        m_SelectedPointIdx = 2;

                        Undo.RecordObject(m_SelectedWidget, "Edit UV");
                    }
                    else if (GUIEditorUtils.IsPointTouched(mousePos, pos, 0, m_EditedArea.Area.height * m_ZoomFactor, m_PointSize * 0.5f))
                    {
                        m_SelectedPointIdx = 3;

                        Undo.RecordObject(m_SelectedWidget, "Edit UV");
                    }
                    else
                    {
                        m_SelectedPointIdx = -1;

                        //Debug.Log(mousePos.x);

                        // Move with whole widget ?

                        float minX = Mathf.Min(pos.x, pos.x + m_EditedArea.Area.width * m_ZoomFactor);
                        float minY = Mathf.Min(pos.y, pos.y + m_EditedArea.Area.height * m_ZoomFactor);

                        if ((mousePos.x >= minX) &&
                            (mousePos.y >= minY) &&
                            (mousePos.x < (minX + Mathf.Abs(m_EditedArea.Area.width) * m_ZoomFactor)) &&
                            (mousePos.y < (minY + Mathf.Abs(m_EditedArea.Area.height) * m_ZoomFactor)))
                        {
                            //Debug.Log("mouse = "+ mousePos.x + ", minX = " + minX);

                            m_WidgetDrag = true;

                            m_DragOrig.x = m_EditedArea.Area.x;
                            m_DragOrig.y = m_EditedArea.Area.y;

                            m_DragMouse = mousePos;
                        }
                    }
                }
            }
        }
        else if (e.type == EventType.MouseUp && e.button == PrimaryButton)
        {
            m_MouseDown          = false;
            m_SelectedPointIdx   = -1;
            m_TexturePosPrepared = false;

            m_Pan        = false;
            m_WidgetDrag = false;
        }
        else
        {
            // movement with widget ?
            if (m_WidgetDrag)
            {
                Vector2 mouseDelta = new Vector2();

                mouseDelta  = Event.current.mousePosition - m_DragMouse;
                mouseDelta /= m_ZoomFactor;

                m_EditedArea.Area.x = m_DragOrig.x + mouseDelta.x;
                m_EditedArea.Area.y = m_DragOrig.y + mouseDelta.y;

                EditorUtility.SetDirty(m_SelectedWidget);
            }
        }
    }
Пример #19
0
    //---------------------------------------------------------------------------------------------
    //
    // Show selected widget and enable its editation
    //
    //	To right (main) window draws texture for current selected widget
    //  Also render area (rectangle) in the texture witch represents widget
    //
    //---------------------------------------------------------------------------------------------
    void RenderRightPanel()
    {
        // Show selected widget and enable its editation
        EditorGUILayout.BeginVertical(GUILayout.MinWidth(300));

        if (m_SelectedWidget)
        {
            Material mat = m_SelectedWidget.GetMaterial();

            if (mat && mat.mainTexture)
            {
                // Draw texture
                EditorGUILayout.Separator();

                Rect r = GUILayoutUtility.GetLastRect();

                // Go a little bit far from border
                //r.x	+= 10;
                //r.y	+= r.height + 10;

                // Take zoom into account
                r.width  = mat.mainTexture.width * m_ZoomFactor * (1.0f + m_PlatformShift.x);
                r.height = mat.mainTexture.height * m_ZoomFactor * (1.0f + m_PlatformShift.y);

                Rect sourceRect = new Rect(-m_PlatformShift.x, 0.0f, 1.0f + m_PlatformShift.x, 1.0f + m_PlatformShift.y);

                Graphics.DrawTexture(r, mat.mainTexture, sourceRect, 0, 0, 0, 0, mat);

                // Edit area ?
                if (Event.current.type == EventType.Repaint)                    // values are not correct during other events !!!
                {
                    m_TexturePosPrepared = true;

                    m_TexturePos.x = r.x;
                    m_TexturePos.y = r.y;

                    m_TextureSize.x = mat.mainTexture.width;
                    m_TextureSize.y = mat.mainTexture.height;

                    //if ((m_SelectedPointIdx != -1) || m_WidgetDrag)
                    if (m_SelectedPointIdx != -1)
                    {
                        MoveWithSelectedVertex();
                    }
                }

                // Draw area rectangle (of selected/edited widget)
                Rect    tmpArea     = new Rect(m_EditedArea.Area.x, m_EditedArea.Area.y, m_EditedArea.Area.width, m_EditedArea.Area.height);
                Vector2 layoutShift = new Vector2(m_PlatformShift.x * m_TextureSize.x * m_ZoomFactor, m_PlatformShift.y * m_TextureSize.y * m_ZoomFactor);

                GUIEditorUtils.SetClipPoint(m_TexturePos);

                GUIEditorUtils.DrawRect(new Vector2(r.x, r.y), tmpArea, 0.0f, m_ZoomFactor, layoutShift, true, GUIEditorUtils.COLOR_AREA_EDGE, GUIEditorUtils.COLOR_AREA_POINT, GUIEditorUtils.COLOR_AREA_SELECTED_POINT, true, m_PointSize, m_SelectedPointIdx);

                //HACK rewrite to DrawLine() later !!!!
                if (m_EditedArea.UsesGrid9 == true)
                {
                    GUIEditorUtils.DrawRect(new Vector2(r.x, r.y), new Rect(tmpArea.x + m_EditedArea.Slices.left, tmpArea.y, 0, tmpArea.height), 0.0f, m_ZoomFactor, layoutShift, GUIEditorUtils.COLOR_AREA_SLICE);
                    GUIEditorUtils.DrawRect(new Vector2(r.x, r.y), new Rect(tmpArea.x + tmpArea.width - m_EditedArea.Slices.right, tmpArea.y, 0, tmpArea.height), 0.0f, m_ZoomFactor, layoutShift, GUIEditorUtils.COLOR_AREA_SLICE);
                    GUIEditorUtils.DrawRect(new Vector2(r.x, r.y), new Rect(tmpArea.x, tmpArea.y + m_EditedArea.Slices.top, tmpArea.width, 0), 0.0f, m_ZoomFactor, layoutShift, GUIEditorUtils.COLOR_AREA_SLICE);
                    GUIEditorUtils.DrawRect(new Vector2(r.x, r.y), new Rect(tmpArea.x, tmpArea.y + tmpArea.height - m_EditedArea.Slices.bottom, tmpArea.width, 0), 0.0f, m_ZoomFactor, layoutShift, GUIEditorUtils.COLOR_AREA_SLICE);
                }

                //GUIEditorUtils.DrawRect(new Vector2(r.x, r.y), new Rect(0, 0, r.width, r.height), 0.0f, 1.0f, new Vector2(0,0), GUIEditorUtils.COLOR_LAYOUT_AREA);
            }
        }

        EditorGUILayout.EndVertical();
    }
Пример #20
0
 /// <summary>
 /// 取得焦点控件名
 /// </summary>
 /// <returns>焦点控件名</returns>
 protected string GetFocusedControl()
 {
     return(GUIEditorUtils.GetFocusedControl());
 }
Пример #21
0
 /// <summary>
 /// 移除控件焦点
 /// </summary>
 /// <param name="iControlName">控件名</param>
 protected void RemoveFocusOnControl(string iControlName = null)
 {
     GUIEditorUtils.RemoveFocusOnControl(iControlName);
 }