/// <returns>
        /// Whether the file creation was successful.
        /// </returns>
        public bool CreateEnumFile()
        {
            string directory = Path.GetDirectoryName(_writePath);;

            string wholeText = GetWholeEnumText();

            LDtkPathUtility.TryCreateDirectory(directory);
            File.WriteAllText(_writePath, wholeText);

            return(true);
        }
Example #2
0
        private List <T> CloneArtifacts <T>(List <T> artifacts, string extraPath, string assetName = null) where T : Object
        {
            if (artifacts.IsNullOrEmpty())
            {
                return(new List <T>());
            }

            string parentPath = $"{_path}{extraPath}";

            LDtkPathUtility.TryCreateDirectory(parentPath);

            List <T> list = new List <T>();

            foreach (T artifact in artifacts)
            {
                if (artifact == null)
                {
                    continue;
                }

                string cloneName       = assetName != null ? assetName : artifact.name;
                string destinationPath = $"{parentPath}/{cloneName}.asset";

                //Debug.Log($"Copy asset\n{artifact.name}\nto\n{destinationPath}");

                Object clone = CreateClone(artifact);
                clone.name = cloneName;

                T loadedAsset = AssetDatabase.LoadAssetAtPath <T>(destinationPath);

                if (loadedAsset)
                {
                    EditorUtility.CopySerializedIfDifferent(clone, loadedAsset);
                    list.Add(loadedAsset);
                }
                else
                {
                    AssetDatabase.CreateAsset(clone, destinationPath);
                    list.Add((T)clone);
                }
            }

            return(list);
        }