예제 #1
0
        /// <summary>
        /// This method will handle the cloning of Hybrid Components (if any) during the batched instantiation of an Entity
        /// </summary>
        /// <param name="srcArray">Array of source managed component indices. One per <paramref name="componentCount"/></param>
        /// <param name="componentCount">Number of component being instantiated</param>
        /// <param name="dstEntities">Array of destination entities. One per <paramref name="instanceCount"/></param>
        /// <param name="dstArray">Array of destination managed component indices. One per <paramref name="componentCount"/>*<paramref name="instanceCount"/>. All indices for the first component stored first etc.</param>
        /// <param name="instanceCount">Number of instances being created</param>
        /// <param name="managedComponentStore">Managed Store that owns the instances we create</param>
        static void InstantiateHybridComponentDelegate(int *srcArray, int componentCount, Entity *dstEntities, int *dstArray, int instanceCount, ManagedComponentStore managedComponentStore)
        {
            object[] gameObjectInstances = null;

            for (int src = 0; src < componentCount; ++src)
            {
                object sourceComponent = managedComponentStore.GetManagedComponent(srcArray[src]);
                if ((sourceComponent as UnityEngine.Component)?.gameObject.GetComponent <CompanionLink>() == null)
                {
                    for (int i = 0; i < instanceCount; ++i)
                    {
                        managedComponentStore.SetManagedComponentValue(dstArray[i], sourceComponent);
                    }
                }
                else
                {
                    var unityComponent = (UnityEngine.Component)sourceComponent;

                    if (gameObjectInstances == null)
                    {
                        gameObjectInstances = new object[instanceCount];

                        for (int i = 0; i < instanceCount; ++i)
                        {
                            var instance = GameObject.Instantiate(unityComponent.gameObject);
                            instance.name          = CompanionLink.GenerateCompanionName(dstEntities[i]);
                            gameObjectInstances[i] = instance;
                            instance.hideFlags    |= HideFlags.HideInHierarchy;
                        }
                    }

                    for (int i = 0; i < instanceCount; i++)
                    {
                        var componentInInstance = ((GameObject)gameObjectInstances[i]).GetComponent(unityComponent.GetType());
                        managedComponentStore.SetManagedComponentValue(dstArray[i], componentInInstance);
                    }
                }

                dstArray += instanceCount;
            }
        }
예제 #2
0
        /// <summary>
        /// This method will handle the cloning of Hybrid Components (if any) during the batched instantiation of an Entity
        /// </summary>
        /// <param name="srcArray">Array of source managed component indices. One per <paramref name="componentCount"/></param>
        /// <param name="componentCount">Number of component being instantiated</param>
        /// <param name="dstEntities">Array of destination entities. One per <paramref name="instanceCount"/></param>
        /// <param name="dstCompanionLinkIndices">Array of destination CompanionLink indices, can be null if the hybrid components are not owned</param>
        /// <param name="dstArray">Array of destination managed component indices. One per <paramref name="componentCount"/>*<paramref name="instanceCount"/>. All indices for the first component stored first etc.</param>
        /// <param name="instanceCount">Number of instances being created</param>
        /// <param name="managedComponentStore">Managed Store that owns the instances we create</param>
        static void InstantiateHybridComponentDelegate(int *srcArray, int componentCount, Entity *dstEntities, int *dstCompanionLinkIndices, int *dstArray, int instanceCount, ManagedComponentStore managedComponentStore)
        {
            if (dstCompanionLinkIndices != null)
            {
                var dstCompanionGameObjects = new GameObject[instanceCount];
                for (int i = 0; i < instanceCount; ++i)
                {
                    var companionLink = (CompanionLink)managedComponentStore.GetManagedComponent(dstCompanionLinkIndices[i]);
                    dstCompanionGameObjects[i] = companionLink.Companion;
                    CompanionLink.SetCompanionName(dstEntities[i], dstCompanionGameObjects[i]);
                }

                for (int src = 0; src < componentCount; ++src)
                {
                    var componentType = managedComponentStore.GetManagedComponent(srcArray[src]).GetType();

                    for (int i = 0; i < instanceCount; i++)
                    {
                        var componentInInstance = dstCompanionGameObjects[i].GetComponent(componentType);
                        var dstIndex            = src * instanceCount + i;
                        managedComponentStore.SetManagedComponentValue(dstArray[dstIndex], componentInInstance);
                    }
                }
            }
            else
            {
                for (int src = 0; src < componentCount; ++src)
                {
                    var component = managedComponentStore.GetManagedComponent(srcArray[src]);

                    for (int i = 0; i < instanceCount; i++)
                    {
                        var dstIndex = src * instanceCount + i;
                        managedComponentStore.SetManagedComponentValue(dstArray[dstIndex], component);
                    }
                }
            }
        }