コード例 #1
0
    public InspectorPlusTracker GetTracker(string name)
    {
        bool refreshNeeded         = false;
        InspectorPlusTracker found = null;

        foreach (InspectorPlusTracker t in trackers)
        {
            if (t.dirty)
            {
                refreshNeeded = true;
            }

            if (t.name == name)
            {
                found = t;
            }
        }

        if (refreshNeeded)
        {
            EditorUtility.SetDirty(this);
        }

        return(found);
    }
コード例 #2
0
    public void DeleteInspector(string name)
    {
        //deselect objects with a custom edtior, or unity crashes. Yeah, unity, sometimes... :-)
        Selection.activeObject = null;
        InspectorPlusTracker t = GetTracker(name);

        refresh = true;
        if (t != null)
        {
            if (!groups.Contains(t.group) || GetGroup(t.group).Count == 1)
            {
                groups.Remove(t.group);
                groupOpen.RemoveAt(0);
            }
        }

        trackers.Remove(t);

        File.Delete(filePath + "/" + name + "InspectorPlus.cs");

        //playmaker specific
        if (File.Exists(Application.dataPath + "/InspectorPlusPlayMaker/" + name + ".cs"))
        {
            foreach (UnityEngine.Object o in FindObjectsOfType(InspectorPlusType.Get(name)))
            {
                MonoBehaviour.DestroyImmediate(o);
            }
            File.Delete(Application.dataPath + "/InspectorPlusPlayMaker/" + name + ".cs");
        }
        //end playmaker specific

        EditorUtility.SetDirty(this);
    }
コード例 #3
0
    public void AddInspector(string name, string filePathTracker)
    {
        InspectorPlusTracker newTracker = new InspectorPlusTracker(name, filePathTracker);

        trackers.Add(newTracker);
        newTracker.UpdateTarget();
        EditorUtility.SetDirty(this);
    }
コード例 #4
0
    public void DeleteInspector(string name)
    {
        //deselect objects with a custom edtior, or unity crashes. Yeah, unity, sometimes... :-)
        Selection.activeObject = null;
        InspectorPlusTracker t = GetTracker(name);

        trackers.Remove(t);
        EditorUtility.SetDirty(this);
    }
コード例 #5
0
    public void AddInspector(string name, string filePathTracker, string group = "")
    {
        InspectorPlusTracker newTracker = new InspectorPlusTracker(name, group, arrowUp, arrowDown, filePathTracker);

        trackers.Add(newTracker);
        newTracker.UpdateTarget();

        if (!groups.Contains(group))
        {
            groups.Add(group);
            groupOpen.Add(false);
        }

        refresh = true;
        EditorUtility.SetDirty(this);
    }
コード例 #6
0
    public void WriteToFile(string _name, InspectorPlusTracker _tracker, string folder)
    {
        _tracker.UpdateFields();
        name        = _name;
        fileName    = name + "Inspector";
        tracker     = _tracker;
        writeString = "";
        Write();

        writeString = writeString.Trim();


        if (!Directory.Exists(Application.dataPath + "/" + folder + "/"))
        {
            Directory.CreateDirectory(Application.dataPath + "/" + folder + "/");
        }

        File.WriteAllText(Application.dataPath + "/" + folder + "/" + fileName + ".cs", writeString);
    }
コード例 #7
0
	public void OnEnable ()
	{
		so = serializedObject;
		
		manager = FindObjectOfType (typeof(InspectorPlusManager)) as InspectorPlusManager;

		if (manager == null)
			manager = (InspectorPlusManager)AssetDatabase.LoadAssetAtPath (AssetPath + "/InspectorPlus.asset", typeof(InspectorPlusManager));

		tracker = manager.GetTracker (target.GetType ().Name);

        if (tracker != null)
        {
            List<InspectorPlusVar> vars = tracker.GetVars();

            int count = vars.Count;

            properties = new SerializedProperty[count];
        }
	}
コード例 #8
0
    public void OnEnable()
    {
        //TODO: Get manager more efficiently
        m_manager = FindObjectOfType(typeof(InspectorPlusManager)) as InspectorPlusManager;
        if (m_manager == null)
        {
            m_manager = (InspectorPlusManager)AssetDatabase.LoadAssetAtPath(AssetPath + "/InspectorPlus.asset",
                                                                            typeof(InspectorPlusManager));
        }

        m_tracker = m_manager.GetTracker(target.GetType().Name);

        if (m_tracker != null)
        {
            List <InspectorPlusVar> vars = m_tracker.GetVars();

            int count = vars.Count;
            m_properties = new SerializedProperty[count];
        }
    }
