GraphObjectProxy.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
  10. #include <AzCore/std/smart_ptr/shared_ptr.h>
  11. namespace AZ
  12. {
  13. struct BehaviorParameter;
  14. struct BehaviorArgument;
  15. class BehaviorClass;
  16. class BehaviorMethod;
  17. class BehaviorProperty;
  18. class ReflectContext;
  19. namespace Python
  20. {
  21. class PythonBehaviorInfo final
  22. {
  23. public:
  24. AZ_RTTI(PythonBehaviorInfo, "{8055BD03-5B3B-490D-AEC5-1B1E2616D529}");
  25. AZ_CLASS_ALLOCATOR(PythonBehaviorInfo, AZ::SystemAllocator);
  26. static void Reflect(AZ::ReflectContext* context);
  27. explicit PythonBehaviorInfo(const AZ::BehaviorClass* behaviorClass);
  28. PythonBehaviorInfo() = delete;
  29. protected:
  30. bool IsMemberLike(const AZ::BehaviorMethod& method, const AZ::TypeId& typeId) const;
  31. AZStd::string FetchPythonType(const AZ::BehaviorParameter& param) const;
  32. void PrepareMethod(AZStd::string_view methodName, const AZ::BehaviorMethod& behaviorMethod);
  33. void PrepareProperty(AZStd::string_view propertyName, const AZ::BehaviorProperty& behaviorProperty);
  34. private:
  35. const AZ::BehaviorClass* m_behaviorClass = nullptr;
  36. AZStd::vector<AZStd::string> m_methodList;
  37. AZStd::vector<AZStd::string> m_propertyList;
  38. };
  39. }
  40. namespace SceneAPI
  41. {
  42. namespace Containers
  43. {
  44. //
  45. // GraphObjectProxy wraps the smart pointer to IGraphObject privately
  46. // so that scripts can access the "graph node content" inside the SceneGraph
  47. //
  48. class GraphObjectProxy final
  49. {
  50. public:
  51. AZ_RTTI(GraphObjectProxy, "{3EF0DDEC-C734-4804-BE99-82058FEBDA71}");
  52. AZ_CLASS_ALLOCATOR(GraphObjectProxy, AZ::SystemAllocator);
  53. static void Reflect(AZ::ReflectContext* context);
  54. GraphObjectProxy(AZStd::shared_ptr<const DataTypes::IGraphObject> graphObject);
  55. GraphObjectProxy() = default;
  56. GraphObjectProxy(const GraphObjectProxy&);
  57. ~GraphObjectProxy();
  58. bool CastWithTypeName(const AZStd::string& classTypeName);
  59. protected:
  60. bool Convert(AZStd::any& input, const AZ::BehaviorParameter* argBehaviorInfo, AZ::BehaviorArgument& behaviorParam);
  61. AZStd::any Invoke(AZStd::string_view method, AZStd::vector<AZStd::any> argList);
  62. AZStd::any Fetch(AZStd::string_view property);
  63. AZStd::any InvokeBehaviorMethod(AZ::BehaviorMethod* behaviorMethod, AZStd::vector<AZStd::any> argList);
  64. private:
  65. AZStd::shared_ptr<const DataTypes::IGraphObject> m_graphObject;
  66. const AZ::BehaviorClass* m_behaviorClass = nullptr;
  67. AZStd::shared_ptr<Python::PythonBehaviorInfo> m_pythonBehaviorInfo;
  68. };
  69. } // Containers
  70. } // SceneAPI
  71. } // AZ