コード例 #1
0
 private void Reset()
 {
     _rope             = null;
     _serializedObject = null;
     _profile          = null;
     _polygon          = null;
 }
コード例 #2
0
    /*Summary of the rope generation:
     * 1. We get the array of platforms, and our 2D int array that stores our platform tiles
     * 2. We now iterate through each platform to make a rope
     * 3. We then iterate through the 2D array to check for an intersection with a platform
     * 4. If there is no intersection, or the vertical test position is outside the array,
     *      then the length of the rope is maxRopeLength, and the rope is added to the array of ropes
     * 5. If there is an intersection, the rope of the length is set to the number of iterations
     *      needed to reach that intersect point, and the rope is added to the array of ropes
     * 6. The function returns a new array of platforms, now with ropes added
     */

    private static PlatformBase[] GenerateRopes(PlatformBase[] platforms, int[,] level)
    {
        PlatformBase[] addRopes = platforms;

        int maxRopeLength = 100;

        foreach (PlatformBase pb in addRopes)
        {
            int ropes = 1;

            pb.Ropes = new RopeBase[ropes];

            for (int r = 0; r < ropes; r++)
            {
                int xRopePos = Random.Range(0, pb.Width);

                //iterate through the level array vertically
                for (int i = 1; i <= maxRopeLength; i++)
                {
                    int xPos = xRopePos + (int)pb.Pivot.x;
                    int yPos = (int)pb.Pivot.y - i;

                    //if we are at the bottom of the array, set the rope length to the max rope length
                    if (yPos <= 0)
                    {
                        RopeBase rb = new RopeBase(xRopePos, maxRopeLength);

                        pb.Ropes [r] = rb;

                        break;
                    }

                    //if we are anywhere else, do the following test
                    if (level [xPos, yPos] == 1)
                    {
                        //hit tile, rope length = i, exit

                        RopeBase rb = new RopeBase(xRopePos, i - 1);

                        pb.Ropes [r] = rb;

                        break;
                    }

                    //if we still haven't hit anything, the rope length is the maxRope length
                    if (i == maxRopeLength)
                    {
                        RopeBase rb = new RopeBase(xRopePos, maxRopeLength);

                        pb.Ropes [r] = rb;
                    }
                }
            }
        }

        return(addRopes);
    }
コード例 #3
0
 public void SetupRope(RopeBase rope)
 {
     _serializedObject = new SerializedObject(rope);
     _rope             = rope;
     if (_view != null)
     {
         _view.Symbols.Clear();
     }
     SetPolygon();
 }
コード例 #4
0
 void OnEnable()
 {
     //Tools.hidden = true;
     _texture = new RenderTexture(1000, 100, 16, RenderTextureFormat.ARGB32);
     _rope    = (RopeBase)target;
     if (_rope == null)
     {
         return;
     }
     _isPrefab = PrefabUtility.GetPrefabType(_rope) == PrefabType.Prefab;
 }
コード例 #5
0
ファイル: CutRopeManager.cs プロジェクト: CarpeDMT/TimeTape
    public void Rope_ObjectWrapping(RopeBase sender, ObjectWrapEventArgs args)
    {
        if (args.WrapPoints.Length == 0)
        {
            return;
        }

        var newRope = Instantiate(RopeInstance1).GetComponent <Rope>();

        _ropes.Add(newRope);

        // Don't want to wrap
        args.Cancel = true;

        // Set new rope ends
        newRope.FrontEnd.transform.position = args.WrapPoints[0];
        newRope.BackEnd.transform.position  = _sourceRope.BackEnd.transform.position;
        // Refresh piece ends positions by rope ends from previous two lines. The rope has only one piece. FrontBandPoint corresponds the FrontEnd. BackBandPoint corresponds the BackEnd.
        newRope.FrontPiece.FrontBandPoint.SetPointInWorldSpace(0f);
        newRope.FrontPiece.BackBandPoint.SetPointInWorldSpace(0f);
        // Call the method below to recalculate length
        newRope.FrontPiece.Relocate();
        // Setting Anchoring mode will constrain current rope length
        newRope.AnchoringMode = AnchoringMode.ByFrontEnd;

        // Temporary off anchoring mode
        _sourceRope.AnchoringMode = AnchoringMode.None;
        // Use native function to shrink the rope
        _sourceRope.CutRopeNotAnchoring((args.WrapPoints[0] - _sourceRope.BackEnd.transform.position).magnitude, Direction.BackToFront);
        // Need to call this method to reset previouse position of piece and stabilize the rope
        _sourceRope.FrontPiece.Relocate();
        // Set anchoring mode to accept new length of rope
        _sourceRope.AnchoringMode = AnchoringMode.ByFrontEnd;

        var projectile      = args.Target.GetComponent <Rigidbody>();
        var projectileVeloc = projectile.GetPointVelocity(args.Target.transform.position).magnitude *(args.WrapPoints[0] - args.Target.transform.position);
        var weigh           = _sourceRope.BackEnd.GetComponent <Rigidbody>();

        weigh.AddForce(projectileVeloc * 2, ForceMode.VelocityChange);
        weigh = newRope.FrontEnd.GetComponent <Rigidbody>();
        weigh.AddForce(projectileVeloc * 4, ForceMode.VelocityChange);
    }