Esempio n. 1
0
        //public void DeActivatedPassiveAgentConditions()
        //{
        //    if (this.gameObject.tag == "De-ActivatedPassive")
        //    {

        //        StartCoroutine(ApplyWindForce(SimulationManager.Get().windForce, SimulationManager.Get().windForceIntervalSeconds));
        //    }


        //}


        IEnumerator ApplyWindForceSignalReceiver(float force, int interval)
        {
            //Vector3 wind = new Vector3(1, 2, 3);


            if (SimulationManager.Get().is2D)
            {
                Vector3 wind = new Vector3(UnityEngine.Random.onUnitSphere.x, 0, UnityEngine.Random.onUnitSphere.z);
                wind.Normalize();

                wind *= force;

                base.IApplyForces(wind);


                yield return(new WaitForSeconds(interval));
            }

            if (SimulationManager.Get().is3D)
            {
                Vector3 wind = new Vector3(5f, 5f, 5f);

                wind.Normalize();

                wind *= force;

                base.IApplyForces(wind);


                yield return(new WaitForSeconds(interval));
            }
        }
        ////////////////////////////////PLACE HOLDER FUNCTIONALITY////////////////////////////////////////////////

        ////////////////////////////////PLACE HOLDER FUNCTIONALITY END////////////////////////////////////////////////


        private void OnDrawGizmos()
        {
            /// draw vectors to target
            ///
            if (GenerationManager.generationCount != 0)
            {
                if (this.gameObject.tag == "Freezed" || this.gameObject.tag == "SignalEmmiter" || this.gameObject.tag == "De-Activated")
                {
                    for (int i = 0; i < base.neighbours.Count; i++)
                    {
                        if (base.neighbours[i] != null)
                        {
                            Gizmos.color = Color.white;
                            Vector3 dir = base.neighbours[i].transform.position - this.gameObject.transform.position;
                            Gizmos.DrawRay(this.gameObject.transform.position, dir);
                        }
                    }
                }

                if (SimulationManager.Get().displayTopology)
                {
                    Gizmos.DrawSphere(this.gameObject.transform.position, 0.1f);
                }
            }
        }
