Пример #1
0
    public void CustomInspector()
    {
        SerializedObject   sObject     = new SerializedObject(_target);
        SerializedProperty comment     = sObject.FindProperty("Comment");
        string             nameForTest = _target.name;

        int   nameConflicts = _nameConflictCounts.ContainsKey(_target.name) ? _nameConflictCounts[_target.name] : 0;
        Color nameColor     = _target.NameConflict == true ? Color.red : Color.white;


        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        GUILayout.Label(new GUIContent(string.Format("Name: {0}", nameConflicts <= 0 ? "" : nameConflicts.ToString()),
                                       nameConflicts <= 0 ? "" : string.Format("There are {0} name conflicts.", nameConflicts.ToString())),
                        GrendelCustomStyles.CustomElement(GUI.skin.label, Color.white, nameColor), GUILayout.Width(64));

        GUI.skin.textField.focused.textColor = nameColor;
        _target.name = GUILayout.TextField(_target.name, GrendelCustomStyles.CustomElement(GUI.skin.textArea, Color.white, nameColor), GUILayout.Width(kTextFieldWidth));
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Comment: ", GUILayout.Width(64));
        GUI.skin.textField.wordWrap = true;
        comment.stringValue         = GUILayout.TextField(comment.stringValue, kCommentCharacterLimit, GUI.skin.textField, new GUILayoutOption[] { GUILayout.Width(kTextFieldWidth), GUILayout.Height(64) });

        GUILayout.EndHorizontal();
        sObject.ApplyModifiedProperties();
        EditorGUIUtility.LookLikeControls();

        OnInspectorGUI();

        GUILayout.EndVertical();


        if (_target.name != nameForTest || _nameConflictCounts == null)
        {
            CheckNameConflicts();
        }
    }
Пример #2
0
    static void DrawGizmos(EditorObject eo, GizmoType gizmoType)
    {
        if (!Application.isPlaying)
        {
            if (SceneView.currentDrawingSceneView.camera == null)
            {
                return;
            }

            Camera currentCamera = SceneView.currentDrawingSceneView.camera;

            if (eo.ActivateHighlight)
            {
                Gizmos.DrawIcon(eo.transform.position, "Gizmo_Activate_Ring");
            }
            if (eo.DeactivateHighlight)
            {
                Gizmos.DrawIcon(eo.transform.position, "Gizmo_Deactivate_Ring");
            }
            if (eo.ToggleHighlight)
            {
                Gizmos.DrawIcon(eo.transform.position, "Gizmo_Toggle_Ring");
            }

            eo.ActivateHighlight   = false;
            eo.DeactivateHighlight = false;
            eo.ToggleHighlight     = false;

            if (Selection.activeGameObject != eo.gameObject)
            {
                Vector3 centre          = eo.transform.position;
                Vector3 right           = (centre + (currentCamera.transform.right * 0.4f));
                Vector3 centreConverted = currentCamera.WorldToScreenPoint(centre);
                Vector3 rightConverted  = currentCamera.WorldToScreenPoint(right);
                float   dist            = Mathf.Abs(centreConverted.x - rightConverted.x);

                centreConverted.y = currentCamera.pixelHeight - centreConverted.y;

                Rect labelRect = new Rect(centreConverted.x - dist, centreConverted.y - dist, dist * 2, dist * 2);
                EditorGUIUtility.AddCursorRect(labelRect, MouseCursor.Link);

                                #if DEBUG
                Handles.BeginGUI();
                GUI.Label(labelRect, "", GUI.skin.box);
                Handles.EndGUI();
                                #endif
                Event e = Event.current;


                if (labelRect.Contains(e.mousePosition))
                {
                    eo.HighlightHighlight = true;

                    foreach (EditorObjectConnection connection in ConnectionRegistry.DesignInstance.Registry)
                    {
                        if (connection.Caller != eo)
                        {
                            continue;
                        }
                        else if (connection.Subject.HighlightHighlight)
                        {
                            Handles.color = Color.cyan;
                            Handles.DrawLine(eo.transform.position, connection.Subject.transform.position);
                            continue;
                        }

                        Handles.color = GrendelColor.FlashingColor(connection.MessageColorDark, 4f);

                        switch (connection.Message)
                        {
                        case EditorObject.EditorObjectMessage.Activate:

                            Handles.DrawLine(eo.transform.position, connection.Subject.transform.position);

                            break;

                        case EditorObject.EditorObjectMessage.Deactivate:

                            Handles.DrawLine(eo.transform.position, connection.Subject.transform.position);

                            break;

                        case EditorObject.EditorObjectMessage.Toggle:

                            Handles.DrawLine(eo.transform.position, connection.Subject.transform.position);

                            break;

                        default:

                            break;
                        }
                    }

                    Gizmos.DrawIcon(eo.transform.position, "Gizmo_Cyan_Ring");
                    Gizmos.DrawIcon(eo.transform.position, "Gizmo_Fill");
                    EditorObject.CurrentHoveredEditorObject = eo;
                }
                else
                {
                    eo.HighlightHighlight = false;
                }

                Vector3 pos = eo.transform.position;
                pos += (currentCamera.transform.right) * 0.5f;
                pos += (currentCamera.transform.up) * 0.15f;

                Handles.color = eo.NameConflict == true ? Color.red : Color.white;

                Handles.Label(pos, eo.name, GrendelCustomStyles.CustomElement(GUI.skin.label, Color.white, Handles.color));

                Handles.color = Color.white;
            }
            else
            {
                eo.HighlightHighlight = false;
                Gizmos.DrawIcon(eo.transform.position, "Gizmo_Selected");
                Gizmos.DrawIcon(eo.transform.position, "Gizmo_White_Ring");
            }
        }        //end Application.isPlaying check

        Gizmos.DrawIcon(eo.transform.position, eo.GizmoName);

        try
        {
            if (SceneView.mouseOverWindow.GetInstanceID() == SceneView.currentDrawingSceneView.GetInstanceID())
            {
                SceneView.RepaintAll();
            }
        }
        catch
        {
            //mouse is out of scene view, no biggie
        }
    }
