备份CatanBuilding瘦身独立工程
This commit is contained in:
59
LocalPackages/InspectorExtension/Runtime/Extensions.cs
Normal file
59
LocalPackages/InspectorExtension/Runtime/Extensions.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace inspector.ext
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string WithoutFileName(this string str)
|
||||
{
|
||||
return WithoutLastFolder(str);
|
||||
}
|
||||
|
||||
public static string WithoutLastFolder(this string str)
|
||||
{
|
||||
return str.Substring(0, str.LastIndexOf("/") + 1);
|
||||
}
|
||||
|
||||
public static FolderInfo ToFolderInfo(this string str)
|
||||
{
|
||||
return JsonUtility.FromJson<FolderInfo>(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remember that the folder must be located in Resources.
|
||||
/// </summary>
|
||||
public static T[] LoadFolder<T>(this string str) where T : Object
|
||||
{
|
||||
string resourcesFolder = "Resources/";
|
||||
|
||||
FolderInfo folder = str.ToFolderInfo();
|
||||
|
||||
if (folder.path.IndexOf(resourcesFolder) == -1) // Ensure the path is in Resources.
|
||||
{
|
||||
Debug.LogError("The folder at path " + folder.path + " must be located in Resources if you want to load it.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// We remove the part of the path that is before Resources
|
||||
folder.path = folder.path.Substring(folder.path.LastIndexOf(resourcesFolder) + resourcesFolder.Length);
|
||||
|
||||
T[] resources = Resources.LoadAll<T>(folder.path);
|
||||
|
||||
if (resources == null || resources.Length == 0) // Maybe the folder was renamed or deleted?
|
||||
{
|
||||
FolderInfo folderInfo = Utils.GetFolderWithGUID(folder.guid);
|
||||
|
||||
if (folderInfo != null) // Indeed, we found it in the file changes!
|
||||
{
|
||||
folder.path = folderInfo.path; // Update with new path
|
||||
folder.path = folder.path.Substring(folder.path.LastIndexOf(resourcesFolder) + resourcesFolder.Length);
|
||||
resources = Resources.LoadAll<T>(folder.path);
|
||||
}
|
||||
}
|
||||
|
||||
return resources;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
LocalPackages/InspectorExtension/Runtime/Extensions.cs.meta
Normal file
11
LocalPackages/InspectorExtension/Runtime/Extensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2debf705c145ce45b0ad51c30c71ea3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
LocalPackages/InspectorExtension/Runtime/FolderAttribute.cs
Normal file
22
LocalPackages/InspectorExtension/Runtime/FolderAttribute.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace inspector.ext
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
|
||||
public class FolderAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class FolderInfo
|
||||
{
|
||||
public string guid;
|
||||
public string path;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return guid + " " + path;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5096b5c23a602c14387cbb8e725852d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
141
LocalPackages/InspectorExtension/Runtime/Utils.cs
Normal file
141
LocalPackages/InspectorExtension/Runtime/Utils.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace inspector.ext
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
private const string dataFilename = "folder_changes.txt";
|
||||
private static string dataFilepath { get { return Path.Combine(Application.persistentDataPath, dataFilename); } }
|
||||
|
||||
private static List<FolderInfo> _folders;
|
||||
private static List<FolderInfo> folders
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_folders == null)
|
||||
_folders = GetFolders();
|
||||
|
||||
return _folders;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateFolderPath(string guid, string filepath)
|
||||
{
|
||||
CreateFoldersFileIfNotExists();
|
||||
|
||||
FolderInfo folder = GetFolderWithGUID(guid);
|
||||
|
||||
if (folder != null)
|
||||
{
|
||||
folder.path = filepath;
|
||||
SaveFolders();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Folder with guid " + guid + " could not be found.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterNewFolder(string filepath, string guid)
|
||||
{
|
||||
CreateFoldersFileIfNotExists();
|
||||
|
||||
FolderInfo folderInfo = GetFolderWithGUID(guid);
|
||||
|
||||
if (folderInfo == null) // FolderInfo creation
|
||||
{
|
||||
folders.Add(new FolderInfo { path = filepath, guid = guid });
|
||||
}
|
||||
else // Simple path update
|
||||
{
|
||||
folderInfo.path = filepath;
|
||||
}
|
||||
|
||||
SaveFolders();
|
||||
}
|
||||
|
||||
public static void RemoveFolderWithPath(string filepath)
|
||||
{
|
||||
_folders = _folders.Where(f => f.path != filepath).ToList();
|
||||
SaveFolders();
|
||||
}
|
||||
|
||||
public static bool FolderWithPathExists(string path)
|
||||
{
|
||||
return GetFolderWithPath(path) != null;
|
||||
}
|
||||
|
||||
public static bool FolderWithGUIDExists(string guid)
|
||||
{
|
||||
return GetFolderWithGUID(guid) != null;
|
||||
}
|
||||
|
||||
public static string GetGUIDFromPath(string path, bool showError = true)
|
||||
{
|
||||
FolderInfo folder = GetFolderWithPath(path);
|
||||
|
||||
if (folder != null)
|
||||
return folder.guid;
|
||||
else
|
||||
{
|
||||
if (showError)
|
||||
Debug.LogError("Folder with path " + path + " could not be found.");
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static FolderInfo GetFolderWithPath(string path)
|
||||
{
|
||||
CreateFoldersFileIfNotExists();
|
||||
return folders.FirstOrDefault(f => f.path == path);
|
||||
}
|
||||
|
||||
public static FolderInfo GetFolderWithGUID(string guid)
|
||||
{
|
||||
CreateFoldersFileIfNotExists();
|
||||
return folders.FirstOrDefault(f => f.guid == guid);
|
||||
}
|
||||
|
||||
private static void CreateFoldersFileIfNotExists()
|
||||
{
|
||||
if (!File.Exists(dataFilepath))
|
||||
{
|
||||
File.WriteAllText(dataFilepath, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<FolderInfo> GetFolders()
|
||||
{
|
||||
CreateFoldersFileIfNotExists();
|
||||
|
||||
string[] lines = File.ReadAllLines(dataFilepath);
|
||||
|
||||
List<FolderInfo> folders = new List<FolderInfo>();
|
||||
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
string[] folderInfos = lines[i].Split(new char[] { ' ' }, 2, StringSplitOptions.None);
|
||||
folders.Add(new FolderInfo { guid = folderInfos[0], path = folderInfos[1] });
|
||||
}
|
||||
|
||||
return folders;
|
||||
}
|
||||
|
||||
private static void SaveFolders()
|
||||
{
|
||||
string content = "";
|
||||
|
||||
for (int i = 0; i < folders.Count; i++)
|
||||
{
|
||||
content += folders[i] + Environment.NewLine;
|
||||
}
|
||||
|
||||
File.WriteAllText(dataFilepath, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
LocalPackages/InspectorExtension/Runtime/Utils.cs.meta
Normal file
11
LocalPackages/InspectorExtension/Runtime/Utils.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62d255dbf0584e342a053f57005469d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "inspector.extension",
|
||||
"rootNamespace": "inspector.ext",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 690dd0c44eaedbd468bcbb5468aaee1f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user