Esempio n. 1
0
 public void UIPointer(ModuleBMRail moduleBlockMover)
 {
     blockMoverPointer = moduleBlockMover;
     if (blockMoverPointer != null)
     {
         blockMoverPointer.block.DetachEvent.Subscribe(ClearPointer);
     }
 }
Esempio n. 2
0
 public void ClearPointer(ModuleBMRail moduleBlockMover)
 {
     if (blockMoverPointer == moduleBlockMover)
     {
         blockMoverPointer.block.DetachEvent.Unsubscribe(ClearPointer);
         blockMoverPointer = null;
     }
 }
Esempio n. 3
0
        public float AddToAnimCurves(Quaternion cachedLocalRot, ModuleBMRail target, float length, ref Quaternion lastRot, AttachPoint otherAP, float weight)//, ref Vector4 vrot)//ref Quaternion rotation)
        {
            int Mod   = target.PartCount * 3;
            int rMod  = target.PartCount * 4;
            var x     = target.posCurves[Mod - 3];
            var y     = target.posCurves[Mod - 2];
            var z     = target.posCurves[Mod - 1];
            var rx    = target.rotCurves[rMod - 4];
            var ry    = target.rotCurves[rMod - 3];
            var rz    = target.rotCurves[rMod - 2];
            var rw    = target.rotCurves[rMod - 1];
            int Ind   = x.length - 1;
            var xLast = x[Ind];
            var yLast = y[Ind];
            var zLast = z[Ind];

            target.TrueLimitVALUE += AnimLength;
            length += AnimLength;

            var change  = cachedLocalRot * AnimPosChange;
            var tangent = cachedLocalRot * Tangent;

            x.AddKey(new Keyframe(xLast.time + 0.01f, xLast.value, xLast.outTangent, xLast.outTangent, weight, weight));
            y.AddKey(new Keyframe(yLast.time + 0.01f, yLast.value, yLast.outTangent, yLast.outTangent, weight, weight));
            z.AddKey(new Keyframe(zLast.time + 0.01f, zLast.value, zLast.outTangent, zLast.outTangent, weight, weight));

            x.AddKey(new Keyframe(length, xLast.value + change.x, tangent.x, tangent.x, weight, weight));
            y.AddKey(new Keyframe(length, yLast.value + change.y, tangent.y, tangent.y, weight, weight));
            z.AddKey(new Keyframe(length, zLast.value + change.z, tangent.z, tangent.z, weight, weight));

            lastRot = Quaternion.RotateTowards(lastRot, Quaternion.LookRotation(cachedLocalRot * otherAP.apDirUp, cachedLocalRot * otherAP.apDirForward), 90);

            rx.AddKey(new Keyframe(length, lastRot.x, 0f, 0f, 0f, 0f));
            ry.AddKey(new Keyframe(length, lastRot.y, 0f, 0f, 0f, 0f));
            rz.AddKey(new Keyframe(length, lastRot.z, 0f, 0f, 0f, 0f));
            rw.AddKey(new Keyframe(length, lastRot.w, 0f, 0f, 0f, 0f));

            return(length);
        }
Esempio n. 4
0
 public void ClearPointer()
 {
     TryUnsubscribeFromPointer();
     blockMoverPointer = null;
 }
Esempio n. 5
0
        internal override bool CanStartGetBlocks(BlockManager blockMan)
        {
            ClearSegmentList();          // Remove pointers to this block

            foreach (var m in posCurves) // Clear position animation
            {
                m.keys = new Keyframe[1] {
                    new Keyframe(0f, 0f, 0f, 0f, 0f, 0f)
                }
            }
            ;
            foreach (var m in rotCurves) // Clear rotation animation
            {
                m.keys = new Keyframe[1] {
                    new Keyframe(0f, 0f, 0f, 0f, 0f, 0f)
                }
            }
            ;

            Quaternion TravelQuat = Quaternion.identity;
            //Vector3 TravelRot = Vector3.zero;
            OrthoRotation OriginalRot        = block.cachedLocalRotation;
            float         Length             = starterAnim.AddToAnimCurves(OrthoRotation.identity, this, 0f, ref TravelQuat, starterAnim, 0f);//, ref TravelQuat);//, ref TravelRot);
            float         prevTrueLimitVALUE = TrueLimitVALUE;

            TrueLimitVALUE = 0f;

            TankBlock   LastBlock = block;
            AttachPoint LastAP    = starterAnim; //For grabbing the block at the next position

            TankBlock Segment = LastAP.GetBlockAtPos(LastBlock, blockMan);

            while (Segment != null)
            {
                Print(">> Found block " + Segment.cachedLocalPosition);
                ModuleBMSegment component = Segment.GetComponent <ModuleBMSegment>();
                if (component == null) // Not a rail segment
                {
                    Print("   Not a segment");
                    ModuleBMRail opposer = Segment.GetComponent <ModuleBMRail>();
                    if (opposer == null || !LastAP.CanConnect(LastBlock, Segment, opposer.starterAnim)) // Not an opposing rail, or not sharing
                    {
                        break;
                    }
                    // Cut shared rail in half to prevent overlap
                    Print("   Is another head!");
                    CutSegmentListInHalf();
                    TrueLimitVALUE = HalfLimitVALUE - 0.5f; // Move back .5 for block-room on the AP
                    break;
                }

                if (component.blockMoverHeadType != m_thisHeadType)//component.blockMoverHeadType.Contains(m_thisHeadType))
                {
                    Print("   Wrong rail type!");
                    break; // A different rail system
                }

                var _Segment = Segment;
                Segment = null; // Nullify this, if not re-set it will break the loop

                for (int i = 0; i < 2; i++)
                {
                    if (LastAP.CanConnect(LastBlock, _Segment, component.APs[i]))
                    {
                        m_Segments.Add(component);
                        LastBlock = _Segment;
                        LastAP    = component.APs[1 - i];

                        Length  = component.APs[i].AddToAnimCurves(Quaternion.Inverse(OriginalRot) * _Segment.cachedLocalRotation, this, Length, ref TravelQuat, LastAP, component.AnimWeight); //, ref TravelQuat);//, ref TravelRot);
                        Segment = LastAP.GetBlockAtPos(_Segment, blockMan);                                                                                                                     // Set the new segment, continue

                        Print("   Connected!");
                        break; // Exit the foreach
                    }
                }
                if (Segment == null)
                {
                    Print(">> No more blocks");
                }
            }

            //if (TrueLimitVALUE == 0f) TrueLimitVALUE = 0.25f;
            ValidateSegmentList(out bool DisableFreeJoint);

            CannotBeFreeJoint = true;//DisableFreeJoint;

            if (MAXVALUELIMIT >= TrueLimitVALUE)
            {
                SetMaxLimit(TrueLimitVALUE);
                if (PVALUE > TrueLimitVALUE)
                {
                    PVALUE = TrueLimitVALUE;
                }
                if (VALUE > TrueLimitVALUE)
                {
                    VALUE = TrueLimitVALUE;
                }
            }
            else if (prevTrueLimitVALUE == 0f || MAXVALUELIMIT == prevTrueLimitVALUE || !UseLIMIT)
            {
                SetMaxLimit(TrueLimitVALUE);
            }

            return(true);
        }