public bool Equals(IEngineGameObject other) { UnityEngineGameObjectAdapter otherGO = null; //can't is/as down cast interface. if (other.GetType() == typeof(UnityEngineGameObjectAdapter)) otherGO = Convert.ChangeType(other, typeof(UnityEngineGameObjectAdapter)) as UnityEngineGameObjectAdapter; return otherGO == null ? false : (otherGO.unityGameObjectAdaptee == unityGameObjectAdaptee); }
public bool Equals(IEngineGameObject other) { UnityEngineGameObjectAdapter otherGO = null; //can't is/as down cast interface. if (other.GetType() == typeof(UnityEngineGameObjectAdapter)) { otherGO = Convert.ChangeType(other, typeof(UnityEngineGameObjectAdapter)) as UnityEngineGameObjectAdapter; } return(otherGO == null ? false : (otherGO.unityGameObjectAdaptee == unityGameObjectAdaptee)); }
/// <summary> /// Destroys the <see cref="IEngineGameObject"/> requested. /// Based on Unity3D's: http://docs.unity3d.com/ScriptReference/Object.Destroy.html /// </summary> /// <param name="toDestroy"><see cref="IEngineGameObject"/> to destroy.</param> /// <returns>Indicates if destruction was sucessful.</returns> public bool Destroy(IEngineGameObject toDestroy) { UnregistrationResult <TActualGameObjectType> result = lifetimeManagerRegister.TryUnregister(toDestroy); if (!result.Success) { return(false); } DestroyObject(result.Value); return(true); }
/// <summary> /// Destroys the <see cref="IEngineGameObject"/> requested approximately time seconds after this call. /// Based on Unity3D's: http://docs.unity3d.com/ScriptReference/Object.Destroy.html overload /// <param name="time">Time in seconds to approximately delay the destruction of the object.</param> /// <param name="toDestroy"><see cref="IEngineGameObject"/> to destroy.</param> /// </summary> /// <returns>Indicates if destruction was sucessful.</returns> public bool DestroyDelayed(IEngineGameObject toDestroy, float time) { //Don't unregister it yet TActualGameObjectType result = lifetimeManagerRegister.TryLookup(toDestroy); if (result == null) { return(false); } //We can't really unregister this value. We have to force the underlying engine to handle the unregistering of the object when its destruction is done. DestroyObject(result, time, () => lifetimeManagerRegister.TryUnregister(toDestroy)); return(true); }
/// <summary> /// Creates a <see cref="IEngineGameObject"/> at the specified <see cref="Vector3{TMathType}"/> postion and <see cref="Quaternion{TMathType}"/> rotation and registers it internally with the adapter registry. /// </summary> /// <param name="position"><see cref="Vector3{TMathType}"/> position of the <see cref="IEngineGameObject"/> to be created.</param> /// <param name="rotation"><see cref="Quaternion{TMathType}"/> representing the rotation of the <see cref="IEngineGameObject"/> to be created.</param> /// <returns>A valid non-null <see cref="IEngineGameObject"/> at specified position and rotation.</returns> public IEngineGameObject Create(Vector3 <float> position, Quaternion <float> rotation) { //Creates an instance of the actual engine gameobject and then registers it. //Once registeration is done it returns it for use. No consumer of the factory will know anything but of the creation. TActualGameObjectType concreteEngineObjectInstance = CreateActualEngineObject(position, rotation); if (concreteEngineObjectInstance == null) { throw new InvalidOperationException(nameof(LifetimeManagedGameObjectFactoryServiceAdapter <TActualGameObjectType>) + " failed to produce a valid " + nameof(TActualGameObjectType) + " via method: " + nameof(CreateActualEngineObject)); } IEngineGameObject bridgedGameObject = CreateGameObjectAdapter(concreteEngineObjectInstance); if (bridgedGameObject == null) { throw new InvalidOperationException(nameof(LifetimeManagedGameObjectFactoryServiceAdapter <TActualGameObjectType>) + " failed to produce a valid " + nameof(IEngineGameObject) + " vai method: " + nameof(CreateGameObjectAdapter)); } lifetimeManagerRegister.Register(bridgedGameObject, concreteEngineObjectInstance); return(bridgedGameObject); }