bool ModelImporter::ImportAnimations()
{
    if (!animationInfo_.Size())
    {
       if (!ImportAnimation(asset_->GetPath(), "RootAnim"))
           return false;
    }

    // embedded animations
    for (unsigned i = 0; i < animationInfo_.Size(); i++)
    {
        const SharedPtr<AnimationImportInfo>& info = animationInfo_[i];
        if (!ImportAnimation(asset_->GetPath(), info->GetName(), info->GetStartTime(), info->GetEndTime()))
            return false;
    }

    // add @ animations

    FileSystem* fs = GetSubsystem<FileSystem>();
    String pathName, fileName, ext;
    SplitPath(asset_->GetPath(), pathName, fileName, ext);

    Vector<String> results;

    fs->ScanDir(results, pathName, ext, SCAN_FILES, false);

    for (unsigned i = 0; i < results.Size(); i++)
    {
        const String& result = results[i];

        if (result.Contains("@"))
        {
            Vector<String> components = GetFileName(result).Split('@');

            if (components.Size() == 2 && components[1].Length() && components[0] == fileName)
            {
                String animationName = components[1];
                AssetDatabase* db = GetSubsystem<AssetDatabase>();
                Asset* asset = db->GetAssetByPath(pathName + result);
                assert(asset);
                assert(asset->GetImporter()->GetType() == ModelImporter::GetTypeStatic());

                ModelImporter* importer = (ModelImporter*) asset->GetImporter();

                if (!importer->animationInfo_.Size())
                {
                   if (!ImportAnimation(asset->GetPath(), animationName))
                       return false;
                }
                else
                {
                    // embedded animations
                    for (unsigned i = 0; i < importer->animationInfo_.Size(); i++)
                    {
                        const SharedPtr<AnimationImportInfo>& info = importer->animationInfo_[i];
                        if (!ImportAnimation(asset->GetPath(), info->GetName(), info->GetStartTime(), info->GetEndTime()))
                            return false;
                    }
                }


            }
        }
    }



    return true;
}
void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventData)
{
    using namespace DragEnterWidget;

    UIWidget* widget = static_cast<UIWidget*>(eventData[P_WIDGET].GetPtr());

    if (widget != this)
        return;

    UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr());

    Object* object = dragObject->GetObject();

    if (!object)
        return;

    if (object->GetType() == Asset::GetTypeStatic())
    {
        Asset* asset = (Asset*) object;
        AssetImporter* importer = asset->GetImporter();

        if (!importer)
            return;

        StringHash importerType = importer->GetType();

        if (importerType == PrefabImporter::GetTypeStatic())
        {
            dragNode_ = scene_->CreateChild(asset->GetName());
            PrefabComponent* pc = dragNode_->CreateComponent<PrefabComponent>();
            pc->SetPrefabGUID(asset->GetGUID());
        }
        else if (importerType == ModelImporter::GetTypeNameStatic())
        {
            dragNode_ = scene_->CreateChild();

            SharedPtr<File> file(new File(context_, asset->GetCachePath()));
            SharedPtr<XMLFile> xml(new XMLFile(context_));

            if (!xml->Load(*file))
                return;

            dragNode_->LoadXML(xml->GetRoot());
            dragNode_->SetName(asset->GetName());
        }
        else if (importerType == SpriterImporter::GetTypeNameStatic())
        {
            AnimationSet2D* animationSet = GetSubsystem<ResourceCache>()->GetResource<AnimationSet2D>(asset->GetPath());

            String animationName;

            if (animationSet && animationSet->GetNumAnimations())
            {
                animationName = animationSet->GetAnimation(0)->GetName();
            }

            dragNode_ = scene_->CreateChild(asset->GetName());

            AnimatedSprite2D* sprite = dragNode_->CreateComponent<AnimatedSprite2D>();

            if (!animationName.Length())
                sprite->SetAnimationSet(animationSet);
            else
                sprite->SetAnimation(animationSet, animationName);

        }
        else if (importerType == TextureImporter::GetTypeNameStatic())
        {
            dragNode_ = scene_->CreateChild(asset->GetName());

            Sprite2D* spriteGraphic = GetSubsystem<ResourceCache>()->GetResource<Sprite2D>(asset->GetPath());

            StaticSprite2D* sprite = dragNode_->CreateComponent<StaticSprite2D>();

            sprite->SetSprite(spriteGraphic);
        }


        if (dragNode_.NotNull())
        {
            Input* input = GetSubsystem<Input>();
            IntVector2 pos = input->GetMousePosition();
            UpdateDragNode(pos.x_, pos.y_);
        }



        //LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
    }

}