コード例 #9
0
    public void OnEnable()
    {
        so = serializedObject;

        manager = FindObjectOfType(typeof(InspectorPlusManager)) as InspectorPlusManager;

        if (manager == null)
        {
            manager = (InspectorPlusManager)AssetDatabase.LoadAssetAtPath(AssetPath + "/InspectorPlus.asset", typeof(InspectorPlusManager));
        }

        tracker = manager.GetTracker(target.GetType().Name);

        if (tracker != null)
        {
            List <InspectorPlusVar> vars = tracker.GetVars();

            int count = vars.Count;

            properties = new SerializedProperty[count];
        }
    }
コード例 #10
0
    void DrawEditor()
    {
        editComp = manager.GetTracker(manager.editName);

        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        editComp.DrawGUI();
        GUILayout.EndScrollView();

        GUILayout.Space(10.0f);
        GUILayout.FlexibleSpace();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Back"))
        {
            editing = false;
        }

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.Space(10.0f);
        GUILayout.FlexibleSpace();
    }
コード例 #11
0
    public void AddInspector(string name, string filePathTracker, string group = "")
    {
        InspectorPlusTracker newTracker = new InspectorPlusTracker(name, group, arrowUp, arrowDown, filePathTracker);
        trackers.Add(newTracker);
        newTracker.UpdateTarget();

        if (!groups.Contains(group))
        {
            groups.Add(group);
            groupOpen.Add(false);
        }

        refresh = true;
        EditorUtility.SetDirty(this);
    }
コード例 #12
0
    public void WriteToFile(string _name, InspectorPlusTracker _tracker, string folder)
    {
        _tracker.UpdateFields();
        name = _name;
        fileName = name + "Inspector";
        tracker = _tracker;
        writeString = "";
        Write();

        writeString = writeString.Trim();


        if (!Directory.Exists(Application.dataPath + "/" + folder + "/"))
            Directory.CreateDirectory(Application.dataPath + "/" + folder + "/");

        File.WriteAllText(Application.dataPath + "/" + folder + "/" + fileName + ".cs", writeString);
    }
コード例 #13
0
    void DrawEditor()
    {
        editComp = manager.GetTracker(manager.editName);

        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        editComp.DrawGUI();
        GUILayout.EndScrollView();

        GUILayout.Space(10.0f);
        GUILayout.FlexibleSpace();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Back"))
            editing = false;

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.Space(10.0f);
        GUILayout.FlexibleSpace();
    }
コード例 #14
0
    public void DrawDragBox(InspectorPlusTracker gui)
    {
        gui.Line(EditorGUIUtility.singleLineHeight + 5.0f);
        var boxRect = gui.GetRect(900.0f);

        boxRect.height = space;
        GUI.Box(boxRect, "");


        gui.Line(0);

        bool guiEnabled = GUI.enabled;

        numSpace = Mathf.Min(4, Mathf.FloorToInt(space / EditorGUIUtility.singleLineHeight));

        for (int i = 0; i < numSpace; i += 1)
        {
            GUI.enabled = true;

            gui.GetRect(10.0f);
            labelEnabled[i] = GUI.Toggle(gui.GetRect(40.0f), labelEnabled[i], "");

            GUI.enabled = labelEnabled[i];
            GUI.Label(gui.GetRect(80.0f), "Label ");
            label[i]     = EditorGUI.TextField(gui.GetRect(140.0f), "", label[i]);
            labelBold[i] = EditorGUI.Toggle(gui.GetRect(40.0f), labelBold[i]);

            GUI.enabled = true;

            for (int j = 0; j < 4; j += 1)
            {
                GUI.enabled = true;

                gui.GetRect(80.0f);

                //button
                buttonEnabled[i * 4 + j] = GUI.Toggle(gui.GetRect(40.0f), buttonEnabled[i * 4 + j], "");


                GUI.enabled = buttonEnabled[i * 4 + j];
                GUI.Label(gui.GetRect(80.0f), "Button ");
                buttonText[i * 4 + j] = EditorGUI.TextField(gui.GetRect(80.0f), "", buttonText[i * 4 + j]);

                GUI.Label(gui.GetRect(80.0f), "Callback ");
                buttonCallback[i * 4 + j] = EditorGUI.TextField(gui.GetRect(80.0f), "", buttonCallback[i * 4 + j]);

                bool buttonToCome = false;
                for (int k = j; k < 4; k += 1)
                {
                    if (buttonEnabled[i * 4 + k])
                    {
                        buttonToCome = true;
                    }
                }

                if (!buttonToCome || j == 3)
                {
                    GUI.enabled = true;
                    if (j > 1)
                    {
                        buttonCondense[i] = GUI.Toggle(gui.GetRect(40.0f), buttonCondense[i], new GUIContent("Condense"));
                    }
                    break;
                }
            }

            gui.Line(space / numSpace);
        }


        GUI.enabled = guiEnabled;

        boxRect.y     += boxRect.height;
        boxRect.height = 5.0f;

        EditorGUIUtility.AddCursorRect(boxRect, MouseCursor.ResizeVertical);

        if (Event.current.type == EventType.mouseDown)
        {
            pressed = false;
            if (boxRect.Contains(Event.current.mousePosition))
            {
                startpos = Event.current.mousePosition;
                pressed  = true;

                Event.current.Use();
            }
        }

        if (Event.current.type == EventType.mouseDrag && pressed)
        {
            space   += (Event.current.mousePosition - startpos).y;
            startpos = Event.current.mousePosition;

            EditorWindow.GetWindow(typeof(InspectorPlusWindow)).Repaint();
            space = Mathf.Clamp(space, 0.0f, 4 * 25.0f);

            GUI.changed = true;
        }

        if (Event.current.type == EventType.mouseUp)
        {
            pressed = false;
        }
    }
