예제 #1
0
    void OnGUI()
    {
        GUILayout.Label("OVR Lint Tool", EditorStyles.boldLabel);
        if (GUILayout.Button("Run Lint", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
        {
            RunCheck();
        }

        string lastCategory = "";

        mScrollPosition = EditorGUILayout.BeginScrollView(mScrollPosition);

        for (int x = 0; x < mRecords.Count; x++)
        {
            FixRecord record = mRecords[x];

            if (!record.category.Equals(lastCategory))                  // new category
            {
                lastCategory = record.category;
                EditorGUILayout.Separator();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(lastCategory, EditorStyles.label, GUILayout.Width(200));
                bool moreThanOne = (x + 1 < mRecords.Count && mRecords[x + 1].category.Equals(lastCategory));
                if (record.buttonNames != null && record.buttonNames.Length > 0)
                {
                    if (moreThanOne)
                    {
                        GUILayout.Label("Apply to all:", EditorStyles.label, GUILayout.Width(75));
                        for (int y = 0; y < record.buttonNames.Length; y++)
                        {
                            if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton, GUILayout.Width(100)))
                            {
                                List <FixRecord> recordsToProcess = new List <FixRecord>();

                                for (int z = x; z < mRecords.Count; z++)
                                {
                                    FixRecord thisRecord = mRecords[z];
                                    bool      isLast     = false;
                                    if (z + 1 >= mRecords.Count || !mRecords[z + 1].category.Equals(lastCategory))
                                    {
                                        isLast = true;
                                    }

                                    if (!thisRecord.complete)
                                    {
                                        recordsToProcess.Add(thisRecord);
                                    }

                                    if (isLast)
                                    {
                                        break;
                                    }
                                }

                                UnityEngine.Object[] undoObjects = new UnityEngine.Object[recordsToProcess.Count];
                                for (int z = 0; z < recordsToProcess.Count; z++)
                                {
                                    undoObjects[z] = recordsToProcess[z].targetObject;
                                }
                                Undo.RecordObjects(undoObjects, record.category + " (Multiple)");
                                for (int z = 0; z < recordsToProcess.Count; z++)
                                {
                                    FixRecord thisRecord = recordsToProcess[z];
                                    thisRecord.fixMethod(thisRecord.targetObject, (z + 1 == recordsToProcess.Count), y);
                                    thisRecord.complete = true;
                                }
                            }
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (moreThanOne || record.targetObject)
                {
                    GUILayout.Label(record.message);
                }
            }

            EditorGUILayout.BeginHorizontal();
            GUI.enabled = !record.complete;
            if (record.targetObject)
            {
                EditorGUILayout.ObjectField(record.targetObject, record.targetObject.GetType(), true);
            }
            else
            {
                GUILayout.Label(record.message);
            }
            for (int y = 0; y < record.buttonNames.Length; y++)
            {
                if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton, GUILayout.Width(100)))
                {
                    if (record.targetObject != null)
                    {
                        Undo.RecordObject(record.targetObject, record.category);
                    }
                    record.fixMethod(record.targetObject, true, y);
                    record.complete = true;
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndScrollView();
    }
예제 #2
0
    void DisplayRecords(List <FixRecord> records)
    {
        for (int x = 0; x < records.Count; x++)
        {
            FixRecord record = records[x];

            int siblingRecordCount = 0;
            while (x + siblingRecordCount + 1 < records.Count && records[x + siblingRecordCount + 1].category.Equals(record.category))
            {
                ++siblingRecordCount;
            }

            EditorGUILayout.BeginHorizontal(record.complete ? mFixCompleteStyle : mFixIncompleteStyle); //2-column wrapper for record
            EditorGUILayout.BeginVertical(GUILayout.Width(20));                                         //column 1: icon
            EditorGUILayout.LabelField(EditorGUIUtility.IconContent(record.complete ? "d_Progress" : "console.warnicon"), GUILayout.Width(20));
            EditorGUILayout.EndVertical();                                                              //end column 1: icon
            EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true));                                 //column 2: label, message, objects
            GUILayout.Label(record.category, EditorStyles.boldLabel);

            if (!string.IsNullOrEmpty(record.message))
            {
                GUILayout.Label(record.message, EditorStyles.wordWrappedLabel);
            }

            for (int i = 0; i <= siblingRecordCount; ++i)
            {
                var iterRecord = records[x + i];
                if (iterRecord.targetObject)
                {
                    EditorGUILayout.ObjectField(iterRecord.targetObject, iterRecord.targetObject.GetType(), true);
                }
            }
            EditorGUILayout.EndVertical();             //end column 2: label, message, objects

            if (record.buttonNames != null && record.buttonNames.Length > 0)
            {
                EditorGUILayout.BeginVertical(GUILayout.Width(200.0f));                 //column 3: buttons
                GUI.enabled = !record.complete;

                for (int y = 0; y < record.buttonNames.Length; y++)
                {
                    if (siblingRecordCount > 0)
                    {
                        GUILayout.Label("(Applies to all entries)", EditorStyles.miniLabel);
                    }

                    if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton))
                    {
                        var undoObjects = new List <UnityEngine.Object>();
                        for (int i = 0; i <= siblingRecordCount; ++i)
                        {
                            if (records[x + i].targetObject)
                            {
                                undoObjects.Add(records[x + i].targetObject);
                            }
                        }

                        if (undoObjects.Count > 0)
                        {
                            Undo.RecordObjects(undoObjects.ToArray(), record.category);
                        }

                        for (int i = 0; i <= siblingRecordCount; ++i)
                        {
                            FixRecord thisRecord = records[x + i];

                            if (thisRecord.editModeRequired)
                            {
                                // Add to the fix record list that requires edit mode
                                mRuntimeEditModeRequiredRecords.Add(record);
                            }
                            else
                            {
                                thisRecord.fixMethod(thisRecord.targetObject, (i == siblingRecordCount), y);
                                OVRPlugin.SendEvent("perf_lint_apply_fix", thisRecord.category);
                                thisRecord.complete = true;
                            }
                        }

                        if (mRuntimeEditModeRequiredRecords.Count != 0)
                        {
                            // Stop the scene to apply edit mode required records
                            EditorApplication.ExecuteMenuItem("Edit/Play");
                        }
                    }
                }
                GUI.enabled = true;
                EditorGUILayout.EndVertical();                 //end column 3: buttons
            }

            EditorGUILayout.EndHorizontal();             //end 3-column wrapper for record
            x += siblingRecordCount;
        }
    }
