Ejemplo n.º 1
0
        static public void Apply(object inObject, UnityEngine.Object inHost = null)
        {
            if (inObject == null)
            {
                return;
            }

            Type objType = inObject.GetType();

            bool bChanged = false;

            foreach (var field in objType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!field.IsPublic && !field.IsDefined(typeof(SerializeField)))
                {
                    continue;
                }

                DefaultAssetAttribute defaultAssetAttr = Reflect.GetAttribute <DefaultAssetAttribute>(field);
                if (defaultAssetAttr != null)
                {
                    Type               type  = field.FieldType;
                    string             name  = defaultAssetAttr.AssetName;
                    UnityEngine.Object asset = (UnityEngine.Object)field.GetValue(inObject);
                    if (asset == null)
                    {
                        asset = AssetDBUtils.FindAsset(type, name);
                        if (asset != null)
                        {
                            field.SetValue(inObject, asset);
                            bChanged = true;
                        }
                    }
                }
            }

            if (bChanged && inHost)
            {
                EditorUtility.SetDirty(inHost);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Forces the assemblies to recompile.
        /// Specify directories to force a subset to recompile.
        /// </summary>
        static public void ForceRecompile(string[] inDirectories = null)
        {
            HashSet <Assembly> affectedAssemblies = new HashSet <Assembly>();

            foreach (var file in AssetDBUtils.FindAssets <MonoScript>(null, inDirectories))
            {
                Type type = file.GetClass();
                if (type != null && affectedAssemblies.Add(type.Assembly))
                {
                    string filePath = AssetDatabase.GetAssetPath(file);
                    Debug.LogFormat("[BuildUtils] Reimporting '{0}'", filePath);
                    AssetDatabase.ImportAsset(filePath, ImportAssetOptions.ForceUpdate);
                }
            }

            if (affectedAssemblies.Count > 0)
            {
                EditorApplication.ExecuteMenuItem("Assets/Open C# Project");
                // TODO(Beau): Replace with a more stable method for syncing C# projects
            }
        }