コード例 #15
0
    public void DrawFieldGUI(InspectorPlusTracker gui)
    {
        if (canWrite)
        {
            gui.GetRect(30.0f);

            if (type == typeof(float).Name)
            {
                GUI.Label(gui.GetRect(80.0f), "Limit: ");
                limitType = (LimitType)EditorGUI.EnumPopup(gui.GetRect(80.0f), limitType);

                bool oldEnabled = GUI.enabled;

                GUI.enabled = limitType == LimitType.Min || limitType == LimitType.Range;
                min         = EditorGUI.FloatField(gui.GetRect(80.0f), min);

                GUI.enabled = limitType == LimitType.Max || limitType == LimitType.Range;
                max         = EditorGUI.FloatField(gui.GetRect(80.0f), max);

                if (limitType == LimitType.Range)
                {
                    GUI.Label(gui.GetRect(80.0f), "ProgressBar: ");
                    progressBar = GUI.Toggle(gui.GetRect(80.0f), progressBar, "");
                }

                GUI.enabled = oldEnabled;
            }
            else if (type == typeof(int).Name)
            {
                GUI.Label(gui.GetRect(80.0f), "Limit: ");
                limitType = (LimitType)EditorGUI.EnumPopup(gui.GetRect(80.0f), limitType);

                bool oldEnabled = GUI.enabled;

                GUI.enabled = limitType == LimitType.Min || limitType == LimitType.Range;
                iMin        = EditorGUI.IntField(gui.GetRect(80.0f), iMin);

                GUI.enabled = limitType == LimitType.Max || limitType == LimitType.Range;
                iMax        = EditorGUI.IntField(gui.GetRect(80.0f), iMax);

                if (limitType == LimitType.Range)
                {
                    GUI.Label(gui.GetRect(80.0f), "ProgressBar: ");
                    progressBar = GUI.Toggle(gui.GetRect(80.0f), progressBar, "");
                }

                GUI.enabled = oldEnabled;
            }
            else if (type == typeof(Vector3).Name || type == typeof(Vector2).Name)
            {
                GUI.Label(gui.GetRect(80.0f), "Draw: ");
                vectorDrawType = (VectorDrawType)EditorGUI.EnumPopup(gui.GetRect(80.0f), vectorDrawType);

                bool oldEnabled = GUI.enabled;

                GUI.enabled = vectorDrawType != VectorDrawType.None;
                GUI.Label(gui.GetRect(80.0f), "Relative: ");
                relative = GUI.Toggle(gui.GetRect(80.0f), relative, "");

                if (vectorDrawType == VectorDrawType.Direction)
                {
                    GUI.Label(gui.GetRect(80.0f), "Scale: ");
                    scale = GUI.Toggle(gui.GetRect(80.0f), scale, "");
                }

                if (vectorDrawType == VectorDrawType.Scale || vectorDrawType == VectorDrawType.Rotation)
                {
                    GUI.Label(gui.GetRect(80.0f), "Offset: ");
                    offset.x = EditorGUI.FloatField(gui.GetRect(40.0f), offset.x);
                    offset.y = EditorGUI.FloatField(gui.GetRect(40.0f), offset.y);
                    offset.z = EditorGUI.FloatField(gui.GetRect(40.0f), offset.z);
                }

                GUI.enabled = oldEnabled;
            }
            else if (type == typeof(Quaternion).Name)
            {
                QuaternionHandle = GUI.Toggle(gui.GetRect(80.0f), QuaternionHandle, new GUIContent("handle"));
                gui.GetRect(20.0f);

                GUI.enabled = QuaternionHandle;
                GUI.Label(gui.GetRect(80.0f), "Offset: ");
                offset.x    = EditorGUI.FloatField(gui.GetRect(40.0f), offset.x);
                offset.y    = EditorGUI.FloatField(gui.GetRect(40.0f), offset.y);
                offset.z    = EditorGUI.FloatField(gui.GetRect(40.0f), offset.z);
                GUI.enabled = true;
            }
            else if (type == typeof(bool).Name)
            {
                toggleStart = GUI.Toggle(gui.GetRect(150.0f), toggleStart, "Toggle group");
                GUI.enabled = toggleStart;
                toggleSize  = EditorGUI.IntSlider(gui.GetRect(120.0f), toggleSize, 1,
                                                  Mathf.Max(1, (maxSize - index) - 1));
                GUI.enabled = true;
            }
            else if (type == typeof(Texture).Name || type == typeof(Texture2D).Name)
            {
                largeTexture = GUI.Toggle(gui.GetRect(120.0f), largeTexture, new GUIContent("large preview"));
                GUI.enabled  = largeTexture;
                textureSize  = EditorGUI.Slider(gui.GetRect(80.0f), textureSize, 35.0f, 300.0f);
                GUI.enabled  = true;
            }
            else if (type == typeof(string).Name)
            {
                GUI.Label(gui.GetRect(80.0f), "Default text");
                textFieldDefault = GUI.TextField(gui.GetRect(180.0f), textFieldDefault);

                GUI.Label(gui.GetRect(80.0f), "Text area: ");
                textArea = GUI.Toggle(gui.GetRect(80.0f), textArea, "");
            }
        }
        else
        {
            GUI.Label(gui.GetRect(80.0f), "Read only");
        }
    }
