fix:1、更换项目,使用winter来创建
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
# 📦 DataStorage 数据存储模块
|
||||
|
||||
## ✨ 简介
|
||||
|
||||
该模块是一个基于 Unity + Easy Save 的本地数据存储系统,具备:
|
||||
|
||||
- ✅ 本地缓存机制(避免频繁磁盘 IO)
|
||||
- ✅ 自动保存机制(按时间间隔或调用次数)
|
||||
- ✅ 云同步支持(支持上传 JSON,或导入云端数据)
|
||||
- ✅ 数据版本控制
|
||||
- ✅ 类型安全的 `DataStorage<T>` 封装
|
||||
- ✅ 可调试的 GM 工具接口
|
||||
|
||||
------
|
||||
|
||||
## 📁 使用说明
|
||||
|
||||
### 🔹 1. 定义数据键
|
||||
|
||||
在模块初始化之前,使用 `DataKeyDic.Register` 注册数据键名(通常在 `DataStorage<T>` 构造时自动完成):
|
||||
|
||||
```c#
|
||||
var playerName = new DataStorage<string>("PlayerName", "Guest");
|
||||
playerName.Value = "Pius123";
|
||||
```
|
||||
|
||||
或使用保存回调监听值变化:
|
||||
|
||||
```c#
|
||||
var coins = new DataStorage<int>("CoinAmount", 0, (oldVal, newVal) => {
|
||||
Debug.Log($"金币变化:{oldVal} -> {newVal}");
|
||||
});
|
||||
```
|
||||
|
||||
### 🔹 2. 保存和读取数据
|
||||
|
||||
```c#
|
||||
coins.Value = 100; // 保存数据(自动缓存 + 标记待保存)
|
||||
var coinAmount = coins.Value; // 从缓存读取(或回退至本地/云端)
|
||||
coins.Save(); // 强制保存(即使值没变)
|
||||
```
|
||||
|
||||
也可直接使用底层 API 操作(不建议):
|
||||
|
||||
```c#
|
||||
DataManager.Instance.SaveData("Level", 5);
|
||||
int level = DataManager.Instance.LoadData("Level", 1);
|
||||
```
|
||||
|
||||
### 🔹 3. 自动保存逻辑
|
||||
|
||||
模块会在以下时机自动保存数据到磁盘(使用 Easy Save):
|
||||
|
||||
- ⏱ 每隔 15 秒(可配置)
|
||||
- 🔁 累积 `SaveData` 达到 20 次(可配置)
|
||||
- 🚫 App 暂停、退出时
|
||||
- 📡 数据版本每增加两次触发一次 `_saveCallback`(用于云上传)
|
||||
|
||||
------
|
||||
|
||||
## 🌐 云同步支持
|
||||
|
||||
### ✅ 导出 JSON 上传云端
|
||||
|
||||
```c#
|
||||
DataManager.Instance.AddSaveCallback((json, version, onQuit) => {
|
||||
// 上传 json 到云端,携带版本 version
|
||||
});
|
||||
```
|
||||
|
||||
每次本地数据保存时(根据频率控制)会自动回调此方法。
|
||||
|
||||
### ✅ 从云端导入数据
|
||||
|
||||
```c#
|
||||
DataManager.Instance.ImportFromJson(jsonFromServer, versionFromServer);
|
||||
```
|
||||
|
||||
- 若云端版本 > 本地版本:自动覆盖并保存到本地
|
||||
- 若云端版本 < 本地版本:会自动触发 `_saveCallback` 上传本地数据覆盖云端
|
||||
|
||||
------
|
||||
|
||||
## 🔧 GM 调试接口(可选)
|
||||
|
||||
调用 `DataManager.Instance.Init()` 可注册 GM 工具按钮:
|
||||
|
||||
- 🧹 清空所有数据
|
||||
- 🗂 打印所有缓存键值对
|
||||
|
||||
------
|
||||
|
||||
## 🧠 数据结构概览
|
||||
|
||||
| 类名 | 说明 |
|
||||
| ---------------------------- | ---------------------------------------------- |
|
||||
| `DataManager` | 核心数据存储与调度管理(自动保存、版本、缓存) |
|
||||
| `DataStorage<T>` | 泛型数据封装,提供属性式访问与变更通知 |
|
||||
| `DataKeyDic` / `DataKeyBase` | 注册键名与云同步标记支持 |
|
||||
| `ES3` | 第三方 Easy Save 工具(需另行导入) |
|
||||
|
||||
|
||||
|
||||
------
|
||||
|
||||
## 📝 配置项
|
||||
|
||||
| 名称 | 默认值 | 说明 |
|
||||
| ------------------------- | ------ | -------------------- |
|
||||
| `InitialAutoSaveInterval` | `15s` | 自动保存时间间隔 |
|
||||
| `SaveThreshold` | `20次` | 自动保存调用次数阈值 |
|
||||
| `DataVersion` | `1` | 数据版本号,内部递增 |
|
||||
|
||||
|
||||
|
||||
------
|
||||
|
||||
## 🔍 调试建议
|
||||
|
||||
- 使用 `DebugAllKeys()` 打印所有持久化键值
|
||||
- 使用 `DebugCache()` 打印当前缓存数据
|
||||
- 检查 `Log.Info/Error` 输出(默认已集成日志标记)
|
||||
|
||||
------
|
||||
|
||||
## 📦 依赖项
|
||||
|
||||
- **Easy Save 3**:第三方持久化框架
|
||||
- **Newtonsoft.Json**:JSON 序列化与反序列化
|
||||
- **自定义框架组件**(如 `SingletonMonoBehaviour`、`Log`、`CommonUtils`、`GMTool` 等)
|
||||
|
||||
------
|
||||
|
||||
## 📌 注意事项
|
||||
|
||||
- 云同步仅同步标记为 `CloudSave = true` 的键
|
||||
- `DataStorage<T>` 会自动触发注册,但手动操作建议提前注册
|
||||
- 非线程安全,不建议多线程并发调用
|
||||
- 建议在游戏入口或登录成功后初始化模块并导入云数据
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce8e2605318941745b94c3ef79611bf6
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 030532982443d94449af00fc7ebcaf95
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a855501e0627ebc49add798f2f023815
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8174a0d08146bad4dad3838c423e1d5a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a8ecc2f6a355324ab2d92ace768db6b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using ES3Internal;
|
||||
using System.Linq;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class AddES3Prefab : Editor
|
||||
{
|
||||
[MenuItem("GameObject/Easy Save 3/Enable Easy Save for Prefab(s)", false, 1001)]
|
||||
[MenuItem("Assets/Easy Save 3/Enable Easy Save for Prefab(s)", false, 1001)]
|
||||
public static void Enable()
|
||||
{
|
||||
if (Selection.gameObjects == null || Selection.gameObjects.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (var obj in Selection.gameObjects)
|
||||
{
|
||||
// Don't add the Component to a GameObject which already has it.
|
||||
if (obj == null || (obj.GetComponent<ES3Prefab>() != null))
|
||||
continue;
|
||||
|
||||
var go = obj;
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
if (PrefabUtility.GetPrefabInstanceStatus(go) != PrefabInstanceStatus.NotAPrefab)
|
||||
{
|
||||
go = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(go);
|
||||
if (go == null)
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
if(PrefabUtility.GetPrefabType(go) != PrefabType.Prefab)
|
||||
{
|
||||
go = (GameObject)PrefabUtility.GetPrefabParent(go);
|
||||
if(go == null)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
var es3Prefab = Undo.AddComponent<ES3Prefab>(go);
|
||||
es3Prefab.GeneratePrefabReferences();
|
||||
|
||||
var mgr = ES3ReferenceMgr.GetManagerFromScene(SceneManager.GetActiveScene());
|
||||
if (mgr != null)
|
||||
{
|
||||
mgr.AddPrefab(es3Prefab);
|
||||
EditorUtility.SetDirty(mgr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Enable Easy Save for Prefab(s)", true, 1001)]
|
||||
[MenuItem("Assets/Easy Save 3/Enable Easy Save for Prefab(s)", true, 1001)]
|
||||
public static bool Validate()
|
||||
{
|
||||
return Selection.gameObjects != null && Selection.gameObjects.Length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class RemoveES3Prefab : Editor
|
||||
{
|
||||
[MenuItem("GameObject/Easy Save 3/Disable Easy Save for Prefab(s)", false, 1001)]
|
||||
[MenuItem("Assets/Easy Save 3/Disable Easy Save for Prefab(s)", false, 1001)]
|
||||
public static void Enable()
|
||||
{
|
||||
if (Selection.gameObjects == null || Selection.gameObjects.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (var obj in Selection.gameObjects)
|
||||
{
|
||||
var es3prefab = obj.GetComponent<ES3Prefab>();
|
||||
if (es3prefab != null)
|
||||
Undo.DestroyObjectImmediate(es3prefab);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Disable Easy Save for Prefab(s)", true, 1001)]
|
||||
[MenuItem("Assets/Easy Save 3/Disable Easy Save for Prefab(s)", true, 1001)]
|
||||
public static bool Validate()
|
||||
{
|
||||
return Selection.gameObjects != null && Selection.gameObjects.Length > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 337c3be705d1942b3bf318b5b29aa7cb
|
||||
timeCreated: 1519132282
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,369 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using ES3Internal;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
[System.Serializable]
|
||||
public class AutoSaveWindow : SubWindow
|
||||
{
|
||||
public bool showAdvancedSettings = false;
|
||||
|
||||
public ES3AutoSaveMgr mgr = null;
|
||||
|
||||
private HierarchyItem[] hierarchy = null;
|
||||
public HierarchyItem selected = null;
|
||||
|
||||
private Vector2 hierarchyScrollPosition = Vector2.zero;
|
||||
|
||||
private bool sceneOpen = true;
|
||||
|
||||
private string searchTerm = "";
|
||||
|
||||
public AutoSaveWindow(EditorWindow window) : base("Auto Save", window)
|
||||
{
|
||||
EditorSceneManager.activeSceneChangedInEditMode += ChangedActiveScene;
|
||||
}
|
||||
|
||||
private void ChangedActiveScene(Scene current, Scene next)
|
||||
{
|
||||
mgr = null;
|
||||
Init();
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
Init();
|
||||
|
||||
if(mgr == null)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("Enable Auto Save for this scene"))
|
||||
mgr = ES3Postprocessor.AddManagerToScene().GetComponent<ES3AutoSaveMgr>();
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
using (var changeCheck = new EditorGUI.ChangeCheckScope())
|
||||
{
|
||||
using (var vertical = new EditorGUILayout.VerticalScope(style.areaPadded))
|
||||
{
|
||||
//GUILayout.Label("Settings for current scene", style.heading);
|
||||
mgr.saveEvent = (ES3AutoSaveMgr.SaveEvent)EditorGUILayout.EnumPopup("Save Event", mgr.saveEvent);
|
||||
mgr.loadEvent = (ES3AutoSaveMgr.LoadEvent)EditorGUILayout.EnumPopup("Load Event", mgr.loadEvent);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
showAdvancedSettings = EditorGUILayout.Foldout(showAdvancedSettings, "Show Advanced Settings");
|
||||
if (showAdvancedSettings)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
mgr.key = EditorGUILayout.TextField("Key", mgr.key);
|
||||
ES3SettingsEditor.Draw(mgr.settings);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
// Display the menu.
|
||||
using (var horizontal = new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Scene", sceneOpen ? style.menuButtonSelected : style.menuButton))
|
||||
{
|
||||
sceneOpen = true;
|
||||
OnFocus();
|
||||
}
|
||||
if (GUILayout.Button("Prefabs", sceneOpen ? style.menuButton : style.menuButtonSelected))
|
||||
{
|
||||
sceneOpen = false;
|
||||
OnFocus();
|
||||
}
|
||||
}
|
||||
|
||||
//EditorGUILayout.HelpBox("Select the Components you want to be saved.\nTo maximise performance, only select the Components with variables which need persisting.", MessageType.None, true);
|
||||
|
||||
if (hierarchy == null || hierarchy.Length == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("Right-click a prefab and select 'Easy Save 3 > Enable Easy Save for Scene' to enable Auto Save for it.\n\nYour scene will also need to reference this prefab for it to be recognised.", style.area);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var scrollView = new EditorGUILayout.ScrollViewScope(hierarchyScrollPosition, style.areaPadded))
|
||||
{
|
||||
hierarchyScrollPosition = scrollView.scrollPosition;
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope(GUILayout.Width(200)))
|
||||
{
|
||||
var searchTextFieldSkin = GUI.skin.FindStyle("ToolbarSearchTextField");
|
||||
if (searchTextFieldSkin == null)
|
||||
searchTextFieldSkin = GUI.skin.FindStyle("ToolbarSeachTextField");
|
||||
|
||||
var searchButtonSkin = GUI.skin.FindStyle("ToolbarSearchCancelButton");
|
||||
if (searchButtonSkin == null)
|
||||
searchButtonSkin = GUI.skin.FindStyle("ToolbarSeachCancelButton");
|
||||
|
||||
searchTerm = GUILayout.TextField(searchTerm, searchTextFieldSkin);
|
||||
if (GUILayout.Button("", searchButtonSkin))
|
||||
{
|
||||
// Remove focus if cleared
|
||||
searchTerm = "";
|
||||
GUI.FocusControl(null);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
foreach (var go in hierarchy)
|
||||
if (go != null)
|
||||
go.DrawHierarchy(searchTerm.ToLowerInvariant());
|
||||
}
|
||||
if (changeCheck.changed)
|
||||
EditorUtility.SetDirty(mgr);
|
||||
}
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (mgr == null)
|
||||
foreach (var thisMgr in Resources.FindObjectsOfTypeAll<ES3AutoSaveMgr>())
|
||||
if (thisMgr != null && thisMgr.gameObject.scene == SceneManager.GetActiveScene())
|
||||
mgr = thisMgr;
|
||||
|
||||
if (hierarchy == null)
|
||||
OnFocus();
|
||||
}
|
||||
|
||||
public override void OnFocus()
|
||||
{
|
||||
|
||||
GameObject[] parentObjects;
|
||||
if (sceneOpen)
|
||||
parentObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
else // Prefabs
|
||||
{
|
||||
var mgr = ES3ReferenceMgr.GetManagerFromScene(SceneManager.GetActiveScene(), false);
|
||||
var prefabs = mgr.prefabs;
|
||||
parentObjects = new GameObject[prefabs.Count];
|
||||
for (int i = 0; i < prefabs.Count; i++)
|
||||
if(prefabs[i] != null)
|
||||
parentObjects[i] = prefabs[i].gameObject;
|
||||
}
|
||||
hierarchy = new HierarchyItem[parentObjects.Length];
|
||||
for (int i = 0; i < parentObjects.Length; i++)
|
||||
if(parentObjects[i] != null)
|
||||
hierarchy[i] = new HierarchyItem(parentObjects[i].transform, null, this);
|
||||
}
|
||||
|
||||
public class HierarchyItem
|
||||
{
|
||||
private ES3AutoSave autoSave;
|
||||
private Transform t;
|
||||
private Component[] components = null;
|
||||
// Immediate children of this GameObject
|
||||
private HierarchyItem[] children = new HierarchyItem[0];
|
||||
private bool showComponents = false;
|
||||
//private AutoSaveWindow window;
|
||||
|
||||
public HierarchyItem(Transform t, HierarchyItem parent, AutoSaveWindow window)
|
||||
{
|
||||
this.autoSave = t.GetComponent<ES3AutoSave>();
|
||||
this.t = t;
|
||||
this.components = t.GetComponents<Component>();
|
||||
|
||||
children = new HierarchyItem[t.childCount];
|
||||
for (int i = 0; i < t.childCount; i++)
|
||||
children[i] = new HierarchyItem(t.GetChild(i), this, window);
|
||||
|
||||
//this.window = window;
|
||||
}
|
||||
|
||||
public void MergeDown(ES3AutoSave autoSave)
|
||||
{
|
||||
if (this.autoSave != autoSave)
|
||||
{
|
||||
if (this.autoSave != null)
|
||||
{
|
||||
autoSave.componentsToSave.AddRange(autoSave.componentsToSave);
|
||||
Object.DestroyImmediate(this.autoSave);
|
||||
}
|
||||
this.autoSave = autoSave;
|
||||
}
|
||||
|
||||
foreach (var child in children)
|
||||
MergeDown(autoSave);
|
||||
}
|
||||
|
||||
public void DrawHierarchy(string searchTerm)
|
||||
{
|
||||
bool containsSearchTerm = false;
|
||||
|
||||
if (t != null)
|
||||
{
|
||||
// Filter by tag if it's prefixed by "tag:"
|
||||
if (searchTerm.StartsWith("tag:") && t.tag.ToLowerInvariant().Contains(searchTerm.Remove(0,4)))
|
||||
containsSearchTerm = true;
|
||||
// Else filter by name
|
||||
else
|
||||
containsSearchTerm = t.name.ToLowerInvariant().Contains(searchTerm);
|
||||
|
||||
if (containsSearchTerm)
|
||||
{
|
||||
GUIContent saveIcon;
|
||||
EditorGUIUtility.SetIconSize(new Vector2(16, 16));
|
||||
|
||||
if (HasSelectedComponentsOrFields())
|
||||
saveIcon = new GUIContent(t.name, EditorStyle.Get.saveIconSelected, "There are Components on this GameObject which will be saved.");
|
||||
else
|
||||
saveIcon = new GUIContent(t.name, EditorStyle.Get.saveIconUnselected, "No Components on this GameObject will be saved");
|
||||
|
||||
GUIStyle style = GUI.skin.GetStyle("Foldout");
|
||||
if (Selection.activeTransform == t)
|
||||
{
|
||||
style = new GUIStyle(style);
|
||||
style.fontStyle = FontStyle.Bold;
|
||||
}
|
||||
|
||||
var open = EditorGUILayout.Foldout(showComponents, saveIcon, style);
|
||||
if (open)
|
||||
{
|
||||
// Ping the GameObject if this was previously closed
|
||||
if (showComponents != open)
|
||||
EditorGUIUtility.PingObject(t.gameObject);
|
||||
DrawComponents();
|
||||
}
|
||||
showComponents = open;
|
||||
|
||||
EditorGUI.indentLevel += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw children
|
||||
if (children != null)
|
||||
foreach (var child in children)
|
||||
if (child != null)
|
||||
child.DrawHierarchy(searchTerm);
|
||||
|
||||
if (containsSearchTerm)
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
public void DrawComponents()
|
||||
{
|
||||
EditorGUI.indentLevel += 3;
|
||||
using (var scope = new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
bool toggle;
|
||||
toggle = EditorGUILayout.ToggleLeft("active", autoSave != null ? autoSave.saveActive : false);
|
||||
if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent<ES3AutoSave>() : autoSave) != null)
|
||||
ApplyBool("saveActive", toggle);
|
||||
|
||||
toggle = EditorGUILayout.ToggleLeft("hideFlags", autoSave != null ? autoSave.saveHideFlags : false);
|
||||
if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent<ES3AutoSave>() : autoSave) != null)
|
||||
ApplyBool("saveHideFlags", toggle);
|
||||
|
||||
toggle = EditorGUILayout.ToggleLeft("layer", autoSave != null ? autoSave.saveLayer : false);
|
||||
if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent<ES3AutoSave>() : autoSave) != null)
|
||||
ApplyBool("saveLayer", toggle);
|
||||
|
||||
toggle = EditorGUILayout.ToggleLeft("name", autoSave != null ? autoSave.saveName : false);
|
||||
if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent<ES3AutoSave>() : autoSave) != null)
|
||||
ApplyBool("saveName", toggle);
|
||||
|
||||
toggle = EditorGUILayout.ToggleLeft("tag", autoSave != null ? autoSave.saveTag : false);
|
||||
if ((autoSave = (toggle && autoSave == null) ? t.gameObject.AddComponent<ES3AutoSave>() : autoSave) != null)
|
||||
ApplyBool("saveTag", toggle);
|
||||
|
||||
foreach (var component in components)
|
||||
{
|
||||
if (component == null)
|
||||
continue;
|
||||
|
||||
using (var horizontalScope = new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
bool saveComponent = false;
|
||||
if (autoSave != null)
|
||||
saveComponent = autoSave.componentsToSave.Contains(component);
|
||||
|
||||
var newValue = EditorGUILayout.ToggleLeft(EditorGUIUtility.ObjectContent(component, component.GetType()), saveComponent);
|
||||
// If the checkbox has changed, we want to save or not save a Component
|
||||
if (newValue != saveComponent)
|
||||
{
|
||||
if (autoSave == null)
|
||||
{
|
||||
autoSave = Undo.AddComponent<ES3AutoSave>(t.gameObject);
|
||||
var so = new SerializedObject(autoSave);
|
||||
so.FindProperty("saveChildren").boolValue = false;
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
// If we've unchecked the box, remove the Component from the array.
|
||||
if (newValue == false)
|
||||
{
|
||||
var so = new SerializedObject(autoSave);
|
||||
var prop = so.FindProperty("componentsToSave");
|
||||
var index = autoSave.componentsToSave.IndexOf(component);
|
||||
prop.DeleteArrayElementAtIndex(index);
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
// Else, add it to the array.
|
||||
else
|
||||
{
|
||||
var so = new SerializedObject(autoSave);
|
||||
var prop = so.FindProperty("componentsToSave");
|
||||
prop.arraySize++;
|
||||
prop.GetArrayElementAtIndex(prop.arraySize - 1).objectReferenceValue = component;
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button(EditorGUIUtility.IconContent("_Popup"), new GUIStyle("Label")))
|
||||
ES3Window.InitAndShowTypes(component.GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if(autoSave != null && isDirty)
|
||||
{
|
||||
EditorUtility.SetDirty(autoSave);
|
||||
if (PrefabUtility.IsPartOfPrefabInstance(autoSave))
|
||||
PrefabUtility.RecordPrefabInstancePropertyModifications(autoSave.gameObject);
|
||||
}*/
|
||||
|
||||
if (autoSave != null && (autoSave.componentsToSave == null || autoSave.componentsToSave.Count == 0) && !autoSave.saveActive && !autoSave.saveChildren && !autoSave.saveHideFlags && !autoSave.saveLayer && !autoSave.saveName && !autoSave.saveTag)
|
||||
{
|
||||
Undo.DestroyObjectImmediate(autoSave);
|
||||
autoSave = null;
|
||||
}
|
||||
EditorGUI.indentLevel -= 3;
|
||||
}
|
||||
|
||||
public void ApplyBool(string propertyName, bool value)
|
||||
{
|
||||
var so = new SerializedObject(autoSave);
|
||||
so.FindProperty(propertyName).boolValue = value;
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
public bool HasSelectedComponentsOrFields()
|
||||
{
|
||||
if (autoSave == null)
|
||||
return false;
|
||||
|
||||
|
||||
foreach (var component in components)
|
||||
if (component != null && autoSave.componentsToSave.Contains(component))
|
||||
return true;
|
||||
|
||||
if (autoSave.saveActive || autoSave.saveHideFlags || autoSave.saveLayer || autoSave.saveName || autoSave.saveTag)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6065cc5492e9f49728674de9a0c1fe84
|
||||
timeCreated: 1519132286
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
public class SetReferenceID : EditorWindow
|
||||
{
|
||||
private long id = 0;
|
||||
public UnityEngine.Object obj;
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Set Reference ID..", false, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Set Reference ID..", false, 33)]
|
||||
|
||||
public static void ShowWindow()
|
||||
{
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.TopLevel);
|
||||
|
||||
if (selected == null || selected.Length == 0)
|
||||
EditorUtility.DisplayDialog("Could not set reference ID", "No reference was selected to set the ID of.", "Ok");
|
||||
else if (selected.Length > 1)
|
||||
EditorUtility.DisplayDialog("Could not set reference ID", "Multiple references are selected. Please select a single reference.", "Ok");
|
||||
else
|
||||
EditorWindow.GetWindow<SetReferenceID>("Set Reference ID").obj = selected[0];
|
||||
}
|
||||
|
||||
[MenuItem("CONTEXT/Component/Easy Save 3/Set Reference ID..", false, 33)]
|
||||
public static void ShowWindowContext(MenuCommand command)
|
||||
{
|
||||
EditorWindow.GetWindow<SetReferenceID>("Set Reference ID").obj = command.context;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Enter new reference ID:", EditorStyles.boldLabel);
|
||||
id = EditorGUILayout.LongField("Reference ID", id);
|
||||
|
||||
if (GUILayout.Button("Apply"))
|
||||
{
|
||||
int setCount = 0;
|
||||
|
||||
string sceneName = null;
|
||||
|
||||
// If this is a scene object, only set the reference ID for the manager in the scene it belongs to.
|
||||
if (!EditorUtility.IsPersistent(obj))
|
||||
{
|
||||
if (obj is GameObject go)
|
||||
sceneName = go.scene.name;
|
||||
else if (obj is Component c)
|
||||
sceneName = c.gameObject.scene.name;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
var loadedScene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (loadedScene != null && loadedScene.IsValid())
|
||||
{
|
||||
if (sceneName != null && loadedScene.name != sceneName)
|
||||
continue;
|
||||
|
||||
var mgr = ES3ReferenceMgr.GetManagerFromScene(loadedScene, false);
|
||||
if (mgr != null)
|
||||
{
|
||||
Undo.RecordObject(mgr, "Changed reference ID in manager");
|
||||
mgr.Remove(obj);
|
||||
mgr.Add(obj, id);
|
||||
setCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setCount == 0)
|
||||
{
|
||||
this.Close();
|
||||
EditorUtility.DisplayDialog("Could not set reference ID", "No open scenes contain reference managers. Add a reference manager by going to Tools > Easy Save 3 > Add Manager to Scene.", "Ok");
|
||||
}
|
||||
|
||||
this.Close();
|
||||
EditorUtility.DisplayDialog($"Reference ID successfully changed", $"Reference ID changed to {id} in {setCount} managers.", "Ok");
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Set Reference ID..", true, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Set Reference ID..", true, 33)]
|
||||
private static bool CanSetReference()
|
||||
{
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.TopLevel);
|
||||
|
||||
return selected != null && selected.Length == 1 && ES3ReferenceMgr.Current != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c119866c01ca0044a7e5e08b8d22692
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
[CustomEditor(typeof(ES3AutoSave))]
|
||||
public class ES3AutoSaveEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
if (GUILayout.Button("Manage Auto Save Settings"))
|
||||
ES3Editor.ES3Window.InitAndShowAutoSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54ded3aeb20a94008a877da330bfc45f
|
||||
timeCreated: 1519132285
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
[CustomEditor(typeof(ES3AutoSaveMgr))]
|
||||
public class ES3AutoSaveMgrEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This manages the saving and loading of GameObjects which have the Auto Save component attached to them.\n\nIf there are no Auto Save components in your scene, this component will do nothing.", MessageType.Info);
|
||||
if(GUILayout.Button("Settings..."))
|
||||
ES3Editor.ES3Window.InitAndShowAutoSave();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f440317f3fd444daf83c27a3381af17c
|
||||
timeCreated: 1519132300
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class EditorStyle
|
||||
{
|
||||
private static EditorStyle style = null;
|
||||
|
||||
public GUIStyle area;
|
||||
public GUIStyle areaPadded;
|
||||
|
||||
public GUIStyle menuButton;
|
||||
public GUIStyle menuButtonSelected;
|
||||
public GUIStyle smallSquareButton;
|
||||
|
||||
public GUIStyle heading;
|
||||
public GUIStyle subheading;
|
||||
public GUIStyle subheading2;
|
||||
|
||||
public GUIStyle boldLabelNoStretch;
|
||||
|
||||
public GUIStyle link;
|
||||
|
||||
public GUIStyle toggle;
|
||||
|
||||
public Texture2D saveIconSelected;
|
||||
public Texture2D saveIconUnselected;
|
||||
|
||||
public static EditorStyle Get { get{ if(style == null) style = new EditorStyle(); return style; } }
|
||||
|
||||
public EditorStyle()
|
||||
{
|
||||
// An area with padding.
|
||||
area = new GUIStyle();
|
||||
area.padding = new RectOffset(10, 10, 10, 10);
|
||||
area.wordWrap = true;
|
||||
|
||||
// An area with more padding.
|
||||
areaPadded = new GUIStyle();
|
||||
areaPadded.padding = new RectOffset(20, 20, 20, 20);
|
||||
areaPadded.wordWrap = true;
|
||||
|
||||
// Unselected menu button.
|
||||
menuButton = new GUIStyle(EditorStyles.toolbarButton);
|
||||
menuButton.fontStyle = FontStyle.Normal;
|
||||
menuButton.fontSize = 14;
|
||||
menuButton.fixedHeight = 24;
|
||||
|
||||
// Selected menu button.
|
||||
menuButtonSelected = new GUIStyle(menuButton);
|
||||
menuButtonSelected.fontStyle = FontStyle.Bold;
|
||||
|
||||
// Main Headings
|
||||
heading = new GUIStyle(EditorStyles.label);
|
||||
heading.fontStyle = FontStyle.Bold;
|
||||
heading.fontSize = 24;
|
||||
|
||||
subheading = new GUIStyle(heading);
|
||||
subheading.fontSize = 18;
|
||||
|
||||
subheading2 = new GUIStyle(heading);
|
||||
subheading2.fontSize = 14;
|
||||
|
||||
boldLabelNoStretch = new GUIStyle(EditorStyles.label);
|
||||
boldLabelNoStretch.stretchWidth = false;
|
||||
boldLabelNoStretch.fontStyle = FontStyle.Bold;
|
||||
|
||||
link = new GUIStyle();
|
||||
link.fontSize = 16;
|
||||
if(EditorGUIUtility.isProSkin)
|
||||
link.normal.textColor = new Color (0.262f, 0.670f, 0.788f);
|
||||
else
|
||||
link.normal.textColor = new Color (0.129f, 0.129f, 0.8f);
|
||||
|
||||
toggle = new GUIStyle(EditorStyles.toggle);
|
||||
toggle.stretchWidth = false;
|
||||
|
||||
saveIconSelected = AssetDatabase.LoadAssetAtPath<Texture2D>(ES3Settings.PathToEasySaveFolder() + "Editor/es3Logo16x16.png");
|
||||
saveIconUnselected = AssetDatabase.LoadAssetAtPath<Texture2D>(ES3Settings.PathToEasySaveFolder() + "Editor/es3Logo16x16-bw.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f556addc6753344019137cbc45d2c4ff
|
||||
timeCreated: 1519132301
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ES3Internal;
|
||||
|
||||
public class ES3EditorUtility : Editor
|
||||
{
|
||||
public static void DisplayLink(string label, string url)
|
||||
{
|
||||
var style = ES3Editor.EditorStyle.Get;
|
||||
if(GUILayout.Button(label, style.link))
|
||||
Application.OpenURL(url);
|
||||
|
||||
var buttonRect = GUILayoutUtility.GetLastRect();
|
||||
buttonRect.width = style.link.CalcSize(new GUIContent(label)).x;
|
||||
|
||||
EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link);
|
||||
}
|
||||
|
||||
public static bool IsPrefabInAssets(UnityEngine.Object obj)
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
return PrefabUtility.IsPartOfPrefabAsset(obj);
|
||||
#else
|
||||
return (PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets all children and components from a GameObject or GameObjects.
|
||||
* We create our own method for this because EditorUtility.CollectDeepHierarchy isn't thread safe in the Editor.
|
||||
*/
|
||||
public static IEnumerable<UnityEngine.Object> CollectDeepHierarchy(IEnumerable<GameObject> gos)
|
||||
{
|
||||
var deepHierarchy = new HashSet<UnityEngine.Object>();
|
||||
foreach (var go in gos)
|
||||
{
|
||||
deepHierarchy.Add(go);
|
||||
deepHierarchy.UnionWith(go.GetComponents<Component>());
|
||||
foreach (Transform t in go.transform)
|
||||
deepHierarchy.UnionWith( CollectDeepHierarchy( new GameObject[] { t.gameObject } ) );
|
||||
}
|
||||
return deepHierarchy;
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Getting Started...", false, 0)]
|
||||
public static void DisplayGettingStarted()
|
||||
{
|
||||
Application.OpenURL("https://docs.moodkie.com/easy-save-3/getting-started/");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Manual...", false, 0)]
|
||||
public static void DisplayManual()
|
||||
{
|
||||
Application.OpenURL("https://docs.moodkie.com/product/easy-save-3/");
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 501719249e8124990973182985feaeb8
|
||||
timeCreated: 1519132285
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
[CustomEditor(typeof(ES3GameObject))]
|
||||
public class ES3GameObjectEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
var es3Go = (ES3GameObject)target;
|
||||
|
||||
EditorGUILayout.HelpBox("This Component allows you to choose which Components are saved when this GameObject is saved using code.", MessageType.Info);
|
||||
|
||||
if (es3Go.GetComponent<ES3AutoSave>() != null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This Component cannot be used on GameObjects which are already managed by Auto Save.", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var component in es3Go.GetComponents<Component>())
|
||||
{
|
||||
var markedToBeSaved = es3Go.components.Contains(component);
|
||||
var newMarkedToBeSaved = EditorGUILayout.Toggle(component.GetType().Name, markedToBeSaved);
|
||||
|
||||
if(markedToBeSaved && !newMarkedToBeSaved)
|
||||
{
|
||||
Undo.RecordObject(es3Go, "Marked Component to save");
|
||||
es3Go.components.Remove(component);
|
||||
}
|
||||
|
||||
if (!markedToBeSaved && newMarkedToBeSaved)
|
||||
{
|
||||
Undo.RecordObject(es3Go, "Unmarked Component to save");
|
||||
es3Go.components.Add(component);
|
||||
}
|
||||
}
|
||||
|
||||
if (es3Go.components.RemoveAll(t => t == null) > 0)
|
||||
Undo.RecordObject(es3Go, "Removed null Component from ES3GameObject");
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7d54ef20554e354eb3c0d40d2a6debe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
#if !ES3GLOBAL_DISABLED
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
[CustomEditor(typeof(ES3Internal.ES3GlobalReferences))]
|
||||
[System.Serializable]
|
||||
public class ES3GlobalReferencesEditor : Editor
|
||||
{
|
||||
private bool isDraggingOver = false;
|
||||
private bool openReferences = false;
|
||||
|
||||
private ES3Internal.ES3GlobalReferences _globalRefs = null;
|
||||
private ES3Internal.ES3GlobalReferences globalRefs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_globalRefs == null)
|
||||
_globalRefs = (ES3Internal.ES3GlobalReferences)serializedObject.targetObject;
|
||||
return _globalRefs;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This stores references to objects in Assets, allowing them to be referenced with the same ID between scenes.", MessageType.Info);
|
||||
|
||||
if (EditorGUILayout.Foldout(openReferences, "References") != openReferences)
|
||||
{
|
||||
openReferences = !openReferences;
|
||||
if (openReferences == true)
|
||||
openReferences = EditorUtility.DisplayDialog("Are you sure?", "Opening this list will display every reference in the manager, which for larger projects can cause the Editor to freeze\n\nIt is strongly recommended that you save your project before continuing.", "Open References", "Cancel");
|
||||
}
|
||||
|
||||
// Make foldout drag-and-drop enabled for objects.
|
||||
if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
|
||||
{
|
||||
Event evt = Event.current;
|
||||
|
||||
switch (evt.type)
|
||||
{
|
||||
case EventType.DragUpdated:
|
||||
case EventType.DragPerform:
|
||||
isDraggingOver = true;
|
||||
break;
|
||||
case EventType.DragExited:
|
||||
isDraggingOver = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isDraggingOver)
|
||||
{
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
|
||||
if (evt.type == EventType.DragPerform)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
Undo.RecordObject(globalRefs, "Add References to Easy Save 3 Reference List");
|
||||
foreach (UnityEngine.Object obj in DragAndDrop.objectReferences)
|
||||
globalRefs.GetOrAdd(obj);
|
||||
// Return now because otherwise we'll change the GUI during an event which doesn't allow it.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (openReferences)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
foreach (var kvp in globalRefs.refId)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.ObjectField(kvp.Key, typeof(UnityEngine.Object), true);
|
||||
EditorGUILayout.LongField(kvp.Value);
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 286fb0c3863779e4d96bc682edb324ce
|
||||
timeCreated: 1519132283
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
[CustomEditor(typeof(ES3InspectorInfo))]
|
||||
public class ES3InspectorInfoEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox(((ES3InspectorInfo)target).message, MessageType.Info);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b344d685b614044aebf5285c5f59f52d
|
||||
timeCreated: 1519132294
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+803
@@ -0,0 +1,803 @@
|
||||
#if PLAYMAKER_1_8_OR_NEWER
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using HutongGames.PlayMaker;
|
||||
using HutongGames.PlayMaker.Actions;
|
||||
using HutongGames.PlayMakerEditor;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ES3PlayMaker
|
||||
{
|
||||
#region Base Actions
|
||||
|
||||
public abstract class BaseEditor : CustomActionEditor
|
||||
{
|
||||
bool showErrorHandling = false;
|
||||
|
||||
public abstract void DrawGUI();
|
||||
|
||||
public override bool OnGUI()
|
||||
{
|
||||
DrawGUI();
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
showErrorHandling = EditorGUILayout.Foldout(showErrorHandling, "Error Handling");
|
||||
if (showErrorHandling)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditField("errorEvent");
|
||||
EditField("errorMessage");
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
return GUI.changed;
|
||||
}
|
||||
|
||||
// Displays the FsmVar field without the unnecessary Type field.
|
||||
protected void FsmVarField(string fieldName)
|
||||
{
|
||||
if (target == null || target.State == null)
|
||||
return;
|
||||
|
||||
var fsmVar = (FsmVar)ES3Internal.ES3Reflection.GetField(target.GetType(), fieldName).GetValue(target);
|
||||
|
||||
if (fsmVar == null)
|
||||
{
|
||||
fsmVar = new FsmVar();
|
||||
ES3Internal.ES3Reflection.GetField(target.GetType(), fieldName).SetValue(target, fsmVar);
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
var label = Regex.Replace(fieldName, @"\p{Lu}", m => " " + m.Value.ToLowerInvariant());
|
||||
EditorGUILayout.PrefixLabel(char.ToUpperInvariant(label[0]) + label.Substring(1));
|
||||
|
||||
var localVariables = target.Fsm.Variables.GetAllNamedVariablesSorted();
|
||||
var globalVariables = FsmVariables.GlobalVariables.GetAllNamedVariablesSorted();
|
||||
|
||||
var variableNames = new string[localVariables.Length + globalVariables.Length];
|
||||
int selected = -1;
|
||||
|
||||
for(int i=0; i<variableNames.Length; i++)
|
||||
{
|
||||
var variable = i >= localVariables.Length ? globalVariables[i - localVariables.Length] : localVariables[i];
|
||||
variableNames[i] = i >= localVariables.Length ? "Globals/"+variable.Name : variable.Name;
|
||||
if (fsmVar.NamedVar == variable)
|
||||
selected = i;
|
||||
}
|
||||
|
||||
var newSelected = EditorGUILayout.Popup(selected, variableNames);
|
||||
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (newSelected == -1)
|
||||
return;
|
||||
|
||||
if (selected != newSelected)
|
||||
{
|
||||
if (newSelected >= localVariables.Length)
|
||||
fsmVar.NamedVar = globalVariables[newSelected - localVariables.Length];
|
||||
else
|
||||
fsmVar.NamedVar = localVariables[newSelected];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SettingsEditor : BaseEditor
|
||||
{
|
||||
public override bool OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
return DrawSettingsEditor();
|
||||
}
|
||||
|
||||
public bool DrawSettingsEditor()
|
||||
{
|
||||
var action = target as ES3PlayMaker.SettingsAction;
|
||||
if (action == null)
|
||||
return false;
|
||||
action.overrideDefaultSettings.Value = EditorGUILayout.ToggleLeft("Override Default Settings", action.overrideDefaultSettings.Value);
|
||||
|
||||
if (action.overrideDefaultSettings.Value)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditField("path");
|
||||
EditField("location");
|
||||
EditField("encryptionType");
|
||||
EditField("encryptionPassword");
|
||||
EditField("compressionType");
|
||||
EditField("directory");
|
||||
EditField("format");
|
||||
EditField("bufferSize");
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
return GUI.changed;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class KeyValueSettingsEditor : SettingsEditor
|
||||
{
|
||||
public override bool OnGUI()
|
||||
{
|
||||
EditField("key");
|
||||
EditField("value");
|
||||
|
||||
base.OnGUI();
|
||||
|
||||
return GUI.changed;
|
||||
}
|
||||
|
||||
public override void DrawGUI(){}
|
||||
}
|
||||
|
||||
public abstract class ES3FileActionEditor : BaseEditor
|
||||
{
|
||||
public override bool OnGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
|
||||
base.OnGUI();
|
||||
|
||||
var action = target as ES3PlayMaker.ES3FileAction;
|
||||
if (action == null)
|
||||
return false;
|
||||
|
||||
return GUI.changed;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#if !PLAYMAKER_1_9_OR_NEWER
|
||||
#region Save Actions
|
||||
|
||||
/*[CustomActionEditor(typeof(ES3PlayMaker.Save))]
|
||||
public class SaveEditor : KeyValueSettingsEditor{}*/
|
||||
|
||||
/*[CustomActionEditor(typeof(ES3PlayMaker.SaveMultiple))]
|
||||
public class SaveMultipleEditor : SettingsEditor
|
||||
{
|
||||
public override bool OnGUI()
|
||||
{
|
||||
return base.OnGUI();
|
||||
}
|
||||
|
||||
public override void DrawGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
}
|
||||
}*/
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.SaveAll))]
|
||||
public class SaveAllEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("key");
|
||||
EditField("saveFsmVariables");
|
||||
EditField("saveGlobalVariables");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.SaveRaw))]
|
||||
public class SaveRawEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("str");
|
||||
EditField("useBase64Encoding");
|
||||
EditField("appendNewline");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.AppendRaw))]
|
||||
public class AppendRawEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("str");
|
||||
EditField("useBase64Encoding");
|
||||
EditField("appendNewline");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.SaveImage))]
|
||||
public class SaveImageEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("imagePath");
|
||||
EditField("texture2D");
|
||||
EditField("quality");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Load Actions
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.Load))]
|
||||
public class LoadEditor : KeyValueSettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditField("defaultValue");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.LoadInto))]
|
||||
public class LoadIntoEditor : KeyValueSettingsEditor{}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.LoadAll))]
|
||||
public class LoadAllEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("key");
|
||||
EditField("loadFsmVariables");
|
||||
EditField("loadGlobalVariables");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.LoadAudio))]
|
||||
public class LoadAudioEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("audioFilePath");
|
||||
EditField("audioClip");
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
EditField("audioType");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.LoadImage))]
|
||||
public class LoadImageEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("imagePath");
|
||||
EditField("texture2D");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.LoadRawString))]
|
||||
public class LoadRawStringEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("str");
|
||||
EditField("useBase64Encoding");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Exists Actions
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.KeyExists))]
|
||||
public class KeyExistsEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("key");
|
||||
EditField("exists");
|
||||
EditorGUILayout.Separator();
|
||||
EditField("existsEvent");
|
||||
EditField("doesNotExistEvent");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.FileExists))]
|
||||
public class FileExistsEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
EditField("exists");
|
||||
EditorGUILayout.Separator();
|
||||
EditField("existsEvent");
|
||||
EditField("doesNotExistEvent");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.DirectoryExists))]
|
||||
public class DirectoryExistsEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("directoryPath");
|
||||
EditField("exists");
|
||||
EditorGUILayout.Separator();
|
||||
EditField("existsEvent");
|
||||
EditField("doesNotExistEvent");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete Actions
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.DeleteKey))]
|
||||
public class DeleteKeyEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("key");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.DeleteFile))]
|
||||
public class DeleteFileEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.DeleteDirectory))]
|
||||
public class DeleteDirectoryEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("directoryPath");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Backup Actions
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.CreateBackup))]
|
||||
public class CreateBackupEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.RestoreBackup))]
|
||||
public class RestoreBackupEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
EditField("backupWasRestored");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Key, File and Directory methods
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.RenameFile))]
|
||||
public class RenameFileEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("oldFilePath");
|
||||
EditField("newFilePath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.CopyFile))]
|
||||
public class CopyFileEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("oldFilePath");
|
||||
EditField("newFilePath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.CopyDirectory))]
|
||||
public class CopyDirectoryEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("oldDirectoryPath");
|
||||
EditField("newDirectoryPath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.GetKeys))]
|
||||
public class GetKeysEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
EditField("keys");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.GetKeyCount))]
|
||||
public class GetKeyCountEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
EditField("keyCount");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.GetFiles))]
|
||||
public class GetFilesEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("directoryPath");
|
||||
EditField("files");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.GetDirectories))]
|
||||
public class GetDirectoriesEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("directoryPath");
|
||||
EditField("directories");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ES3File Actions
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileCreate))]
|
||||
public class ES3FileCreateEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
EditField("filePath");
|
||||
EditField("syncWithFile");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileSync))]
|
||||
public class ES3FileSyncEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
}
|
||||
}
|
||||
|
||||
/*[CustomActionEditor(typeof(ES3PlayMaker.ES3FileSave))]
|
||||
public class ES3FileSaveEditor : SaveEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
base.DrawGUI();
|
||||
}
|
||||
}*/
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileLoad))]
|
||||
public class ES3FileLoadEditor : LoadEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
base.DrawGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileLoadInto))]
|
||||
public class ES3FileLoadIntoEditor : LoadIntoEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
base.DrawGUI();
|
||||
EditField("fsmES3File");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileDeleteKey))]
|
||||
public class ES3FileDeleteKeyEditor : DeleteKeyEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
base.DrawGUI();
|
||||
EditField("fsmES3File");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileKeyExists))]
|
||||
public class ES3FileKeyExistsEditor : KeyExistsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
base.DrawGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileGetKeys))]
|
||||
public class ES3FileGetKeysEditor : ES3FileActionEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("keys");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileClear))]
|
||||
public class ES3FileClearEditor : BaseEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3FileSize))]
|
||||
public class ES3FileSizeEditor : BaseEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("size");
|
||||
EditField("fsmES3File");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ES3Cloud Actions
|
||||
#if !DISABLE_WEB
|
||||
|
||||
public abstract class ES3CloudEditor : SettingsEditor
|
||||
{
|
||||
protected abstract void DrawChildGUI();
|
||||
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("url");
|
||||
EditField("apiKey");
|
||||
EditorGUILayout.Space();
|
||||
DrawChildGUI();
|
||||
EditorGUILayout.Space();
|
||||
EditField("errorCode");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class ES3CloudUserEditor : ES3CloudEditor
|
||||
{
|
||||
public bool showUser = false;
|
||||
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
if((showUser = EditorGUILayout.Foldout(showUser, "User (optional)")))
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditField("user");
|
||||
EditField("password");
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudSync))]
|
||||
public class ES3CloudSyncEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("path");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudDownloadFile))]
|
||||
public class ES3CloudDownloadFileEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("path");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudDownloadES3File))]
|
||||
public class ES3CloudDownloadES3FileEditor : BaseEditor
|
||||
{
|
||||
public bool showUser = false;
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
EditField("url");
|
||||
EditField("apiKey");
|
||||
EditField("errorCode");
|
||||
if ((showUser = EditorGUILayout.Foldout(showUser, "User (optional)")))
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditField("user");
|
||||
EditField("password");
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudUploadFile))]
|
||||
public class ES3CloudUploadFileEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("path");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudUploadES3File))]
|
||||
public class ES3CloudUploadES3FileEditor : BaseEditor
|
||||
{
|
||||
public bool showUser = false;
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3File");
|
||||
EditField("url");
|
||||
EditField("apiKey");
|
||||
EditField("errorCode");
|
||||
if((showUser = EditorGUILayout.Foldout(showUser, "User (optional)")))
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditField("user");
|
||||
EditField("password");
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudDeleteFile))]
|
||||
public class ES3CloudDeleteFileEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("path");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudRenameFile))]
|
||||
public class ES3CloudRenameFileEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("path");
|
||||
EditField("newFilename");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudDownloadFilenames))]
|
||||
public class ES3CloudDownloadFilenamesEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("filenames");
|
||||
EditField("searchPattern");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudSearchFilenames))]
|
||||
public class ES3CloudSearchFilenamesEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("filenames");
|
||||
EditField("searchPattern");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3CloudDownloadTimestamp))]
|
||||
public class ES3CloudDownloadTimestampEditor : ES3CloudUserEditor
|
||||
{
|
||||
protected override void DrawChildGUI()
|
||||
{
|
||||
EditField("path");
|
||||
EditField("timestamp");
|
||||
base.DrawChildGUI();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region ES3SpreadsheetActions
|
||||
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3SpreadsheetCreate))]
|
||||
public class ES3SpreadsheetCreateEditor : BaseEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3Spreadsheet");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3SpreadsheetSetCell))]
|
||||
public class ES3SpreadsheetSetCellEditor : BaseEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3Spreadsheet");
|
||||
EditField("col");
|
||||
EditField("row");
|
||||
EditField("value");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3SpreadsheetGetCell))]
|
||||
public class ES3SpreadsheetGetCellEditor : BaseEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3Spreadsheet");
|
||||
EditField("col");
|
||||
EditField("row");
|
||||
EditField("value");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3SpreadsheetLoad))]
|
||||
public class ES3SpreadsheetLoadEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3Spreadsheet");
|
||||
EditField("filePath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.ES3SpreadsheetSave))]
|
||||
public class ES3SpreadsheetSaveEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("fsmES3Spreadsheet");
|
||||
EditField("filePath");
|
||||
EditField("append");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Caching
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.CacheFile))]
|
||||
public class CacheFileEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
}
|
||||
}
|
||||
|
||||
[CustomActionEditor(typeof(ES3PlayMaker.StoreCachedFile))]
|
||||
public class StoreCachedFileEditor : SettingsEditor
|
||||
{
|
||||
public override void DrawGUI()
|
||||
{
|
||||
EditField("filePath");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61838eb75b8164d699b0f54416e0f0bc
|
||||
timeCreated: 1497347459
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,269 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using ES3Internal;
|
||||
|
||||
|
||||
/*
|
||||
* ---- How Postprocessing works for the reference manager ----
|
||||
* - When the manager is first added to the scene, all top-level dependencies are added to the manager (AddManagerToScene).
|
||||
* - When the manager is first added to the scene, all prefabs with ES3Prefab components are added to the manager (AddManagerToScene).
|
||||
* - All GameObjects and Components in the scene are added to the reference manager when we enter Playmode or the scene is saved (PlayModeStateChanged, OnWillSaveAssets -> AddGameObjectsAndComponentstoManager).
|
||||
* - When a UnityEngine.Object field of a Component is modified, the new UnityEngine.Object reference is added to the reference manager (PostProcessModifications)
|
||||
* - All prefabs with ES3Prefab Components are added to the reference manager when we enter Playmode or the scene is saved (PlayModeStateChanged, OnWillSaveAssets -> AddGameObjectsAndComponentstoManager).
|
||||
* - Local references for prefabs are processed whenever a prefab with an ES3Prefab Component is deselected (SelectionChanged -> ProcessGameObject)
|
||||
*/
|
||||
[InitializeOnLoad]
|
||||
public class ES3Postprocessor : UnityEditor.AssetModificationProcessor
|
||||
{
|
||||
public static GameObject lastSelected = null;
|
||||
|
||||
|
||||
// This constructor is also called once when playmode is activated and whenever recompilation happens
|
||||
// because we have the [InitializeOnLoad] attribute assigned to the class.
|
||||
static ES3Postprocessor()
|
||||
{
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
ObjectChangeEvents.changesPublished += Changed;
|
||||
#endif
|
||||
ObjectFactory.componentWasAdded += ComponentWasAdded;
|
||||
|
||||
// Open the Easy Save 3 window the first time ES3 is installed.
|
||||
//ES3Editor.ES3Window.OpenEditorWindowOnStart();
|
||||
|
||||
EditorApplication.playModeStateChanged -= PlayModeStateChanged;
|
||||
EditorApplication.playModeStateChanged += PlayModeStateChanged;
|
||||
|
||||
EditorSceneManager.sceneOpened += OnSceneOpened;
|
||||
}
|
||||
|
||||
#region Reference Updating
|
||||
|
||||
private static void PlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingEditMode)
|
||||
UpdateAssembliesContainingES3Types();
|
||||
}
|
||||
|
||||
private static void OnSceneOpened(Scene scene, OpenSceneMode mode)
|
||||
{
|
||||
if (mode == OpenSceneMode.AdditiveWithoutLoading || Application.isPlaying)
|
||||
return;
|
||||
|
||||
if (ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences && ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneIsOpened)
|
||||
RefreshScene(scene);
|
||||
}
|
||||
|
||||
private static void RefreshReferences(bool isEnteringPlayMode = false)
|
||||
{
|
||||
/*if (refreshed) // If we've already refreshed, do nothing.
|
||||
return;*/
|
||||
|
||||
if (ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences)
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
RefreshScene(SceneManager.GetSceneAt(i));
|
||||
//refreshed = true;
|
||||
}
|
||||
|
||||
static void RefreshScene(Scene scene, bool isEnteringPlayMode = false)
|
||||
{
|
||||
if (scene != null && scene.isLoaded)
|
||||
{
|
||||
var mgr = (ES3ReferenceMgr)ES3ReferenceMgr.GetManagerFromScene(scene, false);
|
||||
if (mgr != null)
|
||||
mgr.RefreshDependencies(isEnteringPlayMode);
|
||||
}
|
||||
}
|
||||
|
||||
static void ComponentWasAdded(Component c)
|
||||
{
|
||||
var scene = c.gameObject.scene;
|
||||
|
||||
if (!scene.isLoaded)
|
||||
return;
|
||||
|
||||
var mgr = (ES3ReferenceMgr)ES3ReferenceMgr.GetManagerFromScene(scene, false);
|
||||
|
||||
if (mgr != null && ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences && ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneChanges)
|
||||
mgr.AddDependencies(c);
|
||||
}
|
||||
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
static void Changed(ref ObjectChangeEventStream stream)
|
||||
{
|
||||
if (EditorApplication.isUpdating || Application.isPlaying || !ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences || !ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneChanges)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < stream.length; i++)
|
||||
{
|
||||
var eventType = stream.GetEventType(i);
|
||||
int[] instanceIds;
|
||||
Scene scene;
|
||||
|
||||
if (eventType == ObjectChangeKind.ChangeGameObjectOrComponentProperties)
|
||||
{
|
||||
ChangeGameObjectOrComponentPropertiesEventArgs evt;
|
||||
stream.GetChangeGameObjectOrComponentPropertiesEvent(i, out evt);
|
||||
instanceIds = new int[] { evt.instanceId };
|
||||
scene = evt.scene;
|
||||
}
|
||||
else if (eventType == ObjectChangeKind.CreateGameObjectHierarchy)
|
||||
{
|
||||
CreateGameObjectHierarchyEventArgs evt;
|
||||
stream.GetCreateGameObjectHierarchyEvent(i, out evt);
|
||||
instanceIds = new int[] { evt.instanceId };
|
||||
scene = evt.scene;
|
||||
}
|
||||
/*else if (eventType == ObjectChangeKind.ChangeAssetObjectProperties)
|
||||
{
|
||||
ChangeAssetObjectPropertiesEventArgs evt;
|
||||
stream.GetChangeAssetObjectPropertiesEvent(i, out evt);
|
||||
instanceIds = new int[] { evt.instanceId };
|
||||
}*/
|
||||
else if (eventType == ObjectChangeKind.UpdatePrefabInstances)
|
||||
{
|
||||
UpdatePrefabInstancesEventArgs evt;
|
||||
stream.GetUpdatePrefabInstancesEvent(i, out evt);
|
||||
instanceIds = evt.instanceIds.ToArray();
|
||||
scene = evt.scene;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
var mgr = (ES3ReferenceMgr)ES3ReferenceMgr.GetManagerFromScene(scene, false);
|
||||
|
||||
if (mgr == null)
|
||||
return;
|
||||
|
||||
foreach (var id in instanceIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = EditorUtility.InstanceIDToObject(id);
|
||||
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
mgr.AddDependencies(obj);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*public static void PlayModeStateChanged(PlayModeStateChange state)
|
||||
{
|
||||
// Add all GameObjects and Components to the reference manager before we enter play mode.
|
||||
if (state == PlayModeStateChange.ExitingEditMode && ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences)
|
||||
RefreshReferences(true);
|
||||
}*/
|
||||
|
||||
public static string[] OnWillSaveAssets(string[] paths)
|
||||
{
|
||||
// Don't refresh references when the application is playing.
|
||||
if (!EditorApplication.isUpdating && !Application.isPlaying)
|
||||
{
|
||||
if(ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences && ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneIsSaved)
|
||||
RefreshReferences();
|
||||
UpdateAssembliesContainingES3Types();
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private static void UpdateAssembliesContainingES3Types()
|
||||
{
|
||||
var assemblies = UnityEditor.Compilation.CompilationPipeline.GetAssemblies();
|
||||
|
||||
if (assemblies == null || assemblies.Length == 0)
|
||||
return;
|
||||
|
||||
var defaults = ES3Settings.defaultSettingsScriptableObject;
|
||||
var currentAssemblyNames = defaults.settings.assemblyNames;
|
||||
|
||||
var assemblyNames = new List<string>();
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
// Don't include Editor assemblies.
|
||||
if (assembly.flags.HasFlag(UnityEditor.Compilation.AssemblyFlags.EditorAssembly))
|
||||
continue;
|
||||
|
||||
// Assemblies beginning with 'com.' are assumed to be internal.
|
||||
if (assembly.name.StartsWith("com."))
|
||||
continue;
|
||||
|
||||
// If this assembly begins with 'Unity', but isn't created from an Assembly Definition File, skip it.
|
||||
if (assembly.name.StartsWith("Unity"))
|
||||
{
|
||||
bool isAssemblyDefinition = true;
|
||||
|
||||
foreach (string sourceFile in assembly.sourceFiles)
|
||||
{
|
||||
if (!sourceFile.StartsWith("Assets/"))
|
||||
{
|
||||
isAssemblyDefinition = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAssemblyDefinition)
|
||||
continue;
|
||||
}
|
||||
|
||||
assemblyNames.Add(assembly.name);
|
||||
}
|
||||
|
||||
// If there are no assembly names,
|
||||
if (assemblyNames.Count == 0)
|
||||
return;
|
||||
|
||||
// Sort it alphabetically so that the order isn't constantly changing, which can affect version control.
|
||||
assemblyNames.Sort();
|
||||
|
||||
// Only update if the list has changed.
|
||||
for (int i = 0; i < assemblyNames.Count; i++)
|
||||
{
|
||||
if (currentAssemblyNames.Length != assemblyNames.Count || currentAssemblyNames[i] != assemblyNames[i])
|
||||
{
|
||||
defaults.settings.assemblyNames = assemblyNames.ToArray();
|
||||
EditorUtility.SetDirty(defaults);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GameObject AddManagerToScene()
|
||||
{
|
||||
GameObject mgr = null;
|
||||
|
||||
var mgrComponent = ES3ReferenceMgr.GetManagerFromScene(SceneManager.GetActiveScene(), false);
|
||||
if (mgrComponent != null)
|
||||
mgr = mgrComponent.gameObject;
|
||||
|
||||
if (mgr == null)
|
||||
mgr = new GameObject("Easy Save 3 Manager");
|
||||
|
||||
if (mgr.GetComponent<ES3ReferenceMgr>() == null)
|
||||
{
|
||||
var refMgr = mgr.AddComponent<ES3ReferenceMgr>();
|
||||
|
||||
if (!Application.isPlaying && ES3Settings.defaultSettingsScriptableObject.autoUpdateReferences)
|
||||
refMgr.RefreshDependencies();
|
||||
}
|
||||
|
||||
if (mgr.GetComponent<ES3AutoSaveMgr>() == null)
|
||||
mgr.AddComponent<ES3AutoSaveMgr>();
|
||||
|
||||
Undo.RegisterCreatedObjectUndo(mgr, "Enabled Easy Save for Scene");
|
||||
return mgr;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4256380692bcb4e57bdc0a5e13956389
|
||||
timeCreated: 1474041535
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using ES3Internal;
|
||||
|
||||
[CustomEditor(typeof(ES3Prefab))]
|
||||
[System.Serializable]
|
||||
public class ES3PrefabEditor : Editor
|
||||
{
|
||||
bool showAdvanced = false;
|
||||
bool openLocalRefs = false;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var es3Prefab = (ES3Prefab)serializedObject.targetObject;
|
||||
EditorGUILayout.HelpBox("Easy Save is enabled for this prefab, and can be saved and loaded with the ES3 methods.", MessageType.None);
|
||||
|
||||
|
||||
showAdvanced = EditorGUILayout.Foldout(showAdvanced, "Advanced Settings");
|
||||
if(showAdvanced)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
es3Prefab.prefabId = EditorGUILayout.LongField("Prefab ID", es3Prefab.prefabId);
|
||||
EditorGUILayout.LabelField("Reference count", es3Prefab.localRefs.Count.ToString());
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
openLocalRefs = EditorGUILayout.Foldout(openLocalRefs, "localRefs");
|
||||
if (openLocalRefs)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUILayout.LabelField("It is not recommended to manually modify these.");
|
||||
|
||||
foreach (var kvp in es3Prefab.localRefs)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.ObjectField(kvp.Key, typeof(UnityEngine.Object), false);
|
||||
EditorGUILayout.LongField(kvp.Value);
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d25610c9233c4cdfa5a0744c9956f5c
|
||||
timeCreated: 1519132292
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[CustomEditor(typeof(ES3ReferenceMgr))]
|
||||
[System.Serializable]
|
||||
public class ES3ReferenceMgrEditor : Editor
|
||||
{
|
||||
private bool isDraggingOver = false;
|
||||
private bool openReferences = false;
|
||||
|
||||
private ES3ReferenceMgr _mgr = null;
|
||||
private ES3ReferenceMgr mgr
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mgr == null)
|
||||
_mgr = (ES3ReferenceMgr)serializedObject.targetObject;
|
||||
return _mgr;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This allows Easy Save to maintain references to objects in your scene.\n\nIt is automatically updated when you enter Playmode or build your project.", MessageType.Info);
|
||||
|
||||
if (EditorGUILayout.Foldout(openReferences, "References") != openReferences)
|
||||
{
|
||||
openReferences = !openReferences;
|
||||
if (openReferences == true)
|
||||
openReferences = EditorUtility.DisplayDialog("Are you sure?", "Opening this list will display every reference in the manager, which for larger projects can cause the Editor to freeze\n\nIt is strongly recommended that you save your project before continuing.", "Open References", "Cancel");
|
||||
}
|
||||
|
||||
// Make foldout drag-and-drop enabled for objects.
|
||||
if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
|
||||
{
|
||||
Event evt = Event.current;
|
||||
|
||||
switch (evt.type)
|
||||
{
|
||||
case EventType.DragUpdated:
|
||||
case EventType.DragPerform:
|
||||
isDraggingOver = true;
|
||||
break;
|
||||
case EventType.DragExited:
|
||||
isDraggingOver = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isDraggingOver)
|
||||
{
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
|
||||
if (evt.type == EventType.DragPerform)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
Undo.RecordObject(mgr, "Add References to Easy Save 3 Reference List");
|
||||
foreach (UnityEngine.Object obj in DragAndDrop.objectReferences)
|
||||
mgr.Add(obj);
|
||||
// Return now because otherwise we'll change the GUI during an event which doesn't allow it.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (openReferences)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
foreach (var kvp in mgr.idRef)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
var value = EditorGUILayout.ObjectField(kvp.Value, typeof(UnityEngine.Object), true);
|
||||
var key = EditorGUILayout.LongField(kvp.Key);
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (value != kvp.Value || key != kvp.Key)
|
||||
{
|
||||
Undo.RecordObject(mgr, "Change Easy Save 3 References");
|
||||
// If we're deleting a value, delete it.
|
||||
if (value == null)
|
||||
mgr.Remove(key);
|
||||
// Else, update the ID.
|
||||
else
|
||||
mgr.ChangeId(kvp.Key, key);
|
||||
// Break, as removing or changing Dictionary items will make the foreach out of sync.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
mgr.openPrefabs = EditorGUILayout.Foldout(mgr.openPrefabs, "ES3Prefabs");
|
||||
if (mgr.openPrefabs)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
foreach (var prefab in mgr.prefabs)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.ObjectField(prefab, typeof(UnityEngine.Object), true);
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
var sp = serializedObject.FindProperty("excludeObjects");
|
||||
EditorGUILayout.PropertyField(sp);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.LabelField("Reference count", mgr.refId.Count.ToString());
|
||||
EditorGUILayout.LabelField("Prefab count", mgr.prefabs.Count.ToString());
|
||||
|
||||
if (GUILayout.Button("Refresh"))
|
||||
{
|
||||
mgr.RefreshDependencies();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Optimize"))
|
||||
{
|
||||
mgr.Optimize();
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Add Dependencies to Manager", false, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Add Dependencies to Manager", false, 33)]
|
||||
public static void AddDependenciesToManager()
|
||||
{
|
||||
var mgr = ES3ReferenceMgr.GetManagerFromScene(SceneManager.GetActiveScene());
|
||||
if (mgr == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Could not add reference to manager", "This object could not be added to the reference manager because no reference manager exists in this scene. To create one, go to Tools > Easy Save 3 > Add Manager to Scene", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = new HashSet<UnityEngine.Object>(Selection.GetFiltered<UnityEngine.Object>(SelectionMode.DeepAssets));
|
||||
selected.UnionWith(Selection.GetFiltered<UnityEngine.Object>(SelectionMode.TopLevel));
|
||||
|
||||
if (selected == null || selected.Count == 0)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(mgr, "Update Easy Save 3 Reference Manager");
|
||||
|
||||
foreach (var obj in selected)
|
||||
{
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
if (obj.GetType() == typeof(GameObject))
|
||||
{
|
||||
var go = (GameObject)obj;
|
||||
if (ES3EditorUtility.IsPrefabInAssets(go) && go.GetComponent<ES3Internal.ES3Prefab>() != null)
|
||||
mgr.AddPrefab(go.GetComponent<ES3Internal.ES3Prefab>());
|
||||
}
|
||||
|
||||
((ES3ReferenceMgr)mgr).AddDependencies(obj);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Add Reference(s) to Manager", false, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Add Reference(s) to Manager", false, 33)]
|
||||
public static void AddReferencesToManager()
|
||||
{
|
||||
var mgr = ES3ReferenceMgr.Current;
|
||||
if (mgr == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Could not add reference to manager", "This object could not be added to the reference manager because no reference manager exists in this scene. To create one, go to Tools > Easy Save 3 > Add Manager to Scene", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.TopLevel);
|
||||
|
||||
if (selected == null || selected.Length == 0)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(mgr, "Update Easy Save 3 Reference Manager");
|
||||
|
||||
foreach (var obj in selected)
|
||||
{
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
if (obj.GetType() == typeof(GameObject))
|
||||
{
|
||||
var go = (GameObject)obj;
|
||||
if (ES3EditorUtility.IsPrefabInAssets(go) && go.GetComponent<ES3Internal.ES3Prefab>() != null)
|
||||
mgr.AddPrefab(go.GetComponent<ES3Internal.ES3Prefab>());
|
||||
}
|
||||
|
||||
((ES3ReferenceMgr)mgr).Add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Add Reference(s) to Manager", true, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Add Reference(s) to Manager", true, 33)]
|
||||
[MenuItem("GameObject/Easy Save 3/Add Dependencies to Manager", true, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Add Dependencies to Manager", true, 33)]
|
||||
private static bool CanAddReferenceToManager()
|
||||
{
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.Deep);
|
||||
return selected != null && selected.Length > 0 && ES3ReferenceMgr.Current != null;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Exclude Reference(s) from Manager", false, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Exclude Reference(s) from Manager", false, 33)]
|
||||
public static void ExcludeReferenceFromManager()
|
||||
{
|
||||
var mgr = (ES3ReferenceMgr)ES3ReferenceMgr.Current;
|
||||
if (mgr == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Could not exclude reference from manager", "This object could not be excluded from the reference manager because no reference manager exists in this scene. To create one, go to Tools > Easy Save 3 > Add Manager to Scene", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.TopLevel);
|
||||
|
||||
if (selected == null || selected.Length == 0)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(mgr, "Exclude from Easy Save 3 Reference Manager");
|
||||
|
||||
foreach (var obj in selected)
|
||||
{
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
mgr.ExcludeObject(obj);
|
||||
}
|
||||
|
||||
mgr.RemoveNullOrInvalidValues();
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Exclude Dependencies from Manager", false, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Exclude Dependencies from Manager", false, 33)]
|
||||
public static void ExcludeDependenciesFromManager()
|
||||
{
|
||||
var mgr = (ES3ReferenceMgr)ES3ReferenceMgr.Current;
|
||||
if (mgr == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Could not exclude reference from manager", "This object could not be excluded from the reference manager because no reference manager exists in this scene. To create one, go to Tools > Easy Save 3 > Add Manager to Scene", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.TopLevel);
|
||||
|
||||
if (selected == null || selected.Length == 0)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(mgr, "Exclude from Easy Save 3 Reference Manager");
|
||||
|
||||
var dependencies = EditorUtility.CollectDependencies(selected);
|
||||
|
||||
foreach (var dependency in dependencies)
|
||||
mgr.ExcludeObject(dependency);
|
||||
|
||||
mgr.RemoveNullOrInvalidValues();
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Exclude Dependencies from Manager", true, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Exclude Dependencies from Manager", true, 33)]
|
||||
[MenuItem("GameObject/Easy Save 3/Exclude Reference(s) from Manager", true, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Exclude Reference(s) from Manager", true, 33)]
|
||||
private static bool CanExcludeReferencesFromManager()
|
||||
{
|
||||
var selected = Selection.GetFiltered<UnityEngine.Object>(SelectionMode.Deep);
|
||||
return selected != null && selected.Length > 0 && ES3ReferenceMgr.Current != null;
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Add Manager to Scene", false, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Add Manager to Scene", false, 33)]
|
||||
[MenuItem("Tools/Easy Save 3/Add Manager to Scene", false, 150)]
|
||||
public static void EnableForScene()
|
||||
{
|
||||
if(!SceneManager.GetActiveScene().isLoaded)
|
||||
EditorUtility.DisplayDialog("Could not add manager to scene", "Could not add Easy Save 3 Manager to scene because there is not currently a scene open.", "Ok");
|
||||
Selection.activeObject = ES3Postprocessor.AddManagerToScene();
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Easy Save 3/Add Manager to Scene", true, 33)]
|
||||
[MenuItem("Assets/Easy Save 3/Add Manager to Scene", true, 33)]
|
||||
[MenuItem("Tools/Easy Save 3/Add Manager to Scene", true, 150)]
|
||||
private static bool CanEnableForScene()
|
||||
{
|
||||
return ES3ReferenceMgr.GetManagerFromScene(SceneManager.GetActiveScene(), false) == null;
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b43d266ed3464dedaa77757645ad61c
|
||||
timeCreated: 1519132283
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Build;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Compilation;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public class ES3ScriptingDefineSymbols
|
||||
{
|
||||
static ES3ScriptingDefineSymbols()
|
||||
{
|
||||
SetDefineSymbols();
|
||||
}
|
||||
|
||||
static void SetDefineSymbols()
|
||||
{
|
||||
if (Type.GetType("Unity.VisualScripting.IncludeInSettingsAttribute, Unity.VisualScripting.Core") != null)
|
||||
SetDefineSymbol("UNITY_VISUAL_SCRIPTING");
|
||||
|
||||
if (Type.GetType("Ludiq.IncludeInSettingsAttribute, Ludiq.Core.Runtime") != null)
|
||||
SetDefineSymbol("BOLT_VISUAL_SCRIPTING");
|
||||
|
||||
if (Type.GetType("TMPro.TextMeshProUGUI, Unity.TextMeshPro") != null)
|
||||
SetDefineSymbol("ES3_TMPRO");
|
||||
|
||||
if (Type.GetType("UnityEngine.EventSystems.EventSystem, UnityEngine.UI") != null)
|
||||
SetDefineSymbol("ES3_UGUI");
|
||||
}
|
||||
|
||||
internal static bool HasDefineSymbol(string symbol)
|
||||
{
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
foreach (var target in GetAllNamedBuildTargets())
|
||||
{
|
||||
string[] defines;
|
||||
try
|
||||
{
|
||||
PlayerSettings.GetScriptingDefineSymbols(target, out defines);
|
||||
if (defines.Contains(symbol))
|
||||
return true;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#else
|
||||
string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
var allDefines = new HashSet<string>(definesString.Split(';'));
|
||||
if (allDefines.Contains(symbol))
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static void SetDefineSymbol(string symbol)
|
||||
{
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
foreach (var target in GetAllNamedBuildTargets())
|
||||
{
|
||||
string[] defines;
|
||||
try
|
||||
{
|
||||
PlayerSettings.GetScriptingDefineSymbols(target, out defines);
|
||||
if (!defines.Contains(symbol))
|
||||
{
|
||||
ArrayUtility.Add(ref defines, symbol);
|
||||
PlayerSettings.SetScriptingDefineSymbols(target, defines);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#else
|
||||
string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
var allDefines = new HashSet<string>(definesString.Split(';'));
|
||||
if (!allDefines.Contains(symbol))
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", allDefines.Concat(new string[] { symbol }).ToArray()));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
internal static void RemoveDefineSymbol(string symbol)
|
||||
{
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
foreach (var target in GetAllNamedBuildTargets())
|
||||
{
|
||||
string[] defines;
|
||||
try
|
||||
{
|
||||
PlayerSettings.GetScriptingDefineSymbols(target, out defines);
|
||||
ArrayUtility.Remove(ref defines, symbol);
|
||||
PlayerSettings.SetScriptingDefineSymbols(target, defines);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#else
|
||||
string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
definesString.Replace(symbol + ";", ""); // With semicolon
|
||||
definesString.Replace(symbol, ""); // Without semicolon
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, definesString);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
static List<NamedBuildTarget> GetAllNamedBuildTargets()
|
||||
{
|
||||
var staticFields = typeof(NamedBuildTarget).GetFields(BindingFlags.Public | BindingFlags.Static);
|
||||
var buildTargets = new List<NamedBuildTarget>();
|
||||
|
||||
foreach (var staticField in staticFields)
|
||||
{
|
||||
// We exclude 'Unknown' because this can throw errors when used with certain methods.
|
||||
if (staticField.Name == "Unknown")
|
||||
continue;
|
||||
|
||||
// A bug at Unity's end means that Stadia can throw an error.
|
||||
if (staticField.Name == "Stadia")
|
||||
continue;
|
||||
|
||||
if (staticField.FieldType == typeof(NamedBuildTarget))
|
||||
buildTargets.Add((NamedBuildTarget)staticField.GetValue(null));
|
||||
}
|
||||
|
||||
return buildTargets;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69b6276384d46d34fb2705f95689e8cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using ES3Internal;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public static class ES3SettingsEditor
|
||||
{
|
||||
public static void Draw(ES3SerializableSettings settings)
|
||||
{
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
settings.location = (ES3.Location)EditorGUILayout.EnumPopup("Location", settings.location);
|
||||
// If the location is File, show the Directory.
|
||||
if(settings.location == ES3.Location.File)
|
||||
settings.directory = (ES3.Directory)EditorGUILayout.EnumPopup("Directory", settings.directory);
|
||||
|
||||
settings.path = EditorGUILayout.TextField("Default File Path", settings.path);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
settings.encryptionType = (ES3.EncryptionType)EditorGUILayout.EnumPopup("Encryption", settings.encryptionType);
|
||||
settings.encryptionPassword = EditorGUILayout.TextField("Encryption Password", settings.encryptionPassword);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
settings.compressionType = (ES3.CompressionType)EditorGUILayout.EnumPopup("Compression", settings.compressionType);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
settings.saveChildren = EditorGUILayout.Toggle("Save GameObject Children", settings.saveChildren);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if(settings.showAdvancedSettings = EditorGUILayout.Foldout(settings.showAdvancedSettings, "Advanced Settings"))
|
||||
{
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
settings.format = (ES3.Format)EditorGUILayout.EnumPopup("Format", settings.format);
|
||||
if (settings.format == ES3.Format.JSON)
|
||||
settings.prettyPrint = EditorGUILayout.Toggle(new GUIContent("Pretty print JSON"), settings.prettyPrint);
|
||||
settings.bufferSize = EditorGUILayout.IntField("Buffer Size", settings.bufferSize);
|
||||
settings.memberReferenceMode = (ES3.ReferenceMode)EditorGUILayout.EnumPopup("Serialise Unity Object fields", settings.memberReferenceMode);
|
||||
settings.serializationDepthLimit = EditorGUILayout.IntField("Serialisation Depth", settings.serializationDepthLimit);
|
||||
settings.postprocessRawCachedData = EditorGUILayout.Toggle(new GUIContent("Postprocess raw cached data"), settings.postprocessRawCachedData);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35659b9a083a341d7bee216c4b71f4bc
|
||||
timeCreated: 1519132282
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,238 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Linq;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class ES3Window : EditorWindow
|
||||
{
|
||||
private SubWindow[] windows = null;
|
||||
|
||||
public SubWindow currentWindow;
|
||||
|
||||
[MenuItem("Window/Easy Save 3", false, 1000)]
|
||||
[MenuItem("Assets/Easy Save 3/Open Easy Save 3 Window", false, 1000)]
|
||||
public static void Init()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if(window != null)
|
||||
window.Show();
|
||||
}
|
||||
|
||||
public static void InitAndShowHome()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
window.SetCurrentWindow(typeof(HomeWindow));
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Auto Save", false, 100)]
|
||||
public static void InitAndShowAutoSave()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
window.SetCurrentWindow(typeof(AutoSaveWindow));
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitAndShowReferences()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
window.SetCurrentWindow(typeof(ReferencesWindow));
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Types", false, 100)]
|
||||
public static void InitAndShowTypes()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
window.SetCurrentWindow(typeof(TypesWindow));
|
||||
}
|
||||
}
|
||||
|
||||
public static void InitAndShowTypes(System.Type type)
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
var typesWindow = (TypesWindow)window.SetCurrentWindow(typeof(TypesWindow));
|
||||
typesWindow.SelectType(type);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Settings", false, 100)]
|
||||
public static void InitAndShowSettings()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
window.SetCurrentWindow(typeof(SettingsWindow));
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Tools", false, 100)]
|
||||
public static void InitAndShowTools()
|
||||
{
|
||||
// Get existing open window or if none, make a new one:
|
||||
ES3Window window = (ES3Window)EditorWindow.GetWindow(typeof(ES3Window));
|
||||
if (window != null)
|
||||
{
|
||||
window.Show();
|
||||
window.SetCurrentWindow(typeof(ToolsWindow));
|
||||
}
|
||||
}
|
||||
|
||||
public void InitSubWindows()
|
||||
{
|
||||
windows = new SubWindow[]{
|
||||
new HomeWindow(this),
|
||||
new SettingsWindow(this),
|
||||
new ToolsWindow(this),
|
||||
new TypesWindow(this),
|
||||
new AutoSaveWindow(this)
|
||||
//, new ReferencesWindow(this)
|
||||
};
|
||||
}
|
||||
|
||||
void OnLostFocus()
|
||||
{
|
||||
if(currentWindow != null)
|
||||
currentWindow.OnLostFocus();
|
||||
}
|
||||
|
||||
private void OnFocus()
|
||||
{
|
||||
if (currentWindow != null)
|
||||
currentWindow.OnFocus();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if(currentWindow != null)
|
||||
currentWindow.OnDestroy();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(windows == null)
|
||||
InitSubWindows();
|
||||
// Set the window name and icon.
|
||||
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>(ES3Settings.PathToEasySaveFolder()+"Editor/es3Logo16x16.png");
|
||||
titleContent = new GUIContent("Easy Save", icon);
|
||||
|
||||
// Get the last opened window and open it.
|
||||
if(currentWindow == null)
|
||||
{
|
||||
var currentWindowName = EditorPrefs.GetString("ES3Editor.Window.currentWindow", windows[0].name);
|
||||
for(int i=0; i<windows.Length; i++)
|
||||
{
|
||||
if(windows[i].name == currentWindowName)
|
||||
{
|
||||
currentWindow = windows[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHierarchyChange()
|
||||
{
|
||||
if (currentWindow != null)
|
||||
currentWindow.OnHierarchyChange();
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
// Display the menu.
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
for(int i=0; i<windows.Length; i++)
|
||||
{
|
||||
if(GUILayout.Button(windows[i].name, currentWindow == windows[i] ? style.menuButtonSelected : style.menuButton))
|
||||
SetCurrentWindow(windows[i]);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if(currentWindow != null)
|
||||
currentWindow.OnGUI();
|
||||
}
|
||||
|
||||
void SetCurrentWindow(SubWindow window)
|
||||
{
|
||||
if (currentWindow != null)
|
||||
currentWindow.OnLostFocus();
|
||||
currentWindow = window;
|
||||
currentWindow.OnFocus();
|
||||
EditorPrefs.SetString("ES3Editor.Window.currentWindow", window.name);
|
||||
}
|
||||
|
||||
SubWindow SetCurrentWindow(System.Type type)
|
||||
{
|
||||
currentWindow.OnLostFocus();
|
||||
currentWindow = windows.First(w => w.GetType() == type);
|
||||
EditorPrefs.SetString("ES3Editor.Window.currentWindow", currentWindow.name);
|
||||
return currentWindow;
|
||||
}
|
||||
|
||||
// Shows the Easy Save Home window if it's not been disabled.
|
||||
// This method is called from the Postprocessor.
|
||||
public static void OpenEditorWindowOnStart()
|
||||
{
|
||||
if(EditorPrefs.GetBool("Show ES3 Window on Start", true))
|
||||
ES3Window.InitAndShowHome();
|
||||
EditorPrefs.SetBool("Show ES3 Window on Start", false);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SubWindow
|
||||
{
|
||||
public string name;
|
||||
public EditorWindow parent;
|
||||
public abstract void OnGUI();
|
||||
|
||||
public SubWindow(string name, EditorWindow parent)
|
||||
{
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public virtual void OnLostFocus()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnFocus()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnHierarchyChange()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a95d98897f1cf4e7288b53b0fd8036c1
|
||||
timeCreated: 1519132293
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
public class EnableES3AssemblyDefinitions : Editor
|
||||
{
|
||||
[MenuItem("Tools/Easy Save 3/Enable Assembly Definition Files", false, 150)]
|
||||
public static void EnableAsmDef()
|
||||
{
|
||||
var pathToEasySaveFolder = ES3Settings.PathToEasySaveFolder();
|
||||
File.Delete(pathToEasySaveFolder + "Editor/EasySave3.asmdef.disabled.meta");
|
||||
File.Delete(pathToEasySaveFolder + "Editor/EasySave3Editor.asmdef.disabled.meta");
|
||||
File.Move(pathToEasySaveFolder + "Editor/EasySave3Editor.asmdef.disabled", pathToEasySaveFolder + "Editor/EasySave3Editor.asmdef");
|
||||
File.Move(pathToEasySaveFolder + "Editor/EasySave3.asmdef.disabled", pathToEasySaveFolder + "EasySave3.asmdef");
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
EditorUtility.DisplayDialog("Assembly definition files installed", "Assembly definition files for Easy Save 3 installed.\n\nYou may need to go to 'Assets > Reimport' to apply the changes.", "Done");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Enable Assembly Definition Files", true, 150)]
|
||||
public static bool CanEnableAsmDef()
|
||||
{
|
||||
return !File.Exists(ES3Settings.PathToEasySaveFolder() + "EasySave3.asmdef");
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f53975dae5ac26947856dd0b0bd3be7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class HomeWindow : SubWindow
|
||||
{
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
|
||||
public HomeWindow(EditorWindow window) : base("Home", window){}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
GUILayout.Label("Welcome to Easy Save", style.heading);
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
GUILayout.Label("New To Easy Save?", style.subheading);
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
ES3EditorUtility.DisplayLink("• See our Getting Started guide", "http://docs.moodkie.com/easy-save-3/getting-started/");
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
GUILayout.Label("Support", style.subheading);
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
ES3EditorUtility.DisplayLink("• Contact us directly", "http://www.moodkie.com/contact/");
|
||||
ES3EditorUtility.DisplayLink("• Ask a question in our Easy Save 3 forums", "http://moodkie.com/forum/viewforum.php?f=12");
|
||||
ES3EditorUtility.DisplayLink("• Ask a question in the Unity Forum thread","https://forum.unity3d.com/threads/easy-save-the-complete-save-load-asset-for-unity.91040/");
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
GUILayout.Label("Documentation and Guides", style.subheading);
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
ES3EditorUtility.DisplayLink("• Documentation", "http://docs.moodkie.com/product/easy-save-3/");
|
||||
ES3EditorUtility.DisplayLink("• Guides", "http://docs.moodkie.com/product/easy-save-3/es3-guides/");
|
||||
ES3EditorUtility.DisplayLink("• API Scripting Reference", "http://docs.moodkie.com/product/easy-save-3/es3-api/");
|
||||
ES3EditorUtility.DisplayLink("• Supported Types", "http://docs.moodkie.com/easy-save-3/es3-supported-types/");
|
||||
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
GUILayout.Label("PlayMaker Documentation", style.subheading);
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
ES3EditorUtility.DisplayLink("• Actions", "http://docs.moodkie.com/product/easy-save-3/es3-playmaker/es3-playmaker-actions/");
|
||||
ES3EditorUtility.DisplayLink("• Actions Overview", "http://docs.moodkie.com/easy-save-3/es3-playmaker/playmaker-actions-overview/");
|
||||
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 394cc2e77038849709526f44f7efdd22
|
||||
timeCreated: 1519132283
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using ES3Internal;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class ReferencesWindow : SubWindow
|
||||
{
|
||||
|
||||
|
||||
public ReferencesWindow(EditorWindow window) : base("References", window){}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af2d805793e784eef87fbcdebb11fa35
|
||||
timeCreated: 1519132291
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,179 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using ES3Internal;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class SettingsWindow : SubWindow
|
||||
{
|
||||
public ES3Defaults editorSettings = null;
|
||||
public ES3SerializableSettings settings = null;
|
||||
public SerializedObject so = null;
|
||||
public SerializedProperty referenceFoldersProperty = null;
|
||||
|
||||
Vector2 scrollPos = Vector2.zero;
|
||||
const string disableGlobalDefineName = "ES3GLOBAL_DISABLED";
|
||||
|
||||
public SettingsWindow(EditorWindow window) : base("Settings", window){}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if(settings == null || editorSettings == null)
|
||||
Init();
|
||||
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
var labelWidth = EditorGUIUtility.labelWidth;
|
||||
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPos, style.area))
|
||||
{
|
||||
scrollPos = scrollView.scrollPosition;
|
||||
|
||||
EditorGUIUtility.labelWidth = 160;
|
||||
|
||||
GUILayout.Label("Runtime Settings", style.heading);
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(style.area))
|
||||
{
|
||||
ES3SettingsEditor.Draw(settings);
|
||||
}
|
||||
|
||||
GUILayout.Label("Debug Settings", style.heading);
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(style.area))
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 100;
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel("Log Info");
|
||||
editorSettings.logDebugInfo = EditorGUILayout.Toggle(editorSettings.logDebugInfo);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel("Log Warnings");
|
||||
editorSettings.logWarnings = EditorGUILayout.Toggle(editorSettings.logWarnings);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel("Log Errors");
|
||||
editorSettings.logErrors = EditorGUILayout.Toggle(editorSettings.logErrors);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
GUILayout.Label("Editor Settings", style.heading);
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(style.area))
|
||||
{
|
||||
EditorGUIUtility.labelWidth = 170;
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel("Auto Update References");
|
||||
editorSettings.autoUpdateReferences = EditorGUILayout.Toggle(editorSettings.autoUpdateReferences);
|
||||
}
|
||||
|
||||
if (editorSettings.autoUpdateReferences)
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var content = new GUIContent("-- When changes are made", "Should Easy Save update the reference manager when objects in your scene changes?");
|
||||
editorSettings.updateReferencesWhenSceneChanges = EditorGUILayout.Toggle(content, editorSettings.updateReferencesWhenSceneChanges);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var content = new GUIContent("-- When scene is saved", "Should Easy Save update the reference manager when objects in your scene is saved?");
|
||||
editorSettings.updateReferencesWhenSceneIsSaved = EditorGUILayout.Toggle(content, editorSettings.updateReferencesWhenSceneIsSaved);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var content = new GUIContent("-- When scene is opened", "Should Easy Save update the reference manager you open a scene in the Editor?");
|
||||
editorSettings.updateReferencesWhenSceneIsOpened = EditorGUILayout.Toggle(content, editorSettings.updateReferencesWhenSceneIsOpened);
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
so.Update();
|
||||
EditorGUILayout.PropertyField(referenceFoldersProperty, true);
|
||||
so.ApplyModifiedProperties();
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
|
||||
/*using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var content = new GUIContent("Reference depth", "How deep should Easy Save look when gathering references from an object? Higher means deeper.");
|
||||
EditorGUILayout.PrefixLabel(content);
|
||||
editorSettings.collectDependenciesDepth = EditorGUILayout.IntField(editorSettings.collectDependenciesDepth);
|
||||
}*/
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var content = new GUIContent("Reference timeout (seconds)", "How many seconds should Easy Save taking collecting references for an object before timing out?");
|
||||
EditorGUILayout.PrefixLabel(content);
|
||||
editorSettings.collectDependenciesTimeout = EditorGUILayout.IntField(editorSettings.collectDependenciesTimeout);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel("Use Global References");
|
||||
|
||||
bool useGlobalReferences = !ES3ScriptingDefineSymbols.HasDefineSymbol(disableGlobalDefineName);
|
||||
if(EditorGUILayout.Toggle(useGlobalReferences) != useGlobalReferences)
|
||||
{
|
||||
// If global references is currently enabled, we want to disable it.
|
||||
if (!useGlobalReferences)
|
||||
{
|
||||
ES3ScriptingDefineSymbols.RemoveDefineSymbol(disableGlobalDefineName);
|
||||
EditorUtility.DisplayDialog("Global references disabled for build platform", "This will only disable Global References for this build platform. To disable it for other build platforms, open that platform in the Build Settings and uncheck this box again.", "Ok");
|
||||
}
|
||||
// Else we want to enable it.
|
||||
else
|
||||
ES3ScriptingDefineSymbols.SetDefineSymbol(disableGlobalDefineName);
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var content = new GUIContent("Add All Prefabs to Manager", "Should all prefabs with ES3Prefab Components be added to the manager?");
|
||||
EditorGUILayout.PrefixLabel(content);
|
||||
editorSettings.addAllPrefabsToManager = EditorGUILayout.Toggle(editorSettings.addAllPrefabsToManager);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
EditorUtility.SetDirty(editorSettings);
|
||||
|
||||
EditorGUIUtility.labelWidth = labelWidth; // Set the label width back to default
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
editorSettings = ES3Settings.defaultSettingsScriptableObject;
|
||||
settings = editorSettings.settings;
|
||||
so = new SerializedObject(editorSettings);
|
||||
referenceFoldersProperty = so.FindProperty("referenceFolders");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95e7bbc9a5aee44feb088811fb5e7b80
|
||||
timeCreated: 1519132291
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,155 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class ToolsWindow : SubWindow
|
||||
{
|
||||
public ToolsWindow(EditorWindow window) : base("Tools", window){}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
EditorGUILayout.BeginHorizontal(style.area);
|
||||
|
||||
if (GUILayout.Button("Open Persistent Data Path"))
|
||||
OpenPersistentDataPath();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal(style.area);
|
||||
|
||||
if (GUILayout.Button("Clear Persistent Data Path"))
|
||||
ClearPersistentDataPath();
|
||||
|
||||
if (GUILayout.Button("Clear PlayerPrefs"))
|
||||
ClearPlayerPrefs();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Open Persistent Data Path", false, 200)]
|
||||
private static void OpenPersistentDataPath()
|
||||
{
|
||||
EditorUtility.RevealInFinder(Application.persistentDataPath);
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Clear Persistent Data Path", false, 200)]
|
||||
private static void ClearPersistentDataPath()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Clear Persistent Data Path", "Are you sure you wish to clear the persistent data path?\n This action cannot be reversed.", "Clear", "Cancel"))
|
||||
{
|
||||
System.IO.DirectoryInfo di = new DirectoryInfo(Application.persistentDataPath);
|
||||
|
||||
foreach (FileInfo file in di.GetFiles())
|
||||
file.Delete();
|
||||
foreach (DirectoryInfo dir in di.GetDirectories())
|
||||
dir.Delete(true);
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Clear PlayerPrefs", false, 200)]
|
||||
private static void ClearPlayerPrefs()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Clear PlayerPrefs", "Are you sure you wish to clear PlayerPrefs?\nThis action cannot be reversed.", "Clear", "Cancel"))
|
||||
PlayerPrefs.DeleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
/*public static class OSFileBrowser
|
||||
{
|
||||
public static bool IsInMacOS
|
||||
{
|
||||
get
|
||||
{
|
||||
return UnityEngine.SystemInfo.operatingSystem.IndexOf("Mac OS") != -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsInWinOS
|
||||
{
|
||||
get
|
||||
{
|
||||
return UnityEngine.SystemInfo.operatingSystem.IndexOf("Windows") != -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenInMac(string path)
|
||||
{
|
||||
bool openInsidesOfFolder = false;
|
||||
|
||||
// try mac
|
||||
string macPath = path.Replace("\\", "/"); // mac finder doesn't like backward slashes
|
||||
|
||||
if ( System.IO.Directory.Exists(macPath) ) // if path requested is a folder, automatically open insides of that folder
|
||||
{
|
||||
openInsidesOfFolder = true;
|
||||
}
|
||||
|
||||
if ( !macPath.StartsWith("\"") )
|
||||
{
|
||||
macPath = "\"" + macPath;
|
||||
}
|
||||
|
||||
if ( !macPath.EndsWith("\"") )
|
||||
{
|
||||
macPath = macPath + "\"";
|
||||
}
|
||||
|
||||
string arguments = (openInsidesOfFolder ? "" : "-R ") + macPath;
|
||||
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start("open", arguments);
|
||||
}
|
||||
catch ( System.ComponentModel.Win32Exception e )
|
||||
{
|
||||
// tried to open mac finder in windows
|
||||
// just silently skip error
|
||||
// we currently have no platform define for the current OS we are in, so we resort to this
|
||||
e.HelpLink = ""; // do anything with this variable to silence warning about not using it
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenInWin(string path)
|
||||
{
|
||||
bool openInsidesOfFolder = false;
|
||||
|
||||
// try windows
|
||||
string winPath = path.Replace("/", "\\"); // windows explorer doesn't like forward slashes
|
||||
|
||||
if ( System.IO.Directory.Exists(winPath) ) // if path requested is a folder, automatically open insides of that folder
|
||||
openInsidesOfFolder = true;
|
||||
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start("explorer.exe", (openInsidesOfFolder ? "/root," : "/select,") + "\"" + winPath + "\"");
|
||||
}
|
||||
catch ( System.ComponentModel.Win32Exception e )
|
||||
{
|
||||
e.HelpLink = "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void Open(string path)
|
||||
{
|
||||
if ( IsInWinOS )
|
||||
{
|
||||
OpenInWin(path);
|
||||
}
|
||||
else if ( IsInMacOS )
|
||||
{
|
||||
OpenInMac(path);
|
||||
}
|
||||
else // couldn't determine OS
|
||||
{
|
||||
OpenInWin(path);
|
||||
OpenInMac(path);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d6114c1d40624e9e8575e814c45ac1a
|
||||
timeCreated: 1519132280
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,728 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using ES3Types;
|
||||
using System.IO;
|
||||
using ES3Internal;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ES3Editor
|
||||
{
|
||||
public class TypesWindow : SubWindow
|
||||
{
|
||||
TypeListItem[] types = null;
|
||||
const int recentTypeCount = 5;
|
||||
List<int> recentTypes = null;
|
||||
|
||||
Vector2 typeListScrollPos = Vector2.zero;
|
||||
Vector2 typePaneScrollPos = Vector2.zero;
|
||||
int leftPaneWidth = 300;
|
||||
|
||||
string searchFieldValue = "";
|
||||
|
||||
int selectedType = -1;
|
||||
private ES3Reflection.ES3ReflectedMember[] fields = new ES3Reflection.ES3ReflectedMember[0];
|
||||
private bool[] fieldSelected = new bool[0];
|
||||
|
||||
private Texture2D checkmark;
|
||||
//private Texture2D checkmarkSmall;
|
||||
|
||||
private GUIStyle searchBarStyle;
|
||||
private GUIStyle searchBarCancelButtonStyle;
|
||||
private GUIStyle leftPaneStyle;
|
||||
private GUIStyle typeButtonStyle;
|
||||
private GUIStyle selectedTypeButtonStyle;
|
||||
private GUIStyle selectAllNoneButtonStyle;
|
||||
|
||||
private string valueTemplateFile;
|
||||
private string classTemplateFile;
|
||||
private string componentTemplateFile;
|
||||
private string scriptableObjectTemplateFile;
|
||||
|
||||
private bool unsavedChanges = false;
|
||||
|
||||
public TypesWindow(EditorWindow window) : base("Types", window){}
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if(types == null)
|
||||
Init();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.BeginVertical(leftPaneStyle);
|
||||
SearchBar();
|
||||
TypeList();
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.BeginVertical();
|
||||
TypePane();
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void SearchBar()
|
||||
{
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
GUILayout.Label("Enter a type name in the field below\n* Type names are case-sensitive *", style.subheading2);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
// Set control name so we can force a Focus reset for it.
|
||||
string currentSearchFieldValue = EditorGUILayout.TextField(searchFieldValue, searchBarStyle);
|
||||
|
||||
if(searchFieldValue != currentSearchFieldValue)
|
||||
{
|
||||
searchFieldValue = currentSearchFieldValue;
|
||||
PerformSearch(currentSearchFieldValue);
|
||||
}
|
||||
|
||||
GUI.SetNextControlName("Clear");
|
||||
|
||||
if(GUILayout.Button("x", searchBarCancelButtonStyle))
|
||||
{
|
||||
searchFieldValue = "";
|
||||
GUI.FocusControl("Clear");
|
||||
PerformSearch("");
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void RecentTypeList()
|
||||
{
|
||||
if(!string.IsNullOrEmpty(searchFieldValue) || recentTypes.Count == 0)
|
||||
return;
|
||||
|
||||
for(int i=recentTypes.Count-1; i>-1; i--)
|
||||
TypeButton(recentTypes[i]);
|
||||
|
||||
EditorGUILayout.TextArea("",GUI.skin.horizontalSlider);
|
||||
|
||||
}
|
||||
|
||||
private void TypeList()
|
||||
{
|
||||
if(!string.IsNullOrEmpty(searchFieldValue))
|
||||
GUILayout.Label("Search Results", EditorStyles.boldLabel);
|
||||
|
||||
typeListScrollPos = EditorGUILayout.BeginScrollView(typeListScrollPos);
|
||||
|
||||
RecentTypeList();
|
||||
|
||||
if(!string.IsNullOrEmpty(searchFieldValue))
|
||||
for(int i = 0; i < types.Length; i++)
|
||||
TypeButton(i);
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void TypePane()
|
||||
{
|
||||
if(selectedType < 0)
|
||||
return;
|
||||
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
var typeListItem = types[selectedType];
|
||||
var type = typeListItem.type;
|
||||
|
||||
typePaneScrollPos = EditorGUILayout.BeginScrollView(typePaneScrollPos, style.area);
|
||||
|
||||
GUILayout.Label(typeListItem.name, style.subheading);
|
||||
GUILayout.Label(typeListItem.namespaceName);
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
bool hasParameterlessConstructor = ES3Reflection.HasParameterlessConstructor(type);
|
||||
bool isComponent = ES3Reflection.IsAssignableFrom(typeof(Component), type);
|
||||
|
||||
string path = GetOutputPath(types[selectedType].type);
|
||||
// An ES3Type file already exists.
|
||||
if(File.Exists(path))
|
||||
{
|
||||
if(hasParameterlessConstructor || isComponent)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if(GUILayout.Button("Reset to Default"))
|
||||
{
|
||||
SelectNone(true, true);
|
||||
AssetDatabase.MoveAssetToTrash("Assets" + path.Remove(0, Application.dataPath.Length));
|
||||
SelectType(selectedType);
|
||||
}
|
||||
if(GUILayout.Button("Edit ES3Type Script"))
|
||||
AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath("Assets" + path.Remove(0, Application.dataPath.Length)));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to modify the ES3Type script to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
|
||||
if(GUILayout.Button("Click here to edit the ES3Type script"))
|
||||
AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath("Assets" + path.Remove(0, Application.dataPath.Length)));
|
||||
if (GUILayout.Button("Reset to Default"))
|
||||
{
|
||||
SelectAll(true, true);
|
||||
File.Delete(path);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
// No ES3Type file and no fields.
|
||||
else if(fields.Length == 0)
|
||||
{
|
||||
if(!hasParameterlessConstructor && !isComponent)
|
||||
EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to create an ES3Type script and modify it to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
|
||||
|
||||
if(GUILayout.Button("Create ES3Type Script"))
|
||||
Generate();
|
||||
}
|
||||
// No ES3Type file, but fields are selectable.
|
||||
else
|
||||
{
|
||||
if(!hasParameterlessConstructor && !isComponent)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to select the fields you wish to serialize below, and then modify the generated ES3Type script to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
|
||||
if(GUILayout.Button("Select all fields and generate ES3Type script"))
|
||||
{
|
||||
SelectAll(true, false);
|
||||
Generate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(GUILayout.Button("Create ES3Type Script"))
|
||||
Generate();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
PropertyPane();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void PropertyPane()
|
||||
{
|
||||
var style = EditorStyle.Get;
|
||||
|
||||
EditorGUILayout.BeginVertical(style.area);
|
||||
|
||||
GUILayout.Label("Fields", EditorStyles.boldLabel);
|
||||
|
||||
DisplayFieldsOrProperties(true, false);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
GUILayout.Label("Properties", EditorStyles.boldLabel);
|
||||
|
||||
DisplayFieldsOrProperties(false, true);
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private void DisplayFieldsOrProperties(bool showFields, bool showProperties)
|
||||
{
|
||||
// Get field and property counts.
|
||||
int fieldCount = 0;
|
||||
int propertyCount = 0;
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
{
|
||||
if(fields[i].isProperty && showProperties)
|
||||
propertyCount++;
|
||||
else if((!fields[i].isProperty) && showFields)
|
||||
fieldCount++;
|
||||
}
|
||||
|
||||
// If there is nothing to display, show message.
|
||||
if(showFields && showProperties && fieldCount == 0 && propertyCount == 0)
|
||||
GUILayout.Label("This type has no serializable fields or properties.");
|
||||
else if(showFields && fieldCount == 0)
|
||||
GUILayout.Label("This type has no serializable fields.");
|
||||
else if(showProperties && propertyCount == 0)
|
||||
GUILayout.Label("This type has no serializable properties.");
|
||||
|
||||
// Display Select All/Select None buttons only if there are fields to display.
|
||||
if(fieldCount > 0 || propertyCount > 0)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if(GUILayout.Button("Select All", selectAllNoneButtonStyle))
|
||||
{
|
||||
SelectAll(showFields, showProperties);
|
||||
Generate();
|
||||
}
|
||||
|
||||
if(GUILayout.Button("Select None", selectAllNoneButtonStyle))
|
||||
{
|
||||
SelectNone(showFields, showProperties);
|
||||
Generate();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
{
|
||||
var field = fields[i];
|
||||
if((field.isProperty && !showProperties) || ((!field.isProperty) && !showFields))
|
||||
continue;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
var content = new GUIContent(field.Name);
|
||||
|
||||
if(typeof(UnityEngine.Object).IsAssignableFrom(field.MemberType))
|
||||
content.tooltip = field.MemberType.ToString() + "\nSaved by reference";
|
||||
else
|
||||
content.tooltip = field.MemberType.ToString() + "\nSaved by value";
|
||||
|
||||
|
||||
|
||||
bool selected = EditorGUILayout.ToggleLeft(content, fieldSelected[i]);
|
||||
if(selected != fieldSelected[i])
|
||||
{
|
||||
fieldSelected[i] = selected;
|
||||
unsavedChanges = true;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
// Selects all fields, properties or both.
|
||||
private void SelectAll(bool selectFields, bool selectProperties)
|
||||
{
|
||||
for(int i=0; i<fieldSelected.Length; i++)
|
||||
if((fields[i].isProperty && selectProperties) || (!fields[i].isProperty) && selectFields)
|
||||
fieldSelected[i] = true;
|
||||
}
|
||||
|
||||
// Selects all fields, properties or both.
|
||||
private void SelectNone(bool selectFields, bool selectProperties)
|
||||
{
|
||||
for(int i=0; i<fieldSelected.Length; i++)
|
||||
if((fields[i].isProperty && selectProperties) || (!fields[i].isProperty) && selectFields)
|
||||
fieldSelected[i] = false;
|
||||
}
|
||||
|
||||
public override void OnLostFocus()
|
||||
{
|
||||
if(unsavedChanges)
|
||||
Generate();
|
||||
}
|
||||
|
||||
private void TypeButton(int i)
|
||||
{
|
||||
var type = types[i];
|
||||
if(!types[i].showInList)
|
||||
return;
|
||||
|
||||
if(type.hasExplicitES3Type)
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
|
||||
var thisTypeButtonStyle = (i == selectedType) ? selectedTypeButtonStyle : typeButtonStyle;
|
||||
|
||||
if(GUILayout.Button(new GUIContent(type.name, type.namespaceName), thisTypeButtonStyle))
|
||||
SelectType(i);
|
||||
|
||||
// Set the cursor.
|
||||
var buttonRect = GUILayoutUtility.GetLastRect();
|
||||
EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link);
|
||||
|
||||
|
||||
|
||||
if(type.hasExplicitES3Type)
|
||||
{
|
||||
GUILayout.Box(new GUIContent(checkmark, "Type is explicitly supported"), EditorStyles.largeLabel);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
private void PerformSearch(string query)
|
||||
{
|
||||
var lowerCaseQuery = query.ToLowerInvariant();
|
||||
var emptyQuery = string.IsNullOrEmpty(query);
|
||||
|
||||
for(int i=0; i<types.Length; i++)
|
||||
types[i].showInList = (emptyQuery || types[i].lowercaseName.Contains(lowerCaseQuery));
|
||||
}
|
||||
|
||||
public void SelectType(Type type)
|
||||
{
|
||||
Init();
|
||||
for (int i = 0; i < types.Length; i++)
|
||||
if (types[i].type == type)
|
||||
SelectType(i);
|
||||
}
|
||||
|
||||
private void SelectType(int typeIndex)
|
||||
{
|
||||
selectedType = typeIndex;
|
||||
|
||||
if(selectedType == -1)
|
||||
{
|
||||
SaveType("TypesWindowSelectedType", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
SaveType("TypesWindowSelectedType", selectedType);
|
||||
|
||||
if(!recentTypes.Contains(typeIndex))
|
||||
{
|
||||
// If our recent type queue is full, remove an item before adding another.
|
||||
if(recentTypes.Count == recentTypeCount)
|
||||
recentTypes.RemoveAt(0);
|
||||
recentTypes.Add(typeIndex);
|
||||
for(int j=0; j<recentTypes.Count; j++)
|
||||
SaveType("TypesWindowRecentType"+j, recentTypes[j]);
|
||||
}
|
||||
|
||||
var type = types[selectedType].type;
|
||||
|
||||
fields = ES3Reflection.GetSerializableMembers(type, false);
|
||||
fieldSelected = new bool[fields.Length];
|
||||
|
||||
var es3Type = ES3TypeMgr.GetES3Type(type);
|
||||
// If there's no ES3Type for this, only select fields which are supported by reflection.
|
||||
if(es3Type == null)
|
||||
{
|
||||
var safeFields = ES3Reflection.GetSerializableMembers(type, true);
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
fieldSelected[i] = safeFields.Any(item => item.Name == fields[i].Name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get fields and whether they're selected.
|
||||
var selectedFields = new List<string>();
|
||||
var propertyAttributes = es3Type.GetType().GetCustomAttributes(typeof(ES3PropertiesAttribute), false);
|
||||
if(propertyAttributes.Length > 0)
|
||||
selectedFields.AddRange(((ES3PropertiesAttribute)propertyAttributes[0]).members);
|
||||
|
||||
fieldSelected = new bool[fields.Length];
|
||||
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
fieldSelected[i] = selectedFields.Contains(fields[i].Name);
|
||||
}
|
||||
|
||||
private void SaveType(string key, int typeIndex)
|
||||
{
|
||||
if(typeIndex == -1)
|
||||
return;
|
||||
SaveType(key, types[typeIndex].type);
|
||||
}
|
||||
|
||||
private void SaveType(string key, Type type)
|
||||
{
|
||||
EditorPrefs.SetString(key, type.AssemblyQualifiedName);
|
||||
}
|
||||
|
||||
private int LoadTypeIndex(string key)
|
||||
{
|
||||
string selectedTypeName = EditorPrefs.GetString(key, "");
|
||||
if(selectedTypeName != "")
|
||||
{
|
||||
var type = ES3Reflection.GetType(selectedTypeName);
|
||||
if(type != null)
|
||||
{
|
||||
int typeIndex = GetTypeIndex(type);
|
||||
if(typeIndex != -1)
|
||||
return typeIndex;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int GetTypeIndex(Type type)
|
||||
{
|
||||
for(int i=0; i<types.Length; i++)
|
||||
if(types[i].type == type)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
ES3.Init(); // Initialize ES3 as we rely on the Type list being generated to determine whether a type is explicit or not.
|
||||
|
||||
componentTemplateFile = "ES3ComponentTypeTemplate.txt";
|
||||
classTemplateFile = "ES3ClassTypeTemplate.txt";
|
||||
valueTemplateFile = "ES3ValueTypeTemplate.txt";
|
||||
scriptableObjectTemplateFile = "ES3ScriptableObjectTypeTemplate.txt";
|
||||
|
||||
// Init Type List
|
||||
var tempTypes = new List<TypeListItem> ();
|
||||
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.FullName.Contains("Editor") && assembly.FullName != "ES3" && !assembly.FullName.Contains("ES3")).OrderBy(assembly => assembly.GetName().Name).ToArray();
|
||||
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
var assemblyTypes = assembly.GetTypes();
|
||||
|
||||
for(int i = 0; i < assemblyTypes.Length; i++)
|
||||
{
|
||||
var type = assemblyTypes [i];
|
||||
if(type.IsGenericType || type.IsEnum || type.IsNotPublic || type.IsAbstract || type.IsInterface)
|
||||
continue;
|
||||
|
||||
var typeName = type.Name;
|
||||
if(typeName.Length >= 3 && typeName [0] == '$' || typeName [0] == '_' || typeName [0] == '<')
|
||||
continue;
|
||||
|
||||
var typeNamespace = type.Namespace;
|
||||
var namespaceName = typeNamespace == null ? "" : typeNamespace.ToString();
|
||||
|
||||
tempTypes.Add(new TypeListItem (type.Name, namespaceName, type, true, HasExplicitES3Type(type)));
|
||||
}
|
||||
|
||||
}
|
||||
types = tempTypes.OrderBy(type => type.name).ToArray();
|
||||
|
||||
// Load types and recent types.
|
||||
if (recentTypes == null)
|
||||
{
|
||||
recentTypes = new List<int>();
|
||||
for (int i = 0; i < recentTypeCount; i++)
|
||||
{
|
||||
int typeIndex = LoadTypeIndex("TypesWindowRecentType" + i);
|
||||
if (typeIndex != -1)
|
||||
recentTypes.Add(typeIndex);
|
||||
}
|
||||
SelectType(LoadTypeIndex("TypesWindowSelectedType"));
|
||||
}
|
||||
|
||||
|
||||
PerformSearch(searchFieldValue);
|
||||
|
||||
// Init Assets.
|
||||
string es3FolderPath = ES3Settings.PathToEasySaveFolder();
|
||||
checkmark = AssetDatabase.LoadAssetAtPath<Texture2D>(es3FolderPath + "Editor/checkmark.png");
|
||||
//checkmarkSmall = AssetDatabase.LoadAssetAtPath<Texture2D>(es3FolderPath + "Editor/checkmarkSmall.png");
|
||||
|
||||
// Init Styles.
|
||||
searchBarCancelButtonStyle = new GUIStyle(EditorStyles.miniButton);
|
||||
var cancelButtonSize = EditorStyles.miniTextField.CalcHeight(new GUIContent(""), 20);
|
||||
searchBarCancelButtonStyle.fixedWidth = cancelButtonSize;
|
||||
searchBarCancelButtonStyle.fixedHeight = cancelButtonSize;
|
||||
searchBarCancelButtonStyle.fontSize = 8;
|
||||
searchBarCancelButtonStyle.padding = new RectOffset();
|
||||
searchBarStyle = new GUIStyle(EditorStyles.toolbarTextField);
|
||||
searchBarStyle.stretchWidth = true;
|
||||
|
||||
typeButtonStyle = new GUIStyle(EditorStyles.largeLabel);
|
||||
typeButtonStyle.alignment = TextAnchor.MiddleLeft;
|
||||
typeButtonStyle.stretchWidth = false;
|
||||
selectedTypeButtonStyle = new GUIStyle(typeButtonStyle);
|
||||
selectedTypeButtonStyle.fontStyle = FontStyle.Bold;
|
||||
|
||||
leftPaneStyle = new GUIStyle();
|
||||
leftPaneStyle.fixedWidth = leftPaneWidth;
|
||||
leftPaneStyle.clipping = TextClipping.Clip;
|
||||
leftPaneStyle.padding = new RectOffset(10, 10, 10, 10);
|
||||
|
||||
selectAllNoneButtonStyle = new GUIStyle(EditorStyles.miniButton);
|
||||
selectAllNoneButtonStyle.stretchWidth = false;
|
||||
selectAllNoneButtonStyle.margin = new RectOffset(0,0,0,10);
|
||||
}
|
||||
|
||||
private void Generate()
|
||||
{
|
||||
var type = types[selectedType].type;
|
||||
if(type == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Type not selected", "Type not selected. Please ensure you select a type", "Ok");
|
||||
return;
|
||||
}
|
||||
|
||||
unsavedChanges = false;
|
||||
|
||||
// Get the serializable fields of this class.
|
||||
//var fields = ES3Reflection.GetSerializableES3Fields(type);
|
||||
|
||||
// The string that we suffix to the class name. i.e. UnityEngine_UnityEngine_Transform.
|
||||
string es3TypeSuffix = type.Name;
|
||||
// The string for the full C#-safe type name. This name must be suitable for going inside typeof().
|
||||
string fullType = GetFullTypeName(type);
|
||||
// The list of WriteProperty calls to write the properties of this type.
|
||||
string writes = GenerateWrites();
|
||||
// The list of case statements and Read calls to read the properties of this type.
|
||||
string reads = GenerateReads();
|
||||
// A comma-seperated string of fields we've supported in this type.
|
||||
string propertyNames = "";
|
||||
|
||||
bool first = true;
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
{
|
||||
if(!fieldSelected[i])
|
||||
continue;
|
||||
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
propertyNames += ", ";
|
||||
propertyNames += "\"" + fields[i].Name + "\"";
|
||||
}
|
||||
|
||||
var easySaveEditorPath = ES3Settings.PathToEasySaveFolder()+"Editor/";
|
||||
|
||||
// Insert the relevant strings into the template.
|
||||
string template;
|
||||
if(typeof(Component).IsAssignableFrom(type))
|
||||
template = File.ReadAllText(easySaveEditorPath + componentTemplateFile);
|
||||
else if(ES3Reflection.IsValueType(type))
|
||||
template = File.ReadAllText(easySaveEditorPath + valueTemplateFile);
|
||||
else if(typeof(ScriptableObject).IsAssignableFrom(type))
|
||||
template = File.ReadAllText(easySaveEditorPath + scriptableObjectTemplateFile);
|
||||
else
|
||||
template = File.ReadAllText(easySaveEditorPath + classTemplateFile);
|
||||
template = template.Replace("[es3TypeSuffix]", es3TypeSuffix);
|
||||
template = template.Replace("[writes]", writes);
|
||||
template = template.Replace("[reads]", reads);
|
||||
template = template.Replace("[propertyNames]", propertyNames);
|
||||
template = template.Replace("[fullType]", fullType); // Do this last as we use the [fullType] tag in reads.
|
||||
|
||||
// Create the output file.
|
||||
|
||||
|
||||
string outputFilePath = GetOutputPath(type);
|
||||
var fileInfo = new FileInfo(outputFilePath);
|
||||
fileInfo.Directory.Create();
|
||||
File.WriteAllText(outputFilePath, template);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
private string GenerateWrites()
|
||||
{
|
||||
var type = types[selectedType].type;
|
||||
bool isComponent = typeof(Component).IsAssignableFrom(type);
|
||||
string writes = "";
|
||||
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
{
|
||||
var field = fields[i];
|
||||
var selected = fieldSelected[i];
|
||||
var es3Type = ES3TypeMgr.GetES3Type(field.MemberType);
|
||||
|
||||
if(!selected || isComponent && (field.Name == ES3Reflection.componentTagFieldName || field.Name == ES3Reflection.componentNameFieldName))
|
||||
continue;
|
||||
|
||||
string writeByRef = ES3Reflection.IsAssignableFrom(typeof(UnityEngine.Object), field.MemberType) ? "ByRef" : "";
|
||||
string es3TypeParam = HasExplicitES3Type(es3Type) && writeByRef == "" && !field.MemberType.IsEnum ? ", " + es3Type.GetType().Name + ".Instance" : (writeByRef == "" ? ", ES3Internal.ES3TypeMgr.GetOrCreateES3Type(typeof(" + GetFullTypeName(field.MemberType) + "))" : "");
|
||||
|
||||
// If this is static, access the field through the class name rather than through an instance.
|
||||
string instance = (field.IsStatic) ? GetFullTypeName(type) : "instance";
|
||||
|
||||
if(!field.IsPublic)
|
||||
{
|
||||
string memberType = field.isProperty ? "Property" : "Field";
|
||||
writes += String.Format("\r\n\t\t\twriter.WritePrivate{2}{1}(\"{0}\", instance);", field.Name, writeByRef, memberType);
|
||||
}
|
||||
else
|
||||
writes += String.Format("\r\n\t\t\twriter.WriteProperty{1}(\"{0}\", {3}.{0}{2});", field.Name, writeByRef, es3TypeParam, instance);
|
||||
}
|
||||
return writes;
|
||||
}
|
||||
|
||||
private string GenerateReads()
|
||||
{
|
||||
var type = types[selectedType].type;
|
||||
bool isComponent = typeof(Component).IsAssignableFrom(type);
|
||||
string reads = "";
|
||||
|
||||
for(int i=0; i<fields.Length; i++)
|
||||
{
|
||||
var field = fields[i];
|
||||
var selected = fieldSelected[i];
|
||||
|
||||
if(!selected || isComponent && (field.Name == "tag" || field.Name == "name"))
|
||||
continue;
|
||||
|
||||
string fieldTypeName = GetFullTypeName(field.MemberType);
|
||||
string es3TypeParam = HasExplicitES3Type(field.MemberType) ? ES3TypeMgr.GetES3Type(field.MemberType).GetType().Name+".Instance" : "";
|
||||
// If this is static, access the field through the class name rather than through an instance.
|
||||
string instance = (field.IsStatic) ? GetFullTypeName(type) : "instance";
|
||||
|
||||
// If we're writing a private field or property, we need to write it using a different method.
|
||||
if(!field.IsPublic)
|
||||
{
|
||||
es3TypeParam = ", " + es3TypeParam;
|
||||
|
||||
if(field.isProperty)
|
||||
reads += String.Format("\r\n\t\t\t\t\tcase \"{0}\":\r\n\t\t\t\t\tinstance = ([fullType])reader.SetPrivateProperty(\"{0}\", reader.Read<{1}>(), instance);\r\n\t\t\t\t\tbreak;", field.Name, fieldTypeName);
|
||||
else
|
||||
reads += String.Format("\r\n\t\t\t\t\tcase \"{0}\":\r\n\t\t\t\t\tinstance = ([fullType])reader.SetPrivateField(\"{0}\", reader.Read<{1}>(), instance);\r\n\t\t\t\t\tbreak;", field.Name, fieldTypeName);
|
||||
}
|
||||
else
|
||||
reads += String.Format("\r\n\t\t\t\t\tcase \"{0}\":\r\n\t\t\t\t\t\t{3}.{0} = reader.Read<{1}>({2});\r\n\t\t\t\t\t\tbreak;", field.Name, fieldTypeName, es3TypeParam, instance);
|
||||
}
|
||||
return reads;
|
||||
}
|
||||
|
||||
private string GetOutputPath(Type type)
|
||||
{
|
||||
return Application.dataPath + "/Easy Save 3/Types/ES3UserType_"+type.Name+".cs";
|
||||
}
|
||||
|
||||
/* Gets the full Type name, replacing any syntax (such as '+') with a dot to make it a valid type name */
|
||||
private static string GetFullTypeName(Type type)
|
||||
{
|
||||
string typeName = type.ToString();
|
||||
|
||||
typeName = typeName.Replace('+','.');
|
||||
|
||||
// If it's a generic type, replace syntax with angled brackets.
|
||||
int genericArgumentCount = type.GetGenericArguments().Length;
|
||||
if(genericArgumentCount > 0)
|
||||
{
|
||||
return string.Format("{0}<{1}>", type.ToString().Split('`')[0], string.Join(", ", type.GetGenericArguments().Select(x => GetFullTypeName(x)).ToArray()));
|
||||
}
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
/* Whether this type has an explicit ES3Type. For example, ES3ArrayType would return false, but ES3Vector3ArrayType would return true */
|
||||
private static bool HasExplicitES3Type(Type type)
|
||||
{
|
||||
var es3Type = ES3TypeMgr.GetES3Type(type);
|
||||
if(es3Type == null)
|
||||
return false;
|
||||
// If this ES3Type has a static Instance property, return true.
|
||||
if(es3Type.GetType().GetField("Instance", BindingFlags.Public | BindingFlags.Static) != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HasExplicitES3Type(ES3Type es3Type)
|
||||
{
|
||||
if(es3Type == null)
|
||||
return false;
|
||||
// If this ES3Type has a static Instance property, return true.
|
||||
if(es3Type.GetType().GetField("Instance", BindingFlags.Public | BindingFlags.Static) != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public class TypeListItem
|
||||
{
|
||||
public string name;
|
||||
public string lowercaseName;
|
||||
public string namespaceName;
|
||||
public Type type;
|
||||
public bool showInList;
|
||||
public bool hasExplicitES3Type;
|
||||
|
||||
public TypeListItem(string name, string namespaceName, Type type, bool showInList, bool hasExplicitES3Type)
|
||||
{
|
||||
this.name = name;
|
||||
this.lowercaseName = name.ToLowerInvariant();
|
||||
this.namespaceName = namespaceName;
|
||||
this.type = type;
|
||||
this.showInList = showInList;
|
||||
this.hasExplicitES3Type = hasExplicitES3Type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 600b987de172f4a82b182077ceb7fffa
|
||||
timeCreated: 1519132286
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c2c381dbeebc6340b10fc96c19a56c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5989e48214df74e2b9cced724ec2e5c8
|
||||
timeCreated: 1497259720
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21ce5c6c627d1104abe370a16034b267
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37947a5e91cbdb442b2655a7e75325b8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7b340139c9e4d054f904d8b452798652, type: 3}
|
||||
m_Name: ES3Defaults
|
||||
m_EditorClassIdentifier:
|
||||
settings:
|
||||
_location: 0
|
||||
path: SaveFile.es3
|
||||
encryptionType: 0
|
||||
compressionType: 0
|
||||
encryptionPassword: password
|
||||
directory: 0
|
||||
format: 0
|
||||
prettyPrint: 1
|
||||
bufferSize: 2048
|
||||
saveChildren: 1
|
||||
postprocessRawCachedData: 0
|
||||
typeChecking: 1
|
||||
safeReflection: 1
|
||||
memberReferenceMode: 0
|
||||
referenceMode: 2
|
||||
serializationDepthLimit: 64
|
||||
assemblyNames:
|
||||
- AppsFlyer
|
||||
- Assembly-CSharp
|
||||
- DOTween.Modules
|
||||
- DOTweenPro.Scripts
|
||||
- endel.nativewebsocket
|
||||
- IngameDebugConsole.Runtime
|
||||
- MaxSdk.Scripts
|
||||
- NativeGallery.Runtime
|
||||
- OPS.Obfuscator
|
||||
- spine-unity
|
||||
- Unity.Advertisement.IosSupport
|
||||
- Unity.Advertisement.IosSupport.Tests
|
||||
showAdvancedSettings: 0
|
||||
addMgrToSceneAutomatically: 0
|
||||
autoUpdateReferences: 1
|
||||
addAllPrefabsToManager: 1
|
||||
collectDependenciesDepth: 4
|
||||
collectDependenciesTimeout: 10
|
||||
updateReferencesWhenSceneChanges: 1
|
||||
updateReferencesWhenSceneIsSaved: 1
|
||||
updateReferencesWhenSceneIsOpened: 1
|
||||
referenceFolders: []
|
||||
logDebugInfo: 0
|
||||
logWarnings: 1
|
||||
logErrors: 1
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca4d43647cdf3fb4aaa948a958e8c0e0
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4416904d454a58c429d3b39b1f2dc050
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1adc48a002c61c7408132284b5926511
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class ES3Serializable : Attribute{}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class ES3NonSerializable : Attribute { }
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e29c69181d1dff642b20c218819fe2e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8df6646c090cd1043985f6648f2a39aa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ES3AutoSave : MonoBehaviour, ISerializationCallbackReceiver
|
||||
{
|
||||
public bool saveLayer = true;
|
||||
public bool saveTag = true;
|
||||
public bool saveName = true;
|
||||
public bool saveHideFlags = true;
|
||||
public bool saveActive = true;
|
||||
public bool saveChildren = false;
|
||||
|
||||
private bool isQuitting = false;
|
||||
|
||||
//[HideInInspector]
|
||||
public List<Component> componentsToSave = new List<Component>();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
// Initialise saveLayer (etc) to false for all new Components.
|
||||
saveLayer = false;
|
||||
saveTag = false;
|
||||
saveName = false;
|
||||
saveHideFlags = false;
|
||||
saveActive = false;
|
||||
saveChildren = false;
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
if (ES3AutoSaveMgr.Current == null)
|
||||
ES3Internal.ES3Debug.LogWarning("<b>No GameObjects in this scene will be autosaved</b> because there is no Easy Save 3 Manager. To add a manager to this scene, exit playmode and go to Assets > Easy Save 3 > Add Manager to Scene.", this);
|
||||
else
|
||||
ES3AutoSaveMgr.AddAutoSave(this);
|
||||
}
|
||||
|
||||
public void OnApplicationQuit()
|
||||
{
|
||||
isQuitting = true;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
// If this is being destroyed, but not because the application is quitting,
|
||||
// remove the AutoSave from the manager.
|
||||
if (!isQuitting)
|
||||
ES3AutoSaveMgr.RemoveAutoSave(this);
|
||||
}
|
||||
public void OnBeforeSerialize() { }
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
// Remove any null Components
|
||||
componentsToSave.RemoveAll(c => c == null || c.GetType() == typeof(Component));
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfcc9ceea0bf419cb3bcaf548c2600d
|
||||
timeCreated: 1519132292
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Linq;
|
||||
|
||||
#if UNITY_VISUAL_SCRIPTING
|
||||
[Unity.VisualScripting.IncludeInSettings(true)]
|
||||
#elif BOLT_VISUAL_SCRIPTING
|
||||
[Ludiq.IncludeInSettings(true)]
|
||||
#endif
|
||||
public class ES3AutoSaveMgr : MonoBehaviour
|
||||
{
|
||||
public static ES3AutoSaveMgr _current = null;
|
||||
public static ES3AutoSaveMgr Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_current == null /*|| _current.gameObject.scene != SceneManager.GetActiveScene()*/)
|
||||
{
|
||||
var scene = SceneManager.GetActiveScene();
|
||||
var roots = scene.GetRootGameObjects();
|
||||
|
||||
// First, look for Easy Save 3 Manager in the top-level.
|
||||
foreach (var root in roots)
|
||||
if (root.name == "Easy Save 3 Manager")
|
||||
return _current = root.GetComponent<ES3AutoSaveMgr>();
|
||||
|
||||
// If the user has moved or renamed the Easy Save 3 Manager, we need to perform a deep search.
|
||||
foreach (var root in roots)
|
||||
if ((_current = root.GetComponentInChildren<ES3AutoSaveMgr>()) != null)
|
||||
return _current;
|
||||
}
|
||||
return _current;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<Scene, ES3AutoSaveMgr> managers = new Dictionary<Scene, ES3AutoSaveMgr>();
|
||||
|
||||
// Included for backwards compatibility.
|
||||
public static ES3AutoSaveMgr Instance
|
||||
{
|
||||
get { return Current; }
|
||||
}
|
||||
|
||||
public enum LoadEvent { None, Awake, Start }
|
||||
public enum SaveEvent { None, OnApplicationQuit, OnApplicationPause }
|
||||
|
||||
public string key = System.Guid.NewGuid().ToString();
|
||||
public SaveEvent saveEvent = SaveEvent.OnApplicationQuit;
|
||||
public LoadEvent loadEvent = LoadEvent.Start;
|
||||
public ES3SerializableSettings settings = new ES3SerializableSettings("SaveFile.es3", ES3.Location.Cache);
|
||||
|
||||
public HashSet<ES3AutoSave> autoSaves = new HashSet<ES3AutoSave>();
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (autoSaves == null || autoSaves.Count == 0)
|
||||
return;
|
||||
|
||||
ManageSlots();
|
||||
|
||||
// If we're using caching and we've not already cached this file, cache it.
|
||||
if (settings.location == ES3.Location.Cache && !ES3.FileExists(settings))
|
||||
ES3.CacheFile(settings);
|
||||
|
||||
if (autoSaves == null || autoSaves.Count == 0)
|
||||
{
|
||||
ES3.DeleteKey(key, settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
var gameObjects = new List<GameObject>();
|
||||
foreach (var autoSave in autoSaves)
|
||||
{
|
||||
// If the ES3AutoSave component is disabled, don't save it.
|
||||
if (autoSave != null && autoSave.enabled)
|
||||
gameObjects.Add(autoSave.gameObject);
|
||||
}
|
||||
// Save in the same order as their depth in the hierarchy.
|
||||
ES3.Save<GameObject[]>(key, gameObjects.OrderBy(x => GetDepth(x.transform)).ToArray(), settings);
|
||||
}
|
||||
|
||||
if(settings.location == ES3.Location.Cache && ES3.FileExists(settings))
|
||||
ES3.StoreCachedFile(settings);
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
ManageSlots();
|
||||
|
||||
try
|
||||
{
|
||||
// If we're using caching and we've not already cached this file, cache it.
|
||||
if (settings.location == ES3.Location.Cache && !ES3.FileExists(settings))
|
||||
ES3.CacheFile(settings);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
// Ensure that the reference manager for this scene has been initialised.
|
||||
var mgr = ES3ReferenceMgr.GetManagerFromScene(this.gameObject.scene, false);
|
||||
mgr.Awake();
|
||||
|
||||
var gameObjects = ES3.Load<GameObject[]>(key, new GameObject[0], settings);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(loadEvent == LoadEvent.Start)
|
||||
Load();
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
managers[this.gameObject.scene] = this;
|
||||
GetAutoSaves();
|
||||
|
||||
if (loadEvent == LoadEvent.Awake)
|
||||
Load();
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
if(saveEvent == SaveEvent.OnApplicationQuit)
|
||||
Save();
|
||||
}
|
||||
|
||||
void OnApplicationPause(bool paused)
|
||||
{
|
||||
if( (saveEvent == SaveEvent.OnApplicationPause ||
|
||||
(Application.isMobilePlatform && saveEvent == SaveEvent.OnApplicationQuit)) && paused)
|
||||
Save();
|
||||
}
|
||||
|
||||
/* Register an ES3AutoSave with the ES3AutoSaveMgr, if there is one */
|
||||
public static void AddAutoSave(ES3AutoSave autoSave)
|
||||
{
|
||||
if (autoSave == null)
|
||||
return;
|
||||
|
||||
ES3AutoSaveMgr mgr;
|
||||
if (managers.TryGetValue(autoSave.gameObject.scene, out mgr))
|
||||
mgr.autoSaves.Add(autoSave);
|
||||
|
||||
/*if(ES3AutoSaveMgr.Current != null)
|
||||
ES3AutoSaveMgr.Current.autoSaves.Add(autoSave);*/
|
||||
}
|
||||
|
||||
/* Remove an ES3AutoSave from the ES3AutoSaveMgr, for example if it's GameObject has been destroyed */
|
||||
public static void RemoveAutoSave(ES3AutoSave autoSave)
|
||||
{
|
||||
if (autoSave == null)
|
||||
return;
|
||||
|
||||
ES3AutoSaveMgr mgr;
|
||||
if (managers.TryGetValue(autoSave.gameObject.scene, out mgr))
|
||||
mgr.autoSaves.Remove(autoSave);
|
||||
|
||||
/*if (ES3AutoSaveMgr.Current != null)
|
||||
ES3AutoSaveMgr.Current.autoSaves.Remove(autoSave);*/
|
||||
}
|
||||
|
||||
/* Gathers all of the ES3AutoSave Components in the scene and registers them with the manager */
|
||||
public void GetAutoSaves()
|
||||
{
|
||||
autoSaves = new HashSet<ES3AutoSave>();
|
||||
|
||||
foreach (var go in this.gameObject.scene.GetRootGameObjects())
|
||||
autoSaves.UnionWith(go.GetComponentsInChildren<ES3AutoSave>(true));
|
||||
}
|
||||
|
||||
// Gets the depth of a Transform in the hierarchy.
|
||||
static int GetDepth(Transform t)
|
||||
{
|
||||
int depth = 0;
|
||||
|
||||
while (t.parent != null)
|
||||
{
|
||||
t = t.parent;
|
||||
depth++;
|
||||
}
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
// Changes the path for this ES3AutoSave if we're using save slots.
|
||||
void ManageSlots()
|
||||
{
|
||||
#if ES3_TMPRO && ES3_UGUI
|
||||
if (ES3SlotManager.selectedSlotPath != null)
|
||||
settings.path = ES3SlotManager.selectedSlotPath;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9107aee0ced90422da95f0b31680501f
|
||||
timeCreated: 1519132291
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8af5038c70c9da64eb4fa2c079107361
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
internal static class ES3Debug
|
||||
{
|
||||
private const string disableInfoMsg = "\n<i>To disable these messages from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Info'</i>";
|
||||
private const string disableWarningMsg = "\n<i>To disable warnings from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Warnings'</i>";
|
||||
private const string disableErrorMsg = "\n<i>To disable these error messages from Easy Save, go to Window > Easy Save 3 > Settings, and uncheck 'Log Errors'</i>";
|
||||
|
||||
private const char indentChar = '-';
|
||||
|
||||
public static void Log(string msg, Object context = null, int indent=0)
|
||||
{
|
||||
if (!ES3Settings.defaultSettingsScriptableObject.logDebugInfo)
|
||||
return;
|
||||
else if (context != null)
|
||||
Debug.LogFormat(context, Indent(indent) + msg + disableInfoMsg);
|
||||
else
|
||||
Debug.LogFormat(context, Indent(indent) + msg);
|
||||
}
|
||||
|
||||
public static void LogWarning(string msg, Object context=null, int indent = 0)
|
||||
{
|
||||
if (!ES3Settings.defaultSettingsScriptableObject.logWarnings)
|
||||
return;
|
||||
else if (context != null)
|
||||
Debug.LogWarningFormat(context, Indent(indent) + msg + disableWarningMsg);
|
||||
else
|
||||
Debug.LogWarningFormat(context, Indent(indent) + msg + disableWarningMsg);
|
||||
}
|
||||
|
||||
public static void LogError(string msg, Object context = null, int indent = 0)
|
||||
{
|
||||
if (!ES3Settings.defaultSettingsScriptableObject.logErrors)
|
||||
return;
|
||||
else if (context != null)
|
||||
Debug.LogErrorFormat(context, Indent(indent) + msg + disableErrorMsg);
|
||||
else
|
||||
Debug.LogErrorFormat(context, Indent(indent) + msg + disableErrorMsg);
|
||||
}
|
||||
|
||||
private static string Indent(int size)
|
||||
{
|
||||
if (size < 0)
|
||||
return "";
|
||||
return new string(indentChar, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f97d288c55524622a117171a19d3225
|
||||
timeCreated: 1518175265
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca1cdcde6d39a44b39ee5f5b86ddfd73
|
||||
timeCreated: 1499764822
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,208 @@
|
||||
#if !DISABLE_ENCRYPTION
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
#if NETFX_CORE
|
||||
using Windows.Security.Cryptography;
|
||||
using Windows.Security.Cryptography.Core;
|
||||
using Windows.Storage.Streams;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
#endif
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
public static class ES3Hash
|
||||
{
|
||||
#if NETFX_CORE
|
||||
public static string SHA1Hash(string input)
|
||||
{
|
||||
return System.Text.Encoding.UTF8.GetString(UnityEngine.Windows.Crypto.ComputeSHA1Hash(System.Text.Encoding.UTF8.GetBytes(input)));
|
||||
}
|
||||
#else
|
||||
public static string SHA1Hash(string input)
|
||||
{
|
||||
using (SHA1Managed sha1 = new SHA1Managed())
|
||||
return System.Text.Encoding.UTF8.GetString(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract class EncryptionAlgorithm
|
||||
{
|
||||
public abstract byte[] Encrypt(byte[] bytes, string password, int bufferSize);
|
||||
public abstract byte[] Decrypt(byte[] bytes, string password, int bufferSize);
|
||||
public abstract void Encrypt(Stream input, Stream output, string password, int bufferSize);
|
||||
public abstract void Decrypt(Stream input, Stream output, string password, int bufferSize);
|
||||
|
||||
protected static void CopyStream(Stream input, Stream output, int bufferSize)
|
||||
{
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
int read;
|
||||
while ((read = input.Read(buffer, 0, bufferSize)) > 0)
|
||||
output.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
public class AESEncryptionAlgorithm : EncryptionAlgorithm
|
||||
{
|
||||
private const int ivSize = 16;
|
||||
private const int keySize = 16;
|
||||
private const int pwIterations = 100;
|
||||
|
||||
public override byte[] Encrypt(byte[] bytes, string password, int bufferSize)
|
||||
{
|
||||
using (var input = new MemoryStream(bytes))
|
||||
{
|
||||
using (var output = new MemoryStream())
|
||||
{
|
||||
Encrypt(input, output, password, bufferSize);
|
||||
return output.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override byte[] Decrypt(byte[] bytes, string password, int bufferSize)
|
||||
{
|
||||
using (var input = new MemoryStream(bytes))
|
||||
{
|
||||
using (var output = new MemoryStream())
|
||||
{
|
||||
Decrypt(input, output, password, bufferSize);
|
||||
return output.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Encrypt(Stream input, Stream output, string password, int bufferSize)
|
||||
{
|
||||
input.Position = 0;
|
||||
|
||||
#if NETFX_CORE
|
||||
// Generate an IV and write it to the output.
|
||||
var iv = CryptographicBuffer.GenerateRandom(ivSize);
|
||||
output.Write(iv.ToArray(), 0, ivSize);
|
||||
|
||||
var pwBuffer = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
|
||||
var keyDerivationProvider = KeyDerivationAlgorithmProvider.OpenAlgorithm("PBKDF2_SHA1");
|
||||
KeyDerivationParameters pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(iv, pwIterations);
|
||||
// Create a key based on original key and derivation parmaters
|
||||
CryptographicKey keyOriginal = keyDerivationProvider.CreateKey(pwBuffer);
|
||||
IBuffer keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms, keySize);
|
||||
|
||||
var provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
|
||||
var key = provider.CreateSymmetricKey(keyMaterial);
|
||||
|
||||
// Get the input stream as an IBuffer.
|
||||
IBuffer msg;
|
||||
using(var ms = new MemoryStream())
|
||||
{
|
||||
input.CopyTo(ms);
|
||||
msg = ms.ToArray().AsBuffer();
|
||||
}
|
||||
|
||||
var buffEncrypt = CryptographicEngine.Encrypt(key, msg, iv);
|
||||
|
||||
|
||||
output.Write(buffEncrypt.ToArray(), 0, (int)buffEncrypt.Length);
|
||||
output.Dispose();
|
||||
#else
|
||||
using (var alg = Aes.Create())
|
||||
{
|
||||
alg.Mode = CipherMode.CBC;
|
||||
alg.Padding = PaddingMode.PKCS7;
|
||||
alg.GenerateIV();
|
||||
var key = new Rfc2898DeriveBytes(password, alg.IV, pwIterations);
|
||||
alg.Key = key.GetBytes(keySize);
|
||||
// Write the IV to the output stream.
|
||||
output.Write(alg.IV, 0, ivSize);
|
||||
using(var encryptor = alg.CreateEncryptor())
|
||||
using(var cs = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
|
||||
CopyStream(input, cs, bufferSize);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Decrypt(Stream input, Stream output, string password, int bufferSize)
|
||||
{
|
||||
#if NETFX_CORE
|
||||
var thisIV = new byte[ivSize];
|
||||
input.Read(thisIV, 0, ivSize);
|
||||
var iv = thisIV.AsBuffer();
|
||||
|
||||
var pwBuffer = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
|
||||
|
||||
var keyDerivationProvider = KeyDerivationAlgorithmProvider.OpenAlgorithm("PBKDF2_SHA1");
|
||||
KeyDerivationParameters pbkdf2Parms = KeyDerivationParameters.BuildForPbkdf2(iv, pwIterations);
|
||||
// Create a key based on original key and derivation parameters.
|
||||
CryptographicKey keyOriginal = keyDerivationProvider.CreateKey(pwBuffer);
|
||||
IBuffer keyMaterial = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Parms, keySize);
|
||||
|
||||
var provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
|
||||
var key = provider.CreateSymmetricKey(keyMaterial);
|
||||
|
||||
// Get the input stream as an IBuffer.
|
||||
IBuffer msg;
|
||||
using(var ms = new MemoryStream())
|
||||
{
|
||||
input.CopyTo(ms);
|
||||
msg = ms.ToArray().AsBuffer();
|
||||
}
|
||||
|
||||
var buffDecrypt = CryptographicEngine.Decrypt(key, msg, iv);
|
||||
|
||||
output.Write(buffDecrypt.ToArray(), 0, (int)buffDecrypt.Length);
|
||||
#else
|
||||
using (var alg = Aes.Create())
|
||||
{
|
||||
var thisIV = new byte[ivSize];
|
||||
input.Read(thisIV, 0, ivSize);
|
||||
alg.IV = thisIV;
|
||||
|
||||
var key = new Rfc2898DeriveBytes(password, alg.IV, pwIterations);
|
||||
alg.Key = key.GetBytes(keySize);
|
||||
|
||||
using(var decryptor = alg.CreateDecryptor())
|
||||
using(var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
|
||||
CopyStream(cryptoStream, output, bufferSize);
|
||||
|
||||
}
|
||||
#endif
|
||||
output.Position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class UnbufferedCryptoStream : MemoryStream
|
||||
{
|
||||
private readonly Stream stream;
|
||||
private readonly bool isReadStream;
|
||||
private string password;
|
||||
private int bufferSize;
|
||||
private EncryptionAlgorithm alg;
|
||||
private bool disposed = false;
|
||||
|
||||
public UnbufferedCryptoStream(Stream stream, bool isReadStream, string password, int bufferSize, EncryptionAlgorithm alg) : base()
|
||||
{
|
||||
this.stream = stream;
|
||||
this.isReadStream = isReadStream;
|
||||
this.password = password;
|
||||
this.bufferSize = bufferSize;
|
||||
this.alg = alg;
|
||||
|
||||
|
||||
if (isReadStream)
|
||||
alg.Decrypt(stream, this, password, bufferSize);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
disposed = true;
|
||||
|
||||
if (!isReadStream)
|
||||
alg.Encrypt(this, stream, password, bufferSize);
|
||||
stream.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2b3b6335276042569261b3e6bed694e
|
||||
timeCreated: 1519132297
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,524 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System;
|
||||
using ES3Types;
|
||||
using UnityEngine;
|
||||
using ES3Internal;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>Represents a cached file which can be saved to and loaded from, and commited to storage when necessary.</summary>
|
||||
public class ES3File
|
||||
{
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static Dictionary<string, ES3File> cachedFiles = new Dictionary<string, ES3File>();
|
||||
|
||||
|
||||
|
||||
|
||||
public ES3Settings settings;
|
||||
private Dictionary<string, ES3Data> cache = new Dictionary<string, ES3Data>();
|
||||
private bool syncWithFile = false;
|
||||
private DateTime timestamp = DateTime.UtcNow;
|
||||
|
||||
/// <summary>Creates a new ES3File and loads the default file into the ES3File if there is data to load.</summary>
|
||||
public ES3File() : this(new ES3Settings(), true) { }
|
||||
|
||||
/// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
|
||||
/// <param name="filepath">The relative or absolute path of the file in storage our ES3File is associated with.</param>
|
||||
public ES3File(string filePath) : this(new ES3Settings(filePath), true) { }
|
||||
|
||||
/// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
|
||||
/// <param name="filepath">The relative or absolute path of the file in storage our ES3File is associated with.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public ES3File(string filePath, ES3Settings settings) : this(new ES3Settings(filePath, settings), true) { }
|
||||
|
||||
/// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public ES3File(ES3Settings settings) : this(settings, true) { }
|
||||
|
||||
/// <summary>Creates a new ES3File and only loads the default file into it if syncWithFile is set to true.</summary>
|
||||
/// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
|
||||
public ES3File(bool syncWithFile) : this(new ES3Settings(), syncWithFile) { }
|
||||
/// <summary>Creates a new ES3File and only loads the specified file into it if syncWithFile is set to true.</summary>
|
||||
/// <param name="filepath">The relative or absolute path of the file in storage our ES3File is associated with.</param>
|
||||
/// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
|
||||
public ES3File(string filePath, bool syncWithFile) : this(new ES3Settings(filePath), syncWithFile) { }
|
||||
/// <summary>Creates a new ES3File and only loads the specified file into it if syncWithFile is set to true.</summary>
|
||||
/// <param name="filepath">The relative or absolute path of the file in storage our ES3File is associated with.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
/// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
|
||||
public ES3File(string filePath, ES3Settings settings, bool syncWithFile) : this(new ES3Settings(filePath, settings), syncWithFile) { }
|
||||
|
||||
/// <summary>Creates a new ES3File and loads the specified file into the ES3File if there is data to load.</summary>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
/// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
|
||||
public ES3File(ES3Settings settings, bool syncWithFile)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.syncWithFile = syncWithFile;
|
||||
if (syncWithFile)
|
||||
{
|
||||
// Type checking must be enabled when syncing.
|
||||
var settingsWithTypeChecking = (ES3Settings)settings.Clone();
|
||||
settingsWithTypeChecking.typeChecking = true;
|
||||
|
||||
using (var reader = ES3Reader.Create(settingsWithTypeChecking))
|
||||
{
|
||||
if (reader == null)
|
||||
return;
|
||||
foreach (KeyValuePair<string, ES3Data> kvp in reader.RawEnumerator)
|
||||
cache[kvp.Key] = kvp.Value;
|
||||
}
|
||||
|
||||
timestamp = ES3.GetTimestamp(settingsWithTypeChecking);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3File and loads the bytes into the ES3File. Note the bytes must represent that of a file.</summary>
|
||||
/// <param name="bytes">The bytes representing our file.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
/// <param name="syncWithFile">Whether we should sync this ES3File with the one in storage immediately after creating it.</param>
|
||||
public ES3File(byte[] bytes, ES3Settings settings = null)
|
||||
{
|
||||
if (settings == null)
|
||||
this.settings = new ES3Settings();
|
||||
else
|
||||
this.settings = settings;
|
||||
|
||||
syncWithFile = true; // This ensures that the file won't be merged, which would prevent deleted keys from being deleted.
|
||||
|
||||
SaveRaw(bytes, settings);
|
||||
}
|
||||
|
||||
/// <summary>Synchronises this ES3File with a file in storage.</summary>
|
||||
public void Sync()
|
||||
{
|
||||
Sync(this.settings);
|
||||
}
|
||||
|
||||
/// <summary>Synchronises this ES3File with a file in storage.</summary>
|
||||
/// <param name="filepath">The relative or absolute path of the file in storage we want to synchronise with.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public void Sync(string filePath, ES3Settings settings = null)
|
||||
{
|
||||
Sync(new ES3Settings(filePath, settings));
|
||||
}
|
||||
|
||||
/// <summary>Synchronises this ES3File with a file in storage.</summary>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public void Sync(ES3Settings settings = null)
|
||||
{
|
||||
if (settings == null)
|
||||
settings = new ES3Settings();
|
||||
|
||||
if (cache.Count == 0)
|
||||
{
|
||||
ES3.DeleteFile(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var baseWriter = ES3Writer.Create(settings, true, !syncWithFile, false))
|
||||
{
|
||||
foreach (var kvp in cache)
|
||||
{
|
||||
// If we change the name of a type, the type may be null.
|
||||
// In this case, use System.Object as the type.
|
||||
Type type;
|
||||
if (kvp.Value.type == null)
|
||||
type = typeof(System.Object);
|
||||
else
|
||||
type = kvp.Value.type.type;
|
||||
baseWriter.Write(kvp.Key, type, kvp.Value.bytes);
|
||||
}
|
||||
baseWriter.Save(!syncWithFile);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Removes the data stored in this ES3File. The ES3File will be empty after calling this method.</summary>
|
||||
public void Clear()
|
||||
{
|
||||
cache.Clear();
|
||||
}
|
||||
|
||||
/// <summary>Returns an array of all of the key names in this ES3File.</summary>
|
||||
public string[] GetKeys()
|
||||
{
|
||||
var keyCollection = cache.Keys;
|
||||
var keys = new string[keyCollection.Count];
|
||||
keyCollection.CopyTo(keys, 0);
|
||||
return keys;
|
||||
}
|
||||
|
||||
#region Save Methods
|
||||
|
||||
/// <summary>Saves a value to a key in this ES3File.</summary>
|
||||
/// <param name="key">The key we want to use to identify our value in the file.</param>
|
||||
/// <param name="value">The value we want to save.</param>
|
||||
public void Save<T>(string key, T value)
|
||||
{
|
||||
var unencryptedSettings = (ES3Settings)settings.Clone();
|
||||
unencryptedSettings.encryptionType = ES3.EncryptionType.None;
|
||||
unencryptedSettings.compressionType = ES3.CompressionType.None;
|
||||
|
||||
// If T is object, use the value to get it's type. Otherwise, use T so that it works with inheritence.
|
||||
Type type;
|
||||
if (value == null)
|
||||
type = typeof(T);
|
||||
else
|
||||
type = value.GetType();
|
||||
|
||||
ES3Type es3Type = ES3TypeMgr.GetOrCreateES3Type(type);
|
||||
|
||||
cache[key] = new ES3Data(es3Type, ES3.Serialize(value, es3Type, unencryptedSettings));
|
||||
}
|
||||
|
||||
/// <summary>Merges the data specified by the bytes parameter into this ES3File.</summary>
|
||||
/// <param name="bytes">The bytes we want to merge with this ES3File.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public void SaveRaw(byte[] bytes, ES3Settings settings = null)
|
||||
{
|
||||
if (settings == null)
|
||||
settings = new ES3Settings();
|
||||
|
||||
// Type checking must be enabled when syncing.
|
||||
var settingsWithTypeChecking = (ES3Settings)settings.Clone();
|
||||
settingsWithTypeChecking.typeChecking = true;
|
||||
|
||||
using (var reader = ES3Reader.Create(bytes, settingsWithTypeChecking))
|
||||
{
|
||||
if (reader == null)
|
||||
return;
|
||||
foreach (KeyValuePair<string, ES3Data> kvp in reader.RawEnumerator)
|
||||
cache[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Merges the data specified by the bytes parameter into this ES3File.</summary>
|
||||
/// <param name="bytes">The bytes we want to merge with this ES3File.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public void AppendRaw(byte[] bytes, ES3Settings settings = null)
|
||||
{
|
||||
if (settings == null)
|
||||
settings = new ES3Settings();
|
||||
// AppendRaw just does the same thing as SaveRaw in ES3File.
|
||||
SaveRaw(bytes, settings);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Load Methods
|
||||
|
||||
/* Standard load methods */
|
||||
|
||||
/// <summary>Loads the value from this ES3File with the given key.</summary>
|
||||
/// <param name="key">The key which identifies the value we want to load.</param>
|
||||
public object Load(string key)
|
||||
{
|
||||
return Load<object>(key);
|
||||
}
|
||||
|
||||
/// <summary>Loads the value from this ES3File with the given key.</summary>
|
||||
/// <param name="key">The key which identifies the value we want to load.</param>
|
||||
/// <param name="defaultValue">The value we want to return if the key does not exist in this ES3File.</param>
|
||||
public object Load(string key, object defaultValue)
|
||||
{
|
||||
return Load<object>(key, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>Loads the value from this ES3File with the given key.</summary>
|
||||
/// <param name="key">The key which identifies the value we want to load.</param>
|
||||
public T Load<T>(string key)
|
||||
{
|
||||
ES3Data es3Data;
|
||||
|
||||
if (!cache.TryGetValue(key, out es3Data))
|
||||
throw new KeyNotFoundException("Key \"" + key + "\" was not found in this ES3File. Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.");
|
||||
|
||||
var unencryptedSettings = (ES3Settings)this.settings.Clone();
|
||||
unencryptedSettings.encryptionType = ES3.EncryptionType.None;
|
||||
unencryptedSettings.compressionType = ES3.CompressionType.None;
|
||||
|
||||
// If we're loading a derived type using it's parent type, ensure that we use the ES3Type from the ES3Data.
|
||||
if (typeof(T) != es3Data.type.type && ES3Reflection.IsAssignableFrom(typeof(T), es3Data.type.type))
|
||||
return (T)ES3.Deserialize(es3Data.type, es3Data.bytes, unencryptedSettings);
|
||||
return ES3.Deserialize<T>(es3Data.bytes, unencryptedSettings);
|
||||
}
|
||||
|
||||
/// <summary>Loads the value from this ES3File with the given key.</summary>
|
||||
/// <param name="key">The key which identifies the value we want to load.</param>
|
||||
/// <param name="defaultValue">The value we want to return if the key does not exist in this ES3File.</param>
|
||||
public T Load<T>(string key, T defaultValue)
|
||||
{
|
||||
ES3Data es3Data;
|
||||
|
||||
if (!cache.TryGetValue(key, out es3Data))
|
||||
return defaultValue;
|
||||
var unencryptedSettings = (ES3Settings)this.settings.Clone();
|
||||
unencryptedSettings.encryptionType = ES3.EncryptionType.None;
|
||||
unencryptedSettings.compressionType = ES3.CompressionType.None;
|
||||
|
||||
// If we're loading a derived type using it's parent type, ensure that we use the ES3Type from the ES3Data.
|
||||
if (typeof(T) != es3Data.type.type && ES3Reflection.IsAssignableFrom(typeof(T), es3Data.type.type))
|
||||
return (T)ES3.Deserialize(es3Data.type, es3Data.bytes, unencryptedSettings);
|
||||
return ES3.Deserialize<T>(es3Data.bytes, unencryptedSettings);
|
||||
}
|
||||
|
||||
/// <summary>Loads the value from this ES3File with the given key into an existing object.</summary>
|
||||
/// <param name="key">The key which identifies the value we want to load.</param>
|
||||
/// <param name="obj">The object we want to load the value into.</param>
|
||||
public void LoadInto<T>(string key, T obj) where T : class
|
||||
{
|
||||
ES3Data es3Data;
|
||||
|
||||
if (!cache.TryGetValue(key, out es3Data))
|
||||
throw new KeyNotFoundException("Key \"" + key + "\" was not found in this ES3File. Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.");
|
||||
|
||||
var unencryptedSettings = (ES3Settings)this.settings.Clone();
|
||||
unencryptedSettings.encryptionType = ES3.EncryptionType.None;
|
||||
unencryptedSettings.compressionType = ES3.CompressionType.None;
|
||||
|
||||
// If we're loading a derived type using it's parent type, ensure that we use the ES3Type from the ES3Data.
|
||||
if (typeof(T) != es3Data.type.type && ES3Reflection.IsAssignableFrom(typeof(T), es3Data.type.type))
|
||||
ES3.DeserializeInto(es3Data.type, es3Data.bytes, obj, unencryptedSettings);
|
||||
else
|
||||
ES3.DeserializeInto(es3Data.bytes, obj, unencryptedSettings);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Load Raw Methods
|
||||
|
||||
/// <summary>Loads the ES3File as a raw, unencrypted, uncompressed byte array.</summary>
|
||||
public byte[] LoadRawBytes()
|
||||
{
|
||||
var newSettings = (ES3Settings)settings.Clone();
|
||||
if (!newSettings.postprocessRawCachedData)
|
||||
{
|
||||
newSettings.encryptionType = ES3.EncryptionType.None;
|
||||
newSettings.compressionType = ES3.CompressionType.None;
|
||||
}
|
||||
return GetBytes(newSettings);
|
||||
}
|
||||
|
||||
/// <summary>Loads the ES3File as a raw, unencrypted, uncompressed string, using the encoding defined in the ES3File's settings variable.</summary>
|
||||
public string LoadRawString()
|
||||
{
|
||||
if (cache.Count == 0)
|
||||
return "";
|
||||
return settings.encoding.GetString(LoadRawBytes());
|
||||
}
|
||||
|
||||
/*
|
||||
* Same as LoadRawString, except it will return an encrypted/compressed file if these are enabled.
|
||||
*/
|
||||
internal byte[] GetBytes(ES3Settings settings = null)
|
||||
{
|
||||
if (cache.Count == 0)
|
||||
return new byte[0];
|
||||
|
||||
if (settings == null)
|
||||
settings = this.settings;
|
||||
|
||||
using (var ms = new System.IO.MemoryStream())
|
||||
{
|
||||
var memorySettings = (ES3Settings)settings.Clone();
|
||||
memorySettings.location = ES3.Location.InternalMS;
|
||||
// Ensure we return unencrypted bytes.
|
||||
if (!memorySettings.postprocessRawCachedData)
|
||||
{
|
||||
memorySettings.encryptionType = ES3.EncryptionType.None;
|
||||
memorySettings.compressionType = ES3.CompressionType.None;
|
||||
}
|
||||
|
||||
using (var baseWriter = ES3Writer.Create(ES3Stream.CreateStream(ms, memorySettings, ES3FileMode.Write), memorySettings, true, false))
|
||||
{
|
||||
foreach (var kvp in cache)
|
||||
baseWriter.Write(kvp.Key, kvp.Value.type.type, kvp.Value.bytes);
|
||||
baseWriter.Save(false);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Other ES3 Methods
|
||||
|
||||
/// <summary>Deletes a key from this ES3File.</summary>
|
||||
/// <param name="key">The key we want to delete.</param>
|
||||
public void DeleteKey(string key)
|
||||
{
|
||||
cache.Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>Checks whether a key exists in this ES3File.</summary>
|
||||
/// <param name="key">The key we want to check the existence of.</param>
|
||||
/// <returns>True if the key exists, otherwise False.</returns>
|
||||
public bool KeyExists(string key)
|
||||
{
|
||||
return cache.ContainsKey(key);
|
||||
}
|
||||
|
||||
/// <summary>Gets the size of the cached data in bytes.</summary>
|
||||
public int Size()
|
||||
{
|
||||
int size = 0;
|
||||
foreach (var kvp in cache)
|
||||
size += kvp.Value.bytes.Length;
|
||||
return size;
|
||||
}
|
||||
|
||||
public Type GetKeyType(string key)
|
||||
{
|
||||
ES3Data es3data;
|
||||
if (!cache.TryGetValue(key, out es3data))
|
||||
throw new KeyNotFoundException("Key \"" + key + "\" was not found in this ES3File. Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.");
|
||||
|
||||
return es3data.type.type;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static ES3File GetOrCreateCachedFile(ES3Settings settings)
|
||||
{
|
||||
ES3File cachedFile;
|
||||
if (!cachedFiles.TryGetValue(settings.path, out cachedFile))
|
||||
{
|
||||
cachedFile = new ES3File(settings, false);
|
||||
cachedFiles.Add(settings.path, cachedFile);
|
||||
cachedFile.syncWithFile = true; // This ensures that the file won't be merged, which would prevent deleted keys from being deleted.
|
||||
}
|
||||
// Settings might refer to the same file, but might have changed.
|
||||
// To account for this, we update the settings of the ES3File each time we access it.
|
||||
cachedFile.settings = settings;
|
||||
return cachedFile;
|
||||
}
|
||||
|
||||
internal static void CacheFile(ES3Settings settings)
|
||||
{
|
||||
// If we're still using cached settings, set it to the default location.
|
||||
if (settings.location == ES3.Location.Cache)
|
||||
{
|
||||
settings = (ES3Settings)settings.Clone();
|
||||
// If the default settings are also set to cache, assume ES3.Location.File. Otherwise, set it to the default location.
|
||||
settings.location = ES3Settings.defaultSettings.location == ES3.Location.Cache ? ES3.Location.File : ES3Settings.defaultSettings.location;
|
||||
}
|
||||
|
||||
if (!ES3.FileExists(settings))
|
||||
return;
|
||||
|
||||
// Disable compression and encryption when loading the raw bytes, and the ES3File constructor will expect encrypted/compressed bytes.
|
||||
var loadSettings = (ES3Settings)settings.Clone();
|
||||
loadSettings.compressionType = ES3.CompressionType.None;
|
||||
loadSettings.encryptionType = ES3.EncryptionType.None;
|
||||
|
||||
cachedFiles[settings.path] = new ES3File(ES3.LoadRawBytes(loadSettings), settings);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static void Store(ES3Settings settings = null)
|
||||
{
|
||||
if (settings == null)
|
||||
settings = new ES3Settings(ES3.Location.File);
|
||||
// If we're still using cached settings, set it to the default location.
|
||||
else if (settings.location == ES3.Location.Cache)
|
||||
{
|
||||
settings = (ES3Settings)settings.Clone();
|
||||
// If the default settings are also set to cache, assume ES3.Location.File. Otherwise, set it to the default location.
|
||||
settings.location = ES3Settings.defaultSettings.location == ES3.Location.Cache ? ES3.Location.File : ES3Settings.defaultSettings.location;
|
||||
}
|
||||
|
||||
ES3File cachedFile;
|
||||
if (!cachedFiles.TryGetValue(settings.path, out cachedFile))
|
||||
throw new FileNotFoundException("The file '" + settings.path + "' could not be stored because it could not be found in the cache.");
|
||||
cachedFile.Sync(settings);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static void RemoveCachedFile(ES3Settings settings)
|
||||
{
|
||||
cachedFiles.Remove(settings.path);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static void CopyCachedFile(ES3Settings oldSettings, ES3Settings newSettings)
|
||||
{
|
||||
ES3File cachedFile;
|
||||
if (!cachedFiles.TryGetValue(oldSettings.path, out cachedFile))
|
||||
throw new FileNotFoundException("The file '" + oldSettings.path + "' could not be copied because it could not be found in the cache.");
|
||||
if (cachedFiles.ContainsKey(newSettings.path))
|
||||
throw new InvalidOperationException("Cannot copy file '" + oldSettings.path + "' to '" + newSettings.path + "' because '" + newSettings.path + "' already exists");
|
||||
|
||||
cachedFiles.Add(newSettings.path, (ES3File)cachedFile.MemberwiseClone());
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static void DeleteKey(string key, ES3Settings settings)
|
||||
{
|
||||
ES3File cachedFile;
|
||||
if (cachedFiles.TryGetValue(settings.path, out cachedFile))
|
||||
cachedFile.DeleteKey(key);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static bool KeyExists(string key, ES3Settings settings)
|
||||
{
|
||||
ES3File cachedFile;
|
||||
if (cachedFiles.TryGetValue(settings.path, out cachedFile))
|
||||
return cachedFile.KeyExists(key);
|
||||
return false;
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static bool FileExists(ES3Settings settings)
|
||||
{
|
||||
return cachedFiles.ContainsKey(settings.path);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static string[] GetKeys(ES3Settings settings)
|
||||
{
|
||||
ES3File cachedFile;
|
||||
if (!cachedFiles.TryGetValue(settings.path, out cachedFile))
|
||||
throw new FileNotFoundException("Could not get keys from the file '" + settings.path + "' because it could not be found in the cache.");
|
||||
return cachedFile.cache.Keys.ToArray();
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal static string[] GetFiles()
|
||||
{
|
||||
return cachedFiles.Keys.ToArray();
|
||||
}
|
||||
|
||||
internal static DateTime GetTimestamp(ES3Settings settings)
|
||||
{
|
||||
ES3File cachedFile;
|
||||
if (!cachedFiles.TryGetValue(settings.path, out cachedFile))
|
||||
return new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
return cachedFile.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
public struct ES3Data
|
||||
{
|
||||
public ES3Type type;
|
||||
public byte[] bytes;
|
||||
|
||||
public ES3Data(Type type, byte[] bytes)
|
||||
{
|
||||
this.type = type == null ? null : ES3TypeMgr.GetOrCreateES3Type(type);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public ES3Data(ES3Type type, byte[] bytes)
|
||||
{
|
||||
this.type = type;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cd9723dc51904030be3c30362442d47
|
||||
timeCreated: 1499764821
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class ES3GameObject : MonoBehaviour
|
||||
{
|
||||
public List<Component> components = new List<Component>();
|
||||
|
||||
/* Ensures that this Component is always last in the List to guarantee that it's loaded after any Components it references */
|
||||
private void Update()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
return;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditorInternal.ComponentUtility.MoveComponentDown(this);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e2cacabe81aea8468e08e911727ee97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,181 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
public static class ES3IO
|
||||
{
|
||||
#if UNITY_SWITCH
|
||||
internal static readonly string persistentDataPath = "";
|
||||
internal static readonly string dataPath = "";
|
||||
#else
|
||||
internal static readonly string persistentDataPath = Application.persistentDataPath;
|
||||
internal static readonly string dataPath = Application.dataPath;
|
||||
#endif
|
||||
|
||||
internal const string backupFileSuffix = ".bac";
|
||||
internal const string temporaryFileSuffix = ".tmp";
|
||||
|
||||
public enum ES3FileMode { Read, Write, Append }
|
||||
|
||||
public static DateTime GetTimestamp(string filePath)
|
||||
{
|
||||
if (!FileExists(filePath))
|
||||
return new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
|
||||
return File.GetLastWriteTime(filePath).ToUniversalTime();
|
||||
}
|
||||
|
||||
public static string GetExtension(string path)
|
||||
{
|
||||
return Path.GetExtension(path);
|
||||
}
|
||||
|
||||
public static void DeleteFile(string filePath)
|
||||
{
|
||||
if (FileExists(filePath))
|
||||
File.Delete(filePath);
|
||||
}
|
||||
|
||||
public static bool FileExists(string filePath) { return File.Exists(filePath); }
|
||||
public static void MoveFile(string sourcePath, string destPath) { File.Move(sourcePath, destPath); }
|
||||
public static void CopyFile(string sourcePath, string destPath) { File.Copy(sourcePath, destPath); }
|
||||
|
||||
public static void MoveDirectory(string sourcePath, string destPath) { Directory.Move(sourcePath, destPath); }
|
||||
public static void CreateDirectory(string directoryPath) { Directory.CreateDirectory(directoryPath); }
|
||||
public static bool DirectoryExists(string directoryPath) { return Directory.Exists(directoryPath); }
|
||||
|
||||
/*
|
||||
* Given a path, it returns the directory that path points to.
|
||||
* eg. "C:/myFolder/thisFolder/myFile.txt" will return "C:/myFolder/thisFolder".
|
||||
*/
|
||||
public static string GetDirectoryPath(string path, char seperator = '/')
|
||||
{
|
||||
//return Path.GetDirectoryName(path);
|
||||
// Path.GetDirectoryName turns forward slashes to backslashes in some cases on Windows, which is why
|
||||
// Substring is used instead.
|
||||
char slashChar = UsesForwardSlash(path) ? '/' : '\\';
|
||||
|
||||
int slash = path.LastIndexOf(slashChar);
|
||||
|
||||
// If this path ends in a slash it is assumed to already be a path to a Directory.
|
||||
if (slash == path.Length - 1)
|
||||
return path;
|
||||
|
||||
// Ignore trailing slash if necessary.
|
||||
if (slash == (path.Length - 1))
|
||||
slash = path.Substring(0, slash).LastIndexOf(slashChar);
|
||||
if (slash == -1)
|
||||
ES3Debug.LogError("Path provided is not a directory path as it contains no slashes.");
|
||||
return path.Substring(0, slash);
|
||||
}
|
||||
|
||||
public static bool UsesForwardSlash(string path)
|
||||
{
|
||||
if (path.Contains("/"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Takes a directory path and a file or directory name and combines them into a single path.
|
||||
public static string CombinePathAndFilename(string directoryPath, string fileOrDirectoryName)
|
||||
{
|
||||
if (directoryPath[directoryPath.Length - 1] != '/' && directoryPath[directoryPath.Length - 1] != '\\')
|
||||
directoryPath += '/';
|
||||
return directoryPath + fileOrDirectoryName;
|
||||
}
|
||||
|
||||
public static string[] GetDirectories(string path, bool getFullPaths = true)
|
||||
{
|
||||
var paths = Directory.GetDirectories(path);
|
||||
for (int i = 0; i < paths.Length; i++)
|
||||
{
|
||||
if (!getFullPaths)
|
||||
paths[i] = Path.GetFileName(paths[i]);
|
||||
// GetDirectories sometimes returns backslashes, so we need to convert them to
|
||||
// forward slashes.
|
||||
paths[i].Replace("\\", "/");
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
public static void DeleteDirectory(string directoryPath)
|
||||
{
|
||||
if (DirectoryExists(directoryPath))
|
||||
Directory.Delete(directoryPath, true);
|
||||
}
|
||||
|
||||
// Note: Paths not ending in a slash are assumed to be a path to a file.
|
||||
// In this case the Directory containing the file will be searched.
|
||||
public static string[] GetFiles(string path, bool getFullPaths = true)
|
||||
{
|
||||
// If this is pointing to a filename, get the path to it's directory.
|
||||
var directoryPath = path.EndsWith("/") || path.EndsWith("\\") ? path : GetDirectoryPath(path);
|
||||
|
||||
var paths = Directory.GetFiles(directoryPath);
|
||||
if (!getFullPaths)
|
||||
{
|
||||
for (int i = 0; i < paths.Length; i++)
|
||||
paths[i] = Path.GetFileName(paths[i]);
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
return File.ReadAllBytes(path);
|
||||
}
|
||||
|
||||
public static void WriteAllBytes(string path, byte[] bytes)
|
||||
{
|
||||
File.WriteAllBytes(path, bytes);
|
||||
}
|
||||
|
||||
public static void CommitBackup(ES3Settings settings)
|
||||
{
|
||||
ES3Debug.Log("Committing backup for " + settings.path + " to storage location " + settings.location);
|
||||
|
||||
var temporaryFilePath = settings.FullPath + temporaryFileSuffix;
|
||||
|
||||
if (settings.location == ES3.Location.File)
|
||||
{
|
||||
var oldFileBackup = settings.FullPath + temporaryFileSuffix + ".bak";
|
||||
|
||||
// If there's existing save data to overwrite ...
|
||||
if (FileExists(settings.FullPath))
|
||||
{
|
||||
// Delete any old backups.
|
||||
DeleteFile(oldFileBackup);
|
||||
// Rename the old file so we can restore it if it fails.
|
||||
CopyFile(settings.FullPath, oldFileBackup);
|
||||
|
||||
try
|
||||
{
|
||||
// Delete the old file so that we can move it.
|
||||
DeleteFile(settings.FullPath);
|
||||
// Now rename the temporary file to the name of the save file.
|
||||
MoveFile(temporaryFilePath, settings.FullPath);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// If any exceptions occur, restore the original save file.
|
||||
try { DeleteFile(settings.FullPath); } catch { }
|
||||
MoveFile(oldFileBackup, settings.FullPath);
|
||||
throw e;
|
||||
}
|
||||
|
||||
DeleteFile(oldFileBackup);
|
||||
}
|
||||
// Else just rename the temporary file to the main file.
|
||||
else
|
||||
MoveFile(temporaryFilePath, settings.FullPath);
|
||||
}
|
||||
else if (settings.location == ES3.Location.PlayerPrefs)
|
||||
{
|
||||
PlayerPrefs.SetString(settings.FullPath, PlayerPrefs.GetString(temporaryFilePath));
|
||||
PlayerPrefs.DeleteKey(temporaryFilePath);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e3e89d69f37e4fa9b4d60467722ac73
|
||||
timeCreated: 1499764821
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/*
|
||||
* Displays an info message in the inspector.
|
||||
* Only available in the Editor.
|
||||
*/
|
||||
public class ES3InspectorInfo : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
public string message = "";
|
||||
|
||||
public void SetMessage(string message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8714d999c5ae749538494c1347e5a3ca
|
||||
timeCreated: 1519132290
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,218 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using ES3Internal;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
public class ES3Prefab : MonoBehaviour
|
||||
{
|
||||
public long prefabId = GetNewRefID();
|
||||
/*
|
||||
* We need to store references to all dependencies of the prefab because only supported scripts will be serialised.
|
||||
* This means that although supported scripts have their dependencies added to the reference manager when we load the prefab,
|
||||
* there will not be any dependencies in the reference manager for scripts which are not supported. So it will not be possible to save any reference to these.
|
||||
*/
|
||||
public ES3RefIdDictionary localRefs = new ES3RefIdDictionary();
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
// Add the references to the reference list when this prefab is instantiated.
|
||||
var mgr = ES3ReferenceMgrBase.Current;
|
||||
|
||||
if (mgr == null)
|
||||
return;
|
||||
|
||||
foreach (var kvp in localRefs)
|
||||
if (kvp.Key != null)
|
||||
mgr.Add(kvp.Key);
|
||||
}
|
||||
|
||||
public long Get(UnityEngine.Object obj)
|
||||
{
|
||||
long id;
|
||||
if (localRefs.TryGetValue(obj, out id))
|
||||
return id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long Add(UnityEngine.Object obj)
|
||||
{
|
||||
long id;
|
||||
if (localRefs.TryGetValue(obj, out id))
|
||||
return id;
|
||||
|
||||
if (!ES3ReferenceMgr.CanBeSaved(obj))
|
||||
return -1;
|
||||
id = GetNewRefID();
|
||||
localRefs.Add(obj, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetReferences()
|
||||
{
|
||||
var localToGlobal = new Dictionary<string, string>();
|
||||
|
||||
var refMgr = ES3ReferenceMgr.Current;
|
||||
|
||||
if (refMgr == null)
|
||||
return localToGlobal;
|
||||
|
||||
foreach (var kvp in localRefs)
|
||||
{
|
||||
long id = refMgr.Add(kvp.Key);
|
||||
localToGlobal[kvp.Value.ToString()] = id.ToString();
|
||||
}
|
||||
return localToGlobal;
|
||||
}
|
||||
|
||||
public void ApplyReferences(Dictionary<long, long> localToGlobal)
|
||||
{
|
||||
if (ES3ReferenceMgrBase.Current == null)
|
||||
return;
|
||||
|
||||
foreach (var localRef in localRefs)
|
||||
{
|
||||
long globalId;
|
||||
if (localToGlobal.TryGetValue(localRef.Value, out globalId))
|
||||
ES3ReferenceMgrBase.Current.Add(localRef.Key, globalId);
|
||||
}
|
||||
}
|
||||
|
||||
public static long GetNewRefID()
|
||||
{
|
||||
return ES3ReferenceMgrBase.GetNewRefID();
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
public void GeneratePrefabReferences()
|
||||
{
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
if (this.gameObject.scene.name != null || UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null)
|
||||
#elif UNITY_2018_3_OR_NEWER
|
||||
if (this.gameObject.scene.name != null || UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null)
|
||||
#else
|
||||
if (this.gameObject.scene.name != null)
|
||||
#endif
|
||||
return;
|
||||
|
||||
// Create a new reference list so that any objects which are no longer dependencies are removed.
|
||||
var tempLocalRefs = new ES3RefIdDictionary();
|
||||
|
||||
// Get dependencies of children also.
|
||||
var transforms = GetComponentsInChildren<Transform>();
|
||||
var gos = new GameObject[transforms.Length];
|
||||
for (int i = 0; i < transforms.Length; i++)
|
||||
gos[i] = transforms[i].gameObject;
|
||||
|
||||
bool addedNewReference = false;
|
||||
|
||||
// Add the GameObject's dependencies to the reference list.
|
||||
foreach (var obj in EditorUtility.CollectDependencies(gos))
|
||||
{
|
||||
var dependency = (UnityEngine.Object)obj;
|
||||
if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency))
|
||||
continue;
|
||||
|
||||
var id = Get(dependency);
|
||||
// If we're adding a new reference, do an Undo.RecordObject to ensure it persists.
|
||||
if (id == -1)
|
||||
{
|
||||
addedNewReference = true;
|
||||
Undo.RecordObject(this, "Update Easy Save 3 Prefab");
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id);
|
||||
}
|
||||
|
||||
if (addedNewReference || tempLocalRefs.Count != localRefs.Count)
|
||||
localRefs = tempLocalRefs;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a blank ES3Type for ES3Prefab as it does not require serialising/deserialising when stored as a Component.
|
||||
*/
|
||||
namespace ES3Types
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public class ES3Type_ES3Prefab : ES3Type
|
||||
{
|
||||
public static ES3Type Instance = null;
|
||||
|
||||
public ES3Type_ES3Prefab() : base(typeof(ES3Prefab)) { Instance = this; }
|
||||
|
||||
public override void Write(object obj, ES3Writer writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override object Read<T>(ES3Reader reader)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Use this ES3Type to serialise the .
|
||||
*/
|
||||
public class ES3Type_ES3PrefabInternal : ES3Type
|
||||
{
|
||||
public static ES3Type Instance = new ES3Type_ES3PrefabInternal();
|
||||
|
||||
public ES3Type_ES3PrefabInternal() : base(typeof(ES3Type_ES3PrefabInternal)) { Instance = this; }
|
||||
|
||||
public override void Write(object obj, ES3Writer writer)
|
||||
{
|
||||
ES3Prefab es3Prefab = (ES3Prefab)obj;
|
||||
|
||||
writer.WriteProperty("prefabId", es3Prefab.prefabId.ToString(), ES3Type_string.Instance);
|
||||
writer.WriteProperty("refs", es3Prefab.GetReferences());
|
||||
}
|
||||
|
||||
public override object Read<T>(ES3Reader reader)
|
||||
{
|
||||
var prefabId = reader.ReadRefProperty();
|
||||
|
||||
if (ES3ReferenceMgrBase.Current == null)
|
||||
return null;
|
||||
|
||||
var es3Prefab = ES3ReferenceMgrBase.Current.GetPrefab(prefabId);
|
||||
if (es3Prefab == null)
|
||||
throw new MissingReferenceException("Prefab with ID " + prefabId + " could not be found.\nPress the 'Refresh References' button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in the scene to refresh prefabs.");
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Use PrefabUtility.InstantiatePrefab if we're saving in the Editor and the application isn't playing.
|
||||
// This keeps the connection to the prefab, which is useful for Editor scripts saving data outside of runtime.
|
||||
var instance = Application.isPlaying ? GameObject.Instantiate(es3Prefab.gameObject) : PrefabUtility.InstantiatePrefab(es3Prefab.gameObject);
|
||||
#else
|
||||
var instance = GameObject.Instantiate(es3Prefab.gameObject);
|
||||
#endif
|
||||
var instanceES3Prefab = ((GameObject)instance).GetComponent<ES3Prefab>();
|
||||
if (instanceES3Prefab == null)
|
||||
throw new MissingReferenceException("Prefab with ID " + prefabId + " was found, but it does not have an ES3Prefab component attached.");
|
||||
|
||||
ReadInto<T>(reader, instance);
|
||||
|
||||
return instanceES3Prefab.gameObject;
|
||||
}
|
||||
|
||||
public override void ReadInto<T>(ES3Reader reader, object obj)
|
||||
{
|
||||
// Load as ES3Refs and convert to longs.
|
||||
var localToGlobal_refs = reader.ReadProperty<Dictionary<ES3Ref, ES3Ref>>(ES3Type_ES3RefDictionary.Instance);
|
||||
var localToGlobal = new Dictionary<long, long>();
|
||||
foreach (var kvp in localToGlobal_refs)
|
||||
localToGlobal.Add(kvp.Key.id, kvp.Value.id);
|
||||
|
||||
if (ES3ReferenceMgrBase.Current == null)
|
||||
return;
|
||||
|
||||
((GameObject)obj).GetComponent<ES3Prefab>().ApplyReferences(localToGlobal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baff8732cd3074ef88b34f9cc487846d
|
||||
timeCreated: 1519132295
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,262 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using ES3Internal;
|
||||
using UnityEngine.SceneManagement;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine.U2D;
|
||||
#endif
|
||||
|
||||
#if UNITY_VISUAL_SCRIPTING
|
||||
using Unity.VisualScripting;
|
||||
[IncludeInSettings(true)]
|
||||
#endif
|
||||
public class ES3ReferenceMgr : ES3ReferenceMgrBase
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void RefreshDependencies(bool isEnteringPlayMode = false)
|
||||
{
|
||||
// Empty the refId so it has to be refreshed.
|
||||
refId = null;
|
||||
|
||||
ES3ReferenceMgrBase.isEnteringPlayMode = isEnteringPlayMode;
|
||||
|
||||
// This will get the dependencies for all GameObjects and Components from the active scene.
|
||||
AddDependencies(this.gameObject.scene.GetRootGameObjects());
|
||||
AddDependenciesFromFolders();
|
||||
AddPrefabsToManager();
|
||||
RemoveNullOrInvalidValues();
|
||||
|
||||
ES3ReferenceMgrBase.isEnteringPlayMode = false;
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Easy Save 3/Refresh References for All Scenes", false, 150)]
|
||||
static void RefreshDependenciesInAllScenes()
|
||||
{
|
||||
if (!EditorUtility.DisplayDialog("Refresh references in all scenes", "This will open each scene which is enabled in your Build Settings, refresh each reference manager, and save the scene.\n\nWe recommend making a backup of your project before doing this for the first time.", "Ok", "Cancel", DialogOptOutDecisionType.ForThisMachine, "ES3RefreshAllOptOut"))
|
||||
return;
|
||||
|
||||
// Get a list of loaded scenes so we know whether we need to close them after refreshing references or not.
|
||||
var loadedScenePaths = new string[SceneManager.sceneCount];
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
loadedScenePaths[i] = SceneManager.GetSceneAt(i).path;
|
||||
|
||||
var scenes = EditorBuildSettings.scenes;
|
||||
var sceneNameList = ""; // We use this so we can display a list of scenes at the end.
|
||||
|
||||
for (int i = 0; i < scenes.Length; i++)
|
||||
{
|
||||
var buildSettingsScene = scenes[i];
|
||||
|
||||
if (!buildSettingsScene.enabled)
|
||||
continue;
|
||||
|
||||
if (EditorUtility.DisplayCancelableProgressBar("Refreshing references", $"Refreshing references for scene {buildSettingsScene.path}.", i / scenes.Length))
|
||||
return;
|
||||
|
||||
var sceneWasOpen = loadedScenePaths.Contains(buildSettingsScene.path);
|
||||
var scene = EditorSceneManager.OpenScene(buildSettingsScene.path, OpenSceneMode.Additive);
|
||||
|
||||
var mgr = ES3ReferenceMgr.GetManagerFromScene(scene, false);
|
||||
|
||||
if (mgr != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
((ES3ReferenceMgr)mgr).RefreshDependencies();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
ES3Debug.LogError($"Couldn't update references for scene {scene.name} as the following exception occurred:\n\n" + e);
|
||||
}
|
||||
}
|
||||
|
||||
sceneNameList += $"{scene.name}\n";
|
||||
|
||||
// If the scene wasn't originally open, save it and close it.
|
||||
if (!sceneWasOpen)
|
||||
{
|
||||
// Temporarily disable refreshing on save so that it doesn't refresh again.
|
||||
var updateReferencesOnSave = ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneIsSaved;
|
||||
ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneIsSaved = false;
|
||||
|
||||
EditorSceneManager.SaveScene(scene);
|
||||
EditorSceneManager.CloseScene(scene, true);
|
||||
|
||||
ES3Settings.defaultSettingsScriptableObject.updateReferencesWhenSceneIsSaved = updateReferencesOnSave;
|
||||
}
|
||||
}
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
EditorUtility.DisplayDialog("References refreshed", $"Refrences updated for scenes:\n\n{sceneNameList}", "Ok", DialogOptOutDecisionType.ForThisMachine, "ES3RefreshAllCompleteOptOut");
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void Optimize()
|
||||
{
|
||||
var dependencies = EditorUtility.CollectDependencies(this.gameObject.scene.GetRootGameObjects().Where(go => go != this.gameObject).ToArray());
|
||||
var notDependenciesOfScene = new HashSet<UnityEngine.Object>();
|
||||
|
||||
foreach (var kvp in idRef)
|
||||
if (!dependencies.Contains(kvp.Value))
|
||||
notDependenciesOfScene.Add(kvp.Value);
|
||||
|
||||
foreach (var obj in notDependenciesOfScene)
|
||||
Remove(obj);
|
||||
}
|
||||
|
||||
/* Adds all dependencies from this scene to the manager */
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void AddDependencies()
|
||||
{
|
||||
var rootGameObjects = gameObject.scene.GetRootGameObjects();
|
||||
|
||||
for (int j = 0; j < rootGameObjects.Length; j++)
|
||||
{
|
||||
var go = rootGameObjects[j];
|
||||
|
||||
if (EditorUtility.DisplayCancelableProgressBar("Gathering references", "Populating reference manager with your scene dependencies so they can be saved and loaded by reference.", j / rootGameObjects.Length))
|
||||
return;
|
||||
|
||||
AddDependencies(go);
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void AddDependencies(UnityEngine.Object[] objs)
|
||||
{
|
||||
var timeStarted = EditorApplication.timeSinceStartup;
|
||||
var timeout = ES3Settings.defaultSettingsScriptableObject.collectDependenciesTimeout;
|
||||
|
||||
foreach (var obj in objs)
|
||||
{
|
||||
if (obj == null || obj.name == "Easy Save 3 Manager")
|
||||
continue;
|
||||
|
||||
var excludeTextures = new List<Texture2D>();
|
||||
|
||||
foreach (var dependency in EditorUtility.CollectDependencies(new UnityEngine.Object[] { obj }))
|
||||
{
|
||||
if (EditorApplication.timeSinceStartup - timeStarted > timeout)
|
||||
{
|
||||
ES3Debug.LogWarning($"Easy Save cancelled gathering of references for object {obj.name} because it took longer than {timeout} seconds. You can increase the timeout length in Tools > Easy Save 3 > Settings > Reference Gathering Timeout, or adjust the settings so that fewer objects are referenced in your scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Exclude all Texture2Ds which are packed into a SpriteAtlas from this manager.
|
||||
if (dependency is SpriteAtlas)
|
||||
foreach (var atlasDependency in EditorUtility.CollectDependencies(new UnityEngine.Object[] { dependency }))
|
||||
if (atlasDependency is Texture2D)
|
||||
ExcludeObject(atlasDependency);
|
||||
|
||||
Add(dependency);
|
||||
|
||||
if (obj is ES3Prefab prefab)
|
||||
AddPrefabToManager(prefab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void AddDependenciesFromFolders()
|
||||
{
|
||||
var folders = ES3Settings.defaultSettingsScriptableObject.referenceFolders;
|
||||
|
||||
// Remove null or empty values.
|
||||
ArrayUtility.Remove(ref folders, "");
|
||||
ArrayUtility.Remove(ref folders, null);
|
||||
|
||||
if (folders == null || folders.Length == 0)
|
||||
return;
|
||||
|
||||
var guids = AssetDatabase.FindAssets("t:Object", folders);
|
||||
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path);
|
||||
|
||||
if(obj != null)
|
||||
AddDependencies(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/*[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void AddDependenciesLegacy(UnityEngine.Object[] objs)
|
||||
{
|
||||
for (int i = 0; i < objs.Length; i++)
|
||||
{
|
||||
var obj = objs[i];
|
||||
|
||||
if (obj.name == "Easy Save 3 Manager")
|
||||
continue;
|
||||
|
||||
var dependencies = CollectDependenciesLegacy(obj);
|
||||
|
||||
foreach (var dependency in dependencies)
|
||||
{
|
||||
if (dependency != null)
|
||||
{
|
||||
Add(dependency);
|
||||
|
||||
// Add the prefab if it's referenced by this scene.
|
||||
if (dependency.GetType() == typeof(ES3Prefab))
|
||||
AddPrefabToManager((ES3Prefab)dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Undo.RecordObject(this, "Update Easy Save 3 Reference List");
|
||||
}*/
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void AddDependencies(UnityEngine.Object obj)
|
||||
{
|
||||
AddDependencies(new UnityEngine.Object[] { obj });
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void GeneratePrefabReferences()
|
||||
{
|
||||
AddPrefabsToManager();
|
||||
foreach (var es3Prefab in prefabs)
|
||||
es3Prefab.GeneratePrefabReferences();
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public void AddPrefabsToManager()
|
||||
{
|
||||
if (ES3Settings.defaultSettingsScriptableObject.addAllPrefabsToManager)
|
||||
{
|
||||
// Clear any null values. This isn't necessary if we're not adding all prefabs to manager as the list is cleared each time.
|
||||
if (this.prefabs.RemoveAll(item => item == null) > 0)
|
||||
Undo.RecordObject(this, "Update Easy Save 3 Reference List");
|
||||
|
||||
foreach (var es3Prefab in Resources.FindObjectsOfTypeAll<ES3Prefab>())
|
||||
AddPrefabToManager(es3Prefab);
|
||||
}
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
private void AddPrefabToManager(ES3Prefab es3Prefab)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (es3Prefab != null && EditorUtility.IsPersistent(es3Prefab))
|
||||
if(AddPrefab(es3Prefab))
|
||||
Undo.RecordObject(this, "Update Easy Save 3 Reference List");
|
||||
es3Prefab.GeneratePrefabReferences();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a83408fcc9044c4fbc7e5d09a369ab6
|
||||
timeCreated: 1503395115
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+758
@@ -0,0 +1,758 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
[System.Serializable]
|
||||
[DisallowMultipleComponent]
|
||||
public abstract class ES3ReferenceMgrBase : MonoBehaviour
|
||||
{
|
||||
internal object _lock = new object();
|
||||
|
||||
public const string referencePropertyName = "_ES3Ref";
|
||||
private static ES3ReferenceMgrBase _current = null;
|
||||
private static HashSet<ES3ReferenceMgrBase> mgrs = new HashSet<ES3ReferenceMgrBase>();
|
||||
#if UNITY_EDITOR
|
||||
protected static bool isEnteringPlayMode = false;
|
||||
static readonly HideFlags[] invalidHideFlags = new HideFlags[] { HideFlags.DontSave, HideFlags.DontSaveInBuild, HideFlags.DontSaveInEditor, HideFlags.HideAndDontSave };
|
||||
#endif
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
[NonSerialized]
|
||||
#endif
|
||||
public List<UnityEngine.Object> excludeObjects = new List<UnityEngine.Object>();
|
||||
|
||||
private static System.Random rng;
|
||||
|
||||
[HideInInspector]
|
||||
public bool openPrefabs = false; // Whether the prefab list should be open in the Editor.
|
||||
|
||||
public List<ES3Prefab> prefabs = new List<ES3Prefab>();
|
||||
|
||||
public static ES3ReferenceMgrBase Current
|
||||
{
|
||||
get
|
||||
{
|
||||
// If the reference manager hasn't been assigned, or we've got a reference to a manager in a different scene which isn't marked as DontDestroyOnLoad, look for this scene's manager.
|
||||
if (_current == null /*|| (_current.gameObject.scene.buildIndex != -1 && _current.gameObject.scene != SceneManager.GetActiveScene())*/)
|
||||
{
|
||||
ES3ReferenceMgrBase mgr = GetManagerFromScene(SceneManager.GetActiveScene());
|
||||
if (mgr != null)
|
||||
mgrs.Add(_current = mgr);
|
||||
}
|
||||
return _current;
|
||||
}
|
||||
}
|
||||
|
||||
public static ES3ReferenceMgrBase GetManagerFromScene(Scene scene, bool getAnyManagerIfNotInScene = true)
|
||||
{
|
||||
// This has been removed as isLoaded is false during the initial Awake().
|
||||
/*if (!scene.isLoaded)
|
||||
return null;*/
|
||||
|
||||
// If this is a valid scene, search it for the manager.
|
||||
if (scene.IsValid())
|
||||
{
|
||||
// Check whether the mgr is already in the mgr list.
|
||||
foreach (var addedMgr in mgrs)
|
||||
if (addedMgr != null && addedMgr.gameObject.scene == scene)
|
||||
return addedMgr;
|
||||
|
||||
GameObject[] roots;
|
||||
try
|
||||
{
|
||||
roots = scene.GetRootGameObjects();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// First, look for Easy Save 3 Manager in the top-level.
|
||||
foreach (var root in roots)
|
||||
{
|
||||
if (root.name == "Easy Save 3 Manager")
|
||||
{
|
||||
var mgr = root.GetComponent<ES3ReferenceMgr>();
|
||||
if(mgr != null)
|
||||
return mgr;
|
||||
}
|
||||
}
|
||||
|
||||
// If the user has moved or renamed the Easy Save 3 Manager, we need to perform a deep search.
|
||||
foreach (var root in roots)
|
||||
{
|
||||
var mgr = root.GetComponentInChildren<ES3ReferenceMgr>();
|
||||
if(mgr != null)
|
||||
return mgr;
|
||||
}
|
||||
}
|
||||
|
||||
// If we can't find a manager in this scene (for example we're in DontDestroyOnLoad), find a manager in any scene.
|
||||
if (getAnyManagerIfNotInScene)
|
||||
{
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
var loadedScene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (loadedScene != null && loadedScene != scene && loadedScene.IsValid())
|
||||
{
|
||||
var mgr = GetManagerFromScene(loadedScene, false);
|
||||
if (mgr != null)
|
||||
{
|
||||
ES3Debug.LogWarning($"The reference you're trying to save does not exist in any scene, or the scene it belongs to does not contain an Easy Save 3 Manager. Using the reference manager from scene {loadedScene.name} instead. This may cause unexpected behaviour or leak memory in some situations. See <a href=\"https://docs.moodkie.com/easy-save-3/es3-guides/saving-and-loading-references/\">the Saving and Loading References guide</a> for more information.");
|
||||
return mgr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsInitialised { get { return idRef.Count > 0; } }
|
||||
|
||||
[SerializeField]
|
||||
public ES3IdRefDictionary idRef = new ES3IdRefDictionary();
|
||||
private ES3RefIdDictionary _refId = null;
|
||||
|
||||
public ES3RefIdDictionary refId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_refId == null)
|
||||
{
|
||||
_refId = new ES3RefIdDictionary();
|
||||
// Populate the reverse dictionary with the items from the normal dictionary.
|
||||
foreach (var kvp in idRef)
|
||||
if (kvp.Value != null)
|
||||
_refId[kvp.Value] = kvp.Key;
|
||||
}
|
||||
return _refId;
|
||||
}
|
||||
set
|
||||
{
|
||||
_refId = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ES3GlobalReferences GlobalReferences
|
||||
{
|
||||
get
|
||||
{
|
||||
return ES3GlobalReferences.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset static variables to handle disabled domain reloading.
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void Init()
|
||||
{
|
||||
_current = null;
|
||||
mgrs = new HashSet<ES3ReferenceMgrBase>();
|
||||
#if UNITY_EDITOR
|
||||
isEnteringPlayMode = false;
|
||||
#endif
|
||||
rng = null;
|
||||
}
|
||||
|
||||
internal void Awake()
|
||||
{
|
||||
if (_current != null && _current != this)
|
||||
{
|
||||
var existing = _current;
|
||||
|
||||
/* We intentionally use Current rather than _current here, as _current may contain a reference to a manager in another scene,
|
||||
* but Current only returns the Manager for the active scene. */
|
||||
if (Current != null)
|
||||
{
|
||||
RemoveNullValues();
|
||||
|
||||
//existing.Merge(this);
|
||||
//Destroy(this);
|
||||
_current = existing; // Undo the call to Current, which may have set it to NULL.
|
||||
}
|
||||
}
|
||||
else
|
||||
_current = this;
|
||||
mgrs.Add(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_current == this)
|
||||
_current = null;
|
||||
mgrs.Remove(this);
|
||||
}
|
||||
|
||||
// Merges two managers, not allowing any clashes of IDs
|
||||
public void Merge(ES3ReferenceMgrBase otherMgr)
|
||||
{
|
||||
foreach (var kvp in otherMgr.idRef)
|
||||
Add(kvp.Value, kvp.Key);
|
||||
}
|
||||
|
||||
public long Get(UnityEngine.Object obj)
|
||||
{
|
||||
if (!mgrs.Contains(this))
|
||||
mgrs.Add(this);
|
||||
|
||||
foreach (var mgr in mgrs)
|
||||
{
|
||||
if (mgr == null)
|
||||
continue;
|
||||
|
||||
if (obj == null)
|
||||
return -1;
|
||||
|
||||
long id;
|
||||
if (mgr.refId.TryGetValue(obj, out id))
|
||||
return id;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
internal UnityEngine.Object Get(long id, Type type, bool suppressWarnings = false)
|
||||
{
|
||||
if (!mgrs.Contains(this))
|
||||
mgrs.Add(this);
|
||||
|
||||
foreach (var mgr in mgrs)
|
||||
{
|
||||
if (mgr == null)
|
||||
continue;
|
||||
|
||||
if (id == -1)
|
||||
return null;
|
||||
|
||||
UnityEngine.Object obj;
|
||||
if (mgr.idRef.TryGetValue(id, out obj))
|
||||
{
|
||||
if (obj == null) // If obj has been marked as destroyed but not yet destroyed, don't return it.
|
||||
return null;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (GlobalReferences != null)
|
||||
{
|
||||
var globalRef = GlobalReferences.Get(id);
|
||||
if (globalRef != null)
|
||||
return globalRef;
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
ES3Debug.LogWarning("Reference for " + type + " with ID " + id + " could not be found in Easy Save's reference manager. See <a href=\"https://docs.moodkie.com/easy-save-3/es3-guides/saving-and-loading-references/#reference-could-not-be-found-warning\">the Saving and Loading References guide</a> for more information.", this);
|
||||
else
|
||||
ES3Debug.LogWarning("Reference with ID " + id + " could not be found in Easy Save's reference manager. See <a href=\"https://docs.moodkie.com/easy-save-3/es3-guides/saving-and-loading-references/#reference-could-not-be-found-warning\">the Saving and Loading References guide</a> for more information.", this);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public UnityEngine.Object Get(long id, bool suppressWarnings = false)
|
||||
{
|
||||
return Get(id, null, suppressWarnings);
|
||||
}
|
||||
|
||||
public ES3Prefab GetPrefab(long id, bool suppressWarnings = false)
|
||||
{
|
||||
if (!mgrs.Contains(this))
|
||||
mgrs.Add(this);
|
||||
|
||||
foreach (var mgr in mgrs)
|
||||
{
|
||||
if (mgr == null)
|
||||
continue;
|
||||
|
||||
foreach (var prefab in mgr.prefabs)
|
||||
if (prefab != null && prefab.prefabId == id)
|
||||
return prefab;
|
||||
}
|
||||
if (!suppressWarnings)
|
||||
ES3Debug.LogWarning("Prefab with ID " + id + " could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene, or exit play mode and right-click the prefab and select Easy Save 3 > Add Reference(s) to Manager.", this);
|
||||
return null;
|
||||
}
|
||||
|
||||
public long GetPrefab(ES3Prefab prefabToFind, bool suppressWarnings = false)
|
||||
{
|
||||
if (!mgrs.Contains(this))
|
||||
mgrs.Add(this);
|
||||
|
||||
foreach (var mgr in mgrs)
|
||||
{
|
||||
if (mgr == null)
|
||||
continue;
|
||||
|
||||
foreach (var prefab in prefabs)
|
||||
if (prefab == prefabToFind)
|
||||
return prefab.prefabId;
|
||||
}
|
||||
if (!suppressWarnings)
|
||||
ES3Debug.LogWarning("Prefab with name " + prefabToFind.name + " could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene, or exit play mode and right-click the prefab and select Easy Save 3 > Add Reference(s) to Manager.", prefabToFind);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long Add(UnityEngine.Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
|
||||
if (!CanBeSaved(obj))
|
||||
return -1;
|
||||
|
||||
long id;
|
||||
// If it already exists in the list, do nothing.
|
||||
if (refId.TryGetValue(obj, out id))
|
||||
return id;
|
||||
|
||||
if (GlobalReferences != null)
|
||||
{
|
||||
id = GlobalReferences.GetOrAdd(obj);
|
||||
if (id != -1)
|
||||
{
|
||||
Add(obj, id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
// Add the reference to the Dictionary.
|
||||
id = GetNewRefID();
|
||||
return Add(obj, id);
|
||||
}
|
||||
}
|
||||
|
||||
public long Add(UnityEngine.Object obj, long id)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
|
||||
if (!CanBeSaved(obj))
|
||||
return -1;
|
||||
|
||||
// If the ID is -1, auto-generate an ID.
|
||||
if (id == -1)
|
||||
id = GetNewRefID();
|
||||
// Add the reference to the Dictionary.
|
||||
lock (_lock)
|
||||
{
|
||||
idRef[id] = obj;
|
||||
if (obj != null)
|
||||
refId[obj] = id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public bool AddPrefab(ES3Prefab prefab)
|
||||
{
|
||||
if (!prefabs.Contains(prefab))
|
||||
{
|
||||
prefabs.Add(prefab);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Remove(UnityEngine.Object obj)
|
||||
{
|
||||
if (!mgrs.Contains(this))
|
||||
mgrs.Add(this);
|
||||
|
||||
foreach (var mgr in mgrs)
|
||||
{
|
||||
if (mgr == null)
|
||||
continue;
|
||||
|
||||
// Only remove from this manager if we're in the Editor.
|
||||
if (!Application.isPlaying && mgr != this)
|
||||
continue;
|
||||
|
||||
lock (mgr._lock)
|
||||
{
|
||||
mgr.refId.Remove(obj);
|
||||
// There may be multiple references with the same ID, so remove them all.
|
||||
foreach (var item in mgr.idRef.Where(kvp => kvp.Value == obj).ToList())
|
||||
mgr.idRef.Remove(item.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(long referenceID)
|
||||
{
|
||||
foreach (var mgr in mgrs)
|
||||
{
|
||||
if (mgr == null)
|
||||
continue;
|
||||
|
||||
lock (mgr._lock)
|
||||
{
|
||||
mgr.idRef.Remove(referenceID);
|
||||
// There may be multiple references with the same ID, so remove them all.
|
||||
foreach (var item in mgr.refId.Where(kvp => kvp.Value == referenceID).ToList())
|
||||
mgr.refId.Remove(item.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveNullValues()
|
||||
{
|
||||
var nullKeys = idRef.Where(pair => pair.Value == null).Select(pair => pair.Key).ToList();
|
||||
foreach (var key in nullKeys)
|
||||
idRef.Remove(key);
|
||||
}
|
||||
|
||||
public void RemoveNullOrInvalidValues()
|
||||
{
|
||||
var nullKeys = idRef.Where(pair => pair.Value == null || !CanBeSaved(pair.Value) || excludeObjects.Contains(pair.Value)).Select(pair => pair.Key).ToList();
|
||||
foreach (var key in nullKeys)
|
||||
idRef.Remove(key);
|
||||
|
||||
if (GlobalReferences != null)
|
||||
GlobalReferences.RemoveInvalidKeys();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
refId.Clear();
|
||||
idRef.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(UnityEngine.Object obj)
|
||||
{
|
||||
return refId.ContainsKey(obj);
|
||||
}
|
||||
|
||||
public bool Contains(long referenceID)
|
||||
{
|
||||
return idRef.ContainsKey(referenceID);
|
||||
}
|
||||
|
||||
public void ChangeId(long oldId, long newId)
|
||||
{
|
||||
idRef.ChangeKey(oldId, newId);
|
||||
// Empty the refId so it has to be refreshed.
|
||||
refId = null;
|
||||
}
|
||||
|
||||
internal static long GetNewRefID()
|
||||
{
|
||||
if (rng == null)
|
||||
rng = new System.Random();
|
||||
|
||||
byte[] buf = new byte[8];
|
||||
rng.NextBytes(buf);
|
||||
long longRand = BitConverter.ToInt64(buf, 0);
|
||||
|
||||
return (System.Math.Abs(longRand % (long.MaxValue - 0)) + 0);
|
||||
}
|
||||
|
||||
/*#if UNITY_EDITOR
|
||||
public static HashSet<UnityEngine.Object> CollectDependenciesLegacy(UnityEngine.Object obj, HashSet<UnityEngine.Object> dependencies = null, int depth = int.MinValue)
|
||||
{
|
||||
return CollectDependenciesLegacy(new UnityEngine.Object[] { obj }, dependencies, depth);
|
||||
}
|
||||
|
||||
|
||||
//Collects all top-level dependencies of an object.
|
||||
//For GameObjects, it will traverse all children.
|
||||
//For Components or ScriptableObjects, it will get all serialisable UnityEngine.Object fields/properties as dependencies.
|
||||
public static HashSet<UnityEngine.Object> CollectDependenciesLegacy(UnityEngine.Object[] objs, HashSet<UnityEngine.Object> dependencies = null, int depth = int.MinValue)
|
||||
{
|
||||
if (depth == int.MinValue)
|
||||
depth = ES3Settings.defaultSettingsScriptableObject.collectDependenciesDepth;
|
||||
|
||||
if (depth < 0)
|
||||
return dependencies;
|
||||
|
||||
if (dependencies == null)
|
||||
dependencies = new HashSet<UnityEngine.Object>();
|
||||
|
||||
foreach (var obj in objs)
|
||||
{
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
var type = obj.GetType();
|
||||
|
||||
// Skip types which don't need processing
|
||||
if (type == typeof(ES3ReferenceMgr) || type == typeof(ES3AutoSaveMgr) || type == typeof(ES3AutoSave) || type == typeof(ES3InspectorInfo))
|
||||
continue;
|
||||
|
||||
// Add the prefab to the manager but don't process it. We'll use this to work out what prefabs to add to the prefabs list later.
|
||||
if (type == typeof(ES3Prefab))
|
||||
{
|
||||
dependencies.Add(obj);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's a GameObject, get the GameObject's Components and collect their dependencies.
|
||||
if (type == typeof(GameObject))
|
||||
{
|
||||
var go = (GameObject)obj;
|
||||
// If we've not already processed this GameObject ...
|
||||
if (dependencies.Add(go))
|
||||
{
|
||||
// Get the dependencies of each Component in the GameObject.
|
||||
CollectDependenciesLegacy(go.GetComponents<Component>(), dependencies, depth - 1);
|
||||
// Get the dependencies of each child in the GameObject.
|
||||
foreach (Transform child in go.transform)
|
||||
CollectDependenciesLegacy(child.gameObject, dependencies, depth); // Don't decrement child, as we consider this a top-level object.
|
||||
}
|
||||
}
|
||||
// Else if it's a Component or ScriptableObject, add the values of any UnityEngine.Object fields as dependencies.
|
||||
else
|
||||
CollectDependenciesFromFieldsLegacy(obj, dependencies, depth - 1);
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
private static void CollectDependenciesFromFieldsLegacy(UnityEngine.Object obj, HashSet<UnityEngine.Object> dependencies, int depth)
|
||||
{
|
||||
// If we've already collected dependencies for this, do nothing.
|
||||
if (!dependencies.Add(obj))
|
||||
return;
|
||||
|
||||
if (depth == int.MinValue)
|
||||
depth = ES3Settings.defaultSettingsScriptableObject.collectDependenciesDepth;
|
||||
|
||||
if (depth < 0)
|
||||
return;
|
||||
|
||||
var type = obj.GetType();
|
||||
|
||||
if (isEnteringPlayMode && type == typeof(UnityEngine.UI.Text))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// SerializedObject is expensive, so for known classes we manually gather references.
|
||||
|
||||
if (type == typeof(Animator) || obj is Transform || type == typeof(CanvasRenderer) || type == typeof(Mesh) || type == typeof(AudioClip) || type == typeof(Rigidbody) || obj is HorizontalOrVerticalLayoutGroup)
|
||||
return;
|
||||
|
||||
if(obj is Texture)
|
||||
{
|
||||
// This ensures that Sprites which are children of the Texture are also added. In the Editor you would otherwise need to expand the Texture to add the Sprite.
|
||||
foreach(var dependency in UnityEditor.AssetDatabase.LoadAllAssetsAtPath(UnityEditor.AssetDatabase.GetAssetPath(obj)))
|
||||
if (dependency != obj)
|
||||
dependencies.Add(dependency);
|
||||
}
|
||||
|
||||
if (obj is Graphic)
|
||||
{
|
||||
var m = (Graphic)obj;
|
||||
dependencies.Add(m.material);
|
||||
dependencies.Add(m.defaultMaterial);
|
||||
dependencies.Add(m.mainTexture);
|
||||
|
||||
if (type == typeof(Text))
|
||||
{
|
||||
var text = (Text)obj;
|
||||
dependencies.Add(text.font);
|
||||
}
|
||||
else if (type == typeof(Image))
|
||||
{
|
||||
var img = (Image)obj;
|
||||
dependencies.Add(img.sprite);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == typeof(Mesh))
|
||||
{
|
||||
if (UnityEditor.AssetDatabase.Contains(obj))
|
||||
dependencies.Add(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == typeof(Material))
|
||||
{
|
||||
var material = (Material)obj;
|
||||
var shader = material.shader;
|
||||
if (shader != null)
|
||||
{
|
||||
dependencies.Add(material.shader);
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
for (int i = 0; i < shader.GetPropertyCount(); i++)
|
||||
if (shader.GetPropertyType(i) == UnityEngine.Rendering.ShaderPropertyType.Texture)
|
||||
dependencies.Add(material.GetTexture(shader.GetPropertyName(i)));
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == typeof(MeshFilter))
|
||||
{
|
||||
dependencies.Add(((MeshFilter)obj).sharedMesh);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == typeof(MeshCollider))
|
||||
{
|
||||
var mc = (MeshCollider)obj;
|
||||
dependencies.Add(mc.sharedMesh);
|
||||
dependencies.Add(mc.sharedMaterial);
|
||||
dependencies.Add(mc.attachedRigidbody);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == typeof(Camera))
|
||||
{
|
||||
var c = (Camera)obj;
|
||||
dependencies.Add(c.targetTexture);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == typeof(SkinnedMeshRenderer))
|
||||
dependencies.Add(((SkinnedMeshRenderer)obj).sharedMesh); // Don't return. Let this fall through to the if(obj is renderer) call.
|
||||
else if (type == typeof(SpriteRenderer))
|
||||
dependencies.Add(((SpriteRenderer)obj).sprite); // Don't return. Let this fall through to the if(obj is renderer) call.
|
||||
else if (type == typeof(ParticleSystemRenderer))
|
||||
dependencies.Add(((ParticleSystemRenderer)obj).mesh); // Don't return. Let this fall through to the if(obj is renderer) call.
|
||||
|
||||
if (obj is Renderer)
|
||||
{
|
||||
var renderer = (Renderer)obj;
|
||||
foreach (var material in renderer.sharedMaterials)
|
||||
CollectDependenciesFromFieldsLegacy(material, dependencies, depth - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
var so = new UnityEditor.SerializedObject(obj);
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
var property = so.GetIterator();
|
||||
if (property == null)
|
||||
return;
|
||||
|
||||
// Iterate through each of this object's properties.
|
||||
while (property.NextVisible(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
// If it's an array which contains UnityEngine.Objects, add them as dependencies.
|
||||
if (property.isArray && property.propertyType != UnityEditor.SerializedPropertyType.String)
|
||||
{
|
||||
for (int i = 0; i < property.arraySize; i++)
|
||||
{
|
||||
var element = property.GetArrayElementAtIndex(i);
|
||||
|
||||
// If the array contains UnityEngine.Object types, add them to the dependencies.
|
||||
if (element.propertyType == UnityEditor.SerializedPropertyType.ObjectReference)
|
||||
{
|
||||
var elementValue = element.objectReferenceValue;
|
||||
var elementType = elementValue.GetType();
|
||||
|
||||
// If it's a GameObject, use CollectDependencies so that Components are also added.
|
||||
if (elementType == typeof(GameObject))
|
||||
CollectDependenciesLegacy(elementValue, dependencies, depth - 1);
|
||||
else
|
||||
CollectDependenciesFromFieldsLegacy(elementValue, dependencies, depth - 1);
|
||||
}
|
||||
// Otherwise this array does not contain UnityEngine.Object types, so we should stop.
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Else if it's a normal UnityEngine.Object field, add it.
|
||||
else if (property.propertyType == UnityEditor.SerializedPropertyType.ObjectReference)
|
||||
{
|
||||
var propertyValue = property.objectReferenceValue;
|
||||
if (propertyValue == null)
|
||||
continue;
|
||||
|
||||
// If it's a GameObject, use CollectDependencies so that Components are also added.
|
||||
if (propertyValue.GetType() == typeof(GameObject))
|
||||
CollectDependenciesLegacy(propertyValue, dependencies, depth - 1);
|
||||
else
|
||||
CollectDependenciesFromFieldsLegacy(propertyValue, dependencies, depth - 1);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
// Called in the Editor when this Component is added.
|
||||
private void Reset()
|
||||
{
|
||||
// Ensure that Component can only be added by going to Assets > Easy Save 3 > Add Manager to Scene.
|
||||
if (gameObject.name != "Easy Save 3 Manager")
|
||||
{
|
||||
UnityEditor.EditorUtility.DisplayDialog("Cannot add ES3ReferenceMgr directly", "Please go to 'Tools > Easy Save 3 > Add Manager to Scene' to add an Easy Save 3 Manager to your scene.", "Ok");
|
||||
DestroyImmediate(this);
|
||||
}
|
||||
}
|
||||
#endif*/
|
||||
|
||||
internal static bool CanBeSaved(UnityEngine.Object obj)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (obj == null)
|
||||
return true;
|
||||
|
||||
foreach (var flag in invalidHideFlags)
|
||||
if ((obj.hideFlags & flag) != 0 && obj.hideFlags != HideFlags.HideInHierarchy && obj.hideFlags != HideFlags.HideInInspector && obj.hideFlags != HideFlags.NotEditable)
|
||||
if (!(obj is Mesh || obj is Material))
|
||||
return false;
|
||||
|
||||
// Exclude the Easy Save 3 Manager, and all components attached to it.
|
||||
if (obj.name == "Easy Save 3 Manager")
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void ExcludeObject(UnityEngine.Object obj)
|
||||
{
|
||||
if (excludeObjects == null)
|
||||
excludeObjects = new List<UnityEngine.Object>();
|
||||
|
||||
if (!excludeObjects.Contains(obj))
|
||||
excludeObjects.Add(obj);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ES3IdRefDictionary : ES3SerializableDictionary<long, UnityEngine.Object>
|
||||
{
|
||||
protected override bool KeysAreEqual(long a, long b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
|
||||
protected override bool ValuesAreEqual(UnityEngine.Object a, UnityEngine.Object b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[System.Serializable]
|
||||
public class ES3RefIdDictionary : ES3SerializableDictionary<UnityEngine.Object, long>
|
||||
{
|
||||
protected override bool KeysAreEqual(UnityEngine.Object a, UnityEngine.Object b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
|
||||
protected override bool ValuesAreEqual(long a, long b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f659e3ad478b6470d9744732042e7515
|
||||
timeCreated: 1519132301
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,794 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
using ES3Types;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
public static class ES3Reflection
|
||||
{
|
||||
public const string memberFieldPrefix = "m_";
|
||||
public const string componentTagFieldName = "tag";
|
||||
public const string componentNameFieldName = "name";
|
||||
public static readonly string[] excludedPropertyNames = new string[] { "runInEditMode", "useGUILayout", "hideFlags" };
|
||||
|
||||
public static readonly Type serializableAttributeType = typeof(System.SerializableAttribute);
|
||||
public static readonly Type serializeFieldAttributeType = typeof(SerializeField);
|
||||
public static readonly Type obsoleteAttributeType = typeof(System.ObsoleteAttribute);
|
||||
public static readonly Type nonSerializedAttributeType = typeof(System.NonSerializedAttribute);
|
||||
public static readonly Type es3SerializableAttributeType = typeof(ES3Serializable);
|
||||
public static readonly Type es3NonSerializableAttributeType = typeof(ES3NonSerializable);
|
||||
|
||||
public static Type[] EmptyTypes = new Type[0];
|
||||
|
||||
private static Assembly[] _assemblies = null;
|
||||
private static Assembly[] Assemblies
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (_assemblies == null)
|
||||
{
|
||||
var assemblyNames = new ES3Settings().assemblyNames;
|
||||
var assemblyList = new List<Assembly>();
|
||||
|
||||
/* We only use a try/catch block for UWP because exceptions can be disabled on some other platforms (e.g. WebGL), but the non-try/catch method doesn't work on UWP */
|
||||
#if NETFX_CORE
|
||||
for (int i = 0; i < assemblyNames.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var assembly = Assembly.Load(new AssemblyName(assemblyNames[i]));
|
||||
if (assembly != null)
|
||||
assemblyList.Add(assembly);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
#else
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
// This try/catch block is here to catch errors such as assemblies containing double-byte characters in their path.
|
||||
// This obviously won't work if exceptions are disabled.
|
||||
try
|
||||
{
|
||||
if (assemblyNames.Contains(assembly.GetName().Name))
|
||||
{
|
||||
assemblyList.Add(assembly);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endif
|
||||
_assemblies = assemblyList.ToArray();
|
||||
}
|
||||
return _assemblies;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the element type of a collection or array.
|
||||
* Returns null if type is not a collection type.
|
||||
*/
|
||||
public static Type[] GetElementTypes(Type type)
|
||||
{
|
||||
if (IsGenericType(type))
|
||||
return ES3Reflection.GetGenericArguments(type);
|
||||
else if (type.IsArray)
|
||||
return new Type[] { ES3Reflection.GetElementType(type) };
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<FieldInfo> GetSerializableFields(Type type, List<FieldInfo> serializableFields = null, bool safe = true, string[] memberNames = null, BindingFlags bindings = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)
|
||||
{
|
||||
if (type == null)
|
||||
return new List<FieldInfo>();
|
||||
|
||||
var fields = type.GetFields(bindings);
|
||||
|
||||
if (serializableFields == null)
|
||||
serializableFields = new List<FieldInfo>();
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var fieldName = field.Name;
|
||||
|
||||
// If a members array was provided as a parameter, only include the field if it's in the array.
|
||||
if (memberNames != null)
|
||||
if (!memberNames.Contains(fieldName))
|
||||
continue;
|
||||
|
||||
var fieldType = field.FieldType;
|
||||
|
||||
if (AttributeIsDefined(field, es3SerializableAttributeType))
|
||||
{
|
||||
serializableFields.Add(field);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (AttributeIsDefined(field, es3NonSerializableAttributeType))
|
||||
continue;
|
||||
|
||||
if (safe)
|
||||
{
|
||||
// If the field is private, only serialize it if it's explicitly marked as serializable.
|
||||
if (!field.IsPublic && !AttributeIsDefined(field, serializeFieldAttributeType))
|
||||
continue;
|
||||
}
|
||||
|
||||
// Exclude const or readonly fields.
|
||||
if (field.IsLiteral || field.IsInitOnly)
|
||||
continue;
|
||||
|
||||
// Don't store fields whose type is the same as the class the field is housed in unless it's stored by reference (to prevent cyclic references)
|
||||
if (fieldType == type && !IsAssignableFrom(typeof(UnityEngine.Object), fieldType))
|
||||
continue;
|
||||
|
||||
// If property is marked as obsolete or non-serialized, don't serialize it.
|
||||
if (AttributeIsDefined(field, nonSerializedAttributeType) || AttributeIsDefined(field, obsoleteAttributeType))
|
||||
continue;
|
||||
|
||||
if (!TypeIsSerializable(field.FieldType))
|
||||
continue;
|
||||
|
||||
// Don't serialize member fields.
|
||||
if (safe && fieldName.StartsWith(memberFieldPrefix) && field.DeclaringType.Namespace != null && field.DeclaringType.Namespace.Contains("UnityEngine"))
|
||||
continue;
|
||||
|
||||
serializableFields.Add(field);
|
||||
}
|
||||
|
||||
var baseType = BaseType(type);
|
||||
if (baseType != null && baseType != typeof(System.Object) && baseType != typeof(UnityEngine.Object))
|
||||
GetSerializableFields(BaseType(type), serializableFields, safe, memberNames);
|
||||
|
||||
return serializableFields;
|
||||
}
|
||||
|
||||
public static List<PropertyInfo> GetSerializableProperties(Type type, List<PropertyInfo> serializableProperties = null, bool safe = true, string[] memberNames = null, BindingFlags bindings = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)
|
||||
{
|
||||
bool isComponent = IsAssignableFrom(typeof(UnityEngine.Component), type);
|
||||
|
||||
// Only get private properties if we're not getting properties safely.
|
||||
if (!safe)
|
||||
bindings = bindings | BindingFlags.NonPublic;
|
||||
|
||||
var properties = type.GetProperties(bindings);
|
||||
|
||||
if (serializableProperties == null)
|
||||
serializableProperties = new List<PropertyInfo>();
|
||||
|
||||
foreach (var p in properties)
|
||||
{
|
||||
if (AttributeIsDefined(p, es3SerializableAttributeType))
|
||||
{
|
||||
serializableProperties.Add(p);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (AttributeIsDefined(p, es3NonSerializableAttributeType))
|
||||
continue;
|
||||
|
||||
var propertyName = p.Name;
|
||||
|
||||
if (excludedPropertyNames.Contains(propertyName))
|
||||
continue;
|
||||
|
||||
// If a members array was provided as a parameter, only include the property if it's in the array.
|
||||
if (memberNames != null)
|
||||
if (!memberNames.Contains(propertyName))
|
||||
continue;
|
||||
|
||||
if (safe)
|
||||
{
|
||||
// If safe serialization is enabled, only get properties which are explicitly marked as serializable.
|
||||
if (!AttributeIsDefined(p, serializeFieldAttributeType) && !AttributeIsDefined(p, es3SerializableAttributeType))
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyType = p.PropertyType;
|
||||
|
||||
// Don't store properties whose type is the same as the class the property is housed in unless it's stored by reference (to prevent cyclic references)
|
||||
if (propertyType == type && !IsAssignableFrom(typeof(UnityEngine.Object), propertyType))
|
||||
continue;
|
||||
|
||||
if (!p.CanRead || !p.CanWrite)
|
||||
continue;
|
||||
|
||||
// Only support properties with indexing if they're an array.
|
||||
if (p.GetIndexParameters().Length != 0 && !propertyType.IsArray)
|
||||
continue;
|
||||
|
||||
// Check that the type of the property is one which we can serialize.
|
||||
// Also check whether an ES3Type exists for it.
|
||||
if (!TypeIsSerializable(propertyType))
|
||||
continue;
|
||||
|
||||
// Ignore certain properties on components.
|
||||
if (isComponent)
|
||||
{
|
||||
// Ignore properties which are accessors for GameObject fields.
|
||||
if (propertyName == componentTagFieldName || propertyName == componentNameFieldName)
|
||||
continue;
|
||||
}
|
||||
|
||||
// If property is marked as obsolete or non-serialized, don't serialize it.
|
||||
if (AttributeIsDefined(p, obsoleteAttributeType) || AttributeIsDefined(p, nonSerializedAttributeType))
|
||||
continue;
|
||||
|
||||
serializableProperties.Add(p);
|
||||
}
|
||||
|
||||
var baseType = BaseType(type);
|
||||
if (baseType != null && baseType != typeof(System.Object))
|
||||
GetSerializableProperties(baseType, serializableProperties, safe, memberNames);
|
||||
|
||||
return serializableProperties;
|
||||
}
|
||||
|
||||
public static bool TypeIsSerializable(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
return false;
|
||||
|
||||
if (AttributeIsDefined(type, es3NonSerializableAttributeType))
|
||||
return false;
|
||||
|
||||
if (IsPrimitive(type) || IsValueType(type) || IsAssignableFrom(typeof(UnityEngine.Component), type) || IsAssignableFrom(typeof(UnityEngine.ScriptableObject), type))
|
||||
return true;
|
||||
|
||||
var es3Type = ES3TypeMgr.GetOrCreateES3Type(type, false);
|
||||
|
||||
if (es3Type != null && !es3Type.isUnsupported)
|
||||
return true;
|
||||
|
||||
if (TypeIsArray(type))
|
||||
{
|
||||
if (TypeIsSerializable(type.GetElementType()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
var genericArgs = type.GetGenericArguments();
|
||||
for (int i = 0; i < genericArgs.Length; i++)
|
||||
if (!TypeIsSerializable(genericArgs[i]))
|
||||
return false;
|
||||
|
||||
/*if (HasParameterlessConstructor(type))
|
||||
return true;*/
|
||||
return false;
|
||||
}
|
||||
|
||||
public static System.Object CreateInstance(Type type)
|
||||
{
|
||||
if (IsAssignableFrom(typeof(UnityEngine.Component), type))
|
||||
return ES3ComponentType.CreateComponent(type);
|
||||
else if (IsAssignableFrom(typeof(ScriptableObject), type))
|
||||
return ScriptableObject.CreateInstance(type);
|
||||
else if (ES3Reflection.HasParameterlessConstructor(type))
|
||||
return Activator.CreateInstance(type);
|
||||
else
|
||||
{
|
||||
#if NETFX_CORE
|
||||
throw new NotSupportedException($"Cannot create an instance of {type} because it does not have a parameterless constructor, which is required on Universal Windows platform.");
|
||||
#else
|
||||
return System.Runtime.Serialization.FormatterServices.GetUninitializedObject(type);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static System.Object CreateInstance(Type type, params object[] args)
|
||||
{
|
||||
if (IsAssignableFrom(typeof(UnityEngine.Component), type))
|
||||
return ES3ComponentType.CreateComponent(type);
|
||||
else if (IsAssignableFrom(typeof(ScriptableObject), type))
|
||||
return ScriptableObject.CreateInstance(type);
|
||||
return Activator.CreateInstance(type, args);
|
||||
}
|
||||
|
||||
public static Array ArrayCreateInstance(Type type, int length)
|
||||
{
|
||||
return Array.CreateInstance(type, new int[] { length });
|
||||
}
|
||||
|
||||
public static Array ArrayCreateInstance(Type type, int[] dimensions)
|
||||
{
|
||||
return Array.CreateInstance(type, dimensions);
|
||||
}
|
||||
|
||||
public static Type MakeGenericType(Type type, Type genericParam)
|
||||
{
|
||||
return type.MakeGenericType(genericParam);
|
||||
}
|
||||
|
||||
public static ES3ReflectedMember[] GetSerializableMembers(Type type, bool safe = true, string[] memberNames = null)
|
||||
{
|
||||
if (type == null)
|
||||
return new ES3ReflectedMember[0];
|
||||
|
||||
var fieldInfos = GetSerializableFields(type, new List<FieldInfo>(), safe, memberNames);
|
||||
var propertyInfos = GetSerializableProperties(type, new List<PropertyInfo>(), safe, memberNames);
|
||||
var reflectedFields = new ES3ReflectedMember[fieldInfos.Count + propertyInfos.Count];
|
||||
|
||||
for (int i = 0; i < fieldInfos.Count; i++)
|
||||
reflectedFields[i] = new ES3ReflectedMember(fieldInfos[i]);
|
||||
for (int i = 0; i < propertyInfos.Count; i++)
|
||||
reflectedFields[i + fieldInfos.Count] = new ES3ReflectedMember(propertyInfos[i]);
|
||||
|
||||
return reflectedFields;
|
||||
}
|
||||
|
||||
public static ES3ReflectedMember GetES3ReflectedProperty(Type type, string propertyName)
|
||||
{
|
||||
var propertyInfo = ES3Reflection.GetProperty(type, propertyName);
|
||||
return new ES3ReflectedMember(propertyInfo);
|
||||
}
|
||||
|
||||
public static ES3ReflectedMember GetES3ReflectedMember(Type type, string fieldName)
|
||||
{
|
||||
var fieldInfo = ES3Reflection.GetField(type, fieldName);
|
||||
return new ES3ReflectedMember(fieldInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds all classes of a specific type, and then returns an instance of each.
|
||||
* Ignores classes which can't be instantiated (i.e. abstract classes, those without parameterless constructors).
|
||||
*/
|
||||
public static IList<T> GetInstances<T>()
|
||||
{
|
||||
var instances = new List<T>();
|
||||
foreach (var assembly in Assemblies)
|
||||
foreach (var type in assembly.GetTypes())
|
||||
if (IsAssignableFrom(typeof(T), type) && ES3Reflection.HasParameterlessConstructor(type) && !ES3Reflection.IsAbstract(type))
|
||||
instances.Add((T)Activator.CreateInstance(type));
|
||||
return instances;
|
||||
}
|
||||
|
||||
public static IList<Type> GetDerivedTypes(Type derivedType)
|
||||
{
|
||||
return
|
||||
(
|
||||
from assembly in Assemblies
|
||||
from type in assembly.GetTypes()
|
||||
where IsAssignableFrom(derivedType, type)
|
||||
select type
|
||||
).ToList();
|
||||
}
|
||||
|
||||
public static bool IsAssignableFrom(Type a, Type b)
|
||||
{
|
||||
return a.IsAssignableFrom(b);
|
||||
}
|
||||
|
||||
public static Type GetGenericTypeDefinition(Type type)
|
||||
{
|
||||
return type.GetGenericTypeDefinition();
|
||||
}
|
||||
|
||||
public static Type[] GetGenericArguments(Type type)
|
||||
{
|
||||
return type.GetGenericArguments();
|
||||
}
|
||||
|
||||
public static int GetArrayRank(Type type)
|
||||
{
|
||||
return type.GetArrayRank();
|
||||
}
|
||||
|
||||
public static string GetAssemblyQualifiedName(Type type)
|
||||
{
|
||||
return type.AssemblyQualifiedName;
|
||||
}
|
||||
|
||||
public static ES3ReflectedMethod GetMethod(Type type, string methodName, Type[] genericParameters, Type[] parameterTypes)
|
||||
{
|
||||
return new ES3ReflectedMethod(type, methodName, genericParameters, parameterTypes);
|
||||
}
|
||||
|
||||
public static bool TypeIsArray(Type type)
|
||||
{
|
||||
return type.IsArray;
|
||||
}
|
||||
|
||||
public static Type GetElementType(Type type)
|
||||
{
|
||||
return type.GetElementType();
|
||||
}
|
||||
|
||||
#if NETFX_CORE
|
||||
public static bool IsAbstract(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsAbstract;
|
||||
}
|
||||
|
||||
public static bool IsInterface(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsInterface;
|
||||
}
|
||||
|
||||
public static bool IsGenericType(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsGenericType;
|
||||
}
|
||||
|
||||
public static bool IsValueType(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsValueType;
|
||||
}
|
||||
|
||||
public static bool IsEnum(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsEnum;
|
||||
}
|
||||
|
||||
public static bool HasParameterlessConstructor(Type type)
|
||||
{
|
||||
return GetParameterlessConstructor(type) != null;
|
||||
}
|
||||
|
||||
public static ConstructorInfo GetParameterlessConstructor(Type type)
|
||||
{
|
||||
foreach (var cInfo in type.GetTypeInfo().DeclaredConstructors)
|
||||
if (!cInfo.IsStatic && cInfo.GetParameters().Length == 0)
|
||||
return cInfo;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetShortAssemblyQualifiedName(Type type)
|
||||
{
|
||||
if (IsPrimitive (type))
|
||||
return type.ToString ();
|
||||
return type.FullName + "," + type.GetTypeInfo().Assembly.GetName().Name;
|
||||
}
|
||||
|
||||
public static PropertyInfo GetProperty(Type type, string propertyName)
|
||||
{
|
||||
var property = type.GetTypeInfo().GetDeclaredProperty(propertyName);
|
||||
if (property == null && type.BaseType != typeof(object))
|
||||
return GetProperty(type.BaseType, propertyName);
|
||||
return property;
|
||||
}
|
||||
|
||||
public static FieldInfo GetField(Type type, string fieldName)
|
||||
{
|
||||
return type.GetTypeInfo().GetDeclaredField(fieldName);
|
||||
}
|
||||
|
||||
public static MethodInfo[] GetMethods(Type type, string methodName)
|
||||
{
|
||||
return type.GetTypeInfo().GetDeclaredMethods(methodName);
|
||||
}
|
||||
|
||||
public static bool IsPrimitive(Type type)
|
||||
{
|
||||
return (type.GetTypeInfo().IsPrimitive || type == typeof(string) || type == typeof(decimal));
|
||||
}
|
||||
|
||||
public static bool AttributeIsDefined(MemberInfo info, Type attributeType)
|
||||
{
|
||||
var attributes = info.GetCustomAttributes(attributeType, true);
|
||||
foreach(var attribute in attributes)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool AttributeIsDefined(Type type, Type attributeType)
|
||||
{
|
||||
var attributes = type.GetTypeInfo().GetCustomAttributes(attributeType, true);
|
||||
foreach(var attribute in attributes)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ImplementsInterface(Type type, Type interfaceType)
|
||||
{
|
||||
return type.GetTypeInfo().ImplementedInterfaces.Contains(interfaceType);
|
||||
}
|
||||
|
||||
public static Type BaseType(Type type)
|
||||
{
|
||||
return type.GetTypeInfo().BaseType;
|
||||
}
|
||||
#else
|
||||
public static bool IsAbstract(Type type)
|
||||
{
|
||||
return type.IsAbstract;
|
||||
}
|
||||
|
||||
public static bool IsInterface(Type type)
|
||||
{
|
||||
return type.IsInterface;
|
||||
}
|
||||
|
||||
public static bool IsGenericType(Type type)
|
||||
{
|
||||
return type.IsGenericType;
|
||||
}
|
||||
|
||||
public static bool IsValueType(Type type)
|
||||
{
|
||||
return type.IsValueType;
|
||||
}
|
||||
|
||||
public static bool IsEnum(Type type)
|
||||
{
|
||||
return type.IsEnum;
|
||||
}
|
||||
|
||||
public static bool HasParameterlessConstructor(Type type)
|
||||
{
|
||||
if (IsValueType(type) || GetParameterlessConstructor(type) != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ConstructorInfo GetParameterlessConstructor(Type type)
|
||||
{
|
||||
var constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
foreach (var constructor in constructors)
|
||||
if (constructor.GetParameters().Length == 0)
|
||||
return constructor;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetShortAssemblyQualifiedName(Type type)
|
||||
{
|
||||
if (IsPrimitive(type))
|
||||
return type.ToString();
|
||||
return type.FullName + "," + type.Assembly.GetName().Name;
|
||||
}
|
||||
|
||||
public static PropertyInfo GetProperty(Type type, string propertyName)
|
||||
{
|
||||
var property = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (property == null && BaseType(type) != typeof(object))
|
||||
return GetProperty(BaseType(type), propertyName);
|
||||
return property;
|
||||
}
|
||||
|
||||
public static FieldInfo GetField(Type type, string fieldName)
|
||||
{
|
||||
var field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (field == null && BaseType(type) != typeof(object))
|
||||
return GetField(BaseType(type), fieldName);
|
||||
return field;
|
||||
}
|
||||
|
||||
public static MethodInfo[] GetMethods(Type type, string methodName)
|
||||
{
|
||||
return type.GetMethods().Where(t => t.Name == methodName).ToArray();
|
||||
}
|
||||
|
||||
public static bool IsPrimitive(Type type)
|
||||
{
|
||||
return (type.IsPrimitive || type == typeof(string) || type == typeof(decimal));
|
||||
}
|
||||
|
||||
public static bool AttributeIsDefined(MemberInfo info, Type attributeType)
|
||||
{
|
||||
return Attribute.IsDefined(info, attributeType, true);
|
||||
}
|
||||
|
||||
public static bool AttributeIsDefined(Type type, Type attributeType)
|
||||
{
|
||||
return type.IsDefined(attributeType, true);
|
||||
}
|
||||
|
||||
public static bool ImplementsInterface(Type type, Type interfaceType)
|
||||
{
|
||||
return (type.GetInterface(interfaceType.Name) != null);
|
||||
}
|
||||
|
||||
public static Type BaseType(Type type)
|
||||
{
|
||||
return type.BaseType;
|
||||
}
|
||||
|
||||
public static Type GetType(string typeString)
|
||||
{
|
||||
switch (typeString)
|
||||
{
|
||||
case "bool":
|
||||
return typeof(bool);
|
||||
case "byte":
|
||||
return typeof(byte);
|
||||
case "sbyte":
|
||||
return typeof(sbyte);
|
||||
case "char":
|
||||
return typeof(char);
|
||||
case "decimal":
|
||||
return typeof(decimal);
|
||||
case "double":
|
||||
return typeof(double);
|
||||
case "float":
|
||||
return typeof(float);
|
||||
case "int":
|
||||
return typeof(int);
|
||||
case "uint":
|
||||
return typeof(uint);
|
||||
case "long":
|
||||
return typeof(long);
|
||||
case "ulong":
|
||||
return typeof(ulong);
|
||||
case "short":
|
||||
return typeof(short);
|
||||
case "ushort":
|
||||
return typeof(ushort);
|
||||
case "string":
|
||||
return typeof(string);
|
||||
case "Vector2":
|
||||
return typeof(Vector2);
|
||||
case "Vector3":
|
||||
return typeof(Vector3);
|
||||
case "Vector4":
|
||||
return typeof(Vector4);
|
||||
case "Color":
|
||||
return typeof(Color);
|
||||
case "Transform":
|
||||
return typeof(Transform);
|
||||
case "Component":
|
||||
return typeof(UnityEngine.Component);
|
||||
case "GameObject":
|
||||
return typeof(GameObject);
|
||||
case "MeshFilter":
|
||||
return typeof(MeshFilter);
|
||||
case "Material":
|
||||
return typeof(Material);
|
||||
case "Texture2D":
|
||||
return typeof(Texture2D);
|
||||
case "UnityEngine.Object":
|
||||
return typeof(UnityEngine.Object);
|
||||
case "System.Object":
|
||||
return typeof(object);
|
||||
default:
|
||||
return Type.GetType(typeString);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTypeString(Type type)
|
||||
{
|
||||
if (type == typeof(bool))
|
||||
return "bool";
|
||||
else if (type == typeof(byte))
|
||||
return "byte";
|
||||
else if (type == typeof(sbyte))
|
||||
return "sbyte";
|
||||
else if (type == typeof(char))
|
||||
return "char";
|
||||
else if (type == typeof(decimal))
|
||||
return "decimal";
|
||||
else if (type == typeof(double))
|
||||
return "double";
|
||||
else if (type == typeof(float))
|
||||
return "float";
|
||||
else if (type == typeof(int))
|
||||
return "int";
|
||||
else if (type == typeof(uint))
|
||||
return "uint";
|
||||
else if (type == typeof(long))
|
||||
return "long";
|
||||
else if (type == typeof(ulong))
|
||||
return "ulong";
|
||||
else if (type == typeof(short))
|
||||
return "short";
|
||||
else if (type == typeof(ushort))
|
||||
return "ushort";
|
||||
else if (type == typeof(string))
|
||||
return "string";
|
||||
else if (type == typeof(Vector2))
|
||||
return "Vector2";
|
||||
else if (type == typeof(Vector3))
|
||||
return "Vector3";
|
||||
else if (type == typeof(Vector4))
|
||||
return "Vector4";
|
||||
else if (type == typeof(Color))
|
||||
return "Color";
|
||||
else if (type == typeof(Transform))
|
||||
return "Transform";
|
||||
else if (type == typeof(UnityEngine.Component))
|
||||
return "Component";
|
||||
else if (type == typeof(GameObject))
|
||||
return "GameObject";
|
||||
else if (type == typeof(MeshFilter))
|
||||
return "MeshFilter";
|
||||
else if (type == typeof(Material))
|
||||
return "Material";
|
||||
else if (type == typeof(Texture2D))
|
||||
return "Texture2D";
|
||||
else if (type == typeof(UnityEngine.Object))
|
||||
return "UnityEngine.Object";
|
||||
else if (type == typeof(object))
|
||||
return "System.Object";
|
||||
else
|
||||
return GetShortAssemblyQualifiedName(type);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allows us to use FieldInfo and PropertyInfo interchangably.
|
||||
*/
|
||||
public struct ES3ReflectedMember
|
||||
{
|
||||
// The FieldInfo or PropertyInfo for this field.
|
||||
private FieldInfo fieldInfo;
|
||||
private PropertyInfo propertyInfo;
|
||||
public bool isProperty;
|
||||
|
||||
public bool IsNull { get { return fieldInfo == null && propertyInfo == null; } }
|
||||
public string Name { get { return (isProperty ? propertyInfo.Name : fieldInfo.Name); } }
|
||||
public Type MemberType { get { return (isProperty ? propertyInfo.PropertyType : fieldInfo.FieldType); } }
|
||||
public bool IsPublic { get { return (isProperty ? (propertyInfo.GetGetMethod(true).IsPublic && propertyInfo.GetSetMethod(true).IsPublic) : fieldInfo.IsPublic); } }
|
||||
public bool IsProtected { get { return (isProperty ? (propertyInfo.GetGetMethod(true).IsFamily) : fieldInfo.IsFamily); } }
|
||||
public bool IsStatic { get { return (isProperty ? (propertyInfo.GetGetMethod(true).IsStatic) : fieldInfo.IsStatic); } }
|
||||
|
||||
public ES3ReflectedMember(System.Object fieldPropertyInfo)
|
||||
{
|
||||
if (fieldPropertyInfo == null)
|
||||
{
|
||||
this.propertyInfo = null;
|
||||
this.fieldInfo = null;
|
||||
isProperty = false;
|
||||
return;
|
||||
}
|
||||
|
||||
isProperty = ES3Reflection.IsAssignableFrom(typeof(PropertyInfo), fieldPropertyInfo.GetType());
|
||||
if (isProperty)
|
||||
{
|
||||
this.propertyInfo = (PropertyInfo)fieldPropertyInfo;
|
||||
this.fieldInfo = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.fieldInfo = (FieldInfo)fieldPropertyInfo;
|
||||
this.propertyInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue(System.Object obj, System.Object value)
|
||||
{
|
||||
if (isProperty)
|
||||
propertyInfo.SetValue(obj, value, null);
|
||||
else
|
||||
fieldInfo.SetValue(obj, value);
|
||||
}
|
||||
|
||||
public System.Object GetValue(System.Object obj)
|
||||
{
|
||||
if (isProperty)
|
||||
return propertyInfo.GetValue(obj, null);
|
||||
else
|
||||
return fieldInfo.GetValue(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public class ES3ReflectedMethod
|
||||
{
|
||||
private MethodInfo method;
|
||||
|
||||
public ES3ReflectedMethod(Type type, string methodName, Type[] genericParameters, Type[] parameterTypes)
|
||||
{
|
||||
MethodInfo nonGenericMethod = type.GetMethod(methodName, parameterTypes);
|
||||
this.method = nonGenericMethod.MakeGenericMethod(genericParameters);
|
||||
}
|
||||
|
||||
public ES3ReflectedMethod(Type type, string methodName, Type[] genericParameters, Type[] parameterTypes, BindingFlags bindingAttr)
|
||||
{
|
||||
MethodInfo nonGenericMethod = type.GetMethod(methodName, bindingAttr, null, parameterTypes, null);
|
||||
this.method = nonGenericMethod.MakeGenericMethod(genericParameters);
|
||||
}
|
||||
|
||||
public object Invoke(object obj, object[] parameters = null)
|
||||
{
|
||||
return method.Invoke(obj, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 499c212fb9e3c410dacca179f55ba150
|
||||
timeCreated: 1499764821
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
[System.Serializable]
|
||||
public abstract class ES3SerializableDictionary<TKey,TVal> : Dictionary<TKey,TVal>, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField]
|
||||
private List<TKey> _Keys;
|
||||
[SerializeField]
|
||||
private List<TVal> _Values;
|
||||
|
||||
protected abstract bool KeysAreEqual(TKey a, TKey b);
|
||||
protected abstract bool ValuesAreEqual(TVal a, TVal b);
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
_Keys = new List<TKey>();
|
||||
_Values = new List<TVal>();
|
||||
foreach(KeyValuePair<TKey, TVal> pair in this)
|
||||
{
|
||||
try
|
||||
{
|
||||
_Keys.Add(pair.Key);
|
||||
_Values.Add(pair.Value);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
// load dictionary from lists
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
// There are some situations where Unity will not get the serialized data correctly, returning null.
|
||||
// In this case we don't want to change anything, otherwise we'll lose the data entirely.
|
||||
if (_Keys == null || _Values == null)
|
||||
return;
|
||||
|
||||
if(_Keys.Count != _Values.Count)
|
||||
throw new System.Exception(string.Format("Key count is different to value count after deserialising dictionary."));
|
||||
|
||||
this.Clear();
|
||||
|
||||
for (int i = 0; i < _Keys.Count; i++)
|
||||
{
|
||||
if (_Keys[i] != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.Add(_Keys[i], _Values[i]);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
_Keys = null;
|
||||
_Values = null;
|
||||
}
|
||||
|
||||
public int RemoveNullValues()
|
||||
{
|
||||
var nullKeys = this.Where(pair => pair.Value == null)
|
||||
.Select(pair => pair.Key)
|
||||
.ToList();
|
||||
foreach (var nullKey in nullKeys)
|
||||
Remove(nullKey);
|
||||
return nullKeys.Count;
|
||||
}
|
||||
|
||||
// Changes the key of a value without changing it's position in the underlying Lists.
|
||||
// Mainly used in the Editor where position might otherwise change while the user is editing it.
|
||||
// Returns true if a change was made.
|
||||
public bool ChangeKey(TKey oldKey, TKey newKey)
|
||||
{
|
||||
if(KeysAreEqual(oldKey, newKey))
|
||||
return false;
|
||||
|
||||
var val = this [oldKey];
|
||||
Remove(oldKey);
|
||||
this [newKey] = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 681896bd0089c4f7296b3ecbd899f44d
|
||||
timeCreated: 1519132287
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,307 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using ES3Internal;
|
||||
|
||||
#if UNITY_VISUAL_SCRIPTING
|
||||
[Unity.VisualScripting.IncludeInSettings(true)]
|
||||
#elif BOLT_VISUAL_SCRIPTING
|
||||
[Ludiq.IncludeInSettings(true)]
|
||||
#endif
|
||||
public class ES3Spreadsheet
|
||||
{
|
||||
private int cols = 0;
|
||||
private int rows = 0;
|
||||
private Dictionary<Index, string> cells = new Dictionary<Index, string>();
|
||||
|
||||
private const string QUOTE = "\"";
|
||||
private const char QUOTE_CHAR = '"';
|
||||
private const char COMMA_CHAR = ',';
|
||||
private const char NEWLINE_CHAR = '\n';
|
||||
private const string ESCAPED_QUOTE = "\"\"";
|
||||
private static char[] CHARS_TO_ESCAPE = { ',', '"', '\n', ' ' };
|
||||
|
||||
public int ColumnCount
|
||||
{
|
||||
get{ return cols; }
|
||||
}
|
||||
|
||||
public int RowCount
|
||||
{
|
||||
get{ return rows; }
|
||||
}
|
||||
|
||||
public int GetColumnLength(int col)
|
||||
{
|
||||
if (col >= cols)
|
||||
return 0;
|
||||
|
||||
int maxRow = -1;
|
||||
|
||||
foreach(var index in cells.Keys)
|
||||
if (index.col == col && index.row > maxRow)
|
||||
maxRow = index.row;
|
||||
|
||||
return maxRow+1;
|
||||
}
|
||||
|
||||
public int GetRowLength(int row)
|
||||
{
|
||||
if (row >= rows)
|
||||
return 0;
|
||||
|
||||
int maxCol = -1;
|
||||
|
||||
foreach (var index in cells.Keys)
|
||||
if (index.row == row && index.col > maxCol)
|
||||
maxCol = index.col;
|
||||
|
||||
return maxCol + 1;
|
||||
}
|
||||
|
||||
public void SetCell(int col, int row, object value)
|
||||
{
|
||||
var type = value.GetType();
|
||||
|
||||
// If we're writing a string, add it without formatting.
|
||||
if (type == typeof(string))
|
||||
{
|
||||
SetCellString(col, row, (string)value);
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = new ES3Settings();
|
||||
if (ES3Reflection.IsPrimitive(type))
|
||||
SetCellString(col, row, value.ToString());
|
||||
else
|
||||
SetCellString(col, row, settings.encoding.GetString(ES3.Serialize(value, ES3TypeMgr.GetOrCreateES3Type(type))));
|
||||
|
||||
// Expand the spreadsheet if necessary.
|
||||
if (col >= cols)
|
||||
cols = (col + 1);
|
||||
if (row >= rows)
|
||||
rows = (row + 1);
|
||||
}
|
||||
|
||||
private void SetCellString(int col, int row, string value)
|
||||
{
|
||||
cells [new Index (col, row)] = value;
|
||||
|
||||
// Expand the spreadsheet if necessary.
|
||||
if(col >= cols)
|
||||
cols = (col+1);
|
||||
if (row >= rows)
|
||||
rows = (row + 1);
|
||||
}
|
||||
|
||||
|
||||
// Don't create non-generic version of this. Generic parameter is necessary as no type data is stored in the CSV file.
|
||||
public T GetCell<T>(int col, int row)
|
||||
{
|
||||
var val = GetCell(typeof(T), col, row);
|
||||
|
||||
if (val == null)
|
||||
return default(T);
|
||||
return (T)val;
|
||||
}
|
||||
|
||||
public object GetCell(System.Type type, int col, int row)
|
||||
{
|
||||
string value;
|
||||
|
||||
if (col >= cols || row >= rows)
|
||||
throw new System.IndexOutOfRangeException("Cell (" + col + ", " + row + ") is out of bounds of spreadsheet (" + cols + ", " + rows + ").");
|
||||
|
||||
if (!cells.TryGetValue(new Index(col, row), out value) || value == null)
|
||||
return null;
|
||||
|
||||
// If we're loading a string, simply return the string value.
|
||||
if (type == typeof(string))
|
||||
{
|
||||
var str = (object)value;
|
||||
return str;
|
||||
}
|
||||
|
||||
var settings = new ES3Settings();
|
||||
return ES3.Deserialize(ES3TypeMgr.GetOrCreateES3Type(type, true), settings.encoding.GetBytes(value), settings);
|
||||
}
|
||||
|
||||
public void Load(string filePath)
|
||||
{
|
||||
Load(new ES3Settings (filePath));
|
||||
}
|
||||
|
||||
public void Load(string filePath, ES3Settings settings)
|
||||
{
|
||||
Load(new ES3Settings (filePath, settings));
|
||||
}
|
||||
|
||||
public void Load(ES3Settings settings)
|
||||
{
|
||||
Load(ES3Stream.CreateStream(settings, ES3FileMode.Read), settings);
|
||||
}
|
||||
|
||||
public void LoadRaw(string str)
|
||||
{
|
||||
Load(new MemoryStream (((new ES3Settings ()).encoding).GetBytes(str)), new ES3Settings());
|
||||
}
|
||||
|
||||
public void LoadRaw(string str, ES3Settings settings)
|
||||
{
|
||||
Load(new MemoryStream ((settings.encoding).GetBytes(str)), settings);
|
||||
}
|
||||
|
||||
private void Load(Stream stream, ES3Settings settings)
|
||||
{
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
int c_int;
|
||||
char c;
|
||||
string value = "";
|
||||
int col = 0;
|
||||
int row = 0;
|
||||
|
||||
// Read until the end of the stream.
|
||||
while(true)
|
||||
{
|
||||
c_int = reader.Read();
|
||||
c = (char)c_int;
|
||||
if(c == QUOTE_CHAR)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
c = (char)reader.Read();
|
||||
|
||||
if(c == QUOTE_CHAR)
|
||||
{
|
||||
// If this quote isn't escaped by another, it is the last quote, so we should stop parsing this value.
|
||||
if(((char)reader.Peek()) != QUOTE_CHAR)
|
||||
break;
|
||||
else
|
||||
c = (char)reader.Read();
|
||||
}
|
||||
value += c;
|
||||
}
|
||||
}
|
||||
// If this is the end of a column, row, or the stream, add the value to the spreadsheet.
|
||||
else if(c == COMMA_CHAR || c == NEWLINE_CHAR || c_int == -1)
|
||||
{
|
||||
SetCell(col, row, value);
|
||||
value = "";
|
||||
if(c == COMMA_CHAR)
|
||||
col++;
|
||||
else if(c == NEWLINE_CHAR)
|
||||
{
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
value += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(string filePath)
|
||||
{
|
||||
Save(new ES3Settings (filePath), false);
|
||||
}
|
||||
|
||||
public void Save(string filePath, ES3Settings settings)
|
||||
{
|
||||
Save(new ES3Settings (filePath, settings), false);
|
||||
}
|
||||
|
||||
public void Save(ES3Settings settings)
|
||||
{
|
||||
Save(settings, false);
|
||||
}
|
||||
|
||||
public void Save(string filePath, bool append)
|
||||
{
|
||||
Save(new ES3Settings (filePath), append);
|
||||
}
|
||||
|
||||
public void Save(string filePath, ES3Settings settings, bool append)
|
||||
{
|
||||
Save(new ES3Settings (filePath, settings), append);
|
||||
}
|
||||
|
||||
public void Save(ES3Settings settings, bool append)
|
||||
{
|
||||
using (var writer = new StreamWriter(ES3Stream.CreateStream(settings, append ? ES3FileMode.Append : ES3FileMode.Write)))
|
||||
{
|
||||
// If data already exists and we're appending, we need to prepend a newline.
|
||||
if(append && ES3.FileExists(settings))
|
||||
writer.Write(NEWLINE_CHAR);
|
||||
|
||||
var array = ToArray();
|
||||
for(int row = 0; row < rows; row++)
|
||||
{
|
||||
if(row != 0)
|
||||
writer.Write(NEWLINE_CHAR);
|
||||
|
||||
for(int col = 0; col < cols; col++)
|
||||
{
|
||||
if(col != 0)
|
||||
writer.Write(COMMA_CHAR);
|
||||
|
||||
writer.Write( Escape(array [col, row]) );
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!append)
|
||||
ES3IO.CommitBackup(settings);
|
||||
}
|
||||
|
||||
private static string Escape(string str, bool isAlreadyWrappedInQuotes=false)
|
||||
{
|
||||
if (str == "")
|
||||
return "\"\"";
|
||||
else if(str == null)
|
||||
return null;
|
||||
|
||||
// Now escape any other quotes.
|
||||
if(str.Contains(QUOTE))
|
||||
str = str.Replace(QUOTE, ESCAPED_QUOTE);
|
||||
|
||||
// If there's chars to escape, wrap the value in quotes.
|
||||
if(str.IndexOfAny(CHARS_TO_ESCAPE) > -1)
|
||||
str = QUOTE + str + QUOTE;
|
||||
return str;
|
||||
}
|
||||
|
||||
private static string Unescape(string str)
|
||||
{
|
||||
if(str.StartsWith(QUOTE) && str.EndsWith(QUOTE))
|
||||
{
|
||||
str = str.Substring(1, str.Length-2);
|
||||
if(str.Contains(ESCAPED_QUOTE))
|
||||
str = str.Replace(ESCAPED_QUOTE, QUOTE);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private string[,] ToArray()
|
||||
{
|
||||
var array = new string[cols, rows];
|
||||
foreach (var cell in cells)
|
||||
array [cell.Key.col, cell.Key.row] = cell.Value;
|
||||
return array;
|
||||
}
|
||||
|
||||
protected struct Index
|
||||
{
|
||||
public int col;
|
||||
public int row;
|
||||
|
||||
public Index(int col, int row)
|
||||
{
|
||||
this.col = col;
|
||||
this.row = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb1f812633929432dabb61bb8de267ba
|
||||
timeCreated: 1508838134
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad87ae223ed42a54c9eb2a3c28ef0a95
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+571
@@ -0,0 +1,571 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System;
|
||||
using ES3Types;
|
||||
using System.Globalization;
|
||||
|
||||
namespace ES3Internal
|
||||
{
|
||||
/*
|
||||
* Specific ES3Reader for reading JSON data.
|
||||
*
|
||||
* Note: Leading & trailing whitespace is ignored whenever
|
||||
* reading characters which are part of the JSON syntax,
|
||||
* i.e. { } [ ] , " " :
|
||||
*/
|
||||
public class ES3JSONReader : ES3Reader
|
||||
{
|
||||
private const char endOfStreamChar = (char)65535;
|
||||
|
||||
public StreamReader baseReader;
|
||||
|
||||
internal ES3JSONReader(Stream stream, ES3Settings settings, bool readHeaderAndFooter = true) : base(settings, readHeaderAndFooter)
|
||||
{
|
||||
this.baseReader = new StreamReader(stream);
|
||||
|
||||
// Read opening brace from file if we're loading straight from file.
|
||||
if(readHeaderAndFooter)
|
||||
{
|
||||
try
|
||||
{
|
||||
SkipOpeningBraceOfFile();
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.Dispose();
|
||||
throw new FormatException("Cannot load from file because the data in it is not JSON data, or the data is encrypted.\nIf the save data is encrypted, please ensure that encryption is enabled when you load, and that you are using the same password used to encrypt the data.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Property/Key Methods
|
||||
|
||||
/*
|
||||
* Reads the name of a property, and must be positioned (with or without whitespace) either:
|
||||
* - Before the '"' of a property name.
|
||||
* - Before the ',' separating properties.
|
||||
* - Before the '}' or ']' terminating this list of properties.
|
||||
* Can be used in conjunction with Read(ES3Type) to read a property.
|
||||
*/
|
||||
public override string ReadPropertyName()
|
||||
{
|
||||
char c = PeekCharIgnoreWhitespace();
|
||||
|
||||
// Check whether there are any properties left to read.
|
||||
if(IsTerminator(c))
|
||||
return null;
|
||||
else if(c == ',')
|
||||
ReadCharIgnoreWhitespace();
|
||||
else if(!IsQuotationMark(c))
|
||||
throw new FormatException("Expected ',' separating properties or '\"' before property name, found '"+c+"'.");
|
||||
|
||||
var propertyName = Read_string();
|
||||
if(propertyName == null)
|
||||
throw new FormatException("Stream isn't positioned before a property.");
|
||||
|
||||
ES3Debug.Log("<b>"+propertyName+"</b> (reading property)", null, serializationDepth);
|
||||
|
||||
// Skip the ':' seperating property and value.
|
||||
ReadCharIgnoreWhitespace(':');
|
||||
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the type data prefixed to this key.
|
||||
* If ignore is true, it will return null to save the computation of converting
|
||||
* the string to a Type.
|
||||
*/
|
||||
protected override Type ReadKeyPrefix(bool ignoreType=false)
|
||||
{
|
||||
StartReadObject();
|
||||
|
||||
Type dataType = null;
|
||||
|
||||
string propertyName = ReadPropertyName();
|
||||
if(propertyName == ES3Type.typeFieldName)
|
||||
{
|
||||
string typeString = Read_string();
|
||||
dataType = ignoreType ? null : ES3Reflection.GetType(typeString);
|
||||
propertyName = ReadPropertyName();
|
||||
}
|
||||
|
||||
if(propertyName != "value")
|
||||
throw new FormatException("This data is not Easy Save Key Value data. Expected property name \"value\", found \""+propertyName+"\".");
|
||||
|
||||
return dataType;
|
||||
}
|
||||
|
||||
protected override void ReadKeySuffix()
|
||||
{
|
||||
EndReadObject();
|
||||
}
|
||||
|
||||
|
||||
internal override bool StartReadObject()
|
||||
{
|
||||
base.StartReadObject();
|
||||
return ReadNullOrCharIgnoreWhitespace('{');
|
||||
}
|
||||
|
||||
internal override void EndReadObject()
|
||||
{
|
||||
ReadCharIgnoreWhitespace('}');
|
||||
base.EndReadObject();
|
||||
}
|
||||
|
||||
|
||||
internal override bool StartReadDictionary()
|
||||
{
|
||||
return StartReadObject();
|
||||
}
|
||||
|
||||
internal override void EndReadDictionary(){}
|
||||
|
||||
internal override bool StartReadDictionaryKey()
|
||||
{
|
||||
// If this is an empty Dictionary, return false.
|
||||
if(PeekCharIgnoreWhitespace() == '}')
|
||||
{
|
||||
ReadCharIgnoreWhitespace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal override void EndReadDictionaryKey()
|
||||
{
|
||||
ReadCharIgnoreWhitespace(':');
|
||||
}
|
||||
|
||||
internal override void StartReadDictionaryValue(){}
|
||||
|
||||
internal override bool EndReadDictionaryValue()
|
||||
{
|
||||
char c = ReadCharIgnoreWhitespace();
|
||||
// If we find a ']', we reached the end of the array.
|
||||
if(c == '}')
|
||||
return true;
|
||||
// Else, we should expect a comma.
|
||||
else if(c != ',')
|
||||
throw new FormatException("Expected ',' seperating Dictionary items or '}' terminating Dictionary, found '"+c+"'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
internal override bool StartReadCollection()
|
||||
{
|
||||
return ReadNullOrCharIgnoreWhitespace('[');
|
||||
}
|
||||
|
||||
internal override void EndReadCollection(){}
|
||||
|
||||
internal override bool StartReadCollectionItem()
|
||||
{
|
||||
// If this is an empty collection, return false.
|
||||
if(PeekCharIgnoreWhitespace() == ']')
|
||||
{
|
||||
ReadCharIgnoreWhitespace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal override bool EndReadCollectionItem()
|
||||
{
|
||||
char c = ReadCharIgnoreWhitespace();
|
||||
// If we find a ']', we reached the end of the array.
|
||||
if(c == ']')
|
||||
return true;
|
||||
// Else, we should expect a comma.
|
||||
else if(c != ',')
|
||||
throw new FormatException("Expected ',' seperating collection items or ']' terminating collection, found '"+c+"'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Seeking Methods
|
||||
|
||||
/*
|
||||
* Reads a string value into a StreamWriter.
|
||||
* Reader should be positioned after the opening quotation mark.
|
||||
* Will also read the closing quotation mark.
|
||||
* If the 'skip' parameter is true, data will not be written into a StreamWriter and will return null.
|
||||
*/
|
||||
private void ReadString(StreamWriter writer, bool skip=false)
|
||||
{
|
||||
bool endOfString = false;
|
||||
// Read to end of string, or throw error if we reach end of stream.
|
||||
while(!endOfString)
|
||||
{
|
||||
char c = ReadOrSkipChar(writer, skip);
|
||||
switch(c)
|
||||
{
|
||||
case endOfStreamChar:
|
||||
throw new FormatException("String without closing quotation mark detected.");
|
||||
case '\\':
|
||||
ReadOrSkipChar(writer, skip);
|
||||
break;
|
||||
default:
|
||||
if(IsQuotationMark(c))
|
||||
endOfString = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the current object in the stream.
|
||||
* Stream position should be somewhere before the opening brace for the object.
|
||||
* When this method successfully exits, it will be on the closing brace for the object.
|
||||
* If the 'skip' parameter is true, data will not be written into a StreamWriter and will return null.
|
||||
*/
|
||||
internal override byte[] ReadElement(bool skip=false)
|
||||
{
|
||||
// If 'skip' is enabled, don't create a stream or writer as we'll discard all bytes we read.
|
||||
StreamWriter writer = skip ? null : new StreamWriter(new MemoryStream(settings.bufferSize));
|
||||
|
||||
using(writer)
|
||||
{
|
||||
int nesting = 0;
|
||||
char c = (char)baseReader.Peek();
|
||||
|
||||
// Determine if we're skipping a primitive type.
|
||||
// First check if it's an opening object or array brace.
|
||||
if(!IsOpeningBrace(c))
|
||||
{
|
||||
// If we're skipping a string, use SkipString().
|
||||
if(c == '\"')
|
||||
{
|
||||
// Skip initial quotation mark as SkipString() requires this.
|
||||
ReadOrSkipChar(writer, skip);
|
||||
ReadString(writer, skip);
|
||||
}
|
||||
// Else we just need to read until we reach a closing brace.
|
||||
else
|
||||
// While we've not peeked a closing brace.
|
||||
while(!IsEndOfValue((char)baseReader.Peek()))
|
||||
ReadOrSkipChar(writer, skip);
|
||||
|
||||
if(skip)
|
||||
return null;
|
||||
writer.Flush();
|
||||
return ((MemoryStream)writer.BaseStream).ToArray();
|
||||
}
|
||||
|
||||
// Else, we're skipping a type surrounded by braces.
|
||||
// Iterate through every character, logging nesting.
|
||||
while(true)
|
||||
{
|
||||
c = ReadOrSkipChar(writer, skip);
|
||||
|
||||
if(c == endOfStreamChar) // Detect premature end of stream, which denotes missing closing brace.
|
||||
throw new FormatException("Missing closing brace detected, as end of stream was reached before finding it.");
|
||||
|
||||
// Handle quoted strings.
|
||||
// According to the RFC, only '\' and '"' must be escaped in strings.
|
||||
if(IsQuotationMark(c))
|
||||
{
|
||||
ReadString(writer, skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle braces and other characters.
|
||||
switch(c)
|
||||
{
|
||||
case '{': // Entered another level of nesting.
|
||||
case '[':
|
||||
nesting++;
|
||||
break;
|
||||
case '}': // Exited a level of nesting.
|
||||
case ']':
|
||||
nesting--;
|
||||
// If nesting < 1, we've come to the end of the object.
|
||||
if(nesting<1)
|
||||
{
|
||||
if(skip)
|
||||
return null;
|
||||
writer.Flush();
|
||||
return ((MemoryStream)writer.BaseStream).ToArray();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the next char into a stream, or ignores it if 'skip' is true.
|
||||
*/
|
||||
private char ReadOrSkipChar(StreamWriter writer, bool skip)
|
||||
{
|
||||
char c = (char)baseReader.Read();
|
||||
if(!skip) writer.Write(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region JSON-specific methods.
|
||||
|
||||
/*
|
||||
* Reads a char from the stream and ignores leading and trailing whitespace.
|
||||
*/
|
||||
private char ReadCharIgnoreWhitespace(bool ignoreTrailingWhitespace=true)
|
||||
{
|
||||
char c;
|
||||
// Skip leading whitespace and read char.
|
||||
while(IsWhiteSpace(c = (char)baseReader.Read()))
|
||||
{}
|
||||
|
||||
// Skip trailing whitespace.
|
||||
if(ignoreTrailingWhitespace)
|
||||
while(IsWhiteSpace((char)baseReader.Peek()))
|
||||
baseReader.Read();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a char, or the NULL value, from the stream and ignores leading and trailing whitespace.
|
||||
* Returns true if NULL was read.
|
||||
*/
|
||||
private bool ReadNullOrCharIgnoreWhitespace(char expectedChar)
|
||||
{
|
||||
char c = ReadCharIgnoreWhitespace();
|
||||
|
||||
// Check for null
|
||||
if(c == 'n')
|
||||
{
|
||||
var chars = new char[3];
|
||||
baseReader.ReadBlock(chars, 0, 3);
|
||||
if((char)chars[0] == 'u' && (char)chars[1] == 'l' && (char)chars[2] == 'l')
|
||||
return true;
|
||||
}
|
||||
|
||||
if(c != expectedChar)
|
||||
{
|
||||
if(c == endOfStreamChar)
|
||||
throw new FormatException("End of stream reached when expecting '"+expectedChar+"'.");
|
||||
else
|
||||
throw new FormatException("Expected \'"+expectedChar+"\' or \"null\", found \'"+c+"\'.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a char from the stream and ignores leading and trailing whitespace.
|
||||
* Throws an error if the char isn't equal to the one specificed as a parameter, or if it's the end of stream.
|
||||
*/
|
||||
private char ReadCharIgnoreWhitespace(char expectedChar)
|
||||
{
|
||||
char c = ReadCharIgnoreWhitespace();
|
||||
if(c != expectedChar)
|
||||
{
|
||||
if(c == endOfStreamChar)
|
||||
throw new FormatException("End of stream reached when expecting '"+expectedChar+"'.");
|
||||
else
|
||||
throw new FormatException("Expected \'"+expectedChar+"\', found \'"+c+"\'.");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private bool ReadQuotationMarkOrNullIgnoreWhitespace()
|
||||
{
|
||||
char c = ReadCharIgnoreWhitespace(false); // Don't read trailing whitespace as this is the value.
|
||||
|
||||
if(c == 'n')
|
||||
{
|
||||
var chars = new char[3];
|
||||
baseReader.ReadBlock(chars, 0, 3);
|
||||
if((char)chars[0] == 'u' && (char)chars[1] == 'l' && (char)chars[2] == 'l')
|
||||
return true;
|
||||
}
|
||||
else if(!IsQuotationMark(c))
|
||||
{
|
||||
if(c == endOfStreamChar)
|
||||
throw new FormatException("End of stream reached when expecting quotation mark.");
|
||||
else
|
||||
throw new FormatException("Expected quotation mark, found \'"+c+"\'.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Peeks the next char in the stream, ignoring leading whitespace, but not trailing whitespace.
|
||||
*/
|
||||
private char PeekCharIgnoreWhitespace(char expectedChar)
|
||||
{
|
||||
char c = PeekCharIgnoreWhitespace();
|
||||
if(c != expectedChar)
|
||||
{
|
||||
if(c == endOfStreamChar)
|
||||
throw new FormatException("End of stream reached while peeking, when expecting '"+expectedChar+"'.");
|
||||
else
|
||||
throw new FormatException("Expected \'"+expectedChar+"\', found \'"+c+"\'.");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Peeks the next char in the stream, ignoring leading whitespace, but not trailing whitespace.
|
||||
* Throws an error if the char isn't equal to the one specificed as a parameter.
|
||||
*/
|
||||
private char PeekCharIgnoreWhitespace()
|
||||
{
|
||||
char c;
|
||||
// Skip leading whitespace and read char.
|
||||
while(IsWhiteSpace(c = (char)baseReader.Peek()))
|
||||
baseReader.Read();
|
||||
return c;
|
||||
}
|
||||
|
||||
// Skips all whitespace immediately after the current position.
|
||||
private void SkipWhiteSpace()
|
||||
{
|
||||
while(IsWhiteSpace((char)baseReader.Peek()))
|
||||
baseReader.Read();
|
||||
}
|
||||
|
||||
private void SkipOpeningBraceOfFile()
|
||||
{
|
||||
// Skip the whitespace and '{' at the beginning of the JSON file.
|
||||
char firstChar = ReadCharIgnoreWhitespace();
|
||||
if(firstChar != '{') // If first char isn't '{', it's not valid JSON.
|
||||
throw new FormatException("File is not valid JSON. Expected '{' at beginning of file, but found '"+firstChar+"'.");
|
||||
}
|
||||
|
||||
private static bool IsWhiteSpace(char c)
|
||||
{
|
||||
return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
|
||||
}
|
||||
|
||||
private static bool IsOpeningBrace(char c)
|
||||
{
|
||||
return (c == '{' || c == '[');
|
||||
}
|
||||
|
||||
private static bool IsEndOfValue(char c)
|
||||
{
|
||||
return (c == '}' || c == ' ' || c == '\t' || c == ']' || c == ',' || c== ':' || c == endOfStreamChar || c == '\n' || c == '\r');
|
||||
}
|
||||
|
||||
private static bool IsTerminator(char c)
|
||||
{
|
||||
return (c == '}' || c == ']');
|
||||
}
|
||||
|
||||
private static bool IsQuotationMark(char c)
|
||||
{
|
||||
return c == '\"' || c == '“' || c == '”';
|
||||
}
|
||||
|
||||
private static bool IsEndOfStream(char c)
|
||||
{
|
||||
return c == endOfStreamChar;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads a value (i.e. non-string, non-object) from the stream as a string.
|
||||
* Used mostly in Read_[type]() methods.
|
||||
*/
|
||||
private string GetValueString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
while(!IsEndOfValue(PeekCharIgnoreWhitespace()))
|
||||
builder.Append((char)baseReader.Read());
|
||||
|
||||
// If it's an empty value, return null.
|
||||
if(builder.Length == 0)
|
||||
return null;
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Primitive Read() Methods.
|
||||
|
||||
internal override string Read_string()
|
||||
{
|
||||
if(ReadQuotationMarkOrNullIgnoreWhitespace())
|
||||
return null;
|
||||
char c;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
while(!IsQuotationMark((c = (char)baseReader.Read())))
|
||||
{
|
||||
// If escape mark is found, generate correct escaped character.
|
||||
if(c == '\\')
|
||||
{
|
||||
c = (char)baseReader.Read();
|
||||
if(IsEndOfStream(c))
|
||||
throw new FormatException("Reached end of stream while trying to read string literal.");
|
||||
|
||||
switch(c)
|
||||
{
|
||||
case 'b':
|
||||
c = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
c = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
c = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
c = '\r';
|
||||
break;
|
||||
case 't':
|
||||
c = '\t';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
sb.Append(c);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
internal override long Read_ref()
|
||||
{
|
||||
if (ES3ReferenceMgr.Current == null)
|
||||
throw new InvalidOperationException("An Easy Save 3 Manager is required to load references. To add one to your scene, exit playmode and go to Tools > Easy Save 3 > Add Manager to Scene");
|
||||
if (IsQuotationMark(PeekCharIgnoreWhitespace()))
|
||||
return long.Parse(Read_string());
|
||||
return Read_long();
|
||||
}
|
||||
|
||||
internal override char Read_char() { return char.Parse( Read_string()); }
|
||||
internal override float Read_float() { return float.Parse( GetValueString(), CultureInfo.InvariantCulture); }
|
||||
internal override int Read_int() { return int.Parse( GetValueString()); }
|
||||
internal override bool Read_bool() { return bool.Parse( GetValueString()); }
|
||||
internal override decimal Read_decimal() { return decimal.Parse( GetValueString(), CultureInfo.InvariantCulture); }
|
||||
internal override double Read_double() { return double.Parse( GetValueString(), CultureInfo.InvariantCulture); }
|
||||
internal override long Read_long() { return long.Parse( GetValueString()); }
|
||||
internal override ulong Read_ulong() { return ulong.Parse( GetValueString()); }
|
||||
internal override uint Read_uint() { return uint.Parse( GetValueString()); }
|
||||
internal override byte Read_byte() { return (byte)int.Parse( GetValueString()); }
|
||||
internal override sbyte Read_sbyte() { return (sbyte)int.Parse( GetValueString()); }
|
||||
internal override short Read_short() { return (short)int.Parse( GetValueString()); }
|
||||
internal override ushort Read_ushort() { return (ushort)int.Parse( GetValueString()); }
|
||||
|
||||
internal override byte[] Read_byteArray(){ return System.Convert.FromBase64String(Read_string()); }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
baseReader.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8757682770a6c4537a3dcbed278277bc
|
||||
timeCreated: 1499764822
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+459
@@ -0,0 +1,459 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using ES3Types;
|
||||
using ES3Internal;
|
||||
|
||||
public abstract class ES3Reader : System.IDisposable
|
||||
{
|
||||
/// <summary>The settings used to create this reader.</summary>
|
||||
public ES3Settings settings;
|
||||
|
||||
protected int serializationDepth = 0;
|
||||
|
||||
#region ES3Reader Abstract Methods
|
||||
|
||||
internal abstract int Read_int();
|
||||
internal abstract float Read_float();
|
||||
internal abstract bool Read_bool();
|
||||
internal abstract char Read_char();
|
||||
internal abstract decimal Read_decimal();
|
||||
internal abstract double Read_double();
|
||||
internal abstract long Read_long();
|
||||
internal abstract ulong Read_ulong();
|
||||
internal abstract byte Read_byte();
|
||||
internal abstract sbyte Read_sbyte();
|
||||
internal abstract short Read_short();
|
||||
internal abstract ushort Read_ushort();
|
||||
internal abstract uint Read_uint();
|
||||
internal abstract string Read_string();
|
||||
internal abstract byte[] Read_byteArray();
|
||||
internal abstract long Read_ref();
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public abstract string ReadPropertyName();
|
||||
|
||||
protected abstract Type ReadKeyPrefix(bool ignore = false);
|
||||
protected abstract void ReadKeySuffix();
|
||||
internal abstract byte[] ReadElement(bool skip=false);
|
||||
|
||||
/// <summary>Disposes of the reader and it's underlying stream.</summary>
|
||||
public abstract void Dispose();
|
||||
|
||||
// Seeks to the given key. Note that the stream position will not be reset.
|
||||
internal virtual bool Goto(string key)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException("Key cannot be NULL when loading data.");
|
||||
|
||||
string currentKey;
|
||||
while ((currentKey = ReadPropertyName()) != key)
|
||||
{
|
||||
if (currentKey == null)
|
||||
return false;
|
||||
Skip();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
internal virtual bool StartReadObject()
|
||||
{
|
||||
serializationDepth++;
|
||||
return false;
|
||||
}
|
||||
|
||||
internal virtual void EndReadObject()
|
||||
{
|
||||
serializationDepth--;
|
||||
}
|
||||
|
||||
internal abstract bool StartReadDictionary();
|
||||
internal abstract void EndReadDictionary();
|
||||
internal abstract bool StartReadDictionaryKey();
|
||||
internal abstract void EndReadDictionaryKey();
|
||||
internal abstract void StartReadDictionaryValue();
|
||||
internal abstract bool EndReadDictionaryValue();
|
||||
|
||||
internal abstract bool StartReadCollection();
|
||||
internal abstract void EndReadCollection();
|
||||
internal abstract bool StartReadCollectionItem();
|
||||
internal abstract bool EndReadCollectionItem();
|
||||
|
||||
#endregion
|
||||
|
||||
internal ES3Reader(ES3Settings settings, bool readHeaderAndFooter = true)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
// If this is not null, the next call to the Properties will return this name.
|
||||
internal string overridePropertiesName = null;
|
||||
/// <summary>Allows you to enumerate over each field name. This should only be used within an ES3Type file.</summary>
|
||||
public virtual ES3ReaderPropertyEnumerator Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ES3ReaderPropertyEnumerator (this);
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual ES3ReaderRawEnumerator RawEnumerator
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ES3ReaderRawEnumerator (this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Skips the current object in the stream.
|
||||
* Stream position should be somewhere before the opening brace for the object.
|
||||
* When this method successfully exits, it will be on the closing brace for the object.
|
||||
*/
|
||||
/// <summary>Skips the current object in the stream.</summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public virtual void Skip()
|
||||
{
|
||||
ReadElement(true);
|
||||
}
|
||||
|
||||
/// <summary>Reads a value of type T from the reader.</summary>
|
||||
public virtual T Read<T>()
|
||||
{
|
||||
return Read<T>(ES3TypeMgr.GetOrCreateES3Type(typeof(T)));
|
||||
}
|
||||
|
||||
/// <summary>Reads a value of type T from the reader into an existing object.</summary>
|
||||
/// <param name="obj">The object we want to read our value into.</param>
|
||||
public virtual void ReadInto<T>(object obj)
|
||||
{
|
||||
ReadInto<T>(obj, ES3TypeMgr.GetOrCreateES3Type(typeof(T)));
|
||||
}
|
||||
|
||||
/// <summary>Reads a property (i.e. a property name and value) from the reader, ignoring the property name and only returning the value.</summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public T ReadProperty<T>()
|
||||
{
|
||||
return ReadProperty<T>(ES3TypeMgr.GetOrCreateES3Type(typeof(T)));
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public T ReadProperty<T>(ES3Type type)
|
||||
{
|
||||
ReadPropertyName();
|
||||
return Read<T>(type);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public long ReadRefProperty()
|
||||
{
|
||||
ReadPropertyName();
|
||||
return Read_ref();
|
||||
}
|
||||
|
||||
internal Type ReadType()
|
||||
{
|
||||
return ES3Reflection.GetType(Read<string>(ES3Type_string.Instance));
|
||||
}
|
||||
|
||||
/// <summary>Sets the value of a private property on an object.</summary>
|
||||
/// <param name="name">The name of the property we want to set.</param>
|
||||
/// <param name="value">The value we want to set the property to.</param>
|
||||
/// <param name="objectContainingProperty">The object containing the property we want to set.</param>
|
||||
/// <returns>The objectContainingProperty object. This is helpful if you're setting a private property on a struct or other immutable type and need to return the boxed value.</returns>
|
||||
public object SetPrivateProperty(string name, object value, object objectContainingProperty)
|
||||
{
|
||||
var property = ES3Reflection.GetES3ReflectedProperty(objectContainingProperty.GetType(), name);
|
||||
if (property.IsNull)
|
||||
throw new MissingMemberException("A private property named " + name + " does not exist in the type " + objectContainingProperty.GetType());
|
||||
property.SetValue(objectContainingProperty, value);
|
||||
return objectContainingProperty;
|
||||
}
|
||||
|
||||
/// <summary>Sets the value of a private field on an object.</summary>
|
||||
/// <param name="name">The name of the field we want to set.</param>
|
||||
/// <param name="value">The value we want to set the field to.</param>
|
||||
/// <param name="objectContainingField">The object containing the field we want to set.</param>
|
||||
/// <returns>The objectContainingField object. This is helpful if you're setting a private property on a struct or other immutable type and need to return the boxed value.</returns>
|
||||
public object SetPrivateField(string name, object value, object objectContainingField)
|
||||
{
|
||||
var field = ES3Reflection.GetES3ReflectedMember(objectContainingField.GetType(), name);
|
||||
if(field.IsNull)
|
||||
throw new MissingMemberException("A private field named "+ name + " does not exist in the type "+objectContainingField.GetType());
|
||||
field.SetValue(objectContainingField, value);
|
||||
return objectContainingField;
|
||||
}
|
||||
|
||||
#region Read(key) & Read(key, obj) methods
|
||||
|
||||
/// <summary>Reads a value from the reader with the given key.</summary>
|
||||
/// <param name="key">The key which uniquely identifies our value.</param>
|
||||
public virtual T Read<T>(string key)
|
||||
{
|
||||
if(!Goto(key))
|
||||
throw new KeyNotFoundException("Key \"" + key + "\" was not found in file \""+settings.FullPath+"\". Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.");
|
||||
|
||||
Type type = ReadTypeFromHeader<T>();
|
||||
|
||||
T obj = Read<T>(ES3TypeMgr.GetOrCreateES3Type(type));
|
||||
|
||||
//ReadKeySuffix(); //No need to read key suffix as we're returning. Doing so would throw an error at this point for BinaryReaders.
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>Reads a value from the reader with the given key, returning the default value if the key does not exist.</summary>
|
||||
/// <param name="key">The key which uniquely identifies our value.</param>
|
||||
/// <param name="defaultValue">The value we want to return if this key does not exist in the reader.</param>
|
||||
public virtual T Read<T>(string key, T defaultValue)
|
||||
{
|
||||
if(!Goto(key))
|
||||
return defaultValue;
|
||||
|
||||
Type type = ReadTypeFromHeader<T>();
|
||||
T obj = Read<T>(ES3TypeMgr.GetOrCreateES3Type(type));
|
||||
|
||||
//ReadKeySuffix(); //No need to read key suffix as we're returning. Doing so would throw an error at this point for BinaryReaders.
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>Reads a value from the reader with the given key into the provided object.</summary>
|
||||
/// <param name="key">The key which uniquely identifies our value.</param>
|
||||
/// <param name="obj">The object we want to load the value into.</param>
|
||||
public virtual void ReadInto<T>(string key, T obj) where T : class
|
||||
{
|
||||
if(!Goto(key))
|
||||
throw new KeyNotFoundException("Key \"" + key + "\" was not found in file \""+settings.FullPath+"\"");
|
||||
|
||||
Type type = ReadTypeFromHeader<T>();
|
||||
|
||||
ReadInto<T>(obj, ES3TypeMgr.GetOrCreateES3Type(type));
|
||||
|
||||
//ReadKeySuffix(); //No need to read key suffix as we're returning. Doing so would throw an error at this point for BinaryReaders.
|
||||
}
|
||||
|
||||
protected virtual void ReadObject<T>(object obj, ES3Type type)
|
||||
{
|
||||
// Check for null.
|
||||
if(StartReadObject())
|
||||
return;
|
||||
|
||||
type.ReadInto<T>(this, obj);
|
||||
|
||||
EndReadObject();
|
||||
}
|
||||
|
||||
protected virtual T ReadObject<T>(ES3Type type)
|
||||
{
|
||||
if(StartReadObject())
|
||||
return default(T);
|
||||
|
||||
object obj = type.Read<T>(this);
|
||||
|
||||
EndReadObject();
|
||||
return (T)obj;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Read(ES3Type) & Read(obj,ES3Type) methods
|
||||
|
||||
/*
|
||||
* Parses the next JSON Object in the stream (i.e. must be between '{' and '}' chars).
|
||||
* If the first character in the Stream is not a '{', it will throw an error.
|
||||
* Will also read the terminating '}'.
|
||||
* If we have reached the end of stream, it will return null.
|
||||
*/
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public virtual T Read<T>(ES3Type type)
|
||||
{
|
||||
if (type == null || type.isUnsupported)
|
||||
throw new NotSupportedException("Type of " + type + " is not currently supported, and could not be loaded using reflection.");
|
||||
else if (type.isPrimitive)
|
||||
return (T)type.Read<T>(this);
|
||||
else if (type.isCollection)
|
||||
return (T)((ES3CollectionType)type).Read(this);
|
||||
else if (type.isDictionary)
|
||||
return (T)((ES3DictionaryType)type).Read(this);
|
||||
else
|
||||
return ReadObject<T>(type);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public virtual void ReadInto<T>(object obj, ES3Type type)
|
||||
{
|
||||
if(type == null || type.isUnsupported)
|
||||
throw new NotSupportedException("Type of "+obj.GetType()+" is not currently supported, and could not be loaded using reflection.");
|
||||
|
||||
else if(type.isCollection)
|
||||
((ES3CollectionType)type).ReadInto(this, obj);
|
||||
else if(type.isDictionary)
|
||||
((ES3DictionaryType)type).ReadInto(this, obj);
|
||||
else
|
||||
ReadObject<T>(obj, type);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal Type ReadTypeFromHeader<T>()
|
||||
{
|
||||
// Check whether we need to determine the type by reading the header.
|
||||
if(typeof(T) == typeof(object))
|
||||
return ReadKeyPrefix();
|
||||
else if(settings.typeChecking)
|
||||
{
|
||||
Type type = ReadKeyPrefix();
|
||||
|
||||
if(type == null)
|
||||
throw new TypeLoadException("Trying to load data of type " + typeof(T) + ", but the type of data contained in file no longer exists. This may be because the type has been removed from your project or renamed.");
|
||||
else if (type != typeof(T))
|
||||
throw new InvalidOperationException("Trying to load data of type " + typeof(T) + ", but data contained in file is type of " + type + ".");
|
||||
|
||||
return type;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadKeyPrefix(true);
|
||||
return typeof(T);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3Reader and loads the default file into it.</summary>
|
||||
public static ES3Reader Create()
|
||||
{
|
||||
return Create(new ES3Settings());
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3Reader and loads a file in storage into it.</summary>
|
||||
/// <param name="filePath">The relative or absolute path of the file we want to load into the reader.</param>
|
||||
public static ES3Reader Create(string filePath)
|
||||
{
|
||||
return Create(new ES3Settings(filePath));
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3Reader and loads a file in storage into it.</summary>
|
||||
/// <param name="filePath">The relative or absolute path of the file we want to load into the reader.</param>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public static ES3Reader Create(string filePath, ES3Settings settings)
|
||||
{
|
||||
return Create(new ES3Settings(filePath, settings));
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3Reader and loads a file in storage into it.</summary>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public static ES3Reader Create(ES3Settings settings)
|
||||
{
|
||||
Stream stream = ES3Stream.CreateStream(settings, ES3FileMode.Read);
|
||||
if(stream == null)
|
||||
return null;
|
||||
|
||||
// Get the baseWriter using the given Stream.
|
||||
if (settings.format == ES3.Format.JSON)
|
||||
return new ES3JSONReader(stream, settings);
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3Reader and loads the bytes provided into it.</summary>
|
||||
public static ES3Reader Create(byte[] bytes)
|
||||
{
|
||||
return Create(bytes, new ES3Settings());
|
||||
}
|
||||
|
||||
/// <summary>Creates a new ES3Reader and loads the bytes provided into it.</summary>
|
||||
/// <param name="settings">The settings we want to use to override the default settings.</param>
|
||||
public static ES3Reader Create(byte[] bytes, ES3Settings settings)
|
||||
{
|
||||
Stream stream = ES3Stream.CreateStream(new MemoryStream(bytes), settings, ES3FileMode.Read);
|
||||
if(stream == null)
|
||||
return null;
|
||||
|
||||
// Get the baseWriter using the given Stream.
|
||||
if(settings.format == ES3.Format.JSON)
|
||||
return new ES3JSONReader(stream, settings);
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static ES3Reader Create(Stream stream, ES3Settings settings)
|
||||
{
|
||||
stream = ES3Stream.CreateStream(stream, settings, ES3FileMode.Read);
|
||||
|
||||
// Get the baseWriter using the given Stream.
|
||||
if(settings.format == ES3.Format.JSON)
|
||||
return new ES3JSONReader(stream, settings);
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static ES3Reader Create(Stream stream, ES3Settings settings, bool readHeaderAndFooter)
|
||||
{
|
||||
// Get the baseWriter using the given Stream.
|
||||
if(settings.format == ES3.Format.JSON)
|
||||
return new ES3JSONReader(stream, settings, readHeaderAndFooter);
|
||||
return null;
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public class ES3ReaderPropertyEnumerator
|
||||
{
|
||||
public ES3Reader reader;
|
||||
|
||||
public ES3ReaderPropertyEnumerator(ES3Reader reader)
|
||||
{
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
string propertyName;
|
||||
while(true)
|
||||
{
|
||||
// Allows us to repeat a property name or insert one of our own.
|
||||
if(reader.overridePropertiesName != null)
|
||||
{
|
||||
string tempName = reader.overridePropertiesName;
|
||||
reader.overridePropertiesName = null;
|
||||
yield return tempName;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((propertyName = reader.ReadPropertyName()) == null)
|
||||
yield break;
|
||||
yield return propertyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public class ES3ReaderRawEnumerator
|
||||
{
|
||||
public ES3Reader reader;
|
||||
|
||||
public ES3ReaderRawEnumerator(ES3Reader reader)
|
||||
{
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
string key = reader.ReadPropertyName();
|
||||
if(key == null)
|
||||
yield break;
|
||||
|
||||
Type type = reader.ReadTypeFromHeader<object>();
|
||||
|
||||
byte[] bytes = reader.ReadElement();
|
||||
|
||||
reader.ReadKeySuffix();
|
||||
|
||||
if(type != null)
|
||||
yield return new KeyValuePair<string,ES3Data>(key, new ES3Data(type, bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f511cfa2663a045aeac7dfe13754efba
|
||||
timeCreated: 1519132300
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user