Skip to content

Commit

Permalink
- Fix SOEventPlayerSettingManager's version update error on program s…
Browse files Browse the repository at this point in the history
…tart.
  • Loading branch information
wojiuxuihuan committed Feb 23, 2024
1 parent 2eec3ff commit b14a88f
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 135 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [4.2.2]
- Fix SOEventPlayerSettingManager's version update error on program start.

## [4.2.1]
- Fix build error.

Expand Down
2 changes: 1 addition & 1 deletion ProjectConfig~/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"com.threeyes.alivecursor.sdk": "4.2.1",
"com.threeyes.alivecursor.sdk": "4.2.2",
"com.beans.deform": "1.2.1",
"com.coffee.ui-effect": "4.0.0-preview.9",
"com.dbrizov.naughtyattributes": "2.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,137 +10,151 @@ namespace Threeyes.EventPlayer
{
//ToUpdate:应该是管理所有Core的Module的宏定义
[CreateAssetMenu(menuName = "SO/Manager/EventPlayerSettingManager")]
public class SOEventPlayerSettingManager : SOInstacneBase<SOEventPlayerSettingManager>
{
#region Property & Field

//——Static——
public static bool ShowPropertyInHierarchy { get { return Instance ? Instance.showPropertyInHierarchy : true; } set { if (Instance) Instance.showPropertyInHierarchy = value; } }
public static SOEventPlayerSettingManager Instance { get { return GetOrCreateInstance(ref _instance, defaultName, pathInResources, InitSettings); } }
private static SOEventPlayerSettingManager _instance;
static string defaultName = "EventPlayerSetting";
static string pathInResources = "Threeyes";//该Manager在Resources下的路径,默认是Resources根目录


public string version = "0"; //Last cache version

//Display Setting
public bool showPropertyInHierarchy = true;//Show info of subclass

//Other Plugin Support Setting
//[Header("Other Plugin Support")]
public bool useTimeline = false;
public bool useVideoPlayer = false;
public bool useBezierSolution = false;
public bool useDoTweenPro = false;
public bool activeDoTweenProPreview = false;

//RelatePath
static readonly string baseExtendDir = "Base/Timeline";
static readonly string epExtendDir = "EventPlayer/Extend";

class DefineSymbolInfo
{
public bool ActiveState { get { return activeStateGetter(); } set { activeStateSetter(value); } }
public DefineSymbol defineSymbol;
Func<bool> activeStateGetter;
Action<bool> activeStateSetter;

public DefineSymbolInfo(DefineSymbol defineSymbol, Func<bool> activeStateGetter, Action<bool> activeStateSetter)
{
this.defineSymbol = defineSymbol;
this.activeStateGetter = activeStateGetter;
this.activeStateSetter = activeStateSetter;
}
}

////存储宏定义及激活状态
List<DefineSymbolInfo> listDefineSymbolInfo
{
get
{
if (_listDefineSymbolInfo == null)
{
_listDefineSymbolInfo = new List<DefineSymbolInfo>()
{
new DefineSymbolInfo(new DefineSymbol("Threeyes_Timeline", "Timeline Event", "支持Timeline", baseExtendDir+"|"+ epExtendDir),()=>useTimeline,(v)=>useTimeline=v),
new DefineSymbolInfo(new DefineSymbol("Threeyes_VideoPlayer", "VideoPlayer Event", "支持VideoPlayer", epExtendDir+"/"+"Video"),()=>useVideoPlayer,(v)=>useVideoPlayer=v),
new DefineSymbolInfo(new DefineSymbol("Threeyes_BezierSolution", "BezierSolution Support", "支持BezierSolution", epExtendDir+"/"+"BezierSolution"),()=>useBezierSolution,(v)=>useBezierSolution=v),
new DefineSymbolInfo(new DefineSymbol("Threeyes_DoTweenPro", "DoTweenPro Support", "支持DoTweenPro", epExtendDir+"/"+"DoTweenPro"),()=>useDoTweenPro,(v)=>useDoTweenPro=v),
};
}
return _listDefineSymbolInfo;
}
}
List<DefineSymbolInfo> _listDefineSymbolInfo = null;


#endregion

//根据PlayerSettings中的Define,初始化SO(便于项目迁移后的初始化)
static void InitSettings(SOEventPlayerSettingManager sOEventPlayerSettingManager)
{
var listDefine = EditorDefineSymbolTool.GetListDefine();
foreach (var element in sOEventPlayerSettingManager.listDefineSymbolInfo)
{
element.ActiveState = listDefine.Contains(element.defineSymbol.name);
}
EditorUtility.SetDirty(sOEventPlayerSettingManager);//!需要调用该方法保存更改

//Debug.Log("SOEventPlayerSettingManager Init after creation!");
}

public void UpdateVersion(string currentVersion)
{
if (version != currentVersion)
{
//Update Setting
Debug.Log("Update EventPlayerSetting version from " + version + " to " + currentVersion);
version = currentVersion;
EditorUtility.SetDirty(this);//先保存一次这个字段,否则后期的RefreshDefine会导致保存失败
RefreshDefine();
EditorUtility.SetDirty(this);//!需要调用该方法保存更改
}
}



[ContextMenu("RefreshDefine")]
public void RefreshDefine()
{
//ToUpdate:改用EditorDefineSymbolTool.ModifyDefines
List<string> listDefineToAdd = new List<string>();
List<string> listDefineToRemove = new List<string>();
foreach (var element in listDefineSymbolInfo)
{
if (element.ActiveState == true)//激活状态
listDefineToAdd.Add(element.defineSymbol.name);
else
listDefineToRemove.Add(element.defineSymbol.name);
}
EditorDefineSymbolTool.ModifyDefines(listDefineToAdd, listDefineToRemove);
}

void OnValidate()
{
public class SOEventPlayerSettingManager : SOInstacneBase<SOEventPlayerSettingManager>
{
#region Property & Field

//——Static——
public static bool ShowPropertyInHierarchy { get { return Instance ? Instance.showPropertyInHierarchy : true; } set { if (Instance) Instance.showPropertyInHierarchy = value; } }
public static SOEventPlayerSettingManager Instance
{
get
{
bool isFirstCreate = (_instance == null) && !hasInitVersion;//避免程序退出时销毁,导致需要重新设置
SOEventPlayerSettingManager result = GetOrCreateInstance(ref _instance, defaultName, pathInResources, InitSettings);
if (result && isFirstCreate)//首次创建:更新版本号
{
result.UpdateVersion(EventPlayerVersionManager.EventPlayer_Version);
}
return result;
}
}
static bool hasInitVersion = false;
private static SOEventPlayerSettingManager _instance;
static string defaultName = "EventPlayerSetting";
static string pathInResources = "Threeyes";//该Manager在Resources下的路径,默认是Resources根目录


public string version = "0"; //Last cache version

//Display Setting
public bool showPropertyInHierarchy = true;//Show info of subclass

//Other Plugin Support Setting
//[Header("Other Plugin Support")]
public bool useTimeline = false;
public bool useVideoPlayer = false;
public bool useBezierSolution = false;
public bool useDoTweenPro = false;
public bool activeDoTweenProPreview = false;

//RelatePath
static readonly string baseExtendDir = "Base/Timeline";
static readonly string epExtendDir = "EventPlayer/Extend";

class DefineSymbolInfo
{
public bool ActiveState { get { return activeStateGetter(); } set { activeStateSetter(value); } }
public DefineSymbol defineSymbol;
Func<bool> activeStateGetter;
Action<bool> activeStateSetter;

public DefineSymbolInfo(DefineSymbol defineSymbol, Func<bool> activeStateGetter, Action<bool> activeStateSetter)
{
this.defineSymbol = defineSymbol;
this.activeStateGetter = activeStateGetter;
this.activeStateSetter = activeStateSetter;
}
}

////存储宏定义及激活状态
List<DefineSymbolInfo> listDefineSymbolInfo
{
get
{
if (_listDefineSymbolInfo == null)
{
_listDefineSymbolInfo = new List<DefineSymbolInfo>()
{
new DefineSymbolInfo(new DefineSymbol("Threeyes_Timeline", "Timeline Event", "支持Timeline", baseExtendDir+"|"+ epExtendDir),()=>useTimeline,(v)=>useTimeline=v),
new DefineSymbolInfo(new DefineSymbol("Threeyes_VideoPlayer", "VideoPlayer Event", "支持VideoPlayer", epExtendDir+"/"+"Video"),()=>useVideoPlayer,(v)=>useVideoPlayer=v),
new DefineSymbolInfo(new DefineSymbol("Threeyes_BezierSolution", "BezierSolution Support", "支持BezierSolution", epExtendDir+"/"+"BezierSolution"),()=>useBezierSolution,(v)=>useBezierSolution=v),
new DefineSymbolInfo(new DefineSymbol("Threeyes_DoTweenPro", "DoTweenPro Support", "支持DoTweenPro", epExtendDir+"/"+"DoTweenPro"),()=>useDoTweenPro,(v)=>useDoTweenPro=v),
};
}
return _listDefineSymbolInfo;
}
}
List<DefineSymbolInfo> _listDefineSymbolInfo = null;


#endregion

//根据PlayerSettings中的Define,初始化SO(便于项目迁移后的初始化)
static void InitSettings(SOEventPlayerSettingManager sOEventPlayerSettingManager)
{
var listDefine = EditorDefineSymbolTool.GetListDefine();
foreach (var element in sOEventPlayerSettingManager.listDefineSymbolInfo)
{
element.ActiveState = listDefine.Contains(element.defineSymbol.name);
}
EditorUtility.SetDirty(sOEventPlayerSettingManager);//!需要调用该方法保存更改

//Debug.Log("SOEventPlayerSettingManager Init after creation!");
}

public void UpdateVersion(string currentVersion)
{
if (version != currentVersion)
{
//Update Setting
Debug.Log("Update EventPlayerSetting version from " + version + " to " + currentVersion);
version = currentVersion;
EditorUtility.SetDirty(this);//先保存一次这个字段,否则后期的RefreshDefine会导致保存失败
RefreshDefine();
EditorUtility.SetDirty(this);//!需要调用该方法保存更改
}
}



[ContextMenu("RefreshDefine")]
public void RefreshDefine()
{
//ToUpdate:改用EditorDefineSymbolTool.ModifyDefines
List<string> listDefineToAdd = new List<string>();
List<string> listDefineToRemove = new List<string>();
foreach (var element in listDefineSymbolInfo)
{
if (element.ActiveState == true)//激活状态
listDefineToAdd.Add(element.defineSymbol.name);
else
listDefineToRemove.Add(element.defineSymbol.name);
}
EditorDefineSymbolTool.ModifyDefines(listDefineToAdd, listDefineToRemove);
}

void OnValidate()
{
#if UNITY_EDITOR
EditorApplication.RepaintHierarchyWindow();
EditorApplication.RepaintHierarchyWindow();
#endif
}
}

[InitializeOnLoad]
public static class EventPlayerVersionManager
{
public static readonly string EventPlayer_Version = "3.0"; //Plugin Version

static EventPlayerVersionManager()
{
if (SOEventPlayerSettingManager.Instance)
{
SOEventPlayerSettingManager.Instance.UpdateVersion(EventPlayer_Version);
}
}
}
}
}

//[InitializeOnLoad]
public static class EventPlayerVersionManager
{
public static readonly string EventPlayer_Version = "3.0"; //Plugin Version
/////Bug:
/////-在初始化时调用容易导致报错,改为在Instance实例创建时调用
//static EventPlayerVersionManager()
//{
// if (SOEventPlayerSettingManager.Instance)
// {
// SOEventPlayerSettingManager.Instance.UpdateVersion(EventPlayer_Version);
// }
//}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<Style src="project://database/Assets/Threeyes/Plugins/ThreeyesPluginExpert/Module/Steamworks/Editor/Resources/StyleSheets/Common.uss?fileID=7433441132597879392&amp;guid=df1ea2653b87a714c8af53ffced0a5e7&amp;type=3#Common" />
<ui:VisualElement style="width: 100%; height: 100%; min-width: 350px; flex-wrap: nowrap;">
<ui:ScrollView mode="Vertical" name="ScrollView" view-data-key="TopScrollView">
<ui:ScrollView mode="Vertical" name="ScrollView" view-data-key="TopScrollView" horizontal-scroller-visibility="Hidden">
<ui:VisualElement name="ItemManagerGroup" style="border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-width: 0;">
<ui:DropdownField label="ActiveItem" index="-1" choices="System.Collections.Generic.List`1[System.String]" name="ActiveItemDropdownField" />
<ui:VisualElement name="CreateModGroup" view-data-key="CreateModGroup" style="flex-direction: row; justify-content: space-between;">
Expand Down
4 changes: 2 additions & 2 deletions UMod/Resources/Editor/ModToolsSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ MonoBehaviour:
toolsIconSmall: {fileID: 2800000, guid: 01d03c0fabb5c7249b6605e98a09beac, type: 3}
toolsIconLarge: {fileID: 2800000, guid: 01d03c0fabb5c7249b6605e98a09beac, type: 3}
toolsName: AliveCursorSDK
toolsVersion: 4.2.1
toolsVersion: 4.2.2
firstRunWindow:
assemblyQualifiedName:
developerName: Threeyes
syncDeveloperName: 0
gameName: AliveCursor
syncGameName: 0
gameVersion: 4.2.1
gameVersion: 4.2.2
syncGameVersion: 1
modFileExtension: .umod
commandLineLaunchFormat: +mod=$PATH
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.threeyes.alivecursor.sdk",
"displayName": "AliveCursorSDK",
"version": "4.2.1",
"version": "4.2.2",
"unity": "2022.3",
"description": "SDK for AliveCursor.",
"documentationUrl": "https://github.com/Threeyes/AliveCursorSDK/wiki",
Expand Down

0 comments on commit b14a88f

Please sign in to comment.