private static void SetFields() { if (!EditorPrefs.GetBool(IsCreateKey, false)) { return; } if (!EditorPrefs.HasKey(ScriptNameKey) || !EditorPrefs.HasKey(GameobjKey)) { if (EditorPrefs.HasKey(ScriptNameKey)) { EditorPrefs.DeleteKey(ScriptNameKey); } if (EditorPrefs.HasKey(GameobjKey)) { EditorPrefs.DeleteKey(GameobjKey); } EditorPrefs.SetBool(IsCreateKey, false); EditorUtility.ClearProgressBar(); return; } Assembly defaultAssembly = AppDomain.CurrentDomain.GetAssemblies() .First(assembly => assembly.GetName().Name == "Assembly-CSharp"); Type type = defaultAssembly.GetType(ProjectConfig.NameSpace + "." + EditorPrefs.GetString(ScriptNameKey)); GameObject gameObj = GameObject.Find(EditorPrefs.GetString(GameobjKey)); if (gameObj == null || type == null || gameObj.GetComponent <ScriptCreater>() == null) { if (EditorPrefs.HasKey(ScriptNameKey)) { EditorPrefs.DeleteKey(ScriptNameKey); } if (EditorPrefs.HasKey(GameobjKey)) { EditorPrefs.DeleteKey(GameobjKey); } EditorPrefs.SetBool(IsCreateKey, false); EditorUtility.ClearProgressBar(); return; } EditorUtility.DisplayProgressBar("Build Script " + type.Name, "Don't do anything", 0.7f); _scriptCreater = gameObj.GetComponent <ScriptCreater>(); ScriptMark[] scriptMarks = _scriptCreater.scriptMarks; Component component = gameObj.GetComponent(type); if (component == null) { component = gameObj.AddComponent(type); } SerializedObject serialiedScript = new SerializedObject(component); foreach (var _sm in scriptMarks) { serialiedScript.FindProperty(_sm.fieldName).objectReferenceValue = _sm.GetComponent(_sm.fieldType); } serialiedScript.ApplyModifiedPropertiesWithoutUndo(); //serialiedScript.Update(); if (_scriptCreater.isCreatePrefab) { EditorTools.CreatePrefab(gameObj, _scriptCreater.prefabPath); } EditorPrefs.SetBool(IsCreateKey, false); EditorPrefs.DeleteKey(ScriptNameKey); EditorPrefs.DeleteKey(GameobjKey); EditorUtility.ClearProgressBar(); }