Example #1
0
        /// <summary>
        /// Checks if there's a currently active network replacement applied to the given network prop index, and if so, returns the replacement record.
        /// </summary>
        /// <param name="netPrefab">Network prefab to check</param>
        /// <param name="laneIndex">Lane index to check</param>
        /// <param name="propIndex">Prop index to check</param>
        /// <returns>Replacement record if a network replacement is currently applied, null if no network replacement is currently applied</returns>
        internal BOBNetReplacement ActiveReplacement(NetInfo netPrefab, int laneIndex, int propIndex)
        {
            // Safety check.
            if (netPrefab != null && replacements.ContainsKey(netPrefab))
            {
                // Iterate through each entry in master dictionary.
                foreach (PrefabInfo target in replacements[netPrefab].Keys)
                {
                    BOBNetReplacement reference = replacements[netPrefab][target];
                    // Iterate through each network in this entry.
                    foreach (NetPropReference propRef in reference.references)
                    {
                        // Check for a network, lane, and prop index match.
                        if (propRef.network == netPrefab && propRef.laneIndex == laneIndex && propRef.propIndex == propIndex)
                        {
                            // Match!  Return the original prefab.
                            return(replacements[netPrefab][target]);
                        }
                    }
                }
            }

            // If we got here, no entry was found - return null to indicate no active replacement.
            return(null);
        }
Example #2
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);
        }
Example #3
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>Always false (all-network entries never remove parent network elements)</returns>
        protected override bool Revert(BOBNetReplacement replacement, bool removeEntries)
        {
            // Safety check for calls without any current replacement.
            if (replacement?.targetInfo == null)
            {
                return(false);
            }

            // List of prefabs where references need to be removed.
            List <NetInfo> removeList = new List <NetInfo>();

            // Iterate through each entry in prop reference dictionary.
            foreach (KeyValuePair <NetInfo, Dictionary <PrefabInfo, List <NetPropReference> > > keyPair in propReferences)
            {
                // Attempt to get a replacement list for this entry.
                if (keyPair.Value.TryGetValue(replacement.targetInfo, out List <NetPropReference> referenceList))
                {
                    // Got a list - revert all entries.
                    RevertReferences(replacement.targetInfo, referenceList);

                    // Add dictionary to list to be cleared.
                    removeList.Add(keyPair.Key);
                }
            }

            // Remove references from dictionary.
            foreach (NetInfo removeEntry in removeList)
            {
                if (propReferences.ContainsKey(removeEntry))
                {
                    if (propReferences[removeEntry].ContainsKey(replacement.targetInfo))
                    {
                        // Remove target info entries from this network entry.
                        propReferences[removeEntry].Remove(replacement.targetInfo);
                    }

                    // If no entries left for this network, remove entire network entry.
                    if (propReferences[removeEntry].Count == 0)
                    {
                        propReferences.Remove(removeEntry);
                    }
                }
            }

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

            // If we got here, we didn't remove any network entries from the list; return false.
            return(false);
        }
Example #4
0
        /// <summary>
        /// Replaces a prop, using a network replacement.
        /// </summary>
        /// <param name="replacement">Network replacement to apply</param>
        /// <param name="propReference">Individual prop reference to apply to</param>
        protected void ReplaceProp(BOBNetReplacement replacement, NetPropReference propReference)
        {
            // If this is a vanilla network, then we've probably got shared NetLaneProp references, so need to copy to a new instance.
            // If the name doesn't contain a period (c.f. 12345.MyNetwok_Data), then assume it's vanilla - may be a mod or not shared, but better safe than sorry.
            if (!propReference.netInfo.name.Contains("."))
            {
                CloneLanePropInstance(propReference.netInfo, propReference.laneIndex);
            }

            // Convert offset to Vector3.
            Vector3 offset = new Vector3
            {
                x = replacement.offsetX,
                y = replacement.offsetY,
                z = replacement.offsetZ
            };

            NetInfo.Lane thisLane = propReference.netInfo.m_lanes[propReference.laneIndex];

            // Apply replacement.
            if (replacement.replacementInfo is PropInfo propInfo)
            {
                thisLane.m_laneProps.m_props[propReference.propIndex].m_prop = propInfo;
            }
            else if (replacement.replacementInfo is TreeInfo treeInfo)
            {
                thisLane.m_laneProps.m_props[propReference.propIndex].m_tree = treeInfo;
            }
            else
            {
                Logging.Error("invalid replacement ", replacement.replacementInfo?.name ?? "null", " passed to NetworkReplacement.ReplaceProp");
                return;
            }

            // Invert x offset to match original prop x position.
            if (thisLane.m_position + propReference.position.x < 0)
            {
                offset.x = 0 - offset.x;
            }

            // Angle and offset.
            thisLane.m_laneProps.m_props[propReference.propIndex].m_angle    = propReference.angle + replacement.angle;
            thisLane.m_laneProps.m_props[propReference.propIndex].m_position = propReference.position + offset;

            // Probability.
            thisLane.m_laneProps.m_props[propReference.propIndex].m_probability = replacement.probability;

            // Update network prop references.
            propReference.netInfo.CheckReferences();

            // Add network to dirty list.
            NetData.DirtyList.Add(propReference.netInfo);
        }
