protected override GameObject CreateActualEngineObject(IEnginePrefab prefab, Vector3 <float> position, Quaternion <float> rotation) { if (prefab == null) { throw new ArgumentNullException(nameof(prefab), "Prefab service parameter must not be null."); } //This really isn't a good way to handle things but it's the best way I could come up with. UnityEnginePrefabServiceAdapter tryCastedPrefabService = prefab as UnityEnginePrefabServiceAdapter; if (tryCastedPrefabService == null) { throw new ArgumentException("Failed to convert prefab service into Unity3D service. Desired Type: " + nameof(UnityEnginePrefabServiceAdapter) + " Actual Type: " + prefab.GetType(), nameof(prefab)); } return(tryCastedPrefabService.Create(position, rotation)); }
/// <summary> /// Creates a <see cref="IEnginePrefabedGameObject"/> 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="IEnginePrefabedGameObject"/> to be created.</param> /// <param name="rotation"><see cref="Quaternion{TMathType}"/> representing the rotation of the <see cref="IEngineGameObject"/> to be created.</param> /// <param name="prefab">Prefab information service.</param> /// <returns>A valid non-null <see cref="IEnginePrefabedGameObject"/> at specified position and rotation.</returns> public IEnginePrefabedGameObject Create(IEnginePrefab prefab, 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)); } IEnginePrefabedGameObject bridgedGameObject = CreatePrefabbedGameObjectAdapter(prefab, concreteEngineObjectInstance); if (bridgedGameObject == null) { throw new InvalidOperationException(nameof(LifetimeManagedGameObjectFactoryServiceAdapter <TActualGameObjectType>) + " failed to produce a valid " + nameof(IEnginePrefabedGameObject) + " vai method: " + nameof(CreatePrefabbedGameObjectAdapter)); } lifetimeManagerRegister.Register(bridgedGameObject, concreteEngineObjectInstance); return(bridgedGameObject); }
/// <summary> /// Creates an adapter around the <typeparamref name="TActualGameObjectType"/> object instance and <see cref="IEnginePrefab"/> for use externally. /// </summary> /// <param name="actualGameObject">Object to plug in to the adapter.</param> /// <param name="prefab">Prefab information service.</param> /// <returns>A valid adapter around the <typeparamref name="TActualGameObjectType"/> instance.</returns> protected abstract IEnginePrefabedGameObject CreatePrefabbedGameObjectAdapter(IEnginePrefab prefab, TActualGameObjectType actualGameObject);
/// <summary> /// Creates the actual underlying prefabbed GameObject type at the specified position and rotation. /// </summary> /// <param name="position">The <see cref="Vector3{TMathType}"/> position to create the <typeparamref name="TActualGameObjectType"/> object at.</param> /// <param name="rotation">The <see cref="Quaternion{TMathType}"/> rotation to create the <typeparamref name="TActualGameObjectType"/> object with.</param> /// <param name="prefab">Prefab information service.</param> /// <returns>A valid instance of <typeparamref name="TActualGameObjectType"/> with the specified transformation.</returns> protected abstract TActualGameObjectType CreateActualEngineObject(IEnginePrefab prefab, Vector3 <float> position, Quaternion <float> rotation);
protected override IEnginePrefabedGameObject CreatePrefabbedGameObjectAdapter(IEnginePrefab prefab, GameObject actualGameObject) { if (actualGameObject == null) { throw new ArgumentNullException(nameof(actualGameObject), nameof(GameObject) + " parameters must not be null."); } if (prefab == null) { throw new ArgumentNullException(nameof(prefab), "Prefab service parameter must not be null."); } return(new UnityEnginePrefabGameObjectAdapter(actualGameObject)); }