Exemplo n.º 1
0
        UserAssetData GetUserAssetData(Package.Asset assetRef, out string name)
        {
            if (!metaDatas.TryGetValue(assetRef.fullName, out SomeMetaData some))
            {
                ReadMetaData(assetRef.package);
                metaDatas.TryGetValue(assetRef.fullName, out some);
            }

            if (some.userDataRef != null)
            {
                try
                {
                    UserAssetData uad = AssetDeserializer.Instantiate(some.userDataRef) as UserAssetData;

                    if (uad == null)
                    {
                        uad = new UserAssetData();
                    }

                    name = some.name;
                    return(uad);
                }
                catch (Exception)
                {
                    Util.DebugPrint("!Cannot resolve UserAssetData for", assetRef.fullName);
                }
            }

            name = string.Empty;
            return(null);
        }
Exemplo n.º 2
0
        internal void LoadImpl(Package.Asset assetRef)
        {
            try
            {
                stack.Push(assetRef);
                LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(ShortName(assetRef.name));
                CustomAssetMetaData.Type type = GetMetaType(assetRef);

                GameObject go          = AssetDeserializer.Instantiate(assetRef) as GameObject;
                string     packageName = assetRef.package.packageName;
                string     fullName    = type < CustomAssetMetaData.Type.RoadElevation ? packageName + "." + go.name : PillarOrElevationName(packageName, go.name);
                go.name = fullName;
                go.SetActive(false);
                PrefabInfo info = go.GetComponent <PrefabInfo>();
                info.m_isCustomContent = true;

                if (info.m_Atlas != null && !string.IsNullOrEmpty(info.m_InfoTooltipThumbnail) && info.m_Atlas[info.m_InfoTooltipThumbnail] != null)
                {
                    info.m_InfoTooltipAtlas = info.m_Atlas;
                }

                PropInfo     pi;
                TreeInfo     ti;
                BuildingInfo bi;
                VehicleInfo  vi;
                CitizenInfo  ci;
                NetInfo      ni;

                if ((pi = go.GetComponent <PropInfo>()) != null)
                {
                    if (pi.m_lodObject != null)
                    {
                        pi.m_lodObject.SetActive(false);
                    }

                    Initialize(pi);
                }
                else if ((ti = go.GetComponent <TreeInfo>()) != null)
                {
                    Initialize(ti);
                }
                else if ((bi = go.GetComponent <BuildingInfo>()) != null)
                {
                    if (bi.m_lodObject != null)
                    {
                        bi.m_lodObject.SetActive(false);
                    }

                    bi.m_dontSpawnNormally = dontSpawnNormally.Remove(fullName);
                    Initialize(bi);

                    if (bi.GetAI() is IntersectionAI)
                    {
                        loadedIntersections.Add(fullName);
                    }
                }
                else if ((vi = go.GetComponent <VehicleInfo>()) != null)
                {
                    if (vi.m_lodObject != null)
                    {
                        vi.m_lodObject.SetActive(false);
                    }

                    Initialize(vi);
                }
                else if ((ci = go.GetComponent <CitizenInfo>()) != null)
                {
                    if (ci.m_lodObject != null)
                    {
                        ci.m_lodObject.SetActive(false);
                    }

                    if (ci.InitializeCustomPrefab(citizenMetaDatas[assetRef.fullName]))
                    {
                        citizenMetaDatas.Remove(assetRef.fullName);
                        ci.gameObject.SetActive(true);
                        Initialize(ci);
                    }
                    else
                    {
                        info = null;
                        CODebugBase <LogChannel> .Warn(LogChannel.Modding, "Custom citizen [" + assetRef.fullName + "] template not available in selected theme. Asset not added in game.");
                    }
                }
                else if ((ni = go.GetComponent <NetInfo>()) != null)
                {
                    Initialize(ni);
                }
                else
                {
                    info = null;
                }

                if (info != null)
                {
                    string path = Path.GetDirectoryName(assetRef.package.packagePath);

                    if (!string.IsNullOrEmpty(path) && plugins.TryGetValue(path, out PluginInfo plugin))
                    {
                        IAssetDataExtension[] extensions = plugin.GetInstances <IAssetDataExtension>();

                        if (extensions.Length > 0)
                        {
                            UserAssetData uad = GetUserAssetData(assetRef, out string name);

                            if (uad != null)
                            {
                                for (int i = 0; i < extensions.Length; i++)
                                {
                                    try
                                    {
                                        extensions[i].OnAssetLoaded(name, info, uad.Data);
                                    }
                                    catch (Exception e)
                                    {
                                        ModException ex = new ModException("The Mod " + plugin.ToString() + " has caused an error when loading " + fullName, e);
                                        UIView.ForwardException(ex);
                                        Debug.LogException(ex);
                                    }
                                }
                            }
                            else
                            {
                                Util.DebugPrint("UserAssetData is null for", fullName);
                            }
                        }
                    }
                }
            }
            finally
            {
                stack.Pop();
                assetCount++;
                LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading();
            }
        }