Пример #3
0
    void DrawConnectionBox(Color color, EditorObjectConnection editorObjectConnection, Vector3 origin)
    {
        //int connectionWidth = 192;
        GUI.color = color;

        //Rect boxRect = new Rect(origin.x, origin.y, 192, 64);


        //Event e = Event.current;

//		if (boxRect.Contains(e.mousePosition))
//		{
//			editorObjectConnection.Subject.HighlightHighlight = true;
//		}

        if (editorObjectConnection.Subject.HighlightHighlight)
        {
            GUI.color = Color.cyan;
        }

        //GUILayout.BeginArea(boxRect, GrendelCustomStyles.CustomElement(GUI.skin.textArea, color, Color.white,TextAnchor.UpperCenter));

        GUILayout.BeginHorizontal(GUI.skin.textArea);

        //editorObjectConnection.Message = (EditorObject.EditorObjectMessage)EditorGUILayout.EnumPopup(editorObjectConnection.Message);
        SerializedObject   connectionSerialized = new SerializedObject(editorObjectConnection);
        SerializedProperty eventSerialized      = connectionSerialized.FindProperty("OnEvent");
        SerializedProperty messageSerialized    = connectionSerialized.FindProperty("Message");


        string[] eventChoices = new string[Target.AssociatedEvents.Length];
        foreach (EventTransceiver.Events evt in Target.AssociatedEvents)
        {
            eventChoices[(int)evt] = evt.ToString();
        }



        eventSerialized.enumValueIndex   = EditorGUILayout.Popup(eventSerialized.enumValueIndex, eventChoices, EditorStyles.toolbarPopup, GUILayout.Width(128));
        messageSerialized.enumValueIndex = EditorGUILayout.Popup(messageSerialized.enumValueIndex, messageSerialized.enumNames, EditorStyles.toolbarPopup, GUILayout.Width(128));



        //GUILayout.BeginHorizontal();
        //GUILayout.BeginVertical();
        //GUILayout.FlexibleSpace();
        if (GUILayout.Button(editorObjectConnection.Subject.ToString(), GrendelCustomStyles.CustomElement(GUI.skin.button, color, Color.white, TextAnchor.MiddleLeft), GUILayout.Width(256)))
        {
            Selection.activeGameObject = editorObjectConnection.Subject.gameObject;
        }
        //	GUILayout.Label(editorObjectConnection.Subject.name, GrendelCustomStyles.CustomElement(GUI.skin.label, color, Color.white,TextAnchor.MiddleLeft));
        //GUILayout.FlexibleSpace();
        //GUILayout.EndVertical();
        //GUILayout.FlexibleSpace();
        //GUILayout.BeginVertical();

        if (GUILayout.Button("Del", GrendelCustomStyles.CustomElement(GUI.skin.button, color, Color.white, TextAnchor.MiddleCenter), GUILayout.Width(32)))
        {
            //_target.RemoveConnection(editorObjectConnection);
            ConnectionRegistry.DesignInstance.Registry.Remove(editorObjectConnection);
            EditorUtility.SetDirty(ConnectionRegistry.DesignInstance);
        }

//				if( GUILayout.Button("Sel", GrendelCustomStyles.CustomElement(GUI.skin.button, Color.grey, Color.white, TextAnchor.MiddleCenter), GUILayout.Width(32)) )
//				{
//					Selection.activeGameObject = editorObjectConnection.Subject.gameObject;
//				}
        connectionSerialized.ApplyModifiedProperties();
        //GUILayout.EndVertical();

        //GUILayout.EndHorizontal();

        GUILayout.EndHorizontal();

        Rect boxRect = GUILayoutUtility.GetLastRect();

        Event e = Event.current;

        if (boxRect.Contains(e.mousePosition))
        {
            editorObjectConnection.Subject.HighlightHighlight = true;
        }
        else
        {
            //editorObjectConnection.Subject.HighlightHighlight = false;
        }
        //GUILayout.EndArea();

        GUI.color = Color.white;
    }
