Example #1
0
    public void Update()
    {
        if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) {
            if (Input.GetKeyDown(KeyCode.Alpha1)) {
                Movement.autoflyspeed = 0F;
                selfTransform.localPosition = UnityConstants.startingLocOne;
                trackOctant (CommonUtility.getOctantIndicesFromVector3
                    (new remap.NDNMOG.DiscoveryModule.Vector3(UnityConstants.startingLocOne.x, UnityConstants.startingLocOne.y, UnityConstants.startingLocOne.z)));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha2)) {
                Movement.autoflyspeed = 0F;
                selfTransform.localPosition = UnityConstants.startingLocTwo;
                trackOctant (CommonUtility.getOctantIndicesFromVector3
                    (new remap.NDNMOG.DiscoveryModule.Vector3(UnityConstants.startingLocTwo.x, UnityConstants.startingLocTwo.y, UnityConstants.startingLocTwo.z)));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha3)) {
                Movement.autoflyspeed = 0F;
                selfTransform.localPosition = UnityConstants.startingLocThree;
                trackOctant (CommonUtility.getOctantIndicesFromVector3
                    (new remap.NDNMOG.DiscoveryModule.Vector3(UnityConstants.startingLocThree.x, UnityConstants.startingLocThree.y, UnityConstants.startingLocThree.z)));
            }
        }

        selfLocation.x_ = selfTransform.localPosition.x;
        selfLocation.y_ = selfTransform.localPosition.y;
        selfLocation.z_ = selfTransform.localPosition.z;

        // setLocation talks with DiscoveryModule without calling callback.
        instance.getSelfGameEntity ().setLocation (selfLocation, false);
        List<string> toDelete = new List<string> ();
        // For iteration
        Transform entity;
        // Is generating a copy of hashtable a potentially better idea than this?
        hashtableLock.WaitOne ();
        foreach (DictionaryEntry pair in gameEntityHashtable) {
            entity = playersParentTransform.Find(((string)pair.Key).Replace("/", "-"));

            remap.NDNMOG.DiscoveryModule.Vector3 location = new remap.NDNMOG.DiscoveryModule.Vector3 ((remap.NDNMOG.DiscoveryModule.Vector3)pair.Value);
            //Debug.Log(location.x_);
            UnityEngine.Vector3 locationUnity = new UnityEngine.Vector3 (location.x_, location.y_, location.z_);

            if (entity == null) {
                if (locationUnity.x != Constants.DefaultLocationDropEntity && locationUnity.x != Constants.DefaultLocationNewEntity) {
                    Transform newEntity = Instantiate (playerTransform, locationUnity, Quaternion.identity) as Transform;
                    newEntity.name = ((string)pair.Key).Replace("/", "-");
                    newEntity.parent = GameObject.Find(UnityConstants.playerParentPath).transform;
                    newEntity.Find(UnityConstants.labelTransformPath.TrimStart('/')).guiText.text = (string)pair.Key;
                }
            } else {
                if (locationUnity.x != Constants.DefaultLocationDropEntity && locationUnity.x != Constants.DefaultLocationNewEntity) {
                    entity.transform.localPosition = locationUnity;
                } else {
                    Destroy (entity.gameObject);

                    // hashtable deletion in foreach loop is considered illegal
                    toDelete.Add ((string)pair.Key);
                }
            }
        }
        foreach (string str in toDelete) {
            gameEntityHashtable.Remove (str);
        }
        if (instantiated) {
            updateOctantList ((int)selfLocation.x_, (int)selfLocation.y_, (int)selfLocation.z_);
        }

        hashtableLock.ReleaseMutex ();

        renderListLock.WaitOne ();
        if (renderList.Count != 0) {
            // Rendering based on the list...which still tells me collection is modified, even if I have the lock to protect it...finding out why.
            foreach (EntityInfo ei in renderList) {
                GameObject renderEntity = playersParentTransform.Find(ei.name_.Replace("/", "-") + UnityConstants.dollPath).gameObject;
                if (renderEntity != null) {
                    string path = "Materials/" + ei.renderString_;
                    Material unityMaterial = Resources.Load (path, typeof(Material)) as Material;

                    if (unityMaterial != null) {
                        renderEntity.GetComponent<MeshRenderer> ().material = unityMaterial;
                    }
                }
            }

            renderList.Clear();
        }
        renderListLock.ReleaseMutex ();
    }
