Ejemplo n.º 1
0
 public override void _Process(float delta)
 {
     if (shouldCalcNew && ((int)walkedDistance < (int)(walkedDistance + delta * MovementSpeed) || path == null))
     {
         shouldCalcNew = false;
         float  gridSize = this.grid3d.GetGridSize();
         PointI nextGrid = new PointI((int)(Translation.x / gridSize), (int)(Translation.z / gridSize));
         if (pathFinder.FindPath(out points, nextGrid))
         {
             if (points.Length > 1)
             {
                 path = new SplinePath(points, grid3d.GetGridSize(), InterpolationType.Qubic);
             }
             Blocked = false;
             exclamationInst.Visible = false;
         }
         else
         {
             Blocked                 = true;
             path                    = null;
             walkedDistance          = 0;
             exclamationInst.Visible = true;
         }
         walkedDistance = 0;
     }
     if (path != null)
     {
         Vector2 pos = path.GetPoint(walkedDistance);
         walkedDistance  += delta * MovementSpeed;
         this.Translation = new Vector3(pos.x, 0, pos.y);
     }
 }
Ejemplo n.º 2
0
    private void Awake()
    {
        if (spline == null)
        {
            spline = GetComponent <SplinePath>();
        }

        spline.OnPathChanged -= Path_OnPathChanged;
    }
Ejemplo n.º 3
0
 // Called when the node enters the scene tree for the first time.
 public override void _Ready()
 {
     path           = null;
     walkedDistance = 0;
     if (excplamation == null)
     {
         excplamation = GD.Load <PackedScene>("res://Scenes/Objects/Exclamation.tscn");
     }
     exclamationInst = (Spatial)excplamation.Instance();
     AddChild(exclamationInst);
     exclamationInst.Visible = false;
 }
Ejemplo n.º 4
0
 void OnDrawGizmos()
 {
     #if UNITY_EDITOR
     SplinePath parent = GetComponentInParent <SplinePath>();
     if (parent != null)
     {
         Color col     = Gizmos.color;
         Color pathCol = parent.editorColor;
         Gizmos.color = (UnityEditor.Selection.gameObjects != null && UnityEditor.Selection.gameObjects.Contains(gameObject)) ? pathCol : new Color(pathCol.r, pathCol.g, pathCol.b, pathCol.a * 0.25f);
         Gizmos.DrawCube(transform.position, transform.localScale * 0.05f);
         Gizmos.color = col;
     }
     #endif
 }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        splinePath = GetComponent<SplinePath>();
        nodes = splinePath.GetSplinePath();

        //		lineRenderer = GetComponent<LineRenderer>();
        //
        //		if (lineRenderer != null) {
        //			lineRenderer.SetVertexCount(Mathf.FloorToInt(splinePath.GetNodeCount()));
        //		}

        GenerateSmoke();
        //		int numParticles = (splinePath.GetNodeCount() / splinePath.betweenNodeCount) * 10;
        //		for (int i = 0; i < splinePath.GetNodeCount(); i++) {
        //			GameObject g = Instantiate(smokePrefab,
        //		}
    }
Ejemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        SplinePath splinePath = (SplinePath)target;

        DrawDefaultInspector();
        GUILayout.Space(10);
        GUILayout.Label("Splines in CHAR SLBs have times of zero.");
        if (GUILayout.Button("Set Point Times to Zero"))
        {
            splinePath.SetTimesToZero();
        }
        GUILayout.Space(10);
        GUILayout.Label("Splines in SPLINE SLBs have incremental\ntimes.");
        if (GUILayout.Button("Set Point Times Incrementally"))
        {
            splinePath.SetTimesIncrementally();
        }
        GUILayout.Space(10);
        GUILayout.Label("Splines in CAM SLBs have times calculated\nbased on the length of the spline, but\ncalculating that *properly* would require\nthings I haven't gotten around to doing yet.\nThe button below can give you close-ish\nresults though. I just wouldn't recommend\ndoing it on existing camera splines unless\nyou REALLY want to, cause it'll be making\nthem slightly wrong.");
        if (GUILayout.Button("Yes I actually wanna do that"))
        {
            splinePath.SetTimesToNotQuiteRightButCloseEnoughValuesForCams();
        }
    }
 void OnEnable()
 {
     creator  = (PathCreator)target;
     path     = creator.path ?? creator.CreatePath();
     property = serializedObject.FindProperty("path");
 }
Ejemplo n.º 8
0
 public void AddPaths(SplinePath newPath)
 {
     pipePath = newPath;
     SetPipeReady();
 }
