private void SetDeactive(int oldId) { HandleContainer handleContainer = IDHandleMap[oldId]; handleContainer.SetActive(false); Debug.Log("SetDeactive " + oldId + " : " + handleContainer.PointName); }
public void AddParent(THandleClass handleClass, THandle obj, THandleClass depHandleClass, THandle dep) { var objTuple = new HandleContainer(handleClass, obj); UnmanagedObjectContext <THandleClass, THandle> objContext; if (!_trackedObjects.TryGetValue(objTuple, out objContext)) { throw new EObjectNotFound <THandleClass, THandle>(handleClass, obj); } AddParent(objContext, new HandleContainer(depHandleClass, dep)); }
private HandleContainer AddPointAndHandle(Unit[] addedPointHandleList) { DeactivateHandles( ); HandleContainer handleCont = new HandleContainer(addedPointHandleList); IDHandleMap.Add(Counter, handleCont); objects.AddRange(addedPointHandleList); Counter++; // 他のクリックされていないオブジェクトを消す UpdateSelection(addedPointHandleList[0].name); return(handleCont); }
public void RemoveAndCallDestroyHandleDelegate(THandleClass handleClass, THandle obj) { try { var objTuple = new HandleContainer(handleClass, obj); UnmanagedObjectContext <THandleClass, THandle> objContext; if (!_trackedObjects.TryGetValue(objTuple, out objContext)) { throw new EObjectNotFound <THandleClass, THandle>(objTuple.Item1, objTuple.Item2); } var newRefCount = objContext.ReleaseRefCount(); if (newRefCount > 0) { return; // Object still alive } if (newRefCount < 0) { throw new EInvalidRefCount <THandleClass, THandle>(handleClass, obj, newRefCount); } try { objContext.CallDestroyHandleDelegate(obj); if (objContext.parentCollection == null) { return; } foreach (var dep in objContext.parentCollection) { RemoveParent(obj, objContext, dep); } } finally { if (!_trackedObjects.TryRemove(objTuple, out objContext)) { throw new EFailedObjectRemoval <THandleClass, THandle>(objTuple.Item1, objTuple.Item2); } } } catch (Exception e) { if (OnUnregisterException == null) { return; } OnUnregisterException(this, e, handleClass, obj); } }
public void Register(THandleClass handleClass, THandle obj, UnmanagedObjectContext <THandleClass, THandle> .DestroyHandleDelegate destroyHandle = null, HandleCollection <THandleClass, THandle> parentCollection = null) { UnmanagedObjectContext <THandleClass, THandle> existingContextObj; var handleContainer = new HandleContainer(handleClass, obj); var trackedObject = new UnmanagedObjectContext <THandleClass, THandle> { DestroyHandle = destroyHandle, parentCollection = parentCollection }; do { if ((existingContextObj = _trackedObjects.GetOrAdd(handleContainer, trackedObject)) == trackedObject) { if (parentCollection == null) { return; } foreach (var dep in trackedObject.parentCollection) { UnmanagedObjectContext <THandleClass, THandle> depContext; if (!_trackedObjects.TryGetValue(dep, out depContext)) { throw new EObjectNotFound <THandleClass, THandle>(dep.Item1, dep.Item2); } depContext.AddRefCount(); } return; } /* If object already existed, under normal conditions AddRefCount() must return a value > 1. * If it returns <= 1 it means it just got decremented in another thread, reached zero and * it's about to be destroyed. So we will have to wait for that to happen and try again our * entire operation */ var newRefCount = existingContextObj.AddRefCount(); if (newRefCount <= 0) { throw new EInvalidRefCount <THandleClass, THandle>(handleClass, obj, newRefCount); } if (newRefCount > 1) { break; } /* Object is getting removed in another thread. Let's spin while we wait for it to be gone * from our _trackedObjects container */ while (_trackedObjects.TryGetValue(handleContainer, out existingContextObj)) { Thread.Yield(); } } while (true); /* Object already exists, could be an stale object not yet garbage collected, * so we will set the new cleanup methods in place of the current ones */ existingContextObj.DestroyHandle = destroyHandle; if (parentCollection == null) { return; } foreach (var dep in parentCollection) { AddParent(existingContextObj, dep); } }