Example #5
0
        /// <summary>
        /// Updates the target item record for changes in replacement status (e.g. after applying or reverting changes).
        /// </summary>
        /// <param name="propListItem">Target item</param>
        protected override void UpdateTargetItem(PropListItem propListItem)
        {
            if (propListItem is NetPropListItem netItem)
            {
                // Determine lane and index to test - just grab first one from list.
                int lane      = netItem.lanes[0];
                int propIndex = netItem.indexes[0];

                // All-network replacement and original probability (if any).
                BOBNetReplacement allNetReplacement = AllNetworkReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                if (allNetReplacement != null)
                {
                    propListItem.allPrefab = allNetReplacement.replacementInfo;
                    propListItem.allProb   = allNetReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    propListItem.allPrefab = null;
                }

                // Individual network replacement and original probability (if any).
                BOBNetReplacement netReplacement = NetworkReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                if (netReplacement != null)
                {
                    propListItem.replacementPrefab = netReplacement.replacementInfo;
                    propListItem.replacementProb   = netReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    propListItem.replacementPrefab = null;
                }

                // Replacement pack replacement and original probability (if any).
                BOBNetReplacement packReplacement = PackReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                if (packReplacement != null)
                {
                    propListItem.packagePrefab = packReplacement.replacementInfo;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    propListItem.packagePrefab = null;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Adds the given prop reference to the record for the given replacement.
        /// </summary>
        /// <param name="replacement">Replacement reference</param>
        /// <param name="propReference">Pop reference to store</param>
        protected override void AddReference(BOBNetReplacement replacement, NetPropReference propReference)
        {
            // Check to see if we've got an entry for this target prefab in our dictionary, and if not, create one.
            if (!propReferences.ContainsKey(propReference.netInfo))
            {
                propReferences.Add(propReference.netInfo, new Dictionary <PrefabInfo, List <NetPropReference> >());
            }

            // Check to see if we've got an entry for this network prefab in our dictionary entry for this target prefab, and if not, create one.
            if (!propReferences[propReference.netInfo].ContainsKey(replacement.targetInfo))
            {
                propReferences[propReference.netInfo].Add(replacement.targetInfo, new List <NetPropReference>());
            }

            // Add this prop reference to the dictioanry.
            propReferences[propReference.netInfo][replacement.targetInfo].Add(propReference);
        }
Example #7
0
        /// <summary>
        /// Applies a new (or updated) replacement.
        /// </summary>
        /// <param name="netInfo">Targeted network prefab</param>
        /// <param name="targetInfo">Targeted (original) prop prefab</param>
        /// <param name="replacementInfo">Replacment prop prefab</param>
        /// <param name="laneIndex">Targeted lane index (in parent network)</param>
        /// <param name="propIndex">Prop index to apply replacement to</param>
        /// <param name="angle">Replacment prop angle adjustment</param>
        /// <param name="offsetX">Replacment X position offset</param>
        /// <param name="offsetY">Replacment Y position offset</param>
        /// <param name="offsetZ">Replacment Z position offset</param>
        /// <param name="probability">Replacement probability</param>
        internal void Replace(NetInfo netInfo, PrefabInfo targetInfo, PrefabInfo replacementInfo, int laneIndex, int propIndex, float angle, float offsetX, float offsetY, float offsetZ, int probability)
        {
            // Make sure that target and replacement are the same type before doing anything.
            if (targetInfo?.name == null || replacementInfo?.name == null || (targetInfo is TreeInfo && !(replacementInfo is TreeInfo)) || (targetInfo is PropInfo) && !(replacementInfo is PropInfo))
            {
                return;
            }

            // Revert any current replacement entry for this prop.
            Revert(netInfo, targetInfo, laneIndex, propIndex, true);

            // Get configuration file network list entry.
            List <BOBNetReplacement> replacementsList = ReplacementEntry(netInfo);

            // Get current replacement after reversion above.
            BOBNetReplacement thisReplacement = EligibileReplacement(netInfo, targetInfo, laneIndex, propIndex);

            // Create new replacement list entry if none already exists.
            if (thisReplacement == null)
            {
                thisReplacement = new BOBNetReplacement
                {
                    parentInfo = netInfo,
                    target     = targetInfo.name,
                    targetInfo = targetInfo,
                    laneIndex  = laneIndex,
                    propIndex  = propIndex
                };
                replacementsList.Add(thisReplacement);
            }

            // Add/replace replacement data.
            thisReplacement.isTree      = targetInfo is TreeInfo;
            thisReplacement.angle       = angle;
            thisReplacement.offsetX     = offsetX;
            thisReplacement.offsetY     = offsetY;
            thisReplacement.offsetZ     = offsetZ;
            thisReplacement.probability = probability;

            // Record replacement prop.
            thisReplacement.replacementInfo = replacementInfo;
            thisReplacement.Replacement     = replacementInfo.name;

            // Apply replacement.
            ApplyReplacement(thisReplacement);
        }
Example #8
0
        /// <summary>
        /// Restores a replacement, if any (e.g. after a higher-priority replacement has been reverted).
        /// </summary>
        /// <param name="netInfo">Network prefab</param>
        /// <param name="targetInfo">Target prop info</param>
        /// <param name="laneIndex">Lane index</param>
        /// <param name="propIndex">Prop index</param>
        /// <returns>True if a restoration was made, false otherwise</returns>
        internal bool Restore(NetInfo netInfo, PrefabInfo targetInfo, int laneIndex, int propIndex)
        {
            // See if we have a relevant replacement record.
            BOBNetReplacement thisReplacement = EligibileReplacement(netInfo, targetInfo, laneIndex, propIndex);

            if (thisReplacement != null)
            {
                // Yes - add reference data to the list.
                NetPropReference newReference = CreateReference(netInfo, targetInfo, laneIndex, propIndex, thisReplacement.isTree);
                AddReference(thisReplacement, newReference);

                // Apply replacement and return true to indicate restoration.
                ReplaceProp(thisReplacement, newReference);

                return(true);
            }

            // If we got here, no restoration was made.
            return(false);
        }
Example #9
0
        /// <summary>
        /// Applies a replacement.
        /// </summary>
        /// <param name="replacement">Replacement record to apply</param>
        protected override void ApplyReplacement(BOBNetReplacement replacement)
        {
            // Don't do anything if prefabs can't be found.
            if (replacement?.targetInfo == null || replacement.replacementInfo == null || replacement.NetInfo == null)
            {
                return;
            }

            // Check lane index.
            NetInfo.Lane thisLane = replacement.NetInfo.m_lanes[replacement.laneIndex];
            if (thisLane == null)
            {
                return;
            }

            // Check prop index.
            NetLaneProps.Prop thisLaneProp = thisLane.m_laneProps.m_props[replacement.propIndex];
            if (thisLaneProp == null)
            {
                return;
            }

            // Reset any pack, network, or all-network replacements first.
            NetworkReplacement.Instance.RemoveEntry(replacement.NetInfo, replacement.targetInfo, replacement.laneIndex, replacement.propIndex);
            AllNetworkReplacement.Instance.RemoveEntry(replacement.NetInfo, replacement.targetInfo, replacement.laneIndex, replacement.propIndex);
            NetworkPackReplacement.Instance.RemoveEntry(replacement.NetInfo, replacement.targetInfo, replacement.laneIndex, replacement.propIndex);

            // Create replacment entry.
            NetPropReference newPropReference = CreateReference(replacement.NetInfo, replacement.targetInfo, replacement.laneIndex, replacement.propIndex, replacement.isTree);

            // Reset replacement list to be only our new replacement entry.
            replacement.references = new List <NetPropReference> {
                newPropReference
            };

            // Apply the replacement.
            ReplaceProp(replacement, newPropReference);
        }
Example #10
0
        /// <summary>
        /// Replaces a prop using a network replacement.
        /// </summary>
        /// <param name="netElement">Network replacement element to apply</param>
        /// <param name="propReference">Individual prop reference to apply to</param>
        internal void ReplaceProp(BOBNetReplacement netElement, NetPropReference propReference)
        {
            // Convert offset to Vector3.
            Vector3 offset = new Vector3
            {
                x = netElement.offsetX,
                y = netElement.offsetY,
                z = netElement.offsetZ
            };

            // Apply replacement.
            if (netElement.replacementInfo is PropInfo propInfo)
            {
                propReference.network.m_lanes[propReference.laneIndex].m_laneProps.m_props[propReference.propIndex].m_finalProp = propInfo;
            }
            else
            {
                propReference.network.m_lanes[propReference.laneIndex].m_laneProps.m_props[propReference.propIndex].m_finalTree = (TreeInfo)netElement.replacementInfo;
            }

            // Invert x offset if lane position is negative.
            if (propReference.network.m_lanes[propReference.laneIndex].m_position < 0)
            {
                offset.x = 0 - offset.x;
            }

            // Angle and offset.
            propReference.network.m_lanes[propReference.laneIndex].m_laneProps.m_props[propReference.propIndex].m_angle    = propReference.angle + netElement.angle;
            propReference.network.m_lanes[propReference.laneIndex].m_laneProps.m_props[propReference.propIndex].m_position = propReference.postion + offset;

            // Probability.
            propReference.network.m_lanes[propReference.laneIndex].m_laneProps.m_props[propReference.propIndex].m_probability = netElement.probability;

            // Add network to dirty list.
            NetData.DirtyList.Add(propReference.network);
        }
Example #11
0
        /// <summary>
        /// Populates the target fastlist with a list of target-specific trees or props.
        /// </summary>
        protected override void TargetList()
        {
            // List of prefabs that have passed filtering.
            List <NetPropListItem> propList = new List <NetPropListItem>();

            // Check to see if this building contains any props.
            if (currentNet.m_lanes == null || currentNet.m_lanes.Length == 0)
            {
                // No props - show 'no props' label and return an empty list.
                noPropsLabel.Show();
                targetList.m_rowsData = new FastList <object>();
                return;
            }

            // Local reference.
            NetInfo.Lane[] lanes = currentNet.m_lanes;

            // Iterate through each lane.
            for (int lane = 0; lane < lanes.Length; ++lane)
            {
                // Local reference.
                NetLaneProps.Prop[] laneProps = lanes[lane].m_laneProps?.m_props;

                // If no props in this lane, skip it and go to the next one.
                if (laneProps == null)
                {
                    continue;
                }

                // Iterate through each prop in lane.
                for (int propIndex = 0; propIndex < laneProps.Length; ++propIndex)
                {
                    // Create new list item.
                    NetPropListItem propListItem = new NetPropListItem();

                    // Try to get relevant prefab (prop/tree), using finalProp.
                    PrefabInfo finalInfo = IsTree ? (PrefabInfo)laneProps[propIndex]?.m_finalTree : (PrefabInfo)laneProps[propIndex]?.m_finalProp;

                    // Check to see if we were succesful - if not (e.g. we only want trees and this is a prop), continue on to next building prop.
                    if (finalInfo?.name == null)
                    {
                        continue;
                    }

                    // Networks are always grouped - set index and lane to -1 and add to our lists of indexes and lanes.
                    propListItem.index = -1;
                    propListItem.lane  = -1;
                    propListItem.indexes.Add(propIndex);
                    propListItem.lanes.Add(lane);

                    // Get original (pre-replacement) tree/prop prefab and current probability (as default original probability).
                    propListItem.originalPrefab = NetworkReplacement.instance.GetOriginal(currentNet, lane, propIndex) ?? AllNetworkReplacement.instance.GetOriginal(currentNet, lane, propIndex) ?? PackReplacement.instance.GetOriginal(currentNet, lane, propIndex) ?? finalInfo;
                    propListItem.originalProb   = laneProps[propIndex].m_probability;
                    propListItem.originalAngle  = laneProps[propIndex].m_angle;

                    // All-network replacement and original probability (if any).
                    BOBNetReplacement allNetReplacement = AllNetworkReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                    if (allNetReplacement != null)
                    {
                        propListItem.allPrefab = allNetReplacement.replacementInfo;
                        propListItem.allProb   = allNetReplacement.probability;
                    }

                    // Individual network replacement and original probability (if any).
                    BOBNetReplacement netReplacement = NetworkReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                    if (netReplacement != null)
                    {
                        propListItem.replacementPrefab = netReplacement.replacementInfo;
                        propListItem.replacementProb   = netReplacement.probability;
                    }

                    // Replacement pack replacement and original probability (if any).
                    BOBNetReplacement packReplacement = PackReplacement.instance.ActiveReplacement(currentNet, lane, propIndex);
                    if (packReplacement != null)
                    {
                        propListItem.packagePrefab = packReplacement.replacementInfo;
                    }

                    // Are we grouping?
                    if (propListItem.index == -1)
                    {
                        // Yes, grouping - initialise a flag to show if we've matched.
                        bool matched = false;

                        // Iterate through each item in our existing list of props.
                        foreach (NetPropListItem item in propList)
                        {
                            // Check to see if we already have this in the list - matching original prefab, building replacement prefab, all-building replacement prefab, and probability.
                            if (item.originalPrefab == propListItem.originalPrefab && item.replacementPrefab == propListItem.replacementPrefab && propListItem.allPrefab == item.allPrefab)
                            {
                                // We've already got an identical grouped instance of this item - add this index and lane to the lists of indexes and lanes under that item and set the flag to indicate that we've done so.
                                item.indexes.Add(propIndex);
                                item.lanes.Add(lane);
                                matched = true;

                                // No point going any further through the list, since we've already found our match.
                                break;
                            }
                        }

                        // Did we get a match?
                        if (matched)
                        {
                            // Yes - continue on to next network prop (without adding this item separately to the list).
                            continue;
                        }
                    }

                    // Add this item to our list.
                    propList.Add(propListItem);
                }
            }

            // Create return fastlist from our filtered list, ordering by name.
            targetList.m_rowsData = new FastList <object>()
            {
                m_buffer = targetSearchStatus == (int)OrderBy.NameDescending ? propList.OrderByDescending(item => item.DisplayName).ToArray() : propList.OrderBy(item => item.DisplayName).ToArray(),
                m_size   = propList.Count
            };
            targetList.Refresh();

            // If the list is empty, show the 'no props' label; otherwise, hide it.
            if (targetList.m_rowsData.m_size == 0)
            {
                noPropsLabel.Show();
            }
            else
            {
                noPropsLabel.Hide();
            }
        }
Example #12
0
        /// <summary>
        /// Applies an all-building prop replacement.
        /// </summary>
        /// <param name="replacement">Replacement record to apply</param>
        protected override void ApplyReplacement(BOBNetReplacement replacement)
        {
            // Don't do anything if prefabs can't be found.
            if (replacement?.targetInfo == null || replacement.replacementInfo == null)
            {
                return;
            }

            // Create new reference list.
            List <NetPropReference> referenceList = new List <NetPropReference>();

            // Iterate through each loaded network and record props to be replaced.
            for (int i = 0; i < PrefabCollection <NetInfo> .LoadedCount(); ++i)
            {
                // Get local reference.
                NetInfo netInfo = PrefabCollection <NetInfo> .GetLoaded((uint)i);

                // Skip any null networks, or netorks without lanes.
                if (netInfo?.m_lanes == null)
                {
                    continue;
                }

                // Iterate through each lane.
                for (int laneIndex = 0; laneIndex < netInfo.m_lanes.Length; ++laneIndex)
                {
                    // Local reference.
                    NetLaneProps.Prop[] theseLaneProps = netInfo.m_lanes[laneIndex]?.m_laneProps?.m_props;

                    // If no props in this lane, skip it and go to the next one.
                    if (theseLaneProps == null)
                    {
                        continue;
                    }

                    // Iterate through each prop in lane.
                    for (int propIndex = 0; propIndex < theseLaneProps.Length; ++propIndex)
                    {
                        // Local reference.
                        NetLaneProps.Prop thisLaneProp = theseLaneProps[propIndex];

                        // If invalid entry, skip this one.
                        if (thisLaneProp == null)
                        {
                            continue;
                        }

                        // Check for any currently active network or individual replacement.
                        if (NetworkReplacement.Instance.ActiveReplacement(netInfo, laneIndex, propIndex) != null || IndividualNetworkReplacement.Instance.ActiveReplacement(netInfo, laneIndex, propIndex) != null)
                        {
                            // Active network or individual replacement; skip this one.
                            continue;
                        }

                        // Check for any existing pack replacement.
                        PrefabInfo thisProp = NetworkPackReplacement.Instance.ActiveReplacement(netInfo, laneIndex, propIndex)?.targetInfo;
                        if (thisProp == null)
                        {
                            // No active replacement; use current PropInfo.
                            if (replacement.isTree)
                            {
                                thisProp = thisLaneProp.m_finalTree;
                            }
                            else
                            {
                                thisProp = thisLaneProp.m_finalProp;
                            }
                        }

                        // See if this prop matches our replacement.
                        if (thisProp != null && thisProp == replacement.targetInfo)
                        {
                            // Match!  Add reference data to the list.
                            referenceList.Add(CreateReference(netInfo, thisProp, laneIndex, propIndex, replacement.isTree));
                        }
                    }
                }
            }

            // Now, iterate through each entry found and apply the replacement to each one.
            foreach (NetPropReference propReference in referenceList)
            {
                // Remove any pack replacements first.
                NetworkPackReplacement.Instance.RemoveEntry(propReference.netInfo, replacement.targetInfo, propReference.laneIndex, propReference.propIndex);

                // Add entry to dictionary.
                AddReference(replacement, propReference);

                // Apply the replacement.
                ReplaceProp(replacement, propReference);
            }
        }
Example #13
0
        /// <summary>
        /// Updates the target item record for changes in replacement status (e.g. after applying or reverting changes).
        /// </summary>
        /// <param name="propListItem">Target item</param>
        protected override void UpdateTargetItem(TargetListItem targetListItem)
        {
            if (targetListItem is NetTargetListItem netItem)
            {
                // Determine index to test - if no individual index, just grab first one from list.
                int propIndex = netItem.index;
                if (propIndex < 0)
                {
                    propIndex = netItem.indexes[0];
                }

                // Determine lane to test - if no individual lane, just grab first one from list.
                int lane = netItem.lane;
                if (lane < 0)
                {
                    lane = netItem.lanes[0];
                }

                // Replacement pack replacement and original probability (if any).
                BOBNetReplacement packReplacement = NetworkPackReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex);
                if (packReplacement != null)
                {
                    targetListItem.packagePrefab = packReplacement.replacementInfo;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    targetListItem.packagePrefab = null;
                }

                // All-network replacement and original probability (if any).
                BOBNetReplacement allNetReplacement = AllNetworkReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex);
                if (allNetReplacement != null)
                {
                    targetListItem.allPrefab = allNetReplacement.replacementInfo;
                    targetListItem.allProb   = allNetReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    targetListItem.allPrefab = null;
                }

                // Network replacement and original probability (if any).
                BOBNetReplacement netReplacement = NetworkReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex);
                if (netReplacement != null)
                {
                    targetListItem.replacementPrefab = netReplacement.replacementInfo;
                    targetListItem.replacementProb   = netReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    targetListItem.replacementPrefab = null;
                }

                // Individual replacement and original probability (if any).
                BOBNetReplacement individualReplacement = IndividualNetworkReplacement.Instance.ActiveReplacement(SelectedNet, lane, propIndex);
                if (individualReplacement != null)
                {
                    targetListItem.individualPrefab = individualReplacement.replacementInfo;
                    targetListItem.individualProb   = individualReplacement.probability;
                }
                else
                {
                    // If no active current record, ensure that it's reset to null.
                    targetListItem.individualPrefab = null;
                }
            }
        }
