Пример #1
0
    public void Unmoor(Moorable moorable)
    {
        Debug.AssertFormat(dockedShips.Contains(moorable), 
            "tried to unmoor {0} from {1} but it's not moored here",
                moorable,
                gameObject);

        dockedShips.Remove(moorable);
        dockedTraffic.RemoveAll(t => t.Ship.Moorable == moorable);

        Transform undockPoint;
        if (undockPoints.Count == 0)
        {
            undockPoint = mooringTrigger.transform;
        }
        else
        {
            undockPoint = undockPoints[UnityEngine.Random.Range(0, undockPoints.Count)];
        }

        moorable.transform.position = undockPoint.position;
        moorable.transform.rotation = undockPoint.rotation;

        var rigidBody = moorable.GetComponent<Rigidbody>();
        if (rigidBody)
        {
            rigidBody.angularVelocity = Vector3.zero;
            rigidBody.velocity = Vector3.zero;
        }

        var ship = moorable.GetComponent<Ship>();
        if (ship)
        {
            ship.ResetControls();
        }

        moorable.gameObject.SetActive(true);
        moorable.gameObject.SendMessage("OnUnmoored", this, SendMessageOptions.DontRequireReceiver);
    }
Пример #2
0
    //eat a ship, disabling it and storing it in the hangar
    public void AddDockedShip(Moorable docked)
    {
        //just in case...
        docked.transform.position = transform.position;

        docked.gameObject.SendMessage("OnMoored", this, SendMessageOptions.DontRequireReceiver);

        docked.gameObject.SetActive(false);
        dockedShips.Add(docked);
        var traffic = docked.GetComponent<TrafficShip>();
        if (traffic)
        {
            dockedTraffic.Add(traffic);
        }
    }