Beispiel #1
0
        /// <summary>
        /// Generates and displays a pack row.
        /// </summary>
        /// <param name="data">Object to list</param>
        /// <param name="isRowOdd">If the row is an odd-numbered row (for background banding)</param>
        public override void Display(object data, bool isRowOdd)
        {
            thisPrefab = data as BOBRandomPrefab;

            // Perform initial setup for new rows.
            if (rowLabel == null)
            {
                isVisible     = true;
                canFocus      = true;
                isInteractive = true;
                width         = parent.width;
                height        = BOBPackPanel.RowHeight;

                rowLabel                  = AddUIComponent <UILabel>();
                rowLabel.width            = BOBPackPanel.ListWidth;
                rowLabel.relativePosition = new Vector2(TextX, 6f);
                rowLabel.textScale        = TextScale;
            }

            // Show grey if not all prefabs are loaded.
            rowLabel.textColor = thisPrefab == null || thisPrefab.missingVariant ? Color.gray : Color.white;

            // Set selected prop.
            rowLabel.text = thisPrefab?.name ?? "null";

            // Set initial background as deselected state.
            Deselect(isRowOdd);
        }
Beispiel #2
0
        /// <summary>
        /// Serializes the list of random trees into XML.
        /// </summary>
        /// <returns>XML serialized random trees</returns>
        internal static List <BOBRandomPrefab> SerializeRandomTrees()
        {
            // Return list.
            List <BOBRandomPrefab> serializedTrees = new List <BOBRandomPrefab>();

            // Iterate through random props and add to list.
            foreach (TreeInfo randomTree in randomTrees)
            {
                // Serialize prefab record.
                BOBRandomPrefab serializedPrefab = new BOBRandomPrefab
                {
                    name       = randomTree.name,
                    variations = new List <BOBVariation>()
                };

                // Add variations.
                foreach (TreeInfo.Variation variation in randomTree.m_variations)
                {
                    serializedPrefab.variations.Add(new BOBVariation
                    {
                        name        = variation.m_finalTree.name,
                        probability = variation.m_probability
                    });
                }

                // Add serialized prefab to list.
                serializedTrees.Add(serializedPrefab);
            }

            return(serializedTrees);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new random prop prefab.
        /// </summary>
        /// <param name="propName">Name of prefab</param>
        /// <returns>New random prop prefab, or null if creation failed</returns>
        internal static BOBRandomPrefab NewRandomProp(string propName)
        {
            // Need unique name.
            if (DuplicatePropName(propName))
            {
                Logging.Error("duplicate prop name for random prop");
                return(null);
            }

            PropInfo newProp = InstantiateProp(propName);

            if (newProp != null)
            {
                BOBRandomPrefab newPrefab = new BOBRandomPrefab
                {
                    name = propName,
                    prop = newProp
                };

                // Add new tree to list and return direct reference.
                RandomProps.Add(newPrefab);
                return(newPrefab);
            }

            // If we got here, something went wrong; return null.
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new random tree prefab.
        /// </summary>
        /// <param name="propName">Name of prefab</param>
        /// <returns>New random tree prefab, or null if creation failed</returns>
        internal static BOBRandomPrefab NewRandomTree(string treeName)
        {
            // Need unique name.
            if (DuplicateTreeName(treeName))
            {
                Logging.Error("duplicate tree name for random tree");
                return(null);
            }

            TreeInfo newTree = InstantiateTree(treeName);

            if (newTree != null)
            {
                BOBRandomPrefab newPrefab = new BOBRandomPrefab
                {
                    name = treeName,
                    tree = newTree
                };

                // Add new tree to list and return direct reference.
                RandomTrees.Add(newPrefab);
                return(newPrefab);
            }

            // If we got here, something went wrong; return null.
            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Sets the selection to the given random prop.
        /// If no item is found, clears the selection and resets the list.
        /// </summary>
        /// <param name="item">The item to find</param>
        public virtual void FindItem(BOBRandomPrefab randomPrefab)
        {
            // Iterate through the rows list.
            for (int i = 0; i < m_rowsData.m_size; ++i)
            {
                // Look for an index match; individual or grouped (contained within propListItem.indexes list).
                if (m_rowsData.m_buffer[i] is BOBRandomPrefab listItem && listItem == randomPrefab)
                {
                    // Found a match; set the selected index to this one.
                    selectedIndex = i;

                    // If the selected index is outside the current visibility range, move the to show it.
                    if (selectedIndex < listPosition || selectedIndex > listPosition + m_rows.m_size)
                    {
                        listPosition = selectedIndex;
                    }

                    // Done here; return.
                    return;
                }
            }

            // If we got here, we didn't find a match; clear the selection and reset the list position.
            selectedIndex = -1;
            listPosition  = 0f;
        }