예제 #3
0
    void OnGUI()
    {
        GUILayout.Label("OVR Performance Lint Tool", EditorStyles.boldLabel);
        if (GUILayout.Button("Refresh", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
        {
            RunCheck();
        }

        string lastCategory = "";

        mScrollPosition = EditorGUILayout.BeginScrollView(mScrollPosition);

        for (int x = 0; x < mRecords.Count; x++)
        {
            FixRecord record = mRecords[x];

            if (!record.category.Equals(lastCategory))              // new category
            {
                lastCategory = record.category;
                EditorGUILayout.Separator();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(lastCategory, EditorStyles.label, GUILayout.Width(200));
                bool moreThanOne = (x + 1 < mRecords.Count && mRecords[x + 1].category.Equals(lastCategory));
                if (record.buttonNames != null && record.buttonNames.Length > 0)
                {
                    if (moreThanOne)
                    {
                        GUILayout.Label("Apply to all:", EditorStyles.label, GUILayout.Width(75));
                        for (int y = 0; y < record.buttonNames.Length; y++)
                        {
                            if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton, GUILayout.Width(200)))
                            {
                                List <FixRecord> recordsToProcess = new List <FixRecord>();

                                for (int z = x; z < mRecords.Count; z++)
                                {
                                    FixRecord thisRecord = mRecords[z];
                                    bool      isLast     = false;
                                    if (z + 1 >= mRecords.Count || !mRecords[z + 1].category.Equals(lastCategory))
                                    {
                                        isLast = true;
                                    }

                                    if (!thisRecord.complete)
                                    {
                                        recordsToProcess.Add(thisRecord);
                                    }

                                    if (isLast)
                                    {
                                        break;
                                    }
                                }

                                UnityEngine.Object[] undoObjects = new UnityEngine.Object[recordsToProcess.Count];
                                for (int z = 0; z < recordsToProcess.Count; z++)
                                {
                                    undoObjects[z] = recordsToProcess[z].targetObject;
                                }
                                Undo.RecordObjects(undoObjects, record.category + " (Multiple)");
                                for (int z = 0; z < recordsToProcess.Count; z++)
                                {
                                    FixRecord thisRecord = recordsToProcess[z];
                                    thisRecord.fixMethod(thisRecord.targetObject, (z + 1 == recordsToProcess.Count), y);
                                    OVRPlugin.SendEvent("perf_lint_apply_fix", thisRecord.category);
                                    thisRecord.complete = true;
                                }
                            }
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (moreThanOne || record.targetObject)
                {
                    GUILayout.Label(record.message);
                }
            }

            EditorGUILayout.BeginHorizontal();
            GUI.enabled = !record.complete;
            if (record.targetObject)
            {
                EditorGUILayout.ObjectField(record.targetObject, record.targetObject.GetType(), true);
            }
            else
            {
                GUILayout.Label(record.message);
            }
            if (record.buttonNames != null)
            {
                for (int y = 0; y < record.buttonNames.Length; y++)
                {
                    if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton, GUILayout.Width(200)))
                    {
                        if (record.targetObject != null)
                        {
                            Undo.RecordObject(record.targetObject, record.category);
                        }

                        if (record.editModeRequired)
                        {
                            // Add to the fix record list that requires edit mode
                            mRuntimeEditModeRequiredRecords.Add(record);
                        }
                        else
                        {
                            // Apply the fix directly
                            record.fixMethod(record.targetObject, true, y);
                            OVRPlugin.SendEvent("perf_lint_apply_fix", record.category);
                            record.complete = true;
                        }

                        if (mRuntimeEditModeRequiredRecords.Count != 0)
                        {
                            // Stop the scene to apply edit mode required records
                            EditorApplication.ExecuteMenuItem("Edit/Play");
                        }
                    }
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndScrollView();
    }
예제 #4
0
	void OnGUI()
	{
		GUILayout.Label("OVR Performance Lint Tool", EditorStyles.boldLabel):
		if (GUILayout.Button("Refresh", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
		{
			RunCheck():
		}

		string lastCategory = "":

		mScrollPosition = EditorGUILayout.BeginScrollView(mScrollPosition):

		for (int x = 0: x < mRecords.Count: x++)
		{
			FixRecord record = mRecords[x]:

			if (!record.category.Equals(lastCategory))  // new category
			{
				lastCategory = record.category:
				EditorGUILayout.Separator():
				EditorGUILayout.BeginHorizontal():
				GUILayout.Label(lastCategory, EditorStyles.label, GUILayout.Width(200)):
				bool moreThanOne = (x + 1 < mRecords.Count && mRecords[x + 1].category.Equals(lastCategory)):
				if (record.buttonNames != null && record.buttonNames.Length > 0)
				{
					if (moreThanOne)
					{
						GUILayout.Label("Apply to all:", EditorStyles.label, GUILayout.Width(75)):
						for (int y = 0: y < record.buttonNames.Length: y++)
						{
							if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton, GUILayout.Width(200)))
							{
								List<FixRecord> recordsToProcess = new List<FixRecord>():

								for (int z = x: z < mRecords.Count: z++)
								{
									FixRecord thisRecord = mRecords[z]:
									bool isLast = false:
									if (z + 1 >= mRecords.Count || !mRecords[z + 1].category.Equals(lastCategory))
									{
										isLast = true:
									}

									if (!thisRecord.complete)
									{
										recordsToProcess.Add(thisRecord):
									}

									if (isLast)
									{
										break:
									}
								}

								UnityEngine.Object[] undoObjects = new UnityEngine.Object[recordsToProcess.Count]:
								for (int z = 0: z < recordsToProcess.Count: z++)
								{
									undoObjects[z] = recordsToProcess[z].targetObject:
								}
								Undo.RecordObjects(undoObjects, record.category + " (Multiple)"):
								for (int z = 0: z < recordsToProcess.Count: z++)
								{
									FixRecord thisRecord = recordsToProcess[z]:
									thisRecord.fixMethod(thisRecord.targetObject, (z + 1 == recordsToProcess.Count), y):
									thisRecord.complete = true:
								}
							}
						}
					}
				}
				EditorGUILayout.EndHorizontal():
				if (moreThanOne || record.targetObject)
				{
					GUILayout.Label(record.message):
				}
			}

			EditorGUILayout.BeginHorizontal():
			GUI.enabled = !record.complete:
			if (record.targetObject)
			{
				EditorGUILayout.ObjectField(record.targetObject, record.targetObject.GetType(), true):
			}
			else
			{
				GUILayout.Label(record.message):
			}
			if (record.buttonNames != null)
			{
				for (int y = 0: y < record.buttonNames.Length: y++)
				{
					if (GUILayout.Button(record.buttonNames[y], EditorStyles.toolbarButton, GUILayout.Width(200)))
					{
						if (record.targetObject != null)
						{
							Undo.RecordObject(record.targetObject, record.category):
						}
						record.fixMethod(record.targetObject, true, y):
						record.complete = true:
					}
				}

			}
			GUI.enabled = true:
			EditorGUILayout.EndHorizontal():
		}

		EditorGUILayout.EndScrollView():
	}