Пример #4
0
    virtual public void InfoWindow(int windowID)
    {
//		SerializedObject sObject = new SerializedObject (_target);
//		SerializedProperty comment = sObject.FindProperty("Comment");
//		string nameForTest = _target.name;
//
//		int nameConflicts = _nameConflictCounts.ContainsKey(_target.name) ? _nameConflictCounts[_target.name] : 0;
//		Color nameColor = _target.NameConflict == true ? Color.red : Color.white;
//


        GUILayout.BeginVertical();

        GUILayout.BeginArea(new Rect(0, 0, _editorWindowWidth, _editorWindowHeight), _target.GetType().ToString(), GrendelCustomStyles.CustomElement(GUI.skin.window, Color.white, Color.yellow, TextAnchor.MiddleCenter, FontStyle.Bold));

        GUILayout.BeginHorizontal();
//					GUILayout.BeginVertical();
//					GUILayout.BeginHorizontal();
//						GUILayout.Label(new GUIContent(string.Format("Name: {0}", nameConflicts <= 0 ? "" : nameConflicts.ToString()),
//										nameConflicts <= 0 ? "" : string.Format("There are {0} name conflicts.", nameConflicts.ToString())),
//										GrendelCustomStyles.CustomElement(GUI.skin.label, Color.white, nameColor), GUILayout.Width(64) );
//
//						GUI.skin.textField.focused.textColor = nameColor;
//						_target.name = GUILayout.TextField(_target.name, GrendelCustomStyles.CustomElement(GUI.skin.textArea, Color.white, nameColor), GUILayout.Width(kTextFieldWidth));
//					GUILayout.EndHorizontal();
//
//					GUILayout.BeginHorizontal();
//						GUILayout.Label("Comment: ", GUILayout.Width(64));
//						GUI.skin.textField.wordWrap = true;
//						comment.stringValue = GUILayout.TextField(comment.stringValue, kCommentCharacterLimit, GUI.skin.textField, new GUILayoutOption[]{GUILayout.Width(kTextFieldWidth), GUILayout.Height(64)});
//
//					GUILayout.EndHorizontal();
//					sObject.ApplyModifiedProperties();
//					GUILayout.EndVertical();

        CustomInspector();

        _target.LookingForSubject = GUILayout.Toggle(_target.LookingForSubject, "Add", GrendelCustomStyles.CustomElement(GUI.skin.button, Color.green, Color.white, TextAnchor.MiddleCenter, FontStyle.Bold));

        DrawConnectionBoxes();


        GUILayout.EndHorizontal();



        GUILayout.EndArea();

        GUILayout.EndVertical();

//		if (_target.name != nameForTest || _nameConflictCounts == null)
//		{
//			CheckNameConflicts();
//		}
    }
