浏览代码

Single Update Manager + Optimized State Update / OnUpdateEvent (#39)

* Base work for Callable Single Update Manager

* Prevent Exclusion

* Generic Implementation of a SingleUpdate Method on State Machine + OnUpdateEvent

* Made Rig Manager Not Excludeable

* Updated Changelog

* OnUpdateEvent now displays its list as disabled
/main
GitHub 4 年前
当前提交
6c9ef7ce
共有 13 个文件被更改,包括 198 次插入7 次删除
  1. 4
      CHANGELOG.md
  2. 1
      Runtime/Ingredients/Rigs/RigManager.cs
  3. 18
      Runtime/Ingredients/StateMachine/StateMachine.cs
  4. 11
      Runtime/LevelScripting/Events/OnUpdateEvent.cs
  5. 2
      Runtime/Settings/GameplayIngredientsSettings.cs
  6. 54
      Editor/PropertyDrawers/ExcludedManagerPropertyDrawer.cs
  7. 11
      Editor/PropertyDrawers/ExcludedManagerPropertyDrawer.cs.meta
  8. 10
      Runtime/Attributes/ExcludedManagerAttribute.cs
  9. 11
      Runtime/Attributes/ExcludedManagerAttribute.cs.meta
  10. 8
      Runtime/Attributes/NonExcludeableManager.cs
  11. 11
      Runtime/Attributes/NonExcludeableManager.cs.meta
  12. 53
      Runtime/Managers/Implementations/SingleUpdateManager.cs
  13. 11
      Runtime/Managers/Implementations/SingleUpdateManager.cs.meta

4
CHANGELOG.md


* Added Help items in Menu, Added HelpURL class attributes
* Feature: Scene Comments
* Added preferences to control visibility of buttons in Additional Scene View Toolbar
* Added a `[NonExcludeableManager]` class attribute for managers that should not be excluded in Gameplay Ingredients Settings
* Added **SingleUpdateManager** to register/remove update methods that will be updated in its Update() instead of each Dedicated behavior Update()
* **BEHAVIOR CHANGE** : State Machine update and OnUpdateEvent are now updated using the SingleUpdateManager
* GameplayIngredientsSettings Manager Exclusion List now only displays managers that can be excluded.
## 2020.2.2

1
Runtime/Ingredients/Rigs/RigManager.cs


namespace GameplayIngredients.Rigs
{
[NonExcludeableManager]
public class RigManager : Manager
{
Dictionary<int, List<Rig>> m_UpdateRigs;

18
Runtime/Ingredients/StateMachine/StateMachine.cs


using System.Collections.Generic;
using UnityEngine;
using GameplayIngredients.Actions;
using GameplayIngredients.Managers;
namespace GameplayIngredients.StateMachines
{

}
}
private void OnEnable()
{
if (GameplayIngredientsSettings.currentSettings.allowUpdateCalls)
Manager.Get<SingleUpdateManager>().Register(SingleUpdate);
}
private void OnDisable()
{
if (GameplayIngredientsSettings.currentSettings.allowUpdateCalls)
Manager.Get<SingleUpdateManager>().Remove(SingleUpdate);
}
void Start()
{
foreach (var state in States)

// Then Set new current state
m_CurrentState = newState;
// Finally, call State enter
// Call State enter
Callable.Call(m_CurrentState.OnStateEnter, gameObject);
}
else

void Update()
void SingleUpdate()
{
if (GameplayIngredientsSettings.currentSettings.allowUpdateCalls
&& m_CurrentState != null

11
Runtime/LevelScripting/Events/OnUpdateEvent.cs


using GameplayIngredients.Managers;
using NaughtyAttributes;
namespace GameplayIngredients.Events

[ReorderableList, ShowIf("AllowUpdateCalls")]
[ReorderableList, EnableIf("AllowUpdateCalls")]
if(AllowUpdateCalls())
Manager.Get<SingleUpdateManager>().Register(SingleUpdate);
if (AllowUpdateCalls())
Manager.Get<SingleUpdateManager>().Remove(SingleUpdate);
private void Update()
private void SingleUpdate()
{
Callable.Call(OnUpdate, gameObject);
}

2
Runtime/Settings/GameplayIngredientsSettings.cs


protected bool m_DisableWelcomeScreenAutoStart;
[BoxGroup("Managers")]
[SerializeField, ReorderableList, TypeDropDown(typeof(Manager))]
[SerializeField, ReorderableList, ExcludedManager]
protected string[] m_ExcludedManagers;
[BoxGroup("Callables")]

54
Editor/PropertyDrawers/ExcludedManagerPropertyDrawer.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(ExcludedManagerAttribute))]
public class ExcludedManagerPropertyDrawer : PropertyDrawer
{
List<string> cachedTypes;
bool needRecache = true;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (cachedTypes == null || needRecache)
cachedTypes = CacheTypes();
string curValue = property.stringValue;
int index = cachedTypes.IndexOf(curValue);
EditorGUI.BeginChangeCheck();
int newIndex = EditorGUI.Popup(position, index, cachedTypes.ToArray());
if (EditorGUI.EndChangeCheck() && index != newIndex)
{
property.stringValue = cachedTypes[newIndex];
needRecache = true;
}
}
List<string> CacheTypes()
{
var types = new List<string>();
foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach(var type in assembly.GetTypes())
{
if(typeof(Manager).IsAssignableFrom(type)
&& !type.IsAbstract
&& !type.CustomAttributes.Any(o => o.AttributeType == typeof(NonExcludeableManager)))
{
types.Add(type.Name);
}
}
}
needRecache = false;
return types;
}
}
}

