private static List <UnityEngine.Object> GetHiddenReferences(UnityEngine.Object asset, string refsPath = null, List <UnityEngine.Object> refs = null)
        {
            if (refsPath == null)
            {
                refsPath = AssetDatabase.GetAssetPath(asset);
            }

            if (refs == null)
            {
                refs = new List <UnityEngine.Object>();
            }

            var iterator = new SerializedObject(asset).GetIterator();

            while (iterator.Next(true))
            {
                if (iterator.propertyType == SerializedPropertyType.ObjectReference)
                {
                    var obj = iterator.objectReferenceValue;
                    if (obj != null && (obj.hideFlags & HideFlags.HideInHierarchy) != 0)
                    {
                        if (refs.IndexOf(obj) == -1 && AssetDatabase.GetAssetPath(obj) == refsPath)
                        {
                            refs.Add(obj);
                            GetHiddenReferences(obj, refsPath, refs);
                        }
                    }
                }
            }

            return(refs);
        }
	public static UnityObject[] GetReferencesOfAsset(UnityObject[] assets, bool prefabOnly = true) {
		if(assets == null || assets.Length == 0)
			return new GameObject[0];
		var result = new List<UnityObject>();
		var allObjects = UnityObject.FindObjectsOfType(typeof(UnityObject)) as UnityObject[];
		var allGameObjects = !prefabOnly ? GetChildrenWithInactive(allObjects) : new GameObject[0];
		foreach(var target in assets) {
			if(target == null)
				continue;
			if(prefabOnly) {
				foreach(var obj in allObjects)
					if(PrefabUtility.GetPrefabType(obj) == PrefabType.PrefabInstance && PrefabUtility.GetPrefabParent(obj) == target)
						result.Add(obj);
				continue;
			}
			foreach(var gameObject in allGameObjects) {
				var added = false;
				if(result.Contains(gameObject))
					continue;
				if(PrefabUtility.GetPrefabType(gameObject) == PrefabType.PrefabInstance && PrefabUtility.GetPrefabParent(gameObject) == target)
					result.Add(gameObject);
				foreach(var component in gameObject.GetComponents<Component>()) {
					if(target == component) {
						result.Add(gameObject);
						break;
					}
					var property = new SerializedObject(component).GetIterator();
					while(property != null && property.Next(true))
						if(property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue == target) {
							result.Add(gameObject);
							added = true;
							break;
						}
					if(added)
						break;
				}
			}
		}
		return result.ToArray();
	}
        /// <summary>
        /// Adds the copy of a Component to a GameObject.
        /// </summary>
        /// <param name="go">The GameObject that will get the new Component</param>
        /// <param name="original">The original component to copy</param>
        /// <returns>The reference to the newly added Component copy</returns>
        public static Component AddComponent(this GameObject go, Component original)
        {
            var c = go.AddComponent(original.GetType());

            var originalSerialized = new SerializedObject(original).GetIterator();
            var nso = new SerializedObject(c);
            var newSerialized = nso.GetIterator();

            if(originalSerialized.Next(true))
            {
                newSerialized.Next(true);

                while(originalSerialized.NextVisible(true))
                {
                    newSerialized.NextVisible(true);
                    newSerialized.SetValue(originalSerialized.GetValue());
                }
            }

            nso.ApplyModifiedProperties();

            return c;
        }