void Sky::OnMaterialAssetLoaded(AssetPtr asset) { IMaterialAsset* mAsset = dynamic_cast<IMaterialAsset*>(asset.Get()); if (mAsset) { material_.Reset(); material_ = Urho3D::DynamicCast<IMaterialAsset>(asset); if (mAsset->textures_.Size() >= 6) { AssetReferenceList list; for (int i=0 ; i<6 ; ++i) list.Append(mAsset->textures_[i].second_); textureRefs.Set(list, AttributeChange::LocalOnly); // Update call is implicit via OnTextureAssetLoaded() } else Update(); } }
void AssignAttributeValue(duk_context* ctx, duk_idx_t stackIndex, IAttribute* destAttr, AttributeChange::Type change) { if (!destAttr) return; switch (destAttr->TypeId()) { case IAttribute::BoolId: static_cast<Attribute<bool>*>(destAttr)->Set(duk_get_boolean(ctx, stackIndex) ? true : false, change); break; case IAttribute::IntId: static_cast<Attribute<int>*>(destAttr)->Set((int)duk_get_number(ctx, stackIndex), change); break; case IAttribute::UIntId: static_cast<Attribute<uint>*>(destAttr)->Set((uint)duk_get_number(ctx, stackIndex), change); break; case IAttribute::RealId: static_cast<Attribute<float>*>(destAttr)->Set((float)duk_get_number(ctx, stackIndex), change); break; case IAttribute::StringId: static_cast<Attribute<String>*>(destAttr)->Set(String(duk_get_string(ctx, stackIndex)), change); break; case IAttribute::Float2Id: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), float2_ID) == 0) static_cast<Attribute<float2>*>(destAttr)->Set(*GetValueObject<float2>(ctx, stackIndex, nullptr), change); break; case IAttribute::Float3Id: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), float3_ID) == 0) static_cast<Attribute<float3>*>(destAttr)->Set(*GetValueObject<float3>(ctx, stackIndex, nullptr), change); break; case IAttribute::Float4Id: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), float4_ID) == 0) static_cast<Attribute<float4>*>(destAttr)->Set(*GetValueObject<float4>(ctx, stackIndex, nullptr), change); break; case IAttribute::QuatId: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), Quat_ID) == 0) static_cast<Attribute<Quat>*>(destAttr)->Set(*GetValueObject<Quat>(ctx, stackIndex, nullptr), change); break; case IAttribute::TransformId: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), Transform_ID) == 0) static_cast<Attribute<Transform>*>(destAttr)->Set(*GetValueObject<Transform>(ctx, stackIndex, nullptr), change); break; case IAttribute::AssetReferenceId: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), AssetReference_ID) == 0) static_cast<Attribute<AssetReference>*>(destAttr)->Set(*GetValueObject<AssetReference>(ctx, stackIndex, nullptr), change); break; case IAttribute::AssetReferenceListId: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), AssetReferenceList_ID) == 0) static_cast<Attribute<AssetReferenceList>*>(destAttr)->Set(*GetValueObject<AssetReferenceList>(ctx, stackIndex, nullptr), change); // Also allow assigning a single AssetReference to an AssetReferenceList else if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), AssetReference_ID) == 0) { const AssetReference& ref = *GetValueObject<AssetReference>(ctx, stackIndex, nullptr); AssetReferenceList list; list.type = ref.type; list.Append(ref); static_cast<Attribute<AssetReferenceList>*>(destAttr)->Set(list); } break; case IAttribute::EntityReferenceId: if (duk_is_object(ctx, stackIndex) && strcmp(GetValueObjectType(ctx, stackIndex), EntityReference_ID) == 0) static_cast<Attribute<EntityReference>*>(destAttr)->Set(*GetValueObject<EntityReference>(ctx, stackIndex, nullptr), change); break; } }