备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2969cd6bfa4ecd6419975bcb279bab7e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using UnityEditor;
namespace inspector.ext.editor
{
public class FolderAssetPostProcessor : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
if (movedAssets.Length > 0)
{
for (int i = 0; i < movedAssets.Length; i++)
{
string destinationPath = movedAssets[i];
if (IsFolder(destinationPath))
{
string guid = AssetDatabase.AssetPathToGUID(destinationPath);
Utils.RegisterNewFolder(destinationPath, guid);
}
}
}
}
static bool IsFolder(string sourcePath)
{
return sourcePath.LastIndexOf("/") > sourcePath.LastIndexOf(".");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b159054bd5843f4f8e9b71b71eb353c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,112 @@
using System.IO;
using UnityEditor;
using UnityEngine;
namespace inspector.ext.editor
{
[UnityEditor.CustomPropertyDrawer(typeof(FolderAttribute))]
public class FolderAttributeDrawer : PropertyDrawer
{
private const int margin = 15;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
float currentViewWidth = GUILayoutUtility.GetLastRect().width;
Rect labelPosition = position;
labelPosition.width = EditorGUIUtility.labelWidth;
position = EditorGUI.PrefixLabel(labelPosition, GUIUtility.GetControlID(FocusType.Passive), label);
Rect objectPosition = position;
objectPosition.x = labelPosition.width - (EditorGUI.indentLevel - 1) * margin;
objectPosition.width = currentViewWidth - objectPosition.x - 4;
if (property.propertyType != SerializedPropertyType.String)
{
EditorGUI.HelpBox(objectPosition, "[Folder] only works with strings.", MessageType.Error);
}
else
{
Object folder = null;
FolderInfo folderInfo = null;
if (!string.IsNullOrEmpty(property.stringValue))
{
folderInfo = property.stringValue.ToFolderInfo();
folder = AssetDatabase.LoadAssetAtPath(folderInfo.path, typeof(DefaultAsset));
if (folder == null) // The folder has been moved, deleted, or renamed
{
string newPath = AssetDatabase.GUIDToAssetPath(folderInfo.guid); // Try to retrieve from guid
if (newPath != folderInfo.path)
{
folderInfo.path = newPath;
folder = AssetDatabase.LoadAssetAtPath(folderInfo.path, typeof(DefaultAsset));
}
else // Retrieving from the guid led us to the same path: the file could not be found
{
Debug.LogWarning("The folder at path " + folderInfo.path + " could not be found. It has probably been deleted.");
folderInfo = null; // Reset folderInfo
}
}
}
else // The property is unassigned yet
{
//Debug.Log("unassigned");
}
folder = EditorGUI.ObjectField(objectPosition, folder, typeof(DefaultAsset), false);
string folderPathInAssets = AssetDatabase.GetAssetPath(folder);
TryUpdateProperty(folderPathInAssets, folderInfo, property);
}
EditorGUI.EndProperty();
}
private void TryUpdateProperty(string folderPathInAssets, FolderInfo folderInfo, SerializedProperty property)
{
string folderPathOnPC = Application.dataPath.WithoutFileName() + folderPathInAssets;
if (!Directory.Exists(folderPathOnPC))
{
Debug.LogError(folderPathInAssets + " is not a folder.");
}
else
{
if (folderInfo == null)
{
if (!string.IsNullOrEmpty(folderPathInAssets)) // First time we assign a folder
{
folderInfo = new FolderInfo { guid = AssetDatabase.AssetPathToGUID(folderPathInAssets), path = folderPathInAssets };
property.stringValue = JsonUtility.ToJson(folderInfo);
}
else // Folder was deleted
{
property.stringValue = "";
}
}
else
{
if (string.IsNullOrEmpty(folderPathInAssets)) // We just removed the reference
{
property.stringValue = "";
}
else if (folderPathInAssets != folderInfo.path) // We assigned a new folder
{
folderInfo = new FolderInfo { guid = AssetDatabase.AssetPathToGUID(folderPathInAssets), path = folderPathInAssets };
property.stringValue = JsonUtility.ToJson(folderInfo);
}
else // We renamed the folder
{
property.stringValue = JsonUtility.ToJson(folderInfo);
}
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81200e408107e844bb3b907133198937
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
{
"name": "inspector.extension.editor",
"rootNamespace": "inspector.ext.editor",
"references": [
"GUID:690dd0c44eaedbd468bcbb5468aaee1f"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5bd9549e2ac8ddb40b17d38295234528
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b1485eb8ddea8c5478ef403ddaaa99c4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2debf705c145ce45b0ad51c30c71ea3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5096b5c23a602c14387cbb8e725852d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 62d255dbf0584e342a053f57005469d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
{
"name": "inspector.extension",
"rootNamespace": "inspector.ext",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 690dd0c44eaedbd468bcbb5468aaee1f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
{
"name": "com.inspector.extension",
"version": "0.0.1",
"displayName": "inspector extensions",
"unity": "2020.3",
"unityRelease": "4f1",
"author": {
"name": "Skistua",
"email": "b166er.dada@gmail.com"
}
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 612ba011249331f4bb26547f9026f71a
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: