Beispiel #1
0
    public void Step()
    {
        ValidateCurrentCell();

        if (path == null || path.points.Count == 0)
        {
            return;
        }

        float distance = Vector3.Distance(path.points[currentWayPointID], transform.position);

        transform.position = Vector3.MoveTowards(transform.position, path.points[currentWayPointID], Time.deltaTime * TravelSpeed);

        // rotation?
        //var rotation = Quaternion.LookRotation(path.points[currentWayPointID] - transform.position);
        //transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);

        if (distance <= reachDistance)
        {
            currentWayPointID++;
        }

        if (currentWayPointID >= path.points.Count)
        {
            path = null;
            currentWayPointID = 0;
            OnTravelOver?.Invoke();
        }
    }
Beispiel #2
0
    public Moving(Unit unit, List <HexCell> pathToTravel) : base(unit)
    {
        Vector3Path vectorPath = Vector3Path.CreateFromHexPath(pathToTravel);

        unit.Traveller.TravelVectorPath(vectorPath);
        unit.Traveller.OnTravelOver += unit.Stop;

        CheckForSpriteFlip(unit, pathToTravel[pathToTravel.Count - 1].Position);
        animator.SetBool("isMoving", true);
    }
    public bool CreatePathFromChildren()
    {
        if (nameOfPath == "")
        {
            Debug.LogError("No name set for path to be generated by " + gameObject.name);
            Selection.activeGameObject = this.gameObject;
            return(false);
        }

        int childrenAmount = transform.childCount;

        if (childrenAmount == 0)
        {
            Debug.LogError("Path needs at least one position " + gameObject.name);
            Selection.activeGameObject = this.gameObject;
            return(false);
        }

        Vector3Path newPathObject = ScriptableObject.CreateInstance <Vector3Path>();

        Vector3[] newPath = new Vector3[childrenAmount];

        for (int i = 0; i < childrenAmount; i++)
        {
            newPath[i] = localCoordinates ? localToTransform.InverseTransformPoint(transform.GetChild(i).position) : transform.GetChild(i).position;
        }

        string      filePath   = "Assets/Scripts/ScriptableObjects/Vector3Paths/" + nameOfPath + (localCoordinates ? "Local" : "World") + ".asset";
        Vector3Path assetCheck = AssetDatabase.LoadAssetAtPath <Vector3Path>(filePath);

        if (assetCheck != null)
        {
            assetCheck.path             = newPath;
            assetCheck.localCoordinates = localCoordinates;
            Debug.LogWarning("Override of existing path");
            Selection.activeObject = assetCheck;
        }
        else
        {
            newPathObject.path             = newPath;
            newPathObject.localCoordinates = localCoordinates;
            AssetDatabase.CreateAsset(newPathObject, filePath);
            Debug.LogWarning("New path created");
            Selection.activeObject = newPathObject;
        }

        return(true);
    }
Beispiel #4
0
    public static Vector3Path CreateFromHexPath(List <HexCell> hexPath)
    {
        Vector3Path vectorPath = new Vector3Path();

        //foreach (HexCell cell in hexPath)
        //{
        //    vectorPath.points.Add(cell.Position);
        //}

        vectorPath.points.Add(hexPath[0].Position);

        for (int i = 0; i < hexPath.Count - 1; i++)
        {
            Vector3 betweenEdges = (hexPath[i].Position + hexPath[i + 1].Position) * 0.5f;
            vectorPath.points.Add(betweenEdges);
        }
        vectorPath.points.Add(hexPath[hexPath.Count - 1].Position);

        return(vectorPath);
    }
Beispiel #5
0
 public static Tweener <float, Transform> tweenTransformByPath(
     this Transform t, float from, float to, Vector3Path path, Ease ease, float duration
     ) => a(TweenOps.float_.tween(from, to, false, ease, duration), t, TweenMutators.path(path));
Beispiel #6
0
 public static TweenMutator <float, Transform> path(Vector3Path path) =>
 (percentage, transform, relative) => {
     var point = path.evaluate(percentage, constantSpeed: true);
     transform.position = point;
 };
Beispiel #7
0
 public void TravelVectorPath(Vector3Path pathToTravel)
 {
     path = pathToTravel;
     currentWayPointID = 0;
 }