Example #2
0
    public void Update()
    {
        if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
        {
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                Movement.autoflyspeed       = 0F;
                selfTransform.localPosition = UnityConstants.startingLocOne;
                trackOctant(CommonUtility.getOctantIndicesFromVector3
                                (new remap.NDNMOG.DiscoveryModule.Vector3(UnityConstants.startingLocOne.x, UnityConstants.startingLocOne.y, UnityConstants.startingLocOne.z)));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                Movement.autoflyspeed       = 0F;
                selfTransform.localPosition = UnityConstants.startingLocTwo;
                trackOctant(CommonUtility.getOctantIndicesFromVector3
                                (new remap.NDNMOG.DiscoveryModule.Vector3(UnityConstants.startingLocTwo.x, UnityConstants.startingLocTwo.y, UnityConstants.startingLocTwo.z)));
            }
            else if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                Movement.autoflyspeed       = 0F;
                selfTransform.localPosition = UnityConstants.startingLocThree;
                trackOctant(CommonUtility.getOctantIndicesFromVector3
                                (new remap.NDNMOG.DiscoveryModule.Vector3(UnityConstants.startingLocThree.x, UnityConstants.startingLocThree.y, UnityConstants.startingLocThree.z)));
            }
        }

        selfLocation.x_ = selfTransform.localPosition.x;
        selfLocation.y_ = selfTransform.localPosition.y;
        selfLocation.z_ = selfTransform.localPosition.z;

        // setLocation talks with DiscoveryModule without calling callback.
        instance.getSelfGameEntity().setLocation(selfLocation, false);
        List <string> toDelete = new List <string> ();
        // For iteration
        Transform entity;

        // Is generating a copy of hashtable a potentially better idea than this?
        hashtableLock.WaitOne();
        foreach (DictionaryEntry pair in gameEntityHashtable)
        {
            entity = playersParentTransform.Find(((string)pair.Key).Replace("/", "-"));

            remap.NDNMOG.DiscoveryModule.Vector3 location = new remap.NDNMOG.DiscoveryModule.Vector3((remap.NDNMOG.DiscoveryModule.Vector3)pair.Value);
            //Debug.Log(location.x_);
            UnityEngine.Vector3 locationUnity = new UnityEngine.Vector3(location.x_, location.y_, location.z_);

            if (entity == null)
            {
                if (locationUnity.x != Constants.DefaultLocationDropEntity && locationUnity.x != Constants.DefaultLocationNewEntity)
                {
                    Transform newEntity = Instantiate(playerTransform, locationUnity, Quaternion.identity) as Transform;
                    newEntity.name   = ((string)pair.Key).Replace("/", "-");
                    newEntity.parent = GameObject.Find(UnityConstants.playerParentPath).transform;
                    newEntity.Find(UnityConstants.labelTransformPath.TrimStart('/')).guiText.text = (string)pair.Key;
                }
            }
            else
            {
                if (locationUnity.x != Constants.DefaultLocationDropEntity && locationUnity.x != Constants.DefaultLocationNewEntity)
                {
                    entity.transform.localPosition = locationUnity;
                }
                else
                {
                    Destroy(entity.gameObject);

                    // hashtable deletion in foreach loop is considered illegal
                    toDelete.Add((string)pair.Key);
                }
            }
        }
        foreach (string str in toDelete)
        {
            gameEntityHashtable.Remove(str);
        }
        if (instantiated)
        {
            updateOctantList((int)selfLocation.x_, (int)selfLocation.y_, (int)selfLocation.z_);
        }

        hashtableLock.ReleaseMutex();

        renderListLock.WaitOne();
        if (renderList.Count != 0)
        {
            // Rendering based on the list...which still tells me collection is modified, even if I have the lock to protect it...finding out why.
            foreach (EntityInfo ei in renderList)
            {
                GameObject renderEntity = playersParentTransform.Find(ei.name_.Replace("/", "-") + UnityConstants.dollPath).gameObject;
                if (renderEntity != null)
                {
                    string   path          = "Materials/" + ei.renderString_;
                    Material unityMaterial = Resources.Load(path, typeof(Material)) as Material;

                    if (unityMaterial != null)
                    {
                        renderEntity.GetComponent <MeshRenderer> ().material = unityMaterial;
                    }
                }
            }

            renderList.Clear();
        }
        renderListLock.ReleaseMutex();
    }
