コード例 #1
0
        public List <ComponentOperation> GetEditableComponents()
        {
            var editableComponents = new List <ComponentOperation>();

            var archetype = GetArchetypeComponents();

            // TODO: deactivated until node is split between Duplicate and Instantiate
//            foreach (var component in archetype)
//                editableComponents.Add(new ComponentOperation(component, ComponentOperationType.SetComponent, true));

            foreach (var additionalComponent in m_AdditionalComponents)
            {
                var duplicateIndex = editableComponents.FindIndex(comp => comp.Type == additionalComponent.Type);

                //Since we want to preserve the operations in case the archetype Adds/Removes components
                //This will make sure we override whatever operation was in the initial archetype (which is a set/remove)
                if (duplicateIndex != -1)
                {
                    editableComponents[duplicateIndex] = new ComponentOperation(additionalComponent.Type, additionalComponent.OperationType, true);
                }
                else
                {
                    editableComponents.Add(additionalComponent);
                }
            }
            return(editableComponents);
        }
コード例 #2
0
        public void SetComponentOperation(TypeHandle type, ComponentOperationType operation)
        {
            var i = m_AdditionalComponents.FindIndex(compOps => compOps.Type == type);

            if (i == -1)
            {
                m_AdditionalComponents.Add(new ComponentOperation(type, operation));
            }
            else if (operation == ComponentOperationType.AddComponent ||
                     operation == ComponentOperationType.RemoveComponent ||
                     operation == ComponentOperationType.SetComponent)
            {
                m_AdditionalComponents[i] =
                    new ComponentOperation(type, operation, m_AdditionalComponents[i].FromArchetype);
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(operation), operation, null);
            }
        }