Example #1
0
        void save()
        {
            var vm = new DataInputViewModel();

            vm.Text.Get = "Bitte geben Sie den Dateinamen ein";
            ViewManager.ShowDialogView(typeof(Input), vm);
            if (vm.IsOK)
            {
                var data = new SerializableElements
                {
                    Id       = Element.id,
                    Elements = Elements.Get
                };
                Serializer.SerializeBinary(System.IO.Path.Combine(ConfigLoader.Instance.Config.SavePath, vm.Output.Get + ".model"), data);
            }
        }
    // Loads site data from JSON and creates POIs out of it.
    public void LoadSites(string dataPath)
    {
        // If the data file isn't found, create a sample site so the system still shows SOMETHING.
        if (!File.Exists(dataPath))
        {
            // Loads sample data of UCSD.
            SerializableSites sampleSites = new SerializableSites();
            sampleSites.sites = new SerializableSite[1];
            SerializableSite newSite = new SerializableSite();

            // UC San Diego Lat/Lon as sample
            newSite.latitude    = 32.8801f;
            newSite.longitude   = 117.2340f;
            newSite.name        = "UC San Diego";
            newSite.description = "This site was generated as a sample of what the JSON file should look like, roughly";

            sampleSites.sites[0] = newSite;

            string jsonText = JsonUtility.ToJson(sampleSites);

            // Save the JSON file as a sample.
            File.WriteAllText(dataPath, jsonText);

            // Return since there isn't any more we can do.
            return;
        }

        // Read the JSON from file.
        string jsonString = File.ReadAllText(dataPath);

        // Load in the JSON object as a Serializable Sites object.
        SerializableSites siteData = JsonUtility.FromJson <SerializableSites>(jsonString);

        // Load in custom JSON overrides and save
        if (File.Exists(GameManager.instance.caveSettings.pathToCustomOverrideFile))
        {
            jsonString      = File.ReadAllText(GameManager.instance.caveSettings.pathToCustomOverrideFile);
            customOverrides = JsonUtility.FromJson <SerializableElements>(jsonString);
            Debug.Log("loaded custom overrides");
            Debug.Log(customOverrides.elements);
        }
        else
        {
            Debug.LogWarning(GameManager.instance.caveSettings.pathToCustomOverrideFile + " does not exist");
        }

        // If the site data of the JSON isn't null and there are sites that are part of it.
        if (siteData.sites != null && siteData.sites.Length > 0)
        {
            // Iterate through each site from JSON.
            foreach (SerializableSite site in siteData.sites)
            {
                // Create an object for this site and set it's parent.
                GameObject newSiteObject = new GameObject(site.name);
                newSiteObject.transform.parent = this.transform;

                // Add the "Site" component to the new object.
                Site newSite = newSiteObject.AddComponent <Site>();

                // Initialize the site by passing it it's JSON data.
                newSite.InitializeSite(site);

                // Add this site to the list.
                sites.Add(newSite);
            }
        }

        // If there were no sites in the JSON, print an error and return.
        else
        {
            Debug.LogErrorFormat("Error: No sites loaded. Please check the following file: {0}", GameManager.dataJsonFile);
            return;
        }

        Debug.LogFormat("Loaded {0} sites", sites.Count);

        // Create POIs from all the loaded sites.
        StartCoroutine(CreatePOIs());
    }
Example #3
0
    public void Initialize(SerializableSiteElement[] serializableSiteElements, Site parentSite)
    {
        this.parentSite = parentSite;
        setType         = GetSetType();


        Debug.Log("Initializing " + setType + " for site " + parentSite.siteName);

        siteElements = new List <SiteElement>();

        foreach (SerializableSiteElement element in serializableSiteElements)
        {
            //Merge customData string and customdata object, prioritizing previously existing object
            CustomData c = JsonUtility.FromJson <CustomData>(element.customData);
            element.custom = c != null ? c : new CustomData();

            //Add local overrides to json file
            if (SiteManager.instance.customOverrides != null)
            {
                SerializableElements customs = SiteManager.instance.customOverrides;
                foreach (SerializableSiteElement e in customs.elements)
                {
                    //If names are equal, override custom properties
                    Debug.Log(e.name);
                    Debug.Log(element.name);
                    if (e.name == element.name)
                    {
                        if (e.custom.audio != null)
                        {
                            element.custom.audio = e.custom.audio;
                        }
                        if (e.custom.modelType != null && e.custom.modelType != "")
                        {
                            element.custom.modelType = e.custom.modelType;
                        }
                        if (e.custom.startTransform.position != Vector3.zero ||
                            e.custom.startTransform.eulerAngles != Vector3.zero
                            )
                        {
                            Debug.Log("override position: " + e.custom.startTransform.position);
                            element.custom.startTransform = e.custom.startTransform;
                        }
                        if (e.custom.splines != null)
                        {
                            element.custom.splines = e.custom.splines;
                        }
                        if (e.custom.shapefilePath != null && e.custom.shapefilePath != "")
                        {
                            element.custom.shapefilePath = e.custom.shapefilePath;
                        }
                    }
                }
            }

            GameObject  newElementObj = CreateElementObject(element.name);
            SiteElement newElement    = AddElementComponent(newElementObj, element);

            newElement.Initialize(element, parentSite);

            siteElements.Add(newElement);
        }
    }