Beispiel #1
0
 public PathControlledSprite(CurvePath curvePath, Texture2D textureImage, Vector2 position, Point frameSize,
     int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed, Vector2 centerPoint)
     : base(textureImage, position, frameSize, collisionOffset, currentFrame,
     sheetSize, speed, centerPoint)
 {
     curve = curvePath;
 }
Beispiel #2
0
 private void OnDisable()
 {
     EditorPrefs.SetInt("CurvePath.freezeAxis", mFreezeAxis);
     System.Array.Copy(caches, mPath.m_Points, caches.Length);
     mPath.RecalculateLater();
     mPath      = null;
     mPathTrans = null;
 }
//	private GameObject player;

    // Use this for initialization
    void Start()
    {
        curvePath       = FindObjectOfType <PathCreator>().curvePath;
        quadRoadCreator = FindObjectOfType <QuadRoadCreator>();
        //player = GameObject.FindGameObjectWithTag("Player");

        StartCoroutine(GenerateNextPoint());
    }
    // Use this for initialization
    void Start()
    {
        curvePath   = FindObjectOfType <PathCreator>().curvePath;
        roadCreator = FindObjectOfType <RoadCreator>();


        StartCoroutine(GenerateNextPoint());
    }
Beispiel #5
0
    public void ReleaseBall()
    {
        // Ran as an animation event

        // Apply throw force to the ball
        Quaternion towards = transform.rotation;

        if (target != null)
        {
            Transform rHand = animator.GetBoneTransform(HumanBodyBones.RightHand);
            towards = Quaternion.LookRotation(target.position - rHand.position);
        }
        Transform thrownBall = ikCatchController.caughtBall;

        ikCatchController.ReleaseCaughtBall();


        ThrownController ballThrownController = thrownBall.gameObject.AddComponent <ThrownController>() as ThrownController;

        Vector3   beginningPoint = thrownBall.position;
        Vector3   endPoint       = target.position;
        Vector3   direction      = endPoint - beginningPoint;
        Vector3   tmpPoint       = beginningPoint + direction * 0.9f;
        Vector3   controlPoint;
        ThrowPath throwPath = null;

        switch (throwPathState)
        {
        case ThrowPathState.Straight:
            throwPath = new StraightPath(beginningPoint, endPoint, throwSpeed);
            break;

        case ThrowPathState.CurveFromRight:
            controlPoint = tmpPoint + (Quaternion.AngleAxis(-90.0f, direction.normalized) * Vector3.up * 3);
            throwPath    = new CurvePath(beginningPoint, controlPoint, endPoint, throwSpeed);
            break;

        case ThrowPathState.CurveFromLeft:
            controlPoint = tmpPoint + (Quaternion.AngleAxis(90.0f, direction.normalized) * Vector3.up * 3);
            throwPath    = new CurvePath(beginningPoint, controlPoint, endPoint, throwSpeed);
            break;

        case ThrowPathState.CurveFromAbove:
            controlPoint = tmpPoint + (Quaternion.AngleAxis(0.0f, direction.normalized) * Vector3.up * 3);
            throwPath    = new CurvePath(beginningPoint, controlPoint, endPoint, throwSpeed);
            break;

        default:
            print("Unrecognized ThrowPathState");
            break;
        }
        ballThrownController.SetThrowPath(throwPath);

        RemoveTarget();

        throwState = ThrowState.None;
    }
Beispiel #6
0
    private void OnEnable()
    {
        creator = (PathCreator)target;
        if (creator.curvePath == null)
        {
            creator.CreatePath();
        }

        _curvePath = creator.curvePath;
    }
    public void UpdateRoad()
    {
        CurvePath curvePath = GetComponent <PathCreator>().curvePath;

        Vector2[] points = curvePath.CalculateEvenlySpacedPoints(spacing);
        GetComponent <MeshFilter>().mesh = CreateRoadMesh(points, curvePath.IsClosed);

        int textureRepeat = Mathf.RoundToInt(tiling * points.Length * spacing * 0.05f);

        GetComponent <MeshRenderer>().sharedMaterial.mainTextureScale = new Vector2(1, textureRepeat);
    }
Beispiel #8
0
        private void OnEnable()
        {
            mPath      = target as CurvePath;
            mPathTrans = mPath.transform;
            CheckTarget();

            caches = new Vector3[mPath.m_Points.Length];
            System.Array.Copy(mPath.m_Points, caches, caches.Length);

            mFreezeAxis = EditorPrefs.GetInt("CurvePath.freezeAxis");
        }
