예제 #1
0
        /// <summary>
        /// It's purpose is to wrap LoadAgent(agentName, pos)
        /// </summary>
        /// <returns>Failure, success, or the continuation of a coroutine which attempts to establish a connection with the OpenCog embodiment.</returns>
        /// <param name="agentName">The name of the agent to instantiate.</param>
        private IEnumerator LoadAgent(string agentName)
        {
            //get the player object, if it exists
            UnityEngine.GameObject playerObject = GameObject.FindGameObjectWithTag("Player");

            //if it does not exist, we cannot run this wrapper
            if (playerObject == null)
            {
                Debug.LogError("No object tagged with player.");
                yield break;
            }

            //we want to place it ahead of the player
            UnityEngine.Vector3 eulerAngle = playerObject.transform.rotation.eulerAngles;
            UnityEngine.Vector3 position   = playerObject.transform.position;

            //find a position slightly in front of us
            float zFront = 3.0f * (float)Math.Cos((eulerAngle.y / 180) * Math.PI);
            float xFront = 3.0f * (float)Math.Sin((eulerAngle.y / 180) * Math.PI);

            //add the position data together.
            UnityEngine.Vector3 newPos = new Vector3(position.x + xFront, position.y + 2, position.z + zFront);

            // TODO [MULTI-AVATAR] Currently we use the tag "player". However, when there are multiple
            // players in the world, we need to figure out a way to identify.
            // Set agentType and agentTraits in the future.
            // leave agentType and agentTraits to null just for test.
            //get data about the player
            string masterId   = playerObject.GetInstanceID().ToString();
            string masterName = playerObject.name;

            //Attack of the top level management decisions!
            yield return(StartCoroutine(GameManager.entity.load.AtRunTime(newPos, _NPCAgent, agentName, masterName, masterId)));

            //this is unnecessary
            //yield break;
        }
예제 #2
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Private Member Functions

        //---------------------------------------------------------------------------

        /// <summary>
        /// Initializes this instance.  Set default values here.
        /// </summary>
        private void Initialize()
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }
예제 #3
0
		//---------------------------------------------------------------------------

	#endregion

		//---------------------------------------------------------------------------

	#region Private Member Functions

		//---------------------------------------------------------------------------
	
		/// <summary>
		/// Initializes this instance.  Set default values here.
		/// </summary>
		private void Initialize ()
		{
			player = GameObject.FindGameObjectWithTag("Player");
		}
        private IEnumerator LoadAgent(string agentName)
        {
            UnityEngine.GameObject agentClone;

            UnityEngine.GameObject playerObject = GameObject.FindGameObjectWithTag("Player");
            if (playerObject == null)
            {
                Debug.Log("No object tagged with player.");
                yield return("No object tagged with player.");
            }

            // Record the player's position and make the OCAvatar spawn near it.
            UnityEngine.Vector3 playerPos = playerObject.transform.position;

            //Debug.Log ("PlayerPos = [" + playerPos.x + ", " + playerPos.y + ", " + playerPos.z + "]");

            // Calculate the player's forward direction
            UnityEngine.Vector3 eulerAngle = playerObject.transform.rotation.eulerAngles;

            //Debug.Log ("eulerAngle = [" + eulerAngle.x + ", " + eulerAngle.y + ", " + eulerAngle.z + "]");

            float zFront = 3.0f * (float)Math.Cos((eulerAngle.y / 180) * Math.PI);
            float xFront = 3.0f * (float)Math.Sin((eulerAngle.y / 180) * Math.PI);

            UnityEngine.Vector3 spawnPosition = new UnityEngine.Vector3(playerPos.x + xFront, playerPos.y + 2, playerPos.z + zFront);
            spawnPosition.x = (float)((int)spawnPosition.x);
            spawnPosition.y = (float)((int)spawnPosition.y);
            spawnPosition.z = (float)((int)spawnPosition.z);

            //Debug.Log ("spawnPosition = [" + spawnPosition.x + ", " + spawnPosition.y + ", " + spawnPosition.z + "]");

            // Instantiate an OCAvatar in front of the player.

            //Debug.Log ("_NPCAgent is" + (_NPCAgent == null ? " null " : " not null"));

            agentClone = (GameObject)UnityEngine.Object.Instantiate(_NPCAgent, spawnPosition, Quaternion.identity);
            agentClone.transform.parent = GameObject.Find("Characters").transform;
            OCActionController agiAC = agiAC = agentClone.GetComponent <OCActionController>();

            agiAC.DefaultEndTarget   = GameObject.Find("EndPointStub");
            agiAC.DefaultStartTarget = GameObject.Find("StartPointStub");

            //Debug.Log ("agentClone is" + (agentClone == null ? " null " : " not null"));

            OCConnectorSingleton connector = OCConnectorSingleton.Instance;

            UnityEngine.Debug.Log("The GUID of our OCC instance in LoadAgent is " + connector.VerificationGuid);

            //Debug.Log ("connector is" + (connector == null ? " null " : " not null"));

            if (agentName == "")
            {
                agentName = CreateRandomAgentName();
            }

            //Debug.Log("We shall name him '" + agentName + "'");

            agentClone.name = agentName;

//			if (agentClone != null) {
//				if (!OCARepository.AddOCA (agentClone)) {
//					// An avatar with given name is already there.
//					yield break;
//				}
//				Debug.Log ("Add avatar[" + agentName + "] to avatar map.");
//			}

            // Get the player id as the master id of the avatar.
            // TODO Currently we use the tag "player". However, when there are multiple
            // players in the world, we need to figure out a way to identify.
            string masterId   = playerObject.GetInstanceID().ToString();
            string masterName = playerObject.name;

            // TODO Set agentType and agentTraits in the future.
            // leave agentType and agentTraits to null just for test.
            connector.Init(agentName, null, null, masterId, masterName);

            yield return(StartCoroutine(connector.ConnectOAC()));

            if (!connector.IsInitialized)
            {
                // OAC is not loaded normally, destroy the avatar instance.
                Debug.LogError("Cannot connect to the OAC, avatar loading failed.");
                connector.SaveAndExit();
                Destroy(agentClone);
                yield break;
            }
        }