Esempio n. 3
0
        IEnumerator ApplyWindForce(float force, int interval)
        {
            //Vector3 wind = new Vector3(1, 2, 3);


            if (SimulationManager.Get().is2D)
            {
                Vector3 wind = new Vector3(UnityEngine.Random.onUnitSphere.x, 0, UnityEngine.Random.onUnitSphere.z);
                wind.Normalize();

                wind *= force;

                base.IApplyForces(wind);


                yield return(new WaitForSeconds(interval));
            }

            if (SimulationManager.Get().is3D)
            {
                // Vector3 wind = new Vector3(UnityEngine.Random.onUnitSphere.x, UnityEngine.Random.onUnitSphere.y, UnityEngine.Random.onUnitSphere.z);
                // Vector3 wind = new Vector3(5f, 5f,5f);
                Vector3 randomVal = UnityEngine.Random.onUnitSphere;
                Vector3 wind      = new Vector3(randomVal.x, randomVal.y, randomVal.z);
                //wind.Normalize();

                //  wind *= force;

                //base.IApplyForces(wind);
                ApplyForcesRigidBody(wind, force);


                yield return(new WaitForSeconds(interval));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// S
        /// </summary>
        public void ISignalReceiverPassiveConditions()
        {
            if (this.gameObject.tag == "SignalReceiverPassive")
            {
                if (SimulationManager.Get().oneGeneration&& AgentPopulation.freezedAgentList.Count / ((float)AgentPopulation.populationList.Count - AgentPopulation.cancelledAgentList.Count) * 100 < 97)
                {
                    base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
                }

                //if (SimulationManager.Get().displayColorByEmotion)
                //{

                //    DisplayEmotion();
                //}

                if (SimulationManager.Get().addWindForce)
                {
                    //StartCoroutine(ApplyWindForce(SimulationManager.Get().windForce, SimulationManager.Get().windForceIntervalSeconds)); // Used to update object with my physics engine

                    StartCoroutine(ApplyWindForce(SimulationManager.Get().windForce, SimulationManager.Get().windForceIntervalSeconds)); // used to update agent with Rigid body physics AddForce()
                }

                //////////////////// set display////////////////////////////////

                base.ChangeDisplayInspectorInput(gameObject.GetComponent <Agent>(), false);

                //////////////////// set display////////////////////////////////
                base.signalReceiverPassiveCounter++;
            }
        }
        void Start()
        {
            base.IMass = 1f;//REAL MASS OF UNIT

            if (SimulationManager.Get().addRigidBodyCollider == false)
            {
                base.IMaxForce = 0.06f;
                base.IMaxSpeed = 0.06f;
            }

            if (SimulationManager.Get().addRigidBodyCollider)
            {
                base.IMaxForce = 3.5f;
                base.IMaxSpeed = 3.5f;
            }



            if (SimulationManager.Get().runSimulation)
            {
                runSimulation = true;
            }


            base.VisionRadius = (this.gameObject.GetComponent <SphereCollider>().radius * 2) * 1.9f;

            rb = GetComponent <Rigidbody>();
            //rb.velocity = base.velocity;
            //rb.mass = base.IMass = 1;

            agentRadius = this.gameObject.GetComponent <SphereCollider>().radius;
            base.energyDecreasingFactor = 0.05f;
            //base.energyLevel = 650f; // 650 maH --> litjuim batter capacity that we are using



            base.energyCapacity = 650f; // 650 maH --> litjuim batter capacity that we are using

            // if (base.heliumLevel < 0) base.heliumLevel = 0;



            ///////////////////////////////VARIABLE INITIALIZATION////////////////////////////////

            // NON STATIC PUBLIC VARIABLE INITIALIZATION

            agentPopulation = GameObject.Find("AgentPopulation");  // create variable to store game object that holds script top reference
            AP = agentPopulation.GetComponent <AgentPopulation>(); // store script to reference in variable

            generationManager = GameObject.Find("GenerationManager");
            GM = generationManager.GetComponent <GenerationManager>();

            pixelPopulation = GameObject.Find("PixelPopulation");
            pixelPop        = pixelPopulation.GetComponent <PixelPopulation>();

            scalarField = GameObject.Find("ScalarField2D");
            SF          = scalarField.GetComponent <ScalarField2D>();

            ///////////////////////////////METHOD INITIALIZATION////////////////////////////////
        } // END START
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        if (AgentPopulation.populationList.Count != 0 && createPopulation == false)
        {
            GetMinAndMax2DCoordinates(out minVal, out maxVal);
            InitializePeople2DRandom();
            //print(minVal);
            //print(maxVal);
            Parent();
            Material();

            string filePath = SimulationManager.Get().PeopleFilePath;
            string fileName = "PeopleDistribution" + ".txt";
            string fullPath = System.IO.Path.Combine(filePath, fileName);

            StreamWriter writer = new StreamWriter(fullPath);


            // StreamWriter writer = new StreamWriter(@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\2D\People\PeopleDistribution.txt");
            for (int i = 0; i < peopleList.Count; i++)
            {
                string outPut = peopleList[i].gameObject.transform.position.x.ToString() + "," + peopleList[i].gameObject.transform.position.z.ToString() + "," + peopleList[i].gameObject.transform.position.y.ToString();
                writer.WriteLine(outPut);
            }

            writer.Close();

            createPopulation = true;
        }
    }
Esempio n. 7
0
        private void Start()
        {
            ///////////////////////////////VARIABLE INITIALIZATION////////////////////////////////
            // // NON STATIC PUBLIC VARIABLE INITIALIZATION



            if (SimulationManager.Get().runSimulation)
            {
                runSimulation = true;
            }


            guiStyleTxt.normal.background = null;
            guiStyleTxt.normal.textColor  = new Color(1, 1, 1);
            guiStyleTxt.fontSize          = 22;


            guiStyleTitles.normal.background = null;
            guiStyleTitles.normal.textColor  = new Color(1, 1, 1);
            guiStyleTitles.fontSize          = 22;
            guiStyleTitles.fontStyle         = FontStyle.Bold;

            Texture2D texture = new Texture2D(1, 1);

            texture.SetPixel(0, 0, new Color(1, 1, 1, 0.1f));

            texture.Apply();
            guiStyleButton.normal.background = texture;

            guiStyleButton.fontSize         = 22;
            guiStyleButton.normal.textColor = new Color(1, 1, 1);
            ///////////////////////////////METHOD INITIALIZATION////////////////////////////////
        }
        /// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



        private void OnTriggerExit(Collider other)
        {
            if (SimulationManager.Get().addRigidBodyCollider == false)
            {
                for (int i = base.neighbours.Count - 1; i >= 0; i--)
                {
                    if (base.neighbours != null)
                    {
                        base.neighbours.Remove(other.GetComponent <Agent>());
                    }
                }
            }
        }
Esempio n. 9
0
        void Start()
        {
            generationManager = GameObject.Find("GenerationManager");
            GM = generationManager.GetComponent <GenerationManager>();
            pixelPopualtion = GameObject.Find("PixelPopulation");
            pixelPop        = pixelPopualtion.GetComponent <PixelPopulation>();


            cancelledAgentList = new KdTree <Agent>();
            startTime          = Time.time;


            if (SimulationManager.Get().is2D)
            {
                InitializeAgents2DArray(populationCount);

                IntiPopulation = true;
            }

            if (SimulationManager.Get().is3D)
            {
                InitializeAgents3DArray(populationCount);

                range = SharpMatter.SharpMath.SharpMath.Range(populationList.Count);

                IntiPopulation = true;
            }



            Parent();
            AgentName();
            InitializeState();

            string filePath = SimulationManager.Get().ClusterOrganizationFilePath;
            string fileName = "OrganizationInitialState" + ".txt";

            StreamWriter writer = new StreamWriter(filePath + fileName);


            // StreamWriter writer = new StreamWriter(@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\Init state\OrganizationInitialState.txt");
            for (int i = 0; i < populationList.Count; i++)
            {
                string outPut = populationList[i].gameObject.transform.position.x.ToString() + "," + populationList[i].gameObject.transform.position.z.ToString() + "," + populationList[i].gameObject.transform.position.y.ToString();
                writer.WriteLine(outPut);
            }

            writer.Close();
        } // END START
Esempio n. 10
0
        } //END UPDATE

        void FixedUpdate()
        {
            if (SimulationManager.Get().runSimulation)
            {
                if (SimulationManager.Get().addFixedJoints&& SimulationManager.Get().addRigidBodyCollider)
                {
                    //  if (gameObject.tag == "SignalReceiver" || gameObject.tag == "Freezed" || gameObject.tag == "SignalEmmiter")// base.IRunPhysics();


                    //if (gameObject.tag == "SignalReceiver" || gameObject.tag == "Freezed") base.IRunPhysics();

                    IAgentBehaviorConditions();
                }
            }
        }
