示例#1
0
        /// <summary>
        /// Reverts a replacement.
        /// </summary>
        /// <param name="replacement">Replacement record to revert</param>
        /// <param name="removeEntries">True to remove the reverted entries from the list of replacements, false to leave the list unchanged</param>
        /// <returns>True if the entire network record was removed from the list (due to no remaining replacements for that prefab), false if the prefab remains in the list (has other active replacements)</returns>
        protected virtual bool Revert(BOBNetReplacement replacement, bool removeEntries)
        {
            // Safety check for calls without any current replacement.
            if (replacement?.targetInfo == null || replacement.references == null)
            {
                return(false);
            }

            if (replacement.references != null)
            {
                // Revert all entries in list.
                RevertReferences(replacement.targetInfo, replacement.references);


                // Remove replacement entry from list of replacements, if we're doing so.
                if (removeEntries)
                {
                    // Remove from replacement list.
                    ReplacementList(replacement.NetInfo).Remove(replacement);

                    // See if we've got a parent network element record, and if so, if it has any remaining replacement entries.
                    BOBNetworkElement thisElement = NetworkElement(replacement.NetInfo);
                    if (thisElement != null && (thisElement.replacements == null || thisElement.replacements.Count == 0))
                    {
                        // No replacement entries left - delete entire network entry and return true to indicate that we've done so.
                        NetworkElementList.Remove(thisElement);
                        return(true);
                    }
                }
            }

            // If we got here, we didn't remove any network entries from the list; return false.
            return(false);
        }
示例#2
0
        /// <summary>
        /// Gets the relevant network replacement list entry from the active configuration file, creating a new network entry if none already exists.
        /// </summary>
        /// <param name="netInfo">Network prefab</param>
        /// <returns>Replacement list for the specified network prefab</returns>
        protected virtual List <BOBNetReplacement> ReplacementEntry(NetInfo netInfo)
        {
            // Get existing entry for this network.
            BOBNetworkElement thisNetwork = NetworkElement(netInfo);

            // If no existing entry, create a new one.
            if (thisNetwork == null)
            {
                thisNetwork = new BOBNetworkElement(netInfo);
                NetworkElementList.Add(thisNetwork);
            }

            // Return replacement list from this entry.
            return(thisNetwork.replacements);
        }
示例#3
0
        /// <summary>
        /// Deserialises a network replacement list.
        /// </summary>
        /// <param name="elementList">Network element list to deserialise</param>
        private static void DeserializeNetwork(BOBNetworkElement networkElement)
        {
            // Try to find target network.
            NetInfo networkInfo = (NetInfo)PrefabCollection <NetInfo> .FindLoaded(networkElement.network);

            if (networkInfo == null)
            {
                Logging.Message("Couldn't find target network ", networkElement.network);
                return;
            }


            // Iterate through each element in the provided list.
            foreach (BOBNetReplacement replacement in networkElement.replacements)
            {
                // Try to find target prefab.
                PrefabInfo targetPrefab = replacement.tree ? (PrefabInfo)PrefabCollection <TreeInfo> .FindLoaded(replacement.target) : (PrefabInfo)PrefabCollection <PropInfo> .FindLoaded(replacement.target);

                if (targetPrefab == null)
                {
                    Logging.Message("Couldn't find target prefab ", replacement.target);
                    continue;
                }

                // Try to find replacement prefab.
                PrefabInfo replacementPrefab = FindReplacementPrefab(replacement.Replacement, replacement.tree);
                if (replacementPrefab == null)
                {
                    Logging.Message("Couldn't find replacement prefab ", replacement.Replacement);
                    continue;
                }

                // If we got here, it's all good; apply the network replacement.
                NetworkReplacement.instance.Apply(networkInfo, targetPrefab, replacementPrefab, replacement.angle, replacement.offsetX, replacement.offsetY, replacement.offsetZ, replacement.probability);
            }
        }