Example #1
0
    private IEnumerator CycleElements(int direction)
    {
        if (IsMultipleElements())
        {
            if (activeElement != null)
            {
                yield return(activeElement.Deactivate());

                activeElement = null;
            }

            activeElementIndex += direction;

            if (activeElementIndex >= siteElements.Count)
            {
                activeElementIndex = 0;
            }
            else if (activeElementIndex < 0)
            {
                activeElementIndex = siteElements.Count - 1;
            }

            activeElement = siteElements[activeElementIndex];
        }
        else
        {
            activeElement = siteElements[0];
        }
        if (!activeElement.active)
        {
            yield return(activeElement.Activate());
        }
        SiteManager.activeSiteElementSet = this;
    }
    // Loads every single site and it's data.
    // Warning: This can take a LONG time! Best when scheduled when nobody will be using the application.
    public IEnumerator LoadAllSites()
    {
        // Set the status text so the user knows to wait.
        StatusText.SetText("Loading All Sites. Please Wait.");

        // Lock all input.
        GamepadInput.LockInput(true);

        // Check one more time to make sure we're supposed to be doing this.
        if (GameManager.instance.caveSettings.loadAllDataOnStart)
        {
            // Iterate through every single site.
            for (int i = 0; i < sites.Count; i++)
            {
                // Store the site at this array index.
                Site site = sites[i];

                // Iterate through all data sets that are part of this site.
                for (int j = 0; j < site.dataSets.Count; j++)
                {
                    // Store the data set.
                    SiteElementSet dataSet = site.dataSets[j];

                    // Iterate through all data elements that are part of this data set.
                    for (int k = 0; k < dataSet.siteElements.Count; k++)
                    {
                        // Store this data element.
                        SiteElement dataElement = dataSet.siteElements[k];

                        // Set the status text to a helpful message.
                        string statusString = string.Format("Loading element {0} of {1} from set {2} of {3} from site {4} of {5}",
                                                            k, dataSet.siteElements.Count, j, site.dataSets.Count, i, sites.Count);

                        StatusText.SetText(statusString);
                        Debug.Log(statusString);

                        // Wait for this data element to load before proceeding.
                        yield return(dataElement.Load());
                    }
                }
            }
        }

        // Unlock input.
        GamepadInput.LockInput(false);
    }
    // Creates a nice screensaver/scene scroller while idling.
    public IEnumerator IdleScroll()
    {
        // Get all currently loaded site elements.
        List <SiteElement> loadedElements = allLoadedSiteElements;

        // If no sites have been loaded yet, we need to load at least one.
        if (loadedElements.Count <= 0)
        {
            Debug.LogWarning("No data already loaded. Attempting to load very first data set");

            // Loading the first site element.
            yield return(allSiteElements[0].Load());

            loadedElements = allLoadedSiteElements;

            // If we STILL couldn't load an element, quit the application... this means the screensaver failed, and if it failed, we risk burn-in.
            if (loadedElements.Count <= 0)
            {
                Debug.LogError("Could not go to screensaver mode because no data was found! Exiting application in 1 minute to prevent burn-in.");
                yield return(new WaitForSeconds(60.0f));

                Application.Quit();
            }
        }

        // All loaded site elements.
        loadedElements = allLoadedSiteElements;

        // Variable to keep track of our element index.
        int currentElementIndex = 0;

        // While we're supposed to idle.
        while (ShouldIdle())
        {
            // Get a new element.
            SiteElement currentElement = loadedElements[currentElementIndex];

            // Activate the specified element.
            yield return(currentElement.Activate());

            // Initialize an elapsed time.
            float elapsedTime = 0.0f;

            // Save the initial player rotation.
            Quaternion originalPlayerRotation = Player.instance.transform.rotation;

            // While the idle time is less than idle duration we want, and the system should still be idling.
            // If there is only one loaded element, don't try to switch between elements (prevents jumping around)
            while ((elapsedTime < GameManager.instance.secondsPerIdleScene || loadedElements.Count == 1) && ShouldIdle())
            {
                // // If this is a panorama, just rotate the camera around and look at the whole 360 photo.
                // if (currentElement is Panorama)
                // {
                //     // Speed of rotation.
                //     float camRotationSpeed = 0.05f;

                //     // Actually rotate the player.
                //     Player.instance.transform.Rotate(Vector3.up, camRotationSpeed);

                // }

                // // If this element is a model.
                // else if (currentElement is Model)
                // {
                //     // TODO: Add functionality for idling with models.
                // }
                currentElement.idleAnimation.Tick();

                // Wait a frame, then increase the elapsed time and loop again.
                yield return(null);

                elapsedTime += Time.deltaTime;
            }

            // Reset the player's rotation.
            Player.instance.transform.rotation = originalPlayerRotation;

            // Deactivate the last activated element.
            yield return(currentElement.Deactivate());

            // Increment the current element we're loading.
            currentElementIndex++;

            // Wrap back to start if needed.
            if (currentElementIndex >= loadedElements.Count)
            {
                currentElementIndex = 0;
            }

            // Wait a frame, then loop again.
            yield return(null);
        }
    }
Example #4
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);
        }
    }
Example #5
0
 public Site(SiteElement config)
 {
     _config = config;
 }
 public void AddSite(SiteElement e)
 {
     _siteElementCollection.Add(e);
 }
 public void Add(SiteElement e)
 {
     BaseAdd(e);
 }