Esempio n. 11
0
        } // end start

        // Update is called once per frame
        void Update()
        {
            if (GenerationManager.generationChange)
            {
                if (is3D)
                {
                    bool exportArrayPointCloud        = false;
                    bool exportOrganizationPointcloud = false;
                    bool exportMobileAgentData        = true;
                    bool exportClusterAgentData       = false;

                    string filePath = SimulationManager.Get().PixelDataMobileAgentsPath;

                    string fileName = "PixelDataModibleAgents" + GenerationManager.generationCount.ToString() + ".txt";

                    ExportData.ExportPointCloudToTxtFile(filePath, pixel3DArray, pixel2DArray, AgentPopulation.populationList, fileName, columns, rows, height, is3D, is2D, exportArrayPointCloud, exportOrganizationPointcloud,
                                                         exportMobileAgentData, exportClusterAgentData);



                    string filePath1 = SimulationManager.Get().PixelDataClusterAgentsPath;
                    string fileName1 = "ClusterAgents" + GenerationManager.generationCount.ToString() + ".txt";
                    string fullPath1 = System.IO.Path.Combine(filePath1, fileName1);

                    StreamWriter writer1 = new StreamWriter(fullPath1);


                    //StreamWriter writer2 = new StreamWriter(@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\PixelData\ClusterAgents\" +
                    //    "ClusterAgents" + GenerationManager.generationCount.ToString() + ".txt");

                    for (int i = 0; i < columns; i++)
                    {
                        for (int j = 0; j < rows; j++)
                        {
                            for (int k = 0; k < height; k++)
                            {
                                string outPut = pixel3DArray[i, k, j].CountClusterAgents.ToString();


                                writer1.WriteLine(outPut);
                            }
                        }
                    }

                    writer1.Close();
                }
            }
        } // end update
Esempio n. 12
0
        private void OnTriggerEnter(Collider other)
        {
            /// keeps track of neighbours in all other generations
            if (GenerationManager.generationCount != 0 && SimulationManager.Get().addRigidBodyCollider == false)
            {
                if (other.gameObject.tag == "SignalEmmiter")
                {
                    //  base.neighboursTemp.Add(other.gameObject.GetComponent<Agent>());
                    //base.neighbours.Add(other.gameObject.GetComponent<Agent>());
                    //  base.neighboursTempVector.Add(other.gameObject.transform.position);
                    //base.neighbourHistory.Add(other.gameObject.GetComponent<Agent>());
                    //  base.localCollisionHistory++;
                    ChangeStateToSignalReceiverPassive(this.gameObject.GetComponent <Agent>(), 0);
                }

                //if (other.gameObject.tag == "SignalReceiver" && this.gameObject.tag!="De-Activated" && this.gameObject.tag!="Freezed")
                //{
                //    base.neighboursTemp.Add(other.gameObject.GetComponent<Agent>());
                //    base.neighboursTempVector.Add(other.gameObject.transform.position);
                //    base.neighbourHistory.Add(other.gameObject.GetComponent<Agent>());

                //  //  base.localCollisionHistory++;

                //}


                if (other.gameObject.tag != "De-Activated" && other.gameObject.tag != "ActivatedPlaceHolder" &&
                    other.gameObject.tag != "CollidedPlaceHolder")
                {
                    base.neighboursTemp.Add(other.gameObject.GetComponent <Agent>());
                    base.neighboursTempVector.Add(other.gameObject.transform.position);
                }
            }


            ///Keeps track of neighbours of generation 0
            if (GenerationManager.generationCount == 0)
            {
                if (other.gameObject.tag != "De-Activated" && other.gameObject.tag != "ActivatedPlaceHolder" && other.gameObject.tag != "CollidedPlaceHolder")
                {
                    /// Increment the collision history of the Agent. during first collision, SystemCollisionHistory = 1
                    base.neighboursTemp.Add(other.gameObject.GetComponent <Agent>());
                    base.neighboursTempVector.Add(other.gameObject.transform.position);
                    base.neighbourHistory.Add(other.gameObject.GetComponent <Agent>());
                    base.localCollisionHistory++;
                }
            }
        }