コード例 #16
0
    void DrawExtensions()
    {
        GUILayout.BeginHorizontal();



        //Included inspectors

        //NGUI Button
        if (!manager.groups.Contains("NGUI"))
        {
            if (AssetDatabase.LoadAssetAtPath(assetPath + "/" + "NGUI.asset", typeof(InspectorPlusManager)) != null)
            {
                if (GUILayout.Button(new GUIContent(manager.NGUIImage), GUILayout.Width(115.0f), GUILayout.Height(40.0f)) && EditorUtility.DisplayDialog("NGUI Import", "You are about to import custom Inspectors for NGUI. Only do this when you are sure you have (the latest) NGUI installed", "I have the latest NGUI", "Cancel"))
                {
                    manager.ImportManager("NGUI");
                    var imp = new InspectorPlusImporter();
                    List <InspectorPlusTracker> group = manager.GetGroupTrackers("NGUI");

                    foreach (MonoScript m in imp.Importable("NGUI"))
                    {
                        CreateFile(m.name);

                        InspectorPlusTracker t = group.Find(tracker => tracker.name == m.name);

                        if (t == null)
                        {
                            continue;
                        }

                        t.filePath = Application.dataPath + AssetDatabase.GetAssetPath(m).Replace("Assets", "");
                    }

                    AssetDatabase.Refresh();
                }
            }
        }
        else if (GUILayout.Button("Delete NGUI Inspectors"))
        {
            var i = new InspectorPlusImporter();

            foreach (MonoScript m in i.Importable("NGUI"))
            {
                manager.DeleteInspector(m.name);
            }

            AssetDatabase.Refresh();
        }

        GUILayout.FlexibleSpace();


        //Playmaker
        if (Type.GetType("InspectorPlusPlayMakerWindow") == null)
        {
            return;
        }

        if (GUILayout.Button(manager.playMakerImage, GUILayout.Width(115.0f), GUILayout.Height(40.0f)))
        {
            MethodInfo m = Type.GetType("InspectorPlusPlayMakerWindow").GetMethod("ShowWindow", BindingFlags.Static | BindingFlags.Public);
            m.Invoke(null, null);
        }
    }