Esempio n. 1
0
        public static bool CheckForNullReferences(Func <NullReference, bool> filter)
        {
            var detector       = new NullReferenceDetector();
            var nullReferences = detector.FindAllNullReferences(
                PreferencesSerialization.LoadPrefabList(),
                filter,
                PreferencesSerialization.LoadIgnoreList())
                                 .ToList();

            foreach (var nullReference in nullReferences)
            {
                var fieldName = ObjectNames.NicifyVariableName(nullReference.FieldName);
                var color     = ColorFor(nullReference);

                var message = string.Format("Null reference found in <b>{0}</b> > <b>{1}</b> > <color={2}><b>{3}</b></color>\n",
                                            nullReference.GameObjectName,
                                            nullReference.ComponentName,
                                            color,
                                            fieldName);

                Debug.Log(message, nullReference.GameObject);
            }

            return(nullReferences.Any());
        }
        /// <summary>
        /// Do the UI elements for the ignore list
        /// </summary>
        private static void HandleIgnoreListPreferences()
        {
            if (_ignoreList == null)
            {
                _ignoreList = PreferencesSerialization
                              .LoadIgnoreList()
                              .ToList();
            }

            EditorGUILayout.LabelField("Ignore list - enter the name of a GameObject to ignore when scanning (case sensitive)");
            GUILayout.Space(5);

            var rect = EditorGUILayout.BeginHorizontal();

            rect = new Rect(rect.x, rect.y - CellMargin, rect.width, 10 + CellMargin);
            EditorGUI.DrawRect(new Rect(rect.x, rect.y, rect.width, 55 + CellMargin * 2f), new Color(0.5f, 0.5f, 0.5f, 0.3f));//the drawn rectangle is bigger than the actual rectangle to include the buttons

            EditorGUI.LabelField(rect, "Use +/- buttons to increase or decrease number of items in ignore list: (" + _ignoreList.Count.ToString() + ")");

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

            if (GUILayout.Button("+", GUILayout.Width(40)))
            {
                var blacklistItem = new BlacklistItem(string.Empty, ignoreChildren: false);
                _ignoreList.Add(blacklistItem);
            }

            if (GUILayout.Button("-", GUILayout.Width(40)) && _ignoreList.Count > 0)
            {
                _ignoreList.RemoveAt(_ignoreList.Count - 1);
                _dirtyIgnoreList = true;
            }

            GUILayout.Space(18);

            if (_ignoreList.Count != 0)
            {
                // Handle UI and save changes to local ignoreList
                for (int i = 0; i < _ignoreList.Count; i++)
                {
                    _ignoreList[i] = HandleIndividualIgnoreItem(_ignoreList[i]);
                }
            }

            // Save the inputs, if anything changed
            if (_dirtyIgnoreList)
            {
                PreferencesSerialization.SaveIgnoreList(_ignoreList);
                _dirtyIgnoreList = false;
            }
        }
        private static void HandlePrefabPreferences()
        {
            if (_prefabsList == null)
            {
                _prefabsList = PreferencesSerialization.LoadPrefabList().ToList();
            }

            EditorGUILayout.LabelField("Additional Prefabs to scan (only objects in the scene will be scanned, plus any prefabs which you define here)");
            GUILayout.Space(5);

            var rect = EditorGUILayout.BeginHorizontal();

            rect = new Rect(rect.x, rect.y - CellMargin, rect.width, 10 + CellMargin);

            // The drawn rectangle is bigger than the actual rectangle to include the buttons
            EditorGUI.DrawRect(new Rect(rect.x, rect.y, rect.width, 55 + CellMargin * 2f), new Color(0.5f, 0.5f, 0.5f, 0.3f));

            EditorGUI.LabelField(rect, "Use +/- buttons to increase or decrease number of items in external file list: (" + _prefabsList.Count.ToString() + ")");

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

            if (GUILayout.Button("+", GUILayout.Width(40)))
            {
                _prefabsList.Add(null);
            }

            if (GUILayout.Button("-", GUILayout.Width(40)) && _prefabsList.Count > 0)
            {
                _prefabsList.RemoveAt(_prefabsList.Count - 1);
                _dirtyPrefabsList = true;
            }

            GUILayout.Space(18);

            // Handle UI and save changes to local ignoreList
            if (_prefabsList.Count > 0)
            {
                for (int i = 0; i < _prefabsList.Count; i++)
                {
                    _prefabsList[i] = HandleIndividualPrefabItems(_prefabsList[i]);
                }
            }

            // Save the inputs if anything changed
            if (_dirtyPrefabsList)
            {
                PreferencesSerialization.SavePrefabList(_prefabsList);
                _dirtyPrefabsList = false;
            }
        }