| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //
- // Copyright (c) 2008-2017 the Urho3D project.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "../Scene/Component.h"
- namespace Atomic
- {
- /// Placeholder for allowing unregistered components to be loaded & saved along with scenes.
- class ATOMIC_API UnknownComponent : public Component
- {
- public:
- /// Construct.
- UnknownComponent(Context* context);
- /// Register object factory.
- static void RegisterObject(Context* context);
- /// Return type of the stored component.
- virtual StringHash GetType() const { return typeHash_; }
- /// Return type name of the stored component.
- virtual const String& GetTypeName() const { return typeName_; }
- /// Return attribute descriptions, or null if none defined.
- virtual const Vector<AttributeInfo>* GetAttributes() const { return &xmlAttributeInfos_; }
- /// Load from binary data. Return true if successful.
- virtual bool Load(Deserializer& source, bool setInstanceDefault = false);
- /// Load from XML data. Return true if successful.
- virtual bool LoadXML(const XMLElement& source, bool setInstanceDefault = false);
- /// Load from JSON data. Return true if successful.
- virtual bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false);
- /// Save as binary data. Return true if successful.
- virtual bool Save(Serializer& dest) const;
- /// Save as XML data. Return true if successful.
- virtual bool SaveXML(XMLElement& dest) const;
- /// Save as JSON data. Return true if successful.
- virtual bool SaveJSON(JSONValue& dest) const;
- /// Initialize the type name. Called by Node when loading.
- void SetTypeName(const String& typeName);
- /// Initialize the type hash only when type name not known. Called by Node when loading.
- void SetType(StringHash typeHash);
- /// Return the XML format attributes. Empty when loaded with binary serialization.
- const Vector<String>& GetXMLAttributes() const { return xmlAttributes_; }
- /// Return the binary attributes. Empty when loaded with XML serialization.
- const PODVector<unsigned char>& GetBinaryAttributes() const { return binaryAttributes_; }
- /// Return whether was loaded using XML data.
- bool GetUseXML() const { return useXML_; }
- /// Return static type.
- static Atomic::StringHash GetTypeStatic()
- {
- static const StringHash typeStatic("UnknownComponent");
- return typeStatic;
- }
- /// Return static type name.
- static const Atomic::String& GetTypeNameStatic()
- {
- static const String typeNameStatic("UnknownComponent");
- return typeNameStatic;
- }
- private:
- /// Type of stored component.
- StringHash typeHash_;
- /// Type name of the stored component.
- String typeName_;
- /// XML format attribute infos.
- Vector<AttributeInfo> xmlAttributeInfos_;
- /// XML format attribute data (as strings)
- Vector<String> xmlAttributes_;
- /// Binary attributes.
- PODVector<unsigned char> binaryAttributes_;
- /// Flag of whether was loaded using XML/JSON data.
- bool useXML_;
- };
- }
|