Example #3
0
    public void Start()
    {
        UnityConstants.init();

        selfTransform = GameObject.Find (UnityConstants.selfTransformPath).transform;
        playersParentTransform = GameObject.Find(UnityConstants.playerParentPath).transform;

        minimapCamera = GameObject.Find(UnityConstants.selfTransformPath + UnityConstants.minimapCameraPath).transform;

        renderString = Constants.DefaultRenderString;

        AsteroidInstantiate.init ();
        playerTransform = GameObject.Find (UnityConstants.playerTransformPath).transform;
        cubeTransform = GameObject.Find (UnityConstants.cubeTransformPath).transform;

        UnityEngine.Vector3 dollPosUnity = UnityConstants.startingLocOne;
        transform.position = dollPosUnity;

        remap.NDNMOG.DiscoveryModule.Vector3 dollPos = new remap.NDNMOG.DiscoveryModule.Vector3 (dollPosUnity.x, dollPosUnity.y, dollPosUnity.z);
        List<int> startingOct = CommonUtility.getOctantIndicesFromVector3 (dollPos);
        populateAsteroids(startingOct);

        log = new Logging (playerName, UnityConstants.gameLogName, UnityConstants.libraryLogName);
        if (!readConfFromFile (UnityConstants.configFilePath)) {
            playerName = "default";
            log.writeLog ("Didn't parse config file, using default as name.");
        }

        if (loggingLevel != UnityConstants.LoggingLevelNone) {
            log.level_ = LoggingLevel.All;
        } else {
            log.level_ = LoggingLevel.None;
        }

        instance = new Instance (startingOct, playerName, dollPos, setPosCallback, log.libraryWriteCallback, infoCallback, null, null, null, renderString, hubPrefix);
        instance.discovery ();

        instantiated = true;
        // instance is interested in its starting location
        trackOctant (startingOct);

        // set playerName for label: this is the full name of the local player.
        GameObject.Find (UnityConstants.playerTransformPath + UnityConstants.labelTransformPath).guiText.text = instance.getSelfGameEntity().getHubPrefix() + "/" + Constants.PlayersPrefix + "/" + playerName;

        GameObject entity = GameObject.Find (UnityConstants.playerTransformPath + UnityConstants.dollPath);
        if (entity != null) {
            string path = "Materials/" + renderString;
            Material unityMaterial = Resources.Load (path, typeof(Material)) as Material;

            if (unityMaterial != null) {
                entity.GetComponent<MeshRenderer> ().material = unityMaterial;
            }
        }
    }
Example #4
0
    public void Start()
    {
        UnityConstants.init();

        selfTransform          = GameObject.Find(UnityConstants.selfTransformPath).transform;
        playersParentTransform = GameObject.Find(UnityConstants.playerParentPath).transform;

        minimapCamera = GameObject.Find(UnityConstants.selfTransformPath + UnityConstants.minimapCameraPath).transform;

        renderString = Constants.DefaultRenderString;

        AsteroidInstantiate.init();
        playerTransform = GameObject.Find(UnityConstants.playerTransformPath).transform;
        cubeTransform   = GameObject.Find(UnityConstants.cubeTransformPath).transform;

        UnityEngine.Vector3 dollPosUnity = UnityConstants.startingLocOne;
        transform.position = dollPosUnity;

        remap.NDNMOG.DiscoveryModule.Vector3 dollPos = new remap.NDNMOG.DiscoveryModule.Vector3(dollPosUnity.x, dollPosUnity.y, dollPosUnity.z);
        List <int> startingOct = CommonUtility.getOctantIndicesFromVector3(dollPos);

        populateAsteroids(startingOct);

        log = new Logging(playerName, UnityConstants.gameLogName, UnityConstants.libraryLogName);
        if (!readConfFromFile(UnityConstants.configFilePath))
        {
            playerName = "default";
            log.writeLog("Didn't parse config file, using default as name.");
        }

        if (loggingLevel != UnityConstants.LoggingLevelNone)
        {
            log.level_ = LoggingLevel.All;
        }
        else
        {
            log.level_ = LoggingLevel.None;
        }

        instance = new Instance(startingOct, playerName, dollPos, setPosCallback, log.libraryWriteCallback, infoCallback, null, null, null, renderString, hubPrefix);
        instance.discovery();

        instantiated = true;
        // instance is interested in its starting location
        trackOctant(startingOct);

        // set playerName for label: this is the full name of the local player.
        GameObject.Find(UnityConstants.playerTransformPath + UnityConstants.labelTransformPath).guiText.text = instance.getSelfGameEntity().getHubPrefix() + "/" + Constants.PlayersPrefix + "/" + playerName;

        GameObject entity = GameObject.Find(UnityConstants.playerTransformPath + UnityConstants.dollPath);

        if (entity != null)
        {
            string   path          = "Materials/" + renderString;
            Material unityMaterial = Resources.Load(path, typeof(Material)) as Material;

            if (unityMaterial != null)
            {
                entity.GetComponent <MeshRenderer> ().material = unityMaterial;
            }
        }
    }