Пример #5
0
    void OnGUI()
    {
        //Check if the console should be showing
        if (_showConsole)
        {
            GUI.color = ConsoleColor;
            //GUI.Box(new Rect(0, 0,Screen.width, ConsoleHeight), new GUIContent("Console"), GrendelCustomStyles.CustomElement(GUI.skin.box, ConsoleColor, Color.white,TextAnchor.UpperCenter)); //define the console box

            if (_previousCommandCount < ConsoleLineList.Count)
            {
                _scrollPoint.y = 100000000;                                                                                                                                                                                                                       //gotta be a better solution to this
            }
            _scrollPoint = GUILayout.BeginScrollView(_scrollPoint, GrendelCustomStyles.CustomElement(GUI.skin.box, ConsoleColor, Color.white, TextAnchor.UpperCenter), new GUILayoutOption[] { GUILayout.Height(ConsoleHeight), GUILayout.Width(Screen.width) }); //define the console box
            GUI.color    = Color.white;

            //Do our key input checks first, otherwise the Textfield below will eat our input

            //check for enter key input and run the command entered
            if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
            {
                if (string.IsNullOrEmpty(InputString))
                {
                    return;
                }
                OutputToConsole(InputString, Style_UserPrevious);
                RunCommand(InputString);                  //attempt to run the command entered by the user
                InputString = "";                         //reset the textfield string
            }

            //check for UP ARROW input and cycle through previous commands
            if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.UpArrow))
            {
                for (int i = ConsoleLineList.Count - 1; i >= 0; i--)
                {
                    if (ConsoleLineList[i].Style == Style_UserPrevious)
                    {
                        InputString = ConsoleLineList[i].TextString;
                        break;
                    }
                }
            }

            //check for escape or tilde input and close the console
            if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Escape || Event.current.keyCode == KeyCode.BackQuote))
            {
                ToggleConsole();                         //toggle the console
                InputString = "";                        //reset the textfield string
            }

            GUILayout.Label("", GUILayout.Height(ConsoleHeight));                     //blank space to put new commands at the bottom of the console

            //check if we have previous commands to show
            if (ConsoleLineList.Count > 0)
            {
                //if so, cycle through those commands
                for (int i = ConsoleLineList.Count - 1; i >= 0; i--)
                {
                    int count = ConsoleLineList.Count - i;                             //set our count.

                    //Show Command Detail Text
                    GUILayout.BeginHorizontal();
                    GUILayout.TextArea(ConsoleLineList[count - 1].DetailText, Style_Detail, GUILayout.Width(192));

                    //create previous commands as buttons, so the user can click on them to reuse previous commands
                    if (GUILayout.Button(new GUIContent(ConsoleLineList[count - 1].TextString,
                                                        ConsoleLineList[count - 1].Style == Style_UserPrevious ? string.Format("Click to add '{0}' to input field", ConsoleLineList[count - 1].TextString) : ""),
                                         ConsoleLineList[count - 1].Style))
                    {
                        //only allow the user to reuse their commands (as opposed to reusing Admin or Error prompts)
                        if (ConsoleLineList[count - 1].Style == Style_UserPrevious)
                        {
                            InputString = ConsoleLineList[count - 1].TextString;
                        }
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndScrollView();

            GUI.SetNextControlName("Console");                                                                                                                                        //set the name of the console

            InputString = GUILayout.TextField(InputString, GrendelCustomStyles.CustomElement(GUI.skin.box, ConsoleColor, Style_UserCurrent.normal.textColor, TextAnchor.MiddleLeft)); //Set up the textfield for accepting user input

            DetailView = GUILayout.Toggle(DetailView, "Detailed Console");

            GUI.FocusControl("Console");             //focus on the textfield

            if (InputString == "`")
            {
                InputString = "";
            }                                                        //clear the tilde if it shows up in the input string (happens sometimes, probably damn onGUI

            _previousCommandCount = ConsoleLineList.Count;
        }
    }    //end OnGUI