11
Editor/PropertyDrawers/ExcludedManagerPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: 4ed140b4a832bf6499e5a0809233726d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
Runtime/Attributes/ExcludedManagerAttribute.cs


using System;
using UnityEngine;
namespace GameplayIngredients
{
public class ExcludedManagerAttribute : PropertyAttribute
{
public ExcludedManagerAttribute() { }
}
}

11
Runtime/Attributes/ExcludedManagerAttribute.cs.meta


fileFormatVersion: 2
guid: 530796207bf40bf44b7a4d30fcf031ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Attributes/NonExcludeableManager.cs


using System;
namespace GameplayIngredients
{
[AttributeUsage(AttributeTargets.Class)]
public class NonExcludeableManager : Attribute { }
}

11
Runtime/Attributes/NonExcludeableManager.cs.meta


fileFormatVersion: 2
guid: 3138bc54017cceb40810d1eb7cb0a6c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

53
Runtime/Managers/Implementations/SingleUpdateManager.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace GameplayIngredients.Managers
{
[NonExcludeableManager]
public class SingleUpdateManager : Manager
{
public delegate void SingleUpdate();
List<SingleUpdate> updateList;
private void OnEnable()
{
updateList = new List<SingleUpdate>();
}
public void Register(SingleUpdate update)
{
if (!updateList.Any(o => o == update))
{
updateList.Add(update);
}
else
Debug.LogWarning("SingleUpdateManager: Already found an entry for this SingleUpdate, ignoring.");
}
public void Remove(SingleUpdate update)
{
if(updateList.Any(o => o == update))
{
updateList.RemoveAll(o => o == update);
}
else
Debug.LogWarning("SingleUpdateManager: Did not found a matching entry for given SingleUpdate, cannot remove.");
}
public void Update()
{
// Process all Currently Registered (Copy as Array)
foreach(var update in updateList.ToArray())
{
update?.Invoke();
}
// Remove all nulls (Destroyed Objects) in updateList
updateList.RemoveAll(o => o == null);
}
}
}

11
Runtime/Managers/Implementations/SingleUpdateManager.cs.meta


fileFormatVersion: 2
guid: b93856c795788a447a2732cff3dd71b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存