Exemplo n.º 1
0
        /// <summary>
        /// Creates a new Connection GameObject and related components.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="filterExerciseID"></param>
        /// <param name="exerciseID"></param>
        /// <returns></returns>
        public static GameObject CreateConnection(string name, bool filterExerciseID, int exerciseID)
        {
            GameObject connectionGO = new GameObject(name);
            Connection connection   = connectionGO.AddComponent <Connection>();

            // PDU Factory
            GameObject factoryGO = new GameObject("PDU Factory");

            factoryGO.transform.parent = connectionGO.transform;

            DecodeFactory facory = factoryGO.AddComponent <DecodeFactory>();

            connection.Factory = facory;

            // Filters
            GameObject filtersGO = new GameObject("Filters");

            filtersGO.transform.parent = connectionGO.transform;

            // Exercise ID Filter
            if (filterExerciseID)
            {
                ExerciseIDFilter exid = filtersGO.AddComponent <ExerciseIDFilter>();
                exid.AllowedExerciseID = exerciseID;
                facory.Filters.Add(exid);
            }

            return(connectionGO);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the required objects for a DIS exercise using the provided params.
        /// </summary>
        public void Create()
        {
            // Create the root GameObject
            GameObject rootGO = new GameObject(rootName);

            // Exercise info
            GameObject exerciseGO = new GameObject("Exercise Manager");

            exerciseGO.transform.parent = rootGO.transform;
            ExerciseManager exMan = exerciseGO.AddComponent <ExerciseManager>();

            exMan.Address = address;

            // Entity Manager
            GameObject entGO = new GameObject("Entity Manager");

            entGO.transform.parent = rootGO.transform;
            EntityManager entMan = entGO.AddComponent <EntityManager>();

            // Entity type
            GameObject mapGo = new GameObject("Entity Map");

            mapGo.transform.parent = entGO.transform;
            entMan.EntityMap       = mapGo.AddComponent(typeof(EntityTypeMap)) as EntityTypeMap;
            entMan.EntityMap.Load();

            // Create a gameobject to be parent of all remote entities.
            GameObject remoteEntsParent = new GameObject("Remote Entities");

            remoteEntsParent.transform.parent = entGO.transform;
            entMan.RemoteEntityParent         = remoteEntsParent;

            // Connection
            GameObject conGO = new GameObject("Connection");

            conGO.transform.parent = rootGO.transform;
            Connection connection = conGO.AddComponent <Connection>();

            connection.Port = port;
            connection.ReceivePollFrequency = refreshFreq;
            connection.UseBroadcast         = useBroadcast;
            connection.BroadcastAddress     = broadcastAddress;
            connection.MulticastGroups      = multicastAddresses;
            DecodeFactory facory = conGO.AddComponent <DecodeFactory>();

            connection.Factory = facory;

            // Filters
            GameObject filtersGO = new GameObject("Filters");

            filtersGO.transform.parent = conGO.transform;

            // Exercise ID Filter
            ExerciseIDFilter exid = filtersGO.AddComponent <ExerciseIDFilter>();

            exid.AllowedExerciseID = exerciseID;
            facory.Filters.Add(exid);

            Undo.RegisterCreatedObjectUndo(rootGO, "Setup Scene For DIS");
            Close();
        }