コード例 #1
0
ファイル: NewLineCreateJob.cs プロジェクト: Sibz/Lines
        private void CreateLineJoinPoints(LineToolData data)
        {
            var lineObject    = EntityManager.GetComponentObject <EcsLineBehaviour>(data.LineEntity);
            var lineComponent = EntityManager.GetComponentData <Line>(data.LineEntity);

            lineObject.LineEntity = data.LineEntity;

            var direction = float3.zero;

            if (EntityManager.Exists(NewLineCreateEvent.FromJoinPointEntity))
            {
                direction = -EntityManager.GetComponentData <LineJoinPoint>(NewLineCreateEvent.FromJoinPointEntity)
                            .Direction;
            }

            lineComponent.JoinPointA = lineObject.EndNode1.JoinPoint =
                LineJoinPoint.New(data.LineEntity, NewLineCreateEvent.StartingPosition,
                                  direction);
            lineComponent.JoinPointB = lineObject.EndNode2.JoinPoint =
                LineJoinPoint.New(data.LineEntity, NewLineCreateEvent.StartingPosition,
                                  direction);

            EntityManager.SetComponentData(data.LineEntity, lineComponent);

            if (EntityManager.Exists(NewLineCreateEvent.FromJoinPointEntity))
            {
                LineJoinPoint.Join(NewLineCreateEvent.FromJoinPointEntity, lineObject.EndNode1.JoinPoint);
            }
        }
コード例 #2
0
        private void UpdateJoinPoints(Entity thisJoinEntity, JoinState joinState, Line otherLine)
        {
            var otherLineNonMergedJointPoint = LineJoinPoints[joinState == JoinState.AtoA ||
                                                              joinState == JoinState.BtoA
                                                                  ? otherLine.JoinPointB
                                                                  : otherLine.JoinPointA];

            // Un-join other line (it will be destroyed)
            // TODO Check back here as this may be done on destroy other line
            LineJoinPoint.UnJoinIfJoined(Ecb, index, LineJoinPoints, otherLine.JoinPointA);
            LineJoinPoint.UnJoinIfJoined(Ecb, index, LineJoinPoints, otherLine.JoinPointB);

            // Mirror other join
            var thisJoin = otherLineNonMergedJointPoint;

            // Except parent entity
            thisJoin.ParentEntity = lineEntity;
            if (thisJoin.IsJoined)
            {
                LineJoinPoint.Join(Ecb, index, LineJoinPoints,
                                   thisJoinEntity,
                                   thisJoin.JoinToPointEntity,
                                   true, thisJoin);
            }
            else
            {
                Ecb.SetComponent(index, thisJoinEntity, thisJoin);
            }
        }
コード例 #3
0
        public void Execute(int index)
        {
            var eventData = EventData[index];

            if (!eventData.UpdateJoinPoints)
            {
                return;
            }

            var joinData = LineJoinPoints[index];
            var line     = Lines[eventData.LineEntity];

            // Are we trying to update this join to the same join
            // as the other join, AKA joining both ends to the same join point
            // This would be invalid so don't join in this case
            var thisJoinPoint = eventData.JoinPoint == line.JoinPointA
                                    ? joinData.A
                                    : joinData.B;
            var otherJoinPoint = eventData.JoinPoint == line.JoinPointA
                                     ? joinData.B
                                     : joinData.A;
            var otherEndIsJoinedToRequestedJoinToPoint =
                otherJoinPoint.JoinToPointEntity == eventData.JoinTo;

            thisJoinPoint.Pivot = eventData.Position;

            var newJoinPoint = JoinPoints.Exists(eventData.JoinTo)
                                   ? JoinPoints[eventData.JoinTo]
                                   : default;

            if (eventData.JoinTo != Entity.Null &&
                !otherEndIsJoinedToRequestedJoinToPoint)
            {
                thisJoinPoint.Direction         = -newJoinPoint.Direction;
                thisJoinPoint.JoinToPointEntity = eventData.JoinTo;
                newJoinPoint.JoinToPointEntity  = eventData.JoinPoint;
                /*Ecb.SetComponent(index, eventData.JoinPoint, thisJoinPoint);*/
                Ecb.SetComponent(index, eventData.JoinTo, newJoinPoint);
            }
            else if (eventData.JoinTo == Entity.Null && thisJoinPoint.IsJoined)
            {
                // We assume here that no JoinTo data means we don't want to join
                // This should always be the case

                var joinedToPoint = JoinPoints[thisJoinPoint.JoinToPointEntity];
                LineJoinPoint.UnJoin(Ecb, index, ref thisJoinPoint, ref joinedToPoint);
            }

            /*else
             * {
             *  //Ecb.SetComponent(index, eventData.JoinPoint, thisJoinPoint);
             * }*/

            joinData.A = eventData.JoinPoint == line.JoinPointA
                                      ? thisJoinPoint
                                      : otherJoinPoint;
            joinData.B = eventData.JoinPoint == line.JoinPointA
                                      ? otherJoinPoint
                                      : thisJoinPoint;
            LineJoinPoints[index] = joinData;
        }