Ejemplo n.º 9
0
    public void BuildMesh()
    {
        if (spline == null)
        {
            spline = GetComponent <SplinePath>();
        }

        mf = GetComponent <MeshFilter>();

        meshCollider = GetComponent <MeshCollider>();
        if (meshCollider == null)
        {
            meshCollider = gameObject.AddComponent <MeshCollider>();
        }

        if (mf && spline)
        {
            if (mf.sharedMesh != null)
            {
                DestroyImmediate(mf.sharedMesh);
            }

            if (mesh == null)
            {
                mesh = new Mesh();
            }

            verts.Clear();
            indices.Clear();
            normals.Clear();

            Vector3 lastPos = spline.GetPoint(0f);

            List <float> iters = new List <float>();
            iters.Add(0f);

            float iter = 0f;
            while (iter < 1f)
            {
                float moveDist = spacing;
                while (moveDist > 0f && iter < 1f)
                {
                    float prevIter = iter;
                    iter += alphaIter;
                    iter  = Mathf.Clamp01(iter);

                    Vector3 pos       = spline.GetPoint(iter);
                    Vector3 toPos     = pos - lastPos;
                    float   toPosDist = toPos.magnitude;

                    if (toPosDist < moveDist)
                    {
                        moveDist -= toPosDist;
                        lastPos   = pos;
                    }
                    else
                    {
                        float alpha = toPosDist / moveDist;
                        iter    = Mathf.Lerp(prevIter, iter, alpha);
                        lastPos = Vector3.Lerp(lastPos, pos, alpha);

                        iters.Add(iter);

                        moveDist = 0f;
                    }
                }
            }

            iters[iters.Count - 1] = 1f;

            for (int i = 0; i < iters.Count; i++)
            {
                AddSideFaces(iters[i], i);
            }

            if (arcAmount < 1f)
            {
                for (int i = 0; i < iters.Count; i++)
                {
                    AddTopFace(iters[i], i);
                }
            }

            AddFrontBackFaces(iters[0], 0);
            AddFrontBackFaces(iters[iters.Count - 1], iters.Count - 1);

            mesh.SetVertices(verts);
            mesh.SetTriangles(indices, 0);
            mesh.SetNormals(normals);

            mf.sharedMesh           = mesh;
            meshCollider.sharedMesh = mesh;

            OnMeshChanged(this);
        }
    }
