예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            ShowDirection direction = ShowDirection.Vertical;

            if (rdHorizontal.Checked)
            {
                direction = ShowDirection.Horizontal;
            }


            ShowPosition position = ShowPosition.BottomRight;

            if (rdTopRight.Checked)
            {
                position = ShowPosition.TopRight;
            }
            else if (rdTopLeft.Checked)
            {
                position = ShowPosition.TopLeft;
            }
            else if (rdBottomLeft.Checked)
            {
                position = ShowPosition.BottomLeft;
            }

            Image image = Properties.Resources.info;

            if (rdQuestion.Checked)
            {
                image = Properties.Resources.question;
            }
            else if (rdError.Checked)
            {
                image = Properties.Resources.error;
            }
            else if (rdWarning.Checked)
            {
                image = Properties.Resources.warning;
            }

            frmNotify frm = new frmNotify(new NotifyInfo()
            {
                Title       = txtTitle.Text,
                Description = txtDescription.Text,
                Image       = image,
                Link        = "",
                Position    = position,
                WaitingTime = Convert.ToInt32(txtTime.Text),
                Direction   = direction
            });

            frm.Show();
        }
    public override void OnInspectorGUI()
    {
        // if we don't find Tool package path, we ignore the rest of the script
        if (_disable)
        {
            base.OnInspectorGUI();
            return;
        }
        // if we disabled the tool in Editor Preferences Windo, we ignore the rest of the script
        if (!_isEnabled)
        {
            base.OnInspectorGUI();
            return;
        }

        // ref of the component
        Transform transform = (Transform)target;

        // local temporary variables
        // -------------------------
        Vector3 startPosition = transform.localPosition;
        Vector3 startRotation = transform.localEulerAngles;
        Vector3 startScale    = transform.localScale;

        Vector3 position;
        Vector3 rotation;
        Vector3 scale;

        bool lockScale;
        bool is2D;

        // -------------------------

        // Switch between 2D or 3D Transform
        EditorGUILayout.BeginHorizontal();
        {
            is2D = EditorGUILayout.Toggle("Enable 2D Transform", _datas.m_is2D);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        // Reset - Copy - Paste Buttons
        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Reset", EditorStyles.miniButtonLeft))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    Undo.RecordObject(go.transform, "Transform Reset");

                    go.transform.localPosition    = Vector3.zero;
                    go.transform.localEulerAngles = Vector3.zero;
                    go.transform.localScale       = Vector3.one;
                }
                return;
            }
            if (GUILayout.Button("Copy", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(transform, "Datas Changed");

                _datas.m_copyPosition = transform.localPosition;
                _datas.m_copyRotation = transform.localEulerAngles;
                _datas.m_copyScale    = transform.localScale;

                EditorUtility.SetDirty(_datas);
                return;
            }
            if (GUILayout.Button("Paste", EditorStyles.miniButtonRight))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    Undo.RecordObject(go.transform, "Transform Changed");

                    go.transform.localPosition    = _datas.m_copyPosition;
                    go.transform.localEulerAngles = _datas.m_copyRotation;
                    go.transform.localScale       = _datas.m_copyScale;
                }
                return;
            }
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        // 2D Transform Inspector GUI
        if (_datas.m_is2D)
        {
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(20);
                position   = EditorGUILayout.Vector2Field("Position", transform.localPosition);
                position.z = transform.localPosition.z;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(20);
                rotation = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, EditorGUILayout.Slider("Rotation", transform.localEulerAngles.z, 0, 359));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                lockScale = EditorGUILayout.Toggle(_datas.m_lockScale, _guiSkin.customStyles[0], GUILayout.Width(15), GUILayout.Height(15));

                if (_datas.m_lockScale)
                {
                    Vector2 scaleTemp = EditorGUILayout.Vector2Field("Scale", transform.localScale);

                    if (scaleTemp.x != transform.localScale.x)
                    {
                        scale = new Vector3(scaleTemp.x, scaleTemp.x, transform.localScale.z);
                    }
                    else
                    {
                        scale = new Vector3(scaleTemp.y, scaleTemp.y, transform.localScale.z);
                    }
                }
                else
                {
                    scale   = EditorGUILayout.Vector2Field("Scale", transform.localScale);
                    scale.z = transform.localScale.z;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        // 3D Transform Inspector GUI
        else
        {
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(20);
                position = EditorGUILayout.Vector3Field("Position", transform.localPosition);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(20);
                rotation = EditorGUILayout.Vector3Field("Rotation", transform.localEulerAngles);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                lockScale = EditorGUILayout.Toggle(_datas.m_lockScale, _guiSkin.customStyles[0], GUILayout.Width(15), GUILayout.Height(15));

                if (_datas.m_lockScale)
                {
                    Vector3 scaleTemp = EditorGUILayout.Vector3Field("Scale", transform.localScale);

                    if (scaleTemp.x != transform.localScale.x)
                    {
                        scale = new Vector3(scaleTemp.x, scaleTemp.x, scaleTemp.x);
                    }
                    else if (scaleTemp.y != transform.localScale.y)
                    {
                        scale = new Vector3(scaleTemp.y, scaleTemp.y, scaleTemp.y);
                    }
                    else
                    {
                        scale = new Vector3(scaleTemp.z, scaleTemp.z, scaleTemp.z);
                    }
                }
                else
                {
                    scale = EditorGUILayout.Vector3Field("Scale", transform.localScale);
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        // Add & Remove Gizmos Buttons
        EditorGUILayout.BeginHorizontal();
        {
            // Add a 3 colors & directions arrow gizmo to show constantly orientation of GameObject
            if (GUILayout.Button("Add full Gizmo", EditorStyles.miniButtonLeft))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    if (go.GetComponent <DrawAllDirections>() == null)
                    {
                        Undo.RecordObject(go.transform, "Gizmo Added");
                        if (go.GetComponent <ShowDirection>() != null)
                        {
                            EditorApplication.delayCall += () => DestroyImmediate(go.GetComponent <ShowDirection>());
                        }
                        go.AddComponent <DrawAllDirections>().m_arrowSize = _gizmoScale;
                    }
                }
                return;
            }
            // Add a Forward arrow gizmo to show constantly orientation of GameObject
            if (GUILayout.Button("Add Forward Gizmo", EditorStyles.miniButtonMid))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    if (go.GetComponent <ShowDirection>() == null)
                    {
                        Undo.RecordObject(go.transform, "Gizmo Added");
                        if (go.GetComponent <DrawAllDirections>() != null)
                        {
                            EditorApplication.delayCall += () => DestroyImmediate(go.GetComponent <DrawAllDirections>());
                        }
                        ShowDirection dir = go.AddComponent <ShowDirection>();
                        dir.m_arrowSize  = _gizmoScale;
                        dir.m_gizmoColor = Color.blue;
                    }
                }
                return;
            }
            // Remove existing arrow gizmo on GameObject
            if (GUILayout.Button("Remove Gizmos", EditorStyles.miniButtonRight))
            {
                foreach (GameObject go in Selection.gameObjects)
                {
                    if (go.GetComponent <ShowDirection>() != null)
                    {
                        Undo.RecordObject(go.transform, "Gizmo Removed");
                        EditorApplication.delayCall += () => DestroyImmediate(go.GetComponent <ShowDirection>());
                    }
                    else if (go.GetComponent <DrawAllDirections>() != null)
                    {
                        Undo.RecordObject(go.transform, "Gizmo Removed");
                        EditorApplication.delayCall += () => DestroyImmediate(go.GetComponent <DrawAllDirections>());
                    }
                }
                return;
            }
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        // check for changes in Inspector
        if (GUI.changed)
        {
            // Apply Transform changes to all selected GameObject and record change for cancel
            foreach (GameObject go in Selection.gameObjects)
            {
                Undo.RecordObject(go.transform, "Transform Changed");

                Vector3 pos = position - startPosition;
                Vector3 rot = rotation - startRotation;
                Vector3 scl = scale - startScale;

                go.transform.localPosition    += pos;
                go.transform.localEulerAngles += rot;
                go.transform.localScale       += scl;
            }

            // Apply and Record changes in tool datas
            Undo.RecordObject(_datas, "Datas Changed");
            _datas.m_is2D      = is2D;
            _datas.m_lockScale = lockScale;

            // notify the editor taht it should check changes and repaint
            EditorUtility.SetDirty(_datas);
        }
    }