Beispiel #9
0
    // Use this for initialization
    void Start()
    {
        curvePath = FindObjectOfType <PathCreator>().curvePath;


        points = curvePath.CalculateEvenlySpacedPoints(movementSpacing, movementResolution);

        //foreach (Vector2 p in points)
        //{
        //	GameObject.Instantiate(roadLight, new Vector3(p.x, p.y, -1.0f), Quaternion.identity);

        //}
        StartCoroutine(UpdateEvenlySpacedPoints());
    }
Beispiel #10
0
    void Start()
    {
        curvePath = new CurvePath();
        curvePath.SetControlPoints(controlPoints);

        Vector3[] points = curvePath.GetResultPoints();

        for (int i = 0; i < points.Length; ++i)
        {
            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            sphere.transform.position   = points [i];
            sphere.transform.localScale = new Vector3(2, 2, 2);
            sphere.GetComponent <Renderer> ().material.color = Random.ColorHSV();
        }
    }
Beispiel #11
0
    private IEnumerator FollowPathRoutine(CurvePath path, float duration, Action callback)
    {
        _animator.applyRootMotion = true;

        float t = 0;

        while (t <= 1)
        {
            Vector3 prevPos = transform.localPosition;
            transform.position = path.EvaluatePosition(t);
            transform.rotation = path.EvaluateRotation(t);

            Vector3 moveDirection = transform.localPosition - prevPos;
            Vector3 lookDirection = transform.forward;

            // Animation
            ResetMovementAnimation();

            if (Vector3.Angle(lookDirection, moveDirection) < 90)
            {
                _animator.SetBool("IsMovingForward", true);
            }
            else
            {
                _animator.SetBool("IsMovingBackward", true);
            }

            t += Time.deltaTime / duration;

            yield return(null);
        }

        // Reset animation
        _animator.SetBool("IsMovingForward", false);
        _animator.SetBool("IsMovingBackward", false);

        _animator.applyRootMotion = false;

        callback?.Invoke();

        _followPathCoroutineInstance = null;
        _followingPath      = null;
        _followPathCallback = null;
    }
    public void UpdateRoad()
    {
        if (roadQuadsList.Count > 0)
        {
            for (int i = roadQuadsList.Count - 1; i >= 0; i--)
            {
                Destroy(roadQuadsList[i].gameObject);
            }
        }

        CurvePath curvePath = GetComponent <PathCreator>().curvePath;

        Vector2[] points = curvePath.CalculateEvenlySpacedPoints(spacing);

        for (int i = 1; i < points.Length; i++)
        {
            g = Instantiate(roadQuadPrefab, points[i], Quaternion.identity) as GameObject;
            g.transform.localScale = quadScale;
            roadQuadsList.Add(g);
            //g.transform.rotation = Quaternion.LookRotation( Vector3.forward, new Vector3(points[i-1].x,points[i-1].y,0));
        }
    }
Beispiel #13
0
    public void FollowPath(CurvePath path, float duration = -1, Action callback = null)
    {
        // Use real speed
        if (duration == -1)
        {
            duration = path.Length / _speed.Value;
        }

        // Disable manual movement
        _allowManualMovement = false;

        callback += () =>
        {
            _allowManualMovement = true;
        };

        // Reset animation
        ResetMovementAnimation();

        // Start following the path
        _followingPath               = path;
        _followPathCallback          = callback;
        _followPathCoroutineInstance = StartCoroutine(FollowPathRoutine(path, duration, callback));
    }
Beispiel #14
0
    private void OnSceneGUI()
    {
        if (curvePath == null)
        {
            curvePath = target as CurvePath;
        }

        for (int i = 0; i < curvePath.points.Length - 1; i++)
        {
            EditorGUI.BeginChangeCheck();
            Vector3 newTargetPosition = Handles.PositionHandle(curvePath.GetPoint(i), Quaternion.identity);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(curvePath, "Change Look At Target Position");
                curvePath.points[i] = curvePath.transform.InverseTransformPoint(newTargetPosition);

                if (i == 0)
                {
                    curvePath.points[curvePath.points.Length - 1] = curvePath.points[i];
                }
                curvePath.OnValidate();
            }
        }
    }
 public void OnEnable()
 {
     path = target as CurvePath;
 }
Beispiel #16
0
 void Awake()
 {
     path = (CurvePath)target;
 }
Beispiel #17
0
 public void setCurvePath(CurvePath path)
 {
     curve = path;
 }
Beispiel #18
0
 public void CreatePath()
 {
     curvePath = new CurvePath(transform.position);
 }