Esempio n. 13
0
        }     //END UPDATE

        void FixedUpdate()
        {
            if (SimulationManager.Get().runSimulation&& GenerationManager.generationCount != 0)
            {
                if (SimulationManager.Get().addFixedJoints&& SimulationManager.Get().addRigidBodyCollider)
                {
                    //  if (gameObject.tag == "SignalReceiver" || gameObject.tag == "Freezed" || gameObject.tag == "SignalEmmiter") base.IRunPhysics();

                    // //if (gameObject.tag == "SignalReceiver" || gameObject.tag == "Freezed" || gameObject.tag == "De-ActivatedPassive") base.IRunPhysics();

                    //// if (gameObject.tag == "SignalReceiver" || gameObject.tag == "Freezed") base.IRunPhysics();

                    IAgentStatesBehaviorConditions();
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Read exported values from meshField generated in rhino and store in a 2D array
        /// </summary>
        /// <returns></returns>
        private float[,] GetMeshColorValuesFromRhino()
        {
            float[,] dataArray = new float[columns, rows];
            // string[] lines = System.IO.File.ReadAllLines(@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\2D\ScalarField\ToUnity\ColorMapValues.txt");
            string[] lines      = System.IO.File.ReadAllLines(SimulationManager.Get().ImportToUnityInterpolatedFieldFilePath);
            var      linesArray = Make2DArray(lines, columns, rows);

            for (int i = 0; i < columns; i++)
            {
                for (int j = 0; j < rows; j++)
                {
                    dataArray[i, j] = float.Parse(linesArray[i, j]);
                }
            }
            return(dataArray);
        }
Esempio n. 15
0
    private void OnTriggerStay(Collider other)
    {
        if (SimulationManager.Get().addRigidBodyCollider == false)
        {
            if (other.gameObject.tag == "ActivatedPlaceHolder" && other.gameObject.GetComponent <PlaceHolder>().MysignalReceiver != null)
            {
                this.gameObject.tag = "DeActivatedPlaceHolder";
            }
        }


        //if (other.gameObject.tag == "Freezed" || other.gameObject.tag == "SignalEmmiter" || other.gameObject.tag == "De-Activated")
        //{
        //    this.gameObject.tag = "DeActivatedPlaceHolder";
        //}

        //if (other.gameObject.tag == "Freezed" || other.gameObject.tag == "SignalEmmiter" || other.gameObject.tag == "De-Activated" && this.MysignalReceiver == null)
        //{
        //    this.gameObject.tag = "DeActivatedPlaceHolder";
        //}


        //if (other.gameObject.tag == "Freezed" && this.MysignalReceiver == null)
        //{
        //    if (SharpMath.Similar(other.gameObject.transform.position, this.gameObject.transform.position, 2.24f))
        //    {
        //        this.gameObject.tag = "DeActivatedPlaceHolder";
        //    }
        //}

        //if (other.gameObject.tag == "SignalEmmiter" && this.MysignalReceiver == null)
        //{
        //    if (SharpMath.Similar(other.gameObject.transform.position, this.gameObject.transform.position, 2.24f))
        //    {
        //        this.gameObject.tag = "DeActivatedPlaceHolder";
        //    }
        //}

        //if (other.gameObject.tag == "De-Activated" && this.MysignalReceiver == null)
        //{
        //    if (SharpMath.Similar(other.gameObject.transform.position, this.gameObject.transform.position, 2.24f))
        //    {
        //        this.gameObject.tag = "DeActivatedPlaceHolder";
        //    }
        //}
    }
Esempio n. 16
0
        ////////////////////////////////METHODS////////////////////////////////////////////////////////////////////////  ////////////////////////////////METHODS////////////////////////////////////////////////////////////////////////



        public void DisplayEmotion()
        {
            SimulationManager.Get().displayColorByState        = false;
            SimulationManager.Get().displayColorbyEnergy       = false;
            SimulationManager.Get().displayColorbyDisplacement = false;
            SimulationManager.Get().displayColorByComunication = false;
            SimulationManager.Get().displayColorByNeighbours   = false;
            SimulationManager.Get().displayTopology            = false;
            SimulationManager.Get().GPUInstancing = false;



            SimulationManager.Get().updateFieldRealTime = true;

            foreach (var item in ScalarFields.ScalarField2D.scalarFieldValuesProximity) // using  ScalarField2D.scalarFieldValuesProximity makes change faster, using  ScalarField2D.scalarFieldHumanData makes change much slower
            {
                scalarFieldValuesProximityTotal += item;
            }

            // float averege2 = scalarFieldValuesProximityTotal / ScalarFields.ScalarField2D.scalarFieldHumanData.Length;

            averege = scalarFieldValuesProximityTotal / ScalarFields.ScalarField2D.scalarFieldHumanData.Length;
            UserInterface.UI.averegeFiledValues = averege;


            scale += Mathf.Clamp(Mathf.Sin(averege), 0.001f, .2f);
            UserInterface.UI.rateOfChange = scale;
            //Color c = Utility.Lerp3(Color.white, Color.red, Color.blue, Mathf.Cos(base.currentScalarValueHumanData * Mathf.PI + scale)); //Mathf.Cos(base.currentScalarValueHumanData  * Mathf.PI + scale));

            Color c = Utility.Lerp3(Color.grey, Utility.RGBToFloat(255, 0, 13), Utility.RGBToFloat(250, 179, 0), Mathf.Cos(base.currentScalarValueHumanData * Mathf.PI + scale));

            //   Color c = Color.Lerp(Color.grey, Color.black, Mathf.Cos(base.currentScalarValueHumanData * Mathf.PI + scale));

            // Color c = Utility.Lerp3(Color.black, Color.red, Color.blue, Mathf.Cos(base.currentScalarValueHumanData * Mathf.PI + scale)); //Mathf.Cos(base.currentScalarValueHumanData  * Mathf.PI + scale));

            gameObject.GetComponent <MeshRenderer>().material.color = c;

            emissiveMaterial.SetColor("_Emission", c);



            DynamicGI.SetEmissive(gameObject.GetComponent <MeshRenderer>(), c);
        }
Esempio n. 17
0
    void OnValidate()
    {
        if (Application.isPlaying)
        {
            return;
        }

        if (!visualizeTrajectory)
        {
            GetComponent <LineRenderer>().enabled = false;
            return;
        }
        else
        {
            GetComponent <LineRenderer>().enabled = true;
        }

        visualizationHorizon = Mathf.Clamp(visualizationHorizon, 0, 10000);
        GetComponent <LineRenderer>().positionCount = visualizationHorizon / visualizationPeriod;

        List <Vector3> positions = new List <Vector3>();

        SimulationManager.Get().celestialBodies.ForEach((x) => x.InitializeState());
        for (int i = 0; i < visualizationHorizon; i++)
        {
            foreach (CelestialBody body in SimulationManager.Get().celestialBodies)
            {
                body.SimulateStep(SimulationManager.Get().simulationTimeStep);
                Vector3 pointToDraw = body.position;

                if (i % visualizationPeriod == 0 && body == this)
                {
                    if (simulationOrigin)
                    {
                        pointToDraw -= simulationOrigin.position - simulationOrigin.transform.position;
                    }

                    positions.Add(pointToDraw);
                }
            }
        }
        GetComponent <LineRenderer>().SetPositions(positions.ToArray());
    }
Esempio n. 18
0
 public void CalculateEnergyLevelsOnGeneration_0()
 {
     if (this.gameObject.tag == "Freezed")
     {
         base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
     }
     if (this.gameObject.tag == "SignalEmmiter")
     {
         base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
     }
     if (this.gameObject.tag == "SignalReceiver")
     {
         base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
     }
     if (this.gameObject.tag == "SignalReceiverPassive")
     {
         base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
     }
 }
Esempio n. 19
0
        private void Update()
        {
            if (OrganizationBehavior.runSimulation)
            {
                int totalCancelledAgents = AgentPopulation.totalCancelledAgents;

                if (AgentPopulation.freezedAgentList != null)
                {
                    if (AgentPopulation.freezedAgentList.Count / (float)AgentPopulation.populationList.Count * 100 < 97)
                    {
                        gameTime += Time.deltaTime;
                    }

                    if (AgentPopulation.freezedAgentList.Count / (float)AgentPopulation.populationList.Count * 100 > 97)
                    {
                        timeSinceAssemblyFinished += Time.deltaTime;
                    }
                }



                int seconds = (int)(gameTime % 60);
                int minutes = (int)(gameTime / 60) % 60;
                int hours   = (int)(gameTime / 3600) % 24;

                timeFormat = string.Format("{0:0}:{1:00}:{2:00}", hours, minutes, seconds);

                if (SimulationManager.Get().addWindForce)
                {
                    int seconds1 = (int)(timeSinceAssemblyFinished % 60);
                    int minutes1 = (int)(timeSinceAssemblyFinished / 60) % 60;
                    int hours1   = (int)(timeSinceAssemblyFinished / 3600) % 24;

                    timeSinceAssemblyFinishedFormat = string.Format("{0:0}:{1:00}:{2:00}", hours1, minutes1, seconds1);

                    if (timeSinceAssemblyFinishedFormat == string.Format("{0:0}:{1:00}:{2:00}", hours1, 1, 45))
                    {
                        // Debug.Break(); // pauses game
                    }
                }
            }
        }
Esempio n. 20
0
    private void OnCollisionStay(Collision collision)
    {
        if (SimulationManager.Get().addRigidBodyCollider)
        {
            if (collision.gameObject.tag == "ActivatedPlaceHolder" && collision.gameObject.GetComponent <PlaceHolder>().MysignalReceiver != null)
            {
                this.gameObject.tag = "DeActivatedPlaceHolder";
            }



            if (collision.gameObject.tag == "Freezed" || collision.gameObject.tag == "SignalEmmiter" || collision.gameObject.tag == "De-Activated" && this.MysignalReceiver == null)
            {
                this.gameObject.tag = "DeActivatedPlaceHolder";
            }


            if (collision.gameObject.tag == "Freezed" && this.MysignalReceiver == null)
            {
                if (SharpMath.Similar(collision.gameObject.transform.position, this.gameObject.transform.position, 2.24f))
                {
                    this.gameObject.tag = "DeActivatedPlaceHolder";
                }
            }

            if (collision.gameObject.tag == "SignalEmmiter" && this.MysignalReceiver == null)
            {
                if (SharpMath.Similar(collision.gameObject.transform.position, this.gameObject.transform.position, 2.24f))
                {
                    this.gameObject.tag = "DeActivatedPlaceHolder";
                }
            }

            if (collision.gameObject.tag == "De-Activated" && this.MysignalReceiver == null)
            {
                if (SharpMath.Similar(collision.gameObject.transform.position, this.gameObject.transform.position, 2.24f))
                {
                    this.gameObject.tag = "DeActivatedPlaceHolder";
                }
            }
        }
    }
Esempio n. 21
0
        public List <Vector3> GetClusterInitPosFromRhino()
        {
            //string[] lines = System.IO.File.ReadAllLines(@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\2D\ScalarField\ToUnity\ClusterstartingPositions.txt");
            string[]       lines = System.IO.File.ReadAllLines(SimulationManager.Get().ImportToUnityClusterStartingPositionsFilePath);
            List <Vector3> data  = new List <Vector3>();

            foreach (string item in lines)
            {
                string[] sArray = item.Split(',');

                // store as a Vector3
                Vector3 vector = new Vector3(
                    float.Parse(sArray[0]),
                    float.Parse(sArray[2]),
                    float.Parse(sArray[1]));

                data.Add(vector);
            }
            return(data);
        }
Esempio n. 22
0
    Vector3 GetNetForce()
    {
        // F = GmM/d^2
        Vector3 netForce = Vector3.zero;

        foreach (CelestialBody body in SimulationManager.Get().celestialBodies)
        {
            if (body == this)
            {
                continue;
            }

            Vector3 relativePosition = body.position - position;
            float   sqrDistance      = relativePosition.sqrMagnitude;
            Vector3 direction        = relativePosition.normalized;

            netForce += direction * (SimulationManager.Get().gravitationalConstant *body.mass *mass / sqrDistance);
        }

        return(netForce);
    }
Esempio n. 23
0
        private AgentPopulation AP; // store script to reference in variable

        // Use this for initialization
        void Start()
        {
            agentPopulation = GameObject.Find("AgentPopulation");     // create variable to store game object that holds script top reference
            AP = agentPopulation.GetComponent <AgentPopulation>();    // store script to reference in variable

            if (is2D)
            {
                pixel2DArray = new Pixel[columns, rows];
                // DensityValues2D = new float [columns, rows];
                NextDensityValues2D = new Pixel[columns, rows];
            }

            if (is3D)
            {
                pixel3DArray = new Pixel[columns, height, rows];
                //DensityValues3D = new float [columns, height, rows];
                NextDensityValues3D = new Pixel[columns, height, rows];
            }

            Init();
            Name();



            if (is3D)
            {
                bool exportArrayPointCloud        = true;
                bool exportOrganizationPointcloud = false;
                bool exportMobileAgentData        = false;
                bool exportClusterAgentData       = false;

                string filePath = SimulationManager.Get().PixelArrayFilePath;
                string fileName = "PixelArray" + ".txt";



                ExportData.ExportPointCloudToTxtFile(filePath, pixel3DArray, pixel2DArray, AgentPopulation.populationList, fileName, columns, rows, height, is3D, is2D, exportArrayPointCloud, exportOrganizationPointcloud,
                                                     exportMobileAgentData, exportClusterAgentData);
            }
        } // end start
Esempio n. 24
0
        //private void OnTriggerExit(Collider other)
        //{


        //    for (int i = base.neighbours.Count - 1; i >= 0; i--)
        //    {
        //        if (base.neighbours != null)
        //        {
        //            base.neighbours.Remove(other.GetComponent<Agent>());
        //        }
        //    }
        //}


        private void OnCollisionEnter(Collision collision)
        {
            if (GenerationManager.generationCount == 0)
            {
                if (SimulationManager.Get().addFixedJoints&& this.gameObject.tag != "Freezed")
                {
                    AddFixedJoint(collision);
                    //AddSpringJoint(collision);
                }
                if (collision.gameObject.tag != "De-Activated" && collision.gameObject.tag != "ActivatedPlaceHolder" &&
                    collision.gameObject.tag != "CollidedPlaceHolder")
                {
                    base.neighboursTemp.Add(collision.gameObject.GetComponent <Agent>());
                    base.neighboursTempVector.Add(collision.gameObject.transform.position);
                }

                //if (this.gameObject.tag == "Freezed")
                //{
                //    for (int i = 0; i < base.neighbours.Count; i++)
                //    {

                //        if (collision.gameObject.tag == "SignalEmmiter" && collision.gameObject.name != base.neighbours[i].name)
                //        {


                //            base.ChangeStateToSignalReceiverPassive(this.gameObject.GetComponent<Agent>(), 0);


                //        }

                //    }
                //}

                if (collision.gameObject.tag == "SignalEmmiter" && this.gameObject.tag != "Freezed" && this.gameObject.tag != "SignalEmmiter")
                {
                    base.ChangeStateToSignalReceiverPassive(this.gameObject.GetComponent <Agent>(), 0);
                }
            }
        }
Esempio n. 25
0
        public void WandererBehaviorConditions()
        {
            if (this.gameObject.tag == "Wanderer")
            {
                countToSearchForEmptyPixel++;

                base.neighboursTemp.Clear();
                Pixel currentPixel;
                PixelDataLookUp3D(pixelPop, out currentPixel);
                base.currentPixel = currentPixel.PixelName;

                base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
                base.EnergyLevelSharing(this.gameObject.GetComponent <Agent>());

                if (SimulationManager.Get().addFixedJoints)
                {
                    var Container = gameObject.GetComponent <FixedJoint>();

                    Destroy(Container);
                }

                //    if (currentPixel.CountMobileAgents > 1)

                base.Wander();

                if (currentPixel.CountMobileAgents < 2 || countToSearchForEmptyPixel > wandererTreshhold)
                {
                    base.ChangeStateToSignalReceiver(this.gameObject.GetComponent <Agent>(), 0);
                }

                // if (countToSearchForEmptyPixel > internalTreshhold) base.ChangeStateToSignalReceiver(this.gameObject.GetComponent<Agent>(), 0);

                Bounds();

                KdTree <Agent> neighbours = base.FindNeighboursKd(this.gameObject.GetComponent <Agent>(), 3.0f, AgentPopulation.populationList);

                base.Separation(neighbours, 0.2f, 1.5f);
            }
        }
Esempio n. 26
0
        /// <summary>
        ///
        /// </summary>
        public void ISignalReceiverPassiveBehaviorConditions()
        {
            if (this.gameObject.tag == "SignalReceiverPassive")

            {
                base.signalReceiverPassiveCounter++;
                base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
                base.EnergyLevelSharing(this.gameObject.GetComponent <Agent>());

                //   StartCoroutine(ApplyWindForce(SimulationManager.Get().windForce, SimulationManager.Get().windForceIntervalSeconds));

                //////////////////// set display////////////////////////////////

                base.ChangeDisplayInspectorInput(gameObject.GetComponent <Agent>(), false);

                //////////////////// set display////////////////////////////////

                if (base.signalReceiverPassiveCounter > 100)
                {
                    base.ChangeStateToSignalEmmiter(this.gameObject.GetComponent <Agent>(), 0);
                }
            } /// END CONDITIONS SIGNAL RECEIVER PASSIVE
        }
Esempio n. 27
0
        public void DeactivatedAgentBehaviorConditions()
        {
            if (this.gameObject.tag == "De-Activated")
            {
                if (SimulationManager.Get().addWindForce)
                {
                    StartCoroutine(ApplyWindForce(SimulationManager.Get().windForce, SimulationManager.Get().windForceIntervalSeconds));
                }

                //////////////////// set display////////////////////////////////

                base.ChangeDisplayInspectorInput(gameObject.GetComponent <Agent>(), false);

                //////////////////// set display////////////////////////////////

                //Pixel currentPixel;
                //PixelDataLookUp3D(pixelPop, out currentPixel);
                //base.currentPixel = currentPixel.PixelName;

                base.CalculateEnergyLevels(SimulationManager.Get().gridDistribution_6Neighbours, SimulationManager.Get()._12Neighbours, SimulationManager.Get().is3D, SimulationManager.Get().is2D);
                base.EnergyLevelSharing(this.gameObject.GetComponent <Agent>());
            }
        }
Esempio n. 28
0
        private void OnCollisionEnter(Collision collision)
        {
            if (GenerationManager.generationCount != 0 && SimulationManager.Get().addRigidBodyCollider == true)
            {
                if (SimulationManager.Get().addFixedJoints)
                {
                    AddFixedJoint(collision);
                }

                if (collision.gameObject.tag == "SignalEmmiter" && this.gameObject.tag != "Freezed")
                {
                    base.ChangeStateToSignalReceiverPassive(this.gameObject.GetComponent <Agent>(), 0);
                }


                if (collision.gameObject.tag != "De-Activated" && collision.gameObject.tag != "ActivatedPlaceHolder" &&
                    collision.gameObject.tag != "CollidedPlaceHolder")
                {
                    base.neighboursTemp.Add(collision.gameObject.GetComponent <Agent>());
                    base.neighboursTempVector.Add(collision.gameObject.transform.position);
                }
            }


            ///Keeps track of neighbours of generation 0
            if (GenerationManager.generationCount == 0 && SimulationManager.Get().addRigidBodyCollider == true)
            {
                if (collision.gameObject.tag != "De-Activated" && collision.gameObject.tag != "ActivatedPlaceHolder" && collision.gameObject.tag != "CollidedPlaceHolder")
                {
                    /// Increment the collision history of the Agent. during first collision, SystemCollisionHistory = 1
                    base.neighboursTemp.Add(collision.gameObject.GetComponent <Agent>());
                    base.neighboursTempVector.Add(collision.gameObject.transform.position);
                    base.neighbourHistory.Add(collision.gameObject.GetComponent <Agent>());
                    base.localCollisionHistory++;
                }
            }
        }
Esempio n. 29
0
        public void StorageDoesNotDecrement()
        {
            SimulationManager mgr = new SimulationManager();
            var s = SimulationFactory.When.Delete().From("/ThePath").Once().Simulation;
            mgr.Add(s);

            var match = mgr.Match(System.Net.Http.HttpMethod.Delete, "/ThePath", null, null, false, null);
            Assert.IsNotNull(match);
            Assert.AreEqual(1, match.Condition.SimulationConditionContent.Repeat);

            var all = mgr.Get();
            Assert.AreEqual(1, all.Count);
            Assert.AreEqual(1, all[0].Condition.SimulationConditionContent.Repeat);
        }
Esempio n. 30
0
        } // END START

        void Update()
        {
            // if (runSimulation)
            if (SimulationManager.Get().runSimulation)
            {
                if (GenerationManager.generationCount == 0)
                {
                    //  if(SimulationManager.Get().oneGeneration==false) CheckNeighours(); // this does not decrese performance

                    CheckNeighours();

                    if (base.energyLevel < 0)
                    {
                        base.energyLevel = 0;
                    }

                    base.neighbours = base.neighboursTemp.Distinct().ToList();

                    //if(displacementPositions.Count>500)
                    //{
                    //    displacementPositions.RemoveRange(0, displacementPositions.Count-500);
                    //}

                    RulesContinous();
                    IAgentBehaviorConditions();

                    base.CalculateEmmiterHistory();
                    base.CalculateReceiverHistory();
                    base.CalculateDeActivatedHistory();
                    base.CalculateFreezedHistory();



                    for (int i = 0; i < AgentPopulation.signalReceiverPassiveAgentList.Count; i++)
                    {
                        if (AgentPopulation.signalReceiverPassiveAgentList[i].GetComponent <OrganizationBehavior>().signalReceiverPassiveCounter > signalReceiverPassiveThreshhold)
                        {
                            base.ChangeStateToSignalEmmiter(AgentPopulation.signalReceiverPassiveAgentList[i], 0);
                        }
                    }


                    if (SimulationManager.Get().addFixedJoints == false && SimulationManager.Get().addRigidBodyCollider == false && gameObject.tag == "SignalReceiver")
                    {
                        base.IRunPhysics();
                    }

                    //if (SimulationManager.Get().addFixedJoints == false && SimulationManager.Get().addRigidBodyCollider == false)
                    //{

                    //    RulesContinous();
                    //    IAgentBehaviorConditions();
                    //}



                    //if (SimulationManager.Get().addFixedJoints == true && SimulationManager.Get().addRigidBodyCollider == false)
                    //{

                    //    RulesContinous();
                    //    IAgentBehaviorConditions();
                    //    base.IRunPhysics();
                    //}
                }
            }
        } //END UPDATE
Esempio n. 31
0
        void Start()
        {
            emissiveMaterial = gameObject.GetComponent <MeshRenderer>().material;
            startTime        = Time.time;



            ///////////////////////////////VARIABLE INITIALIZATION////////////////////////////////

            // NON STATIC PUBLIC VARIABLE INITIALIZATION


            agentPopulation = GameObject.Find("AgentPopulation");  // create variable to store game object that holds script top reference
            AP = agentPopulation.GetComponent <AgentPopulation>(); // store script to reference in variable


            pixelPopulation = GameObject.Find("PixelPopulation");
            pixelPop        = pixelPopulation.GetComponent <PixelPopulation>();
            //  NON STATIC PUBLIC VARIABLE INITIALIZATION



            scalarField = GameObject.Find("ScalarField2D");
            SF          = scalarField.GetComponent <ScalarField2D>();

            generationManager = GameObject.Find("GenerationManager");
            GM = generationManager.GetComponent <GenerationManager>();

            ///////////////////////////////METHOD INITIALIZATION////////////////////////////////



            base.IMass = 1f;//REAL MASS OF UNIT

            if (SimulationManager.Get().addRigidBodyCollider == false)
            {
                base.IMaxForce = 0.06f;
                base.IMaxSpeed = 0.06f;
            }

            if (SimulationManager.Get().addRigidBodyCollider)
            {
                base.IMaxForce = 2.6f;
                base.IMaxSpeed = 2.6f;
            }

            base.VisionRadius = (this.gameObject.GetComponent <SphereCollider>().radius * 2) * 0.9f;

            rb = GetComponent <Rigidbody>();


            base.energyDecreasingFactor = 0.1f;
            base.energyLevel            = 650f; // 650 maH --> litjuim batter capacity that we are using


            base.energyCapacity = 650f; // 650 maH --> litjuim batter capacity that we are using



            if (SimulationManager.Get().addRigidBodyCollider)
            {
                this.gameObject.GetComponent <SphereCollider>().isTrigger = false;
                rb.isKinematic = false;
            }
        } // END START