/// <summary> /// Enable the plugin in your scene. /// </summary> public virtual void Enable() { string managerName = GetReadableName() + " " + GetManagerType().Name.ToString().Prettify(); string suffix = ""; if (MultipleAllowed) { int index = (DigitalPaintingManager.gameObject.GetComponentsInChildren(GetManagerType()).Count() + 1); suffix = " " + index; while (GameObject.Find(managerName + suffix) != null) { index++; suffix = " " + index; } } GameObject go = new GameObject(managerName + suffix); AbstractPluginManager manager = (AbstractPluginManager)go.AddComponent(GetManagerType()); go.transform.SetParent(DigitalPaintingManager.gameObject.transform); MonoScript script = MonoScript.FromScriptableObject(this); string scriptPath = AssetDatabase.GetAssetPath(script); int lastIndex = scriptPath.LastIndexOf("Scripts"); string fromPath = scriptPath.Substring("Assets/".Length, lastIndex - 7) + AssetDatabaseUtility.dataFolderName; string toPath = GetPathToScene(); SetupDefaultSettings(manager, fromPath, toPath); }
private void SetupDefaultSettings(AbstractPluginManager manager, string fromPath, string toPath) { Scene scene = EditorSceneManager.GetActiveScene(); string sceneName = scene.name; if (!AssetDatabase.IsValidFolder(toPath + "/" + AssetDatabaseUtility.dataFolderName)) { AssetDatabase.CreateFolder(toPath, AssetDatabaseUtility.dataFolderName); } string pluginFolder = fromPath.Split('/').First(); string fullToPath = toPath + "/" + AssetDatabaseUtility.dataFolderName + "/" + pluginFolder; if (!AssetDatabase.IsValidFolder(fullToPath)) { AssetDatabase.CreateFolder(toPath + "/" + AssetDatabaseUtility.dataFolderName, pluginFolder); } try { string[] fileEntries = Directory.GetFiles(Application.dataPath + "/" + fromPath); foreach (string fileName in fileEntries) { string temp = fileName.Replace("\\", "/"); int index = temp.LastIndexOf("/"); string localPath = "Assets/" + fromPath; if (index > 0) { localPath += temp.Substring(index); } UnityEngine.Object original = AssetDatabase.LoadAssetAtPath(localPath, typeof(ScriptableObject)); if (original != null) { string filename = Path.GetFileName(localPath); filename = filename.Replace("_Default", "_" + sceneName); if (AssetDatabase.GetMainAssetTypeAtPath(fullToPath + "/" + filename) == null) { AssetDatabase.CopyAsset(localPath, fullToPath + "/" + filename); } } // if AbstractPluginProfile copy it into Profile AbstractPluginProfile profile = (AbstractPluginProfile)AssetDatabase.LoadAssetAtPath(localPath, typeof(AbstractPluginProfile)); if (profile != null) { string filename = Path.GetFileName(localPath); filename = filename.Replace("_Default", "_" + sceneName); AssetDatabase.CopyAsset(localPath, toPath + "/" + AssetDatabaseUtility.dataFolderName + "/" + filename); manager.Profile = profile; } } } catch (Exception e) { Debug.LogError("Unable to copy plugin default settings. Digital Painting expects to find the default settings in " + fromPath + " see following exception for more information", this); Debug.LogException(e); } }