void Update()
 {
     if (Input.GetMouseButtonDown(0) &&
         Physics.SphereCast(Camera.main.ScreenPointToRay(Input.mousePosition), 0.33f, out RaycastHit hit, float.MaxValue, SatelliteLayer, QueryTriggerInteraction.Ignore))
     {
         SatelliteComms comms = hit.transform.gameObject.GetComponent <SatelliteComms>();
         comms.Node.Active = !comms.Node.Active;
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        //commLineRenderer.startWidth = 0.025f;
        //commLineRenderer.endWidth = 0.025f;
        //commLineRenderer.material = CommsMat;


        targetPositionLineRenderer.startWidth = 0.1f;
        targetPositionLineRenderer.endWidth   = 0.1f;
        targetPositionLineRenderer.material.SetColor("_BaseColor", LeaderMat);
        targetPositionLineRenderer.material.SetColor("_EmissionColor", LeaderMat);

        comms    = GetComponent <SatelliteComms>();
        commsSim = GetComponent <CommsSim>();

        meshRenderer = transform.GetComponentsInChildren <MeshRenderer>().ToList().Find(mesh => mesh.transform.tag == "SatIcon");
    }
Beispiel #3
0
    public void Send(uint?nextHop, Response response)
    {
        if (Constants.EnableDebug)
        {
            Debug.Log(comms.Node.Id + " -> " + nextHop + "\t : " + response.GetType() + ": " + response.ResponseCode + "." + "\t dst: " + response.DestinationID);
        }

        SatelliteComms hop = SatManager._instance.satellites.Find(sat => sat.Node.Id == nextHop);

        SatManager.MessageProps message = new SatManager.MessageProps(BackendHelpers.UnityVectorFromNumerics(comms.Node.Position),
                                                                      BackendHelpers.UnityVectorFromNumerics(hop.Node.Position),
                                                                      Color.cyan,
                                                                      Constants.SEND_DURATION_TIME / Constants.TimeScale);

        satMan.SentMessages.Add(message);

        if (System.Numerics.Vector3.Distance(comms.Node.Position, hop.Node.Position) < Constants.ScaleToSize(comms.CommRadius))
        {
            hop.Node.CommsModule.Receive(response);
            ActiveCommSat = hop;
            ActiveCommSat = null;
        }
    }
Beispiel #4
0
    public void Send(uint?nextHop, Request request)
    {
        request.SenderID = comms.Node.Id;
        SatelliteComms hop = SatManager._instance.satellites.Find(sat => sat.Node.Id == nextHop);

        SatManager.MessageProps message = new SatManager.MessageProps(
            BackendHelpers.UnityVectorFromNumerics(comms.Node.Position),
            BackendHelpers.UnityVectorFromNumerics(hop.Node.Position),
            Color.yellow,
            Constants.SEND_DURATION_TIME / Constants.TimeScale);

        switch (request.Command)
        {
        case Request.Commands.DETECTFAILURE:
            message.Color = Color.red;
            break;

        case Request.Commands.HEARTBEAT:
            message.Color = Color.red;
            break;

        case Request.Commands.PING:
            message.Color = Color.red;
            break;

        case Request.Commands.DISCOVER:
            message.Color = Color.green;
            break;

        case Request.Commands.POSITION:
            message.Color = Color.green;
            break;

        case Request.Commands.ADDITION:
            message.Color = Color.green;
            break;

        case Request.Commands.GENERATE:
            message.Color = Color.yellow;
            break;

        case Request.Commands.EXECUTE:
            message.Color = Color.yellow;
            break;
        }

        satMan.SentMessages.Add(message);

        if (System.Numerics.Vector3.Distance(comms.Node.Position, hop.Node.Position) < Constants.ScaleToSize(comms.CommRadius))
        {
            ActiveCommSat = hop;

            if (request.MessageIdentifer == null)
            {
                request.MessageIdentifer = DateTime.Now.ToString() + " milli " + DateTime.Now.Millisecond;
            }

            if (Constants.EnableDebug)
            {
                Debug.Log(request.Dir + ": " + comms.Node.Id + " -> " + nextHop + "\t : " + request.Command.ToString() + "\t dst: " + request.DestinationID + "\t msgID: " + request.MessageIdentifer);
            }

            hop.Node.CommsModule.Receive(request);
            ActiveCommSat = null;
        }
        else
        {
            if (Constants.EnableDebug)
            {
                Debug.Log(request.Dir + ": " + comms.Node.Id + " -> " + nextHop + "\t : " + request.Command.ToString() + "\t dst: " + request.DestinationID + "\t msgID: " + request.MessageIdentifer);
            }
        }
    }
Beispiel #5
0
 private void Start()
 {
     comms  = GetComponent <SatelliteComms>();
     satMan = GameObject.FindGameObjectWithTag("SatelliteManager").GetComponent <SatManager>();
 }
    private void Update()
    {
        if (SatManager._instance.satellites.TrueForAll(sat => sat.Node.State != Node.NodeState.PLANNING))
        {
            GameObject.FindGameObjectsWithTag("LocationPlaceholder")?.ToList().ForEach(Destroy);
        }

        if (GameObject.FindGameObjectsWithTag("LocationPlaceholder").Length == 0 && SatManager._instance.satellites.Any(sat => sat.Node.State == Node.NodeState.PLANNING))
        {
            SatelliteComms planningNode =
                SatManager._instance.satellites.Find(sat => sat.Node.State == Node.NodeState.PLANNING);

            planningNode.Node.GeneratingPlan.Entries.ForEach(entry => Instantiate(SatLocationPlaceholderPrefab, BackendHelpers.UnityVectorFromNumerics(entry.Position), Quaternion.identity));
        }

        if (nodes.Count == 0)
        {
            Sats.ForEach(sat => nodes.Add(sat.GetComponent <SatelliteComms>().Node));
        }


        if (plan == null)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0) &&
            Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, float.MaxValue, ManualDesignMask) &&
            plan.Entries.TrueForAll(entry => nodes.Any(node => System.Numerics.Vector3.Distance(node.Position, entry.Position) < 0.1f)))
        {
            if (EnableManualDesign == false)
            {
                Clear();
            }

            if (GameObject.FindGameObjectsWithTag("LocationPlaceholder")?.ToList().Count < nodes.Count)
            {
                Instantiate(SatLocationPlaceholderPrefab, hit.point, Quaternion.identity);


                EnableAutotest     = false;
                EnableManualDesign = true;
            }
            else if (EnableManualDesign)
            {
                List <ConstellationPlanEntry> entries = new List <ConstellationPlanEntry>();

                foreach (Vector3 pos in GameObject.FindGameObjectsWithTag("LocationPlaceholder")?.ToList().Select(loc => loc.transform.position))
                {
                    System.Numerics.Vector3       position = new System.Numerics.Vector3(pos.x, pos.y, pos.z);
                    List <ConstellationPlanField> fields   = new List <ConstellationPlanField> {
                        new ConstellationPlanField("DeltaV", 0, (x, y) => x.CompareTo(y))
                    };
                    ConstellationPlanEntry entry = new ConstellationPlanEntry(position, fields, (x, y) => 1);
                    entries.Add(entry);
                }

                plan = new ConstellationPlan(entries);

                //Send the targetconstellation to random sat
                INode       targetSat = Sats[UnityEngine.Random.Range(0, Sats.Count - 1)].GetComponent <SatelliteComms>().Node;
                PlanRequest request   = new PlanRequest();
                request.Command          = Request.Commands.GENERATE;
                request.DestinationID    = targetSat.Id;
                request.Plan             = plan;
                request.MessageIdentifer = "42";
                targetSat.Communicate(request);


                EnableManualDesign = false;
            }
        }
    }