暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829
  1. using UnityEditor.ShaderGraph;
  2. using ActionType = UnityEditor.ShaderGraph.IGraphDataAction;
  3. using System;
  4. using UnityEngine;
  5. namespace UnityEditor.ShaderGraph
  6. {
  7. class DataStore<T>
  8. {
  9. Action<T, ActionType> m_Reducer;
  10. internal T State { get; private set; }
  11. public Action<T, ActionType> Subscribe;
  12. internal DataStore(Action<T, ActionType> reducer, T initialState)
  13. {
  14. m_Reducer = reducer;
  15. State = initialState;
  16. }
  17. public void Dispatch(ActionType action)
  18. {
  19. m_Reducer(State, action);
  20. // Note: This would only work with reference types, as value types would require creating a new copy, this works given that we use GraphData which is a heap object
  21. // Notifies any listeners about change in state
  22. Subscribe?.Invoke(State, action);
  23. }
  24. }
  25. }