Example #14
0
 /// <summary>
 /// Dummy entry - DO NOT USE
 /// </summary>
 /// <param name="replacement">Replacement record to apply</param>
 protected override void ApplyReplacement(BOBNetReplacement replacement)
 {
 }
Example #15
0
 /// <summary>
 /// Adds the given prop reference to the record for the given replacement.
 /// </summary>
 /// <param name="replacement">Replacement reference</param>
 /// <param name="propReference">Pop reference to store</param>
 protected virtual void AddReference(BOBNetReplacement replacement, NetPropReference propReference) => replacement.references.Add(propReference);
Example #16
0
        /// <summary>
        /// Applies a replacement.
        /// </summary>
        /// <param name="replacement">Replacement record to apply</param>
        protected override void ApplyReplacement(BOBNetReplacement replacement)
        {
            // Don't do anything if prefabs can't be found.
            if (replacement?.targetInfo == null || replacement.replacementInfo == null || replacement.NetInfo == null)
            {
                return;
            }

            // (Re)set replacement list.
            replacement.references = new List <NetPropReference>();

            // Iterate through each lane.
            for (int laneIndex = 0; laneIndex < replacement.NetInfo.m_lanes.Length; ++laneIndex)
            {
                // Local reference.
                NetLaneProps.Prop[] theseLaneProps = replacement.NetInfo.m_lanes[laneIndex]?.m_laneProps?.m_props;

                // If no props in this lane, skip it and go to the next one.
                if (theseLaneProps == null)
                {
                    continue;
                }

                // Iterate through each prop in lane.
                for (int propIndex = 0; propIndex < theseLaneProps.Length; ++propIndex)
                {
                    // Local reference.
                    NetLaneProps.Prop thisLaneProp = theseLaneProps[propIndex];

                    // If invalid entry, skip this one.
                    if (thisLaneProp == null)
                    {
                        continue;
                    }

                    // Check for any currently active individual network prop replacement.
                    if (IndividualNetworkReplacement.Instance.ActiveReplacement(replacement.NetInfo, laneIndex, propIndex) != null)
                    {
                        // Active individual network prop replacement; skip this one.
                        continue;
                    }

                    // Reset any pack or all-network replacements first.
                    AllNetworkReplacement.Instance.RemoveEntry(replacement.NetInfo, replacement.targetInfo, replacement.laneIndex, replacement.propIndex);
                    NetworkPackReplacement.Instance.RemoveEntry(replacement.NetInfo, replacement.targetInfo, replacement.laneIndex, replacement.propIndex);

                    // Check for any existing all-network or pack replacement.
                    PrefabInfo thisProp = NetworkPackReplacement.Instance.ActiveReplacement(replacement.NetInfo, laneIndex, propIndex)?.targetInfo ?? AllNetworkReplacement.Instance.ActiveReplacement(replacement.NetInfo, laneIndex, propIndex)?.targetInfo;
                    if (thisProp == null)
                    {
                        // No active replacement; use current PropInfo.
                        if (replacement.targetInfo is PropInfo)
                        {
                            thisProp = thisLaneProp.m_finalProp;
                        }
                        else
                        {
                            thisProp = thisLaneProp.m_finalTree;
                        }
                    }

                    // See if this prop matches our replacement.
                    if (thisProp != null && thisProp == replacement.targetInfo)
                    {
                        // Match!  Add reference data to the list.
                        replacement.references.Add(CreateReference(replacement.NetInfo, thisProp, laneIndex, propIndex, replacement.isTree));
                    }
                }
            }

            // Now, iterate through each entry found.
            foreach (NetPropReference propReference in replacement.references)
            {
                // Reset any pack or all-network replacements first.
                AllNetworkReplacement.Instance.RemoveEntry(propReference.netInfo, replacement.targetInfo, propReference.laneIndex, propReference.propIndex);
                NetworkPackReplacement.Instance.RemoveEntry(propReference.netInfo, replacement.targetInfo, propReference.laneIndex, propReference.propIndex);

                // Apply the replacement.
                ReplaceProp(replacement, propReference);
            }
        }
Example #17
0
 /// <summary>
 /// Applies a replacement.
 /// </summary>
 /// <param name="replacement">Replacement record to apply</param>
 protected abstract void ApplyReplacement(BOBNetReplacement replacement);