Ejemplo n.º 10
0
    public void Move(Vector2 amount)
    {
        //if (!onMovingPlatform)
        //amount.y -= gravity * Time.deltaTime;
        moveDelta = amount;

        // get the collider's center anchor
        anchor.x = cacheTransform.position.x + center.x;
        anchor.y = cacheTransform.position.y + center.y;

        // get the player's direction
        float dirY = Mathf.Sign(moveDelta.y);
        float dirX = Mathf.Sign(moveDelta.x);

        grounded = false;

        // check for floor collisions
        for (int i = 1; i >= -1 ; i--) {
            // get the point at the bottom-right, bottom-center, and bottom-left portions
            // (relative to the player's direction, set as the z-axis)
            // of the collider, and draw downward rays from each of them
            rayPoint = cacheTransform.position + (dirX * i * cacheTransform.forward * bounds.extents.x);
            //rayPoint.y = anchor.y + bounds.extents.y * dirY;
            rayPoint.y = anchor.y;

            ray = new Ray(rayPoint, cacheTransform.up * dirY);

            magnitude = Mathf.Abs(bounds.extents.y) + Mathf.Abs(moveDelta.y) + SKIN;

            // draw colorful rays lol
            // the red-colored ray must be at the front side of the player!
            if (i == 1)
                Debug.DrawRay(rayPoint, cacheTransform.up * dirY * magnitude, Color.red);
            if (i == 0)
                Debug.DrawRay(rayPoint, cacheTransform.up * dirY * magnitude, Color.green);
            if (i == -1)
                Debug.DrawRay(rayPoint, cacheTransform.up * dirY * magnitude, Color.blue);

            if (Physics.Raycast(ray, out hit, magnitude, collisionMask)) {

                distance = boxCollider.ClosestPointOnBounds(hit.point).y - hit.point.y;
                //Debug.Log("Distance: " + distance);
                releaseTimer = 0;

                if (hit.transform.CompareTag(JUNCTION_START_TAG)) {
                    onJunction = true;
                } else if (hit.transform.CompareTag(JUNCTION_END_TAG)) {
                    onJunction = false;
                }

                if (hit.transform.CompareTag(GLUED_TAG)) {
                    canJump = false;
                } else {
                    canJump = true;
                }

                if (hit.transform.CompareTag(MOVINGPLATFORM_TAG)) {
                    if (hit.transform != cacheTransform.parent && !onMovingPlatform) {
                        cacheTransform.parent = hit.transform;
                        onMovingPlatform = true;
                    }
                } else {
                    if (onMovingPlatform) {
                        cacheTransform.parent = null;
                        onMovingPlatform = false;
                    }
                }

                // check if the distance is within skin-width.
                // if so, consider that a collision has occured.
                if (distance > SKIN) {
                    moveDelta.y = (distance - SKIN) * dirY;
                } else {
                    moveDelta.y = 0;
                }

                grounded = true;
                break;
            } else {
                releaseTimer += ignoreTimeScale? RealTime.realDeltaTime : Time.deltaTime;
                if (onMovingPlatform && releaseTimer >= RELEASE_TIME) {
                    cacheTransform.parent = null;
                    onMovingPlatform = false;
                    releaseTimer = RELEASE_TIME;
                }
            }
        }

        if (distance < 0) {
            moveDelta.y = (distance + SKIN) * -dirY;
        }

        // check for wall collisions
        blocked = false;

        for (int i = 1; i >= -1; i--) {
            // get the point at the bottom-right, center-right, and top-right portions
            // of the collider, and draw forward rays from each of them
            rayPoint = cacheTransform.position;
            rayPoint.y = anchor.y + bounds.extents.y * i;

            ray = new Ray(rayPoint, cacheTransform.forward * dirX);
            magnitude = Mathf.Abs(bounds.extents.x) + Mathf.Abs(moveDelta.x) + SKIN;

            Debug.DrawRay(rayPoint, cacheTransform.forward * dirX * magnitude);

            if (Physics.Raycast(ray, out hit, magnitude, collisionMask)) {

                distance = boxCollider.ClosestPointOnBounds(hit.point).x - hit.point.x;

                // check if the distance is within skin-width.
                // if so, consider that a collision has occured.
                if (distance > SKIN) {
                    moveDelta.x = (distance - SKIN) * dirX;
                } else {
                    moveDelta.x = 0;
                }

                blocked = true;
                break;
            }
        }

        // check for spline paths
        rayPoint = cacheTransform.position;
        rayPoint.y = anchor.y;

        ray = new Ray(rayPoint, cacheTransform.up * dirY);
        magnitude = Mathf.Abs(bounds.extents.y) + Mathf.Abs(moveDelta.y) + SKIN;
        Debug.DrawRay(rayPoint, cacheTransform.up * dirY * magnitude, Color.yellow);

        if (Physics.Raycast(ray, out hit, magnitude * 2, collisionMask)) {
            // check if player is on a spline path
            // if it is, set it on rails
            if (hit.transform.tag.Contains(SPLINE_TAG) && !onJunction) {
                if (!railed) {
                    railed = true;
                    splinePathComponent = hit.transform.parent.GetComponent<SplinePath>();
                    splinePath = splinePathComponent.GetSplinePathArray();

                    // set appropriate starting index based on entry point
                    if (hit.transform.CompareTag(SPLINE_START_TAG)) {
                        splineIndex = 0;
                        splinePosition = Vector3.Distance(splinePath[0], hit.point) * SPLINE_FACTOR;
                    } else if (hit.transform.CompareTag(SPLINE_END_TAG)) {
                        splineIndex = splinePath.Length - 1;
                        splinePosition = splinePathComponent.arcLength -
                                Vector3.Distance(hit.point, splinePath[splineIndex]) * SPLINE_FACTOR;
                    }

                    Debug.Log ("Spline!");
                }

            } else {
                // remove spline path reference
                if (railed) {
                    railed = false;
                    splinePath = null;
                    cacheTransform.forward = hit.transform.right;
                    Debug.Log ("No Spline...");
                }
            }
        }

        // make player follow the spline path, if it's on one
        if (railed) {
            splinePosition += moveDelta.x;
            Vector3 newPosition;
            int oldIndex = splineIndex;

            // map linear position to position on the spline path
            splineIndex = Mathf.FloorToInt(
                Mathf.Clamp01(splinePosition * splinePathComponent.inverseArcLength) * (splinePath.Length));

            if (splineIndex < splinePath.Length) {
                newPosition = splinePath[splineIndex];
                newPosition.y = cacheTransform.position.y;
                cacheTransform.LookAt(newPosition);

                if (splineIndex < oldIndex) {
                    cacheTransform.forward = -cacheTransform.forward;
                }

                cacheTransform.position = newPosition;
            }
        } else {
            cacheTransform.Translate(0, moveDelta.y, moveDelta.x);
        }
    }
Ejemplo n.º 11
0
 /// <summary>
 /// Setups source SplineMesh and destined SplinePath components for mesh generation.
 /// </summary>
 public void Setup(SplineMesh splineMesh, SplinePath splinePath)
 {
     this.splineMesh = splineMesh;
     this.splinePath = splinePath;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MeshJobExecutor"/> class.
 /// </summary>
 /// <param name="splineMesh">SplineMesh component for getting parameters for mesh generation.</param>
 /// <param name="splinePath">SplinePath object for keeping parameters for mesh generation.</param>
 public MeshJobExecutor(SplineMesh splineMesh, SplinePath splinePath)
 {
     Setup(splineMesh, splinePath);
 }
Ejemplo n.º 13
0
 void OnEnable()
 {
     path = (SplinePath)target;
 }
Ejemplo n.º 14
0
 void Awake()
 {
     path = GetComponent <SplinePath>();
 }
Ejemplo n.º 15
0
 void Awake()
 {
     path = GetComponent<SplinePath>();
 }
Ejemplo n.º 16
0
 public SplinePath CreatePath()
 {
     return(path = new SplinePath(Vector2.zero));
 }