Esempio n. 1
0
	public DockableObject GetDockedObject ()
	{
		return dockedWith.GetComponentInParent<DockableObject> ();
	}
Esempio n. 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (isDockedToGradle)
        {
        }
        else if (isDockedToPayload)
        {
        }
        else if (isAlignedWithPort)
        {
            // Move to dock
            if (MoveTowardsPoint(targetPort.transform.position + targetPort.transform.forward * 0.6f))
            {
                dockingPorts [0].DockWith(targetPort);
                Joint joint = transform.gameObject.AddComponent <FixedJoint> ();
                joint.connectedBody = targetPort.GetComponentInParent <Rigidbody> ();
                if (dockingPorts [0].GetDockedObject().dockingPorts.Length == 1)
                {
                    // Docked at wall
                    Debug.Log("Docked at wall");
                    isDockedToGradle = true;
                }
                else
                {
                    // Docked at payload
                    Debug.Log("Docked with payload");
                    isDockedToPayload = true;
                    // Reset
                    isInFrontOfTargetPort = false;
                    isAlignedWithPort     = false;
                    isOnHighway           = false;
                }
            }
        }
        else if (isInFrontOfTargetPort)
        {
            // Align with target port
            Vector3 targetVector = targetPort.transform.position - transform.position;
            if (RotateToAlignWithForwardAndUp(targetVector, targetPort.transform.up))
            {
                // Aligned with port
                isAlignedWithPort = true;
                Debug.Log("Aligned with port");
            }
        }
        else if (isInRoomWithTarget)
        {
            // Move to port
            if (MoveTowardsPoint(targetPort.getDockingNearLocation()))
            {
                isInFrontOfTargetPort = true;
                Debug.Log("Arrived at target port");
            }
        }
        else if (isOnHighway)
        {
            // Move along highway
            PathNode nextHighwayNode = highwayPath.GetCurrentNode();
            if (MoveTowardsPoint(nextHighwayNode.transform.position))
            {
                // Arrived at node
                highwayPath.AdvanceToNextNode();
                nextHighwayNode = highwayPath.GetCurrentNode();
                if (nextHighwayNode == null)
                {
                    // Arrived in target room
                    isInRoomWithTarget = true;
                    targetPort         = targetDock.GetFreeDockingPort();
                    Debug.Log("Arrived in target room");
                }
            }
        }
        else
        {
            // Move to highway
            Vector3 highwayIntersection = game.GetClosestPathIntersection(transform.position);

            if (MoveTowardsPoint(highwayIntersection))
            {
                // Arrived on highway, calculate highway path
                isOnHighway = true;
                PathNode exitNode = game.GetClosestPathNodeToTargetPosition(targetDock.transform.position);
                highwayPath = game.GetPathToNode(transform.position, exitNode);
                Debug.Log("Arrived at highway, nodes to go: " + highwayPath.nodes.Length + ", first node: " + highwayPath.GetCurrentNode());
            }
        }
    }