コード例 #1
0
        private void RemoveSinkLazy(MyResourceSinkComponent sink, bool resetSinkInput = true)
        {
            foreach (var acceptedResourceId in sink.AcceptedResources)
		    {
                MyDefinitionId typeId = acceptedResourceId;
			    var sinksOfType = GetSinksOfType(ref typeId, sink.Group);
                if (sinksOfType == null)
                {
                    //Debug.Fail("SinksOfType is null on removal of " + typeId.ToString());
                    continue;
                }
			    int typeIndex = GetTypeIndex(ref typeId);

                if (!sinksOfType.Remove(sink))
                {
                    int foundIndex = -1;
                    for(int pairIndex = 0; pairIndex < m_dataPerType[typeIndex].InputOutputList.Count; ++pairIndex)
		            {
                        if (m_dataPerType[typeIndex].InputOutputList[pairIndex].Item1 != sink)
		                    continue;

		                foundIndex = pairIndex;
		                break;
		            }

                    if (foundIndex != -1)
                    {
                        var matchingSource = m_dataPerType[typeIndex].InputOutputList[foundIndex].Item2;
                        m_dataPerType[typeIndex].InputOutputList.RemoveAtFast(foundIndex);
                        m_dataPerType[typeIndex].SourcesByPriority[GetPriority(matchingSource)].Add(matchingSource);
                    }
                }

			    m_dataPerType[typeIndex].NeedsRecompute = true;
                m_dataPerType[typeIndex].GroupsDirty = true;
				m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
				if (resetSinkInput)
					sink.SetInputFromDistributor(typeId, 0.0f, IsAdaptible(sink), false);
		    }

            sink.OnRemoveType -= Sink_OnRemoveType;
	        sink.OnAddType -= Sink_OnAddType;
		    sink.RequiredInputChanged -= Sink_RequiredInputChanged;
		    sink.ResourceAvailable -= Sink_IsResourceAvailable;
        }
コード例 #2
0
	    public void RemoveSink(MyResourceSinkComponent sink, bool resetSinkInput = true, bool markedForClose = false)
	    {
		    if (markedForClose)
			    return;
		    Debug.Assert(sink != null);

		    foreach (var typeId in sink.AcceptedResources)
		    {
			    var sinksOfType = GetSinksOfType(typeId, sink.Group);
			    int typeIndex = GetTypeIndex(typeId);

                if (!sinksOfType.Remove(sink))
                {
                    int foundIndex = -1;
                    for(int pairIndex = 0; pairIndex < m_dataPerType[typeIndex].InputOutputList.Count; ++pairIndex)
		            {
                        if (m_dataPerType[typeIndex].InputOutputList[pairIndex].Item1 != sink)
		                    continue;

		                foundIndex = pairIndex;
		                break;
		            }

                    if (foundIndex != -1)
                    {
                        var matchingSource = m_dataPerType[typeIndex].InputOutputList[foundIndex].Item2;
                        m_dataPerType[typeIndex].InputOutputList.RemoveAtFast(foundIndex);
                        m_dataPerType[typeIndex].SourcesByPriority[GetPriority(matchingSource)].Add(matchingSource);
                    }
                }

			    m_dataPerType[typeIndex].NeedsRecompute = true;
				m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
				if (resetSinkInput)
					sink.SetInputFromDistributor(typeId, 0.0f, IsAdaptible(sink));
		    }

	        sink.OnAddType -= Sink_OnAddType;
		    sink.RequiredInputChanged -= Sink_RequiredInputChanged;
		    sink.ResourceAvailable -= Sink_IsResourceAvailable;
	    }