public override void Decorate(GameObject go, GameObject hider, ParkitectObj parkitectObj, AssetBundle bundle)
    {
        BuildableObject component = go.GetComponent <BuildableObject>();

        component.price = Price;
        component.setDisplayName(InGameName);
    }
Example #2
0
    public virtual void Decorate()
    {
        Debug.Log("Decorating: " + Name);
        BuildableObject BO = Object.GetComponent <BuildableObject>();

        BO.price = Price;
        BO.setDisplayName(Name);
        BO.dontSerialize = true;
        BO.isPreview     = true;
        string shader;

        if (Recolorable)
        {
            Debug.Log("Recolorable! : " + Shader);
            CustomColors cc = Object.AddComponent <CustomColors>();
            cc.setColors(Colors);
            shader = "CustomColors" + Shader;
        }
        else
        {
            shader = Shader;
        }
        foreach (Material material in AssetManager.Instance.objectMaterials)
        {
            if (material.name == shader)
            {
                SetMaterial(Object, material);

                // edge case for fences
                Fence fence = Object.GetComponent <Fence>();

                if (fence != null)
                {
                    if (fence.flatGO != null)
                    {
                        SetMaterial(fence.flatGO, material);
                    }

                    if (fence.postGO != null)
                    {
                        SetMaterial(fence.postGO, material);
                    }
                }

                break;
            }
        }
    }
        public void onEnabled()
        {
            String BannerPath = FilePaths.getFolderPath("Banners");


            if (!Directory.Exists(BannerPath))
            {
                char dsc = System.IO.Path.DirectorySeparatorChar;

                Directory.CreateDirectory(BannerPath);
                Directory.CreateDirectory(BannerPath + dsc + "long");
                Directory.CreateDirectory(BannerPath + dsc + "wide");
                Directory.CreateDirectory(BannerPath + dsc + "square");

                File.Copy(Path + dsc + "Banners" + dsc + "long" + dsc + "long.png", BannerPath + dsc + "long" + dsc + "long.png");
                File.Copy(Path + dsc + "Banners" + dsc + "wide" + dsc + "wide.png", BannerPath + dsc + "wide" + dsc + "wide.png");
                File.Copy(Path + dsc + "Banners" + dsc + "square" + dsc + "square.png", BannerPath + dsc + "square" + dsc + "square.png");
            }

            AssetPack   assetPack = JsonUtility.FromJson <AssetPack>(File.ReadAllText(System.IO.Path.Combine(Path, "billboard.json")));
            AssetBundle bundle    = AssetBundle.LoadFromFile(System.IO.Path.Combine(Path, "assetPack"));

            if (bundle == null)
            {
                throw new Exception("Failed to load AssetBundle!");
            }
            hider = new GameObject("Hider");
            Object.DontDestroyOnLoad(hider);

            foreach (var asset in assetPack.Assets)
            {
                if (asset.Type == AssetType.Deco)
                {
                    try
                    {
                        GameObject gameObject =
                            Object.Instantiate(
                                bundle.LoadAsset <GameObject>($"Assets/Resources/AssetPack/{asset.Guid}.prefab"));


                        new BillboardDecorator().Decorate(gameObject, asset, bundle);
                        new MaterialDecorator().Decorate(gameObject, asset, bundle);
                        new CustomColorDecorator().Decorate(gameObject, asset, bundle);
                        new LightEffectsDecorator().Decorate(gameObject, asset, bundle);
                        Object.DontDestroyOnLoad(gameObject);
                        BuildableObject component = gameObject.GetComponent <BuildableObject>();
                        component.name = asset.Guid;
                        component.setDisplayName(asset.Name);
                        component.price         = asset.Price;
                        component.dontSerialize = true;
                        component.isPreview     = true;
                        component.isStatic      = true;
                        Object.DontDestroyOnLoad(component.gameObject);
                        assetSMBs.Add(component);
                        component.transform.SetParent(hider.transform);
                        ScriptableSingleton <AssetManager> .Instance.registerObject(component);
                    }
                    catch (Exception message)
                    {
                        Debug.LogError(message);
                    }
                }
            }
            hider.SetActive(false);
            bundle.Unload(false);
        }
Example #4
0
    public void LoadScenery()
    {
        LoadFromXML();
        try
        {
            GameObject hider = new GameObject();

            char dsc = System.IO.Path.DirectorySeparatorChar;

            using (WWW www = new WWW("file://" + Path + dsc + "assetbundle" + dsc + "mod"))
            {
                if (www.error != null)
                {
                    throw new Exception("Loading had an error:" + www.error);
                }

                AssetBundle bundle = www.assetBundle;

                foreach (ParkitectObject PO in ParkitectObjects)
                {
                    try
                    {
                        Debug.Log("================== [Loading: " + PO.ObjName + "-- InGame Named: " + PO.inGameName + " -HP- ] ==================");
                        GameObject asset = Instantiate(bundle.LoadAsset(PO.inGameName)) as GameObject;

                        switch (PO.type)
                        {
                        case ParkitectObject.ObjType.deco:
                        case ParkitectObject.ObjType.trashbin:
                        case ParkitectObject.ObjType.seating:
                        case ParkitectObject.ObjType.seatingAuto:
                        case ParkitectObject.ObjType.lamp:
                        case ParkitectObject.ObjType.fence:
                            Debug.Log("Decoration are not supported for this template");
                            break;

                        case ParkitectObject.ObjType.FlatRide:
                            (new FlatRideDecorator()).Decorate(asset, PO);
                            break;

                        default:
                            print("Failed");
                            break;
                        }

                        Deco deco = asset.GetComponent <Deco>();
                        if (deco)
                        {
                            deco.categoryTag = PO.XMLNode["category"].InnerText;
                            deco.buildOnGrid = PO.grid;
                        }

                        if (PO.XMLNode["BoudingBoxes"] != null)
                        {
                            XmlNodeList BoudingBoxNodes = PO.XMLNode.SelectNodes("BoudingBoxes/BoudingBox");
                            foreach (XmlNode Box in BoudingBoxNodes)
                            {
                                BoundingBox BB = asset.AddComponent <BoundingBox>();
                                BB.isStatic   = false;
                                BB.bounds.min = getVector3(Box["min"].InnerText);
                                BB.bounds.max = getVector3(Box["max"].InnerText);
                                BB.layers     = BoundingVolume.Layers.Buildvolume;
                                BB.isStatic   = true;
                                Debug.Log("BoudingBox Added");
                            }
                        }

                        BuildableObject BO = asset.GetComponent <BuildableObject>();
                        BO.price = PO.price;
                        BO.setDisplayName(PO.inGameName);

                        new RecolorableDecorator().Decorate(asset, PO);
                        DontDestroyOnLoad(asset);

                        BuildableObject buildableObject = asset.GetComponent <BuildableObject>();
                        buildableObject.dontSerialize = true;
                        buildableObject.isPreview     = true;
                        AssetManager.Instance.registerObject(buildableObject);
                        _sceneryObjects.Add(asset.GetComponent <BuildableObject>());


                        Debug.Log("Loaded: " + buildableObject.gameObject.name);
                        // hide it from view
                        asset.transform.parent = hider.transform;
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e);

                        LogException(e);
                    }
                }

                bundle.Unload(false);
            }

            hider.SetActive(false);
        }
        catch (Exception e)
        {
            LogException(e);
        }
    }