/// <summary> /// Use this for initialization /// </summary> public void Start() { _connector = GetComponent <OCConnectorSingleton>() as OCConnectorSingleton; _feelingTextureMap = new Dictionary <string, UnityEngine.Texture2D>(); System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + gameObject.name + " is started."); }
/// <summary> /// Use this for initialization /// </summary> public void Start() { _connector = GetComponent <OCConnectorSingleton>() as OCConnectorSingleton; _feelingTextureMap = new Dictionary <string, UnityEngine.Texture2D>(); OCLogger.Fine(gameObject.name + " is started."); }
//--------------------------------------------------------------------------- #endregion #region Public Member Functions //--------------------------------------------------------------------------- void Awake() { _config = OCConfig.Instance; // Initialize parameters below. _modeCounts = new int[3]; _modeCounts[(int)AvatarMode.IDLE] = 0; _modeCounts[(int)AvatarMode.SLEEP] = 0; _modeCounts[(int)AvatarMode.ACTIVE] = 0; _millisecondsPerTick = _config.getLong("MILLISECONDS_PER_TICK"); this.IDLE_ENERGY_DECREASE_RATE = -_millisecondsPerTick / (MILLISECONDS_PER_DAY / _config.getInt("EAT_STOPS_PER_DAY")); this.SLEEP_ENERGY_INCREASE_RATE = -IDLE_ENERGY_DECREASE_RATE * 5; this.STARVING_ENERGY_DECREASE_RATE = IDLE_ENERGY_DECREASE_RATE * 2; this.FITNESS_DECREASE_OUTSIDE_HOME = _config.getFloat("FITNESS_DECREASE_OUTSIDE_HOME"); this.EAT_ENERGY_INCREASE = _config.getFloat("EAT_ENERGY_INCREASE"); this.EAT_POO_INCREASE = _config.getFloat("EAT_POO_INCREASE"); this.DRINK_THIRST_DECREASE = _config.getFloat("EAT_THIRST_DECREASE"); this.DRINK_PEE_INCREASE = _config.getFloat("DRINK_PEE_INCREASE"); _energy = _config.getFloat("INIT_ENERGY"); _fitness = _config.getFloat("INIT_FITNESS"); _currentMode = AvatarMode.IDLE; // this.AT_HOME_DISTANCE = config.getFloat("AT_HOME_DISTANCE"); // this.FITNESS_INCREASE_AT_HOME = config.getFloat("FITNESS_INCREASE_AT_HOME"); // this.at_home_flag = false; SetupBasicFactors(); _connector = OCConnectorSingleton.Instance; }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- /// <summary> /// Initializes this instance. Set default values here. /// </summary> private void Initialize() { _connector = (OCConnectorSingleton)OCConnectorSingleton.Instance; }
void OnGUI() { // left inset, bottom right int inset = 3; int width = 200; Rect window = new Rect(inset, Screen.height - Screen.height / 3 - inset, width, Screen.height / 3); // TODO: Verify that action list is gone. // if(_selectedAvatar == null) // { // GUILayout.Window(2, window, ActionWindow, "Your Action List"); // } // else // { // GUILayout.Window(2, window, ActionWindow, _selectedAvatar.gameObject.transform.name + "'s Action List"); // Psi (feeling, demand etc.) panel controlling section // TODO: Figure out when / if to display the emotion panel. // if(_selectedAvatar.tag == "OCA") // { // if (_connector == null) // _connector = OCConnectorSingleton.Instance; // // if(_connector != null) // { // ShowPsiPanel(); // } // // If the avatar has no connector it's a puppet Avatar controlled by the console only // if(_panelSkin != null) // { // GUI.skin = _panelSkin; // } // } // else // { // HidePsiPanel(); // _connector = null; // } if (_connector == null) _connector = OCConnectorSingleton.Instance; if(_connector != null) { if (_connector.IsEstablished) ShowPsiPanel(); } // If the avatar has no connector it's a puppet Avatar controlled by the console only if(panelSkin != null) { GUI.skin = panelSkin; } if(_showPsiPanel) { if(_connector != null) { float theWidth = Screen.width * 0.25f; float theHeight = Screen.height / 3; _panel = new Rect(Screen.width - theWidth - inset, Screen.height - theHeight - inset, theWidth, theHeight); GUILayout.Window(3, _panel, PsiPanel, _connector.Name + "'s Psi States Panel", GUILayout.MinWidth(theWidth), GUILayout.MinHeight(theHeight)); } } // }// if // TODO: Reenable this once it is clear what it does. // WorldGameObject world = GameObject.Find("World").GetComponent<WorldGameObject>(); // GUIStyle theStyle = new GUIStyle(); // theStyle.normal.background = world.storedBlockTexture; // GUI.Box(new Rect(8, 8, 40, 40), ""); // GUI.Box(new Rect(12, 12, 32, 32), "", theStyle); // the force is looping between minForce and maxForce, util the mouse button released // if(_isShowingForcePanel) // { // float currentTime = Time.time; // float deltaForce = (currentTime - _lastTimeRenderForcePanel) * MAX_FORCE; // if(_isForceIncrease) // { // _currentForce += deltaForce; // if(_currentForce > MAX_FORCE) // { // _currentForce = MAX_FORCE; // _isForceIncrease = false; // } // } // else // { // _currentForce -= deltaForce; // if(_currentForce < MIN_FORCE) // { // _currentForce = MIN_FORCE; // _isForceIncrease = true; // } // } // // DisplayForcePanel(_currentForce); // // _lastTimeRenderForcePanel = currentTime; // } }
/// <summary> /// Use this for initialization /// </summary> public void Start() { _connector = GetComponent<OCConnectorSingleton>() as OCConnectorSingleton; _feelingTextureMap = new Dictionary<string, UnityEngine.Texture2D>(); OCLogger.Fine(gameObject.name + " is started."); }
//--------------------------------------------------------------------------- #endregion #region Public Member Functions //--------------------------------------------------------------------------- void Awake() { _config = OCConfig.Instance; // Initialize parameters below. _modeCounts = new int[3]; _modeCounts[(int)AvatarMode.IDLE] = 0; _modeCounts[(int)AvatarMode.SLEEP] = 0; _modeCounts[(int)AvatarMode.ACTIVE] = 0; _millisecondsPerTick = _config.getLong("MILLISECONDS_PER_TICK"); this.IDLE_ENERGY_DECREASE_RATE = - _millisecondsPerTick / (MILLISECONDS_PER_DAY / _config.getInt("EAT_STOPS_PER_DAY")); this.SLEEP_ENERGY_INCREASE_RATE = - IDLE_ENERGY_DECREASE_RATE * 5; this.STARVING_ENERGY_DECREASE_RATE = IDLE_ENERGY_DECREASE_RATE * 2; this.FITNESS_DECREASE_OUTSIDE_HOME = _config.getFloat("FITNESS_DECREASE_OUTSIDE_HOME"); this.EAT_ENERGY_INCREASE = _config.getFloat("EAT_ENERGY_INCREASE"); this.EAT_POO_INCREASE = _config.getFloat("EAT_POO_INCREASE"); this.DRINK_THIRST_DECREASE = _config.getFloat("EAT_THIRST_DECREASE"); this.DRINK_PEE_INCREASE = _config.getFloat("DRINK_PEE_INCREASE"); _energy = _config.getFloat("INIT_ENERGY"); _fitness = _config.getFloat("INIT_FITNESS"); _currentMode = AvatarMode.IDLE; // this.AT_HOME_DISTANCE = config.getFloat("AT_HOME_DISTANCE"); // this.FITNESS_INCREASE_AT_HOME = config.getFloat("FITNESS_INCREASE_AT_HOME"); // this.at_home_flag = false; SetupBasicFactors(); _connector = OCConnectorSingleton.Instance; }
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; } }
void OnGUI() { // left inset, bottom right int inset = 3; //int width = 200; //Rect window = new Rect(inset, Screen.height - Screen.height / 3 - inset, width, Screen.height / 3); // DEPRECATED: Verify that action list is gone. // if(_selectedAvatar == null) // { // GUILayout.Window(2, window, ActionWindow, "Your Action List"); // } // else // { // GUILayout.Window(2, window, ActionWindow, _selectedAvatar.gameObject.transform.name + "'s Action List"); // Psi (feeling, demand etc.) panel controlling section // DEPRECATED: Figure out when / if to display the emotion panel. // if(_selectedAvatar.tag == "OCA") // { // if (_connector == null) // _connector = OCConnectorSingleton.Instance; // // if(_connector != null) // { // ShowPsiPanel(); // } // // If the avatar has no connector it's a puppet Avatar controlled by the console only // if(_panelSkin != null) // { // GUI.skin = _panelSkin; // } // } // else // { // HidePsiPanel(); // _connector = null; // } if (_connector == null) { _connector = OCConnectorSingleton.Instance; } if (_connector != null) { if (_connector.IsEstablished) { ShowPsiPanel(); } } // If the avatar has no connector it's a puppet Avatar controlled by the console only if (panelSkin != null) { GUI.skin = panelSkin; } if (_showPsiPanel) { if (_connector != null) { float theWidth = Screen.width * 0.25f; float theHeight = Screen.height / 3; _panel = new Rect(Screen.width - theWidth - inset, Screen.height - theHeight - inset, theWidth, theHeight); GUILayout.Window(3, _panel, PsiPanel, _connector.Name + "'s Psi States Panel", GUILayout.MinWidth(theWidth), GUILayout.MinHeight(theHeight)); } } // }// if // DEPRECATED: Reenable this once it is clear what it does. // WorldGameObject world = GameObject.Find("World").GetComponent<WorldGameObject>(); // GUIStyle theStyle = new GUIStyle(); // theStyle.normal.background = world.storedBlockTexture; // GUI.Box(new Rect(8, 8, 40, 40), ""); // GUI.Box(new Rect(12, 12, 32, 32), "", theStyle); // the force is looping between minForce and maxForce, util the mouse button released // if(_isShowingForcePanel) // { // float currentTime = Time.time; // float deltaForce = (currentTime - _lastTimeRenderForcePanel) * MAX_FORCE; // if(_isForceIncrease) // { // _currentForce += deltaForce; // if(_currentForce > MAX_FORCE) // { // _currentForce = MAX_FORCE; // _isForceIncrease = false; // } // } // else // { // _currentForce -= deltaForce; // if(_currentForce < MIN_FORCE) // { // _currentForce = MIN_FORCE; // _isForceIncrease = true; // } // } // // DisplayForcePanel(_currentForce); // // _lastTimeRenderForcePanel = currentTime; // } }
public OCObjectMapInfo(UnityEngine.GameObject gameObject) { UnityEngine.Debug.Log("OCObjectMapInfo::OCObjectMapInfo, passed object is of type: " + gameObject.GetType().ToString() + ", and name " + gameObject.name); _id = gameObject.GetInstanceID().ToString(); // // Get id of a game object // _id = gameObject.GetInstanceID ().ToString (); // Get name _name = gameObject.name; // TODO: By default, we are using object type. _type = OCEmbodimentXMLTags.ORDINARY_OBJECT_TYPE; // Convert from unity coordinate to OAC coordinate. this.position = Utility.VectorUtil.ConvertToOpenCogCoord(gameObject.transform.position); // Get rotation _rotation = new Utility.Rotation(gameObject.transform.rotation); // Calculate the velocity later _velocity = UnityEngine.Vector3.zero; // Get size if (gameObject.collider != null) { // Get size information from collider. _width = gameObject.collider.bounds.size.z; _height = gameObject.collider.bounds.size.y; _length = gameObject.collider.bounds.size.x; } else { OCLogger.Warn("No collider for gameobject " + gameObject.name + ", assuming a point."); // Set default value of the size. _width = 0.1f; _height = 0.1f; _length = 0.1f; } if (gameObject.tag == "OCAGI") { // This is an OC avatar, we will use the brain id instead of unity id. OCConnectorSingleton connector = OCConnectorSingleton.Instance; if (connector != null) { _id = connector.BrainID; _type = OCEmbodimentXMLTags.PET_OBJECT_TYPE; } UnityEngine.Debug.Log("Just made an OCObjectMapInfo stating the AGI is at [" + this.position.x + ", " + this.position.y + ", " + this.position.z + "]"); } else if (gameObject.tag == "OCNPC") { // This is a human player avatar. _type = OCEmbodimentXMLTags.AVATAR_OBJECT_TYPE; _length = OCObjectMapInfo.DEFAULT_AVATAR_LENGTH; _width = OCObjectMapInfo.DEFAULT_AVATAR_WIDTH; _height = OCObjectMapInfo.DEFAULT_AVATAR_HEIGHT; } if (gameObject.tag == "OCNPC" || gameObject.tag == "OCAGI" || gameObject.tag == "Player") { if (_height > 1.1f) // just to make sure that the center point of the character will not be in the block where the feet are { this.position = new UnityEngine.Vector3(this.position.x, this.position.y, this.position.z + 1.0f); } } if (gameObject.name == "Hearth") { this.AddProperty("petHome", "TRUE", System.Type.GetType("System.Boolean")); } // Get weight if (gameObject.rigidbody != null) { _weight = gameObject.rigidbody.mass; } else { _weight = 0.0f; } if (gameObject.GetComponent <OpenCog.Extensions.OCConsumableData>() != null) { UnityEngine.Debug.Log("Adding edible and foodbowl tags to '" + gameObject.name + "' with ID " + gameObject.GetInstanceID()); this.AddProperty("edible", "TRUE", System.Type.GetType("System.Boolean")); this.AddProperty("pickupable", "TRUE", System.Type.GetType("System.Boolean")); this.AddProperty("holder", "none", System.Type.GetType("System.String")); } // Get a property manager instance // TODO: may need to re-enable this for other object types. // OCPropertyManager manager = gameObject.GetComponent<OCPropertyManager> () as OCPropertyManager; // if (manager != null) { // // Copy all OC properties from the manager, if any. // foreach (OpenCog.Serialization.OCPropertyField ocp in manager.propertyList) { // this.AddProperty (ocp.Key, ocp.value, ocp.valueType); // } // } this.AddProperty("visibility-status", "visible", System.Type.GetType("System.String")); this.AddProperty("detector", "true", System.Type.GetType("System.Boolean")); string gameObjectName = gameObject.name; if (gameObjectName.Contains("(")) { gameObjectName = gameObjectName.Remove(gameObjectName.IndexOf('(')); } // For Einstein puzzle if (gameObject.name.Contains("_man")) { _id = _name; this.AddProperty("class", "people", System.Type.GetType("System.String")); } else { this.AddProperty("class", gameObjectName, System.Type.GetType("System.String")); } }
//DEPRECATED: This was useful once; //if (!OCARepository.AddOCA (agentClone)) { // Note, lambda expressions (ie myLamb = (x) => successBool = (bool)(x == "true")) are *terrifying* to look at // and can use up a lot of memory, but they're really good for returning values from IEnumerators/coroutines; // especially ones we don't expect will be called frquently /// <summary> /// Allows entities to be loaded to the screen at any point while the game is running /// </summary> /// <returns>Failure, success, or a coroutine concerned with making a connection to the embodiment.</returns> /// <param name="spawnPosition">The position at which to instantiate the agent.</param> /// <param name="agentPrefab">The prefab to instantiate.</param> /// <param name="agentName">The name of the agent to instantiate.</param> /// <param name="masterName">The owner of the instance</param> /// <param name="masterId">The id of the instance</param> /// <param name="report">An Action that can be constructed easily with a lambda expression which will report back the string "true" if it successfully /// created the agent and the string "false" if it was unsuccessful in creating the agent.</param> public IEnumerator AtRunTime(UnityEngine.Vector3 spawnPosition, GameObject agentPrefab, string agentName = "", string masterName = "", string masterId = "", System.Action <string> report = null) //The lambda expression enter-er gets its own line, because it's SCARY! { //get the spawn position in terms of the grid spawnPosition.x = (float)((int)spawnPosition.x); spawnPosition.y = (float)((int)spawnPosition.y); spawnPosition.z = (float)((int)spawnPosition.z); //Debug.Log ("_NPCAgent is" + (_NPCAgent == null ? " null " : " not null")); //instantiate the game object, specified by NPCAgent at point spawn position and rotated as per the identity Quaternion (that is, not at all) UnityEngine.GameObject agentClone = (GameObject)UnityEngine.Object.Instantiate(agentPrefab, spawnPosition, Quaternion.identity); //All agents belong to the Characters parent game object. agentClone.transform.parent = GameObject.Find("Characters").transform; //the _NPCAgent should have come with an OCActionController OCActionController 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; //Debug.Log ("connector is" + (connector == null ? " null " : " not null")); //Ensure our agent is properly named if (agentName == "") { agentName = CreateRandomAgentName(); } agentClone.name = agentName; //initialize the connector connector.InitAvatar(agentName, null, null, masterId, masterName); //and try to connect yield return(StartCoroutine(connector.ConnectOAC())); //if we failed to initialize the connector if (!connector.IsInitialized) { // OAC is not loaded normally, destroy the avatar instance. Debug.LogError(OCLogSymbol.ERROR + "Could not connect to Embodiment"); System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + "LoadMethods.AtRunTime is reporting !connector.Initialize. Cannot connect to the OAC, avatar loading failed."); connector.SaveAndExit(); Destroy(agentClone); if (report != null) { report("false"); } } else { Debug.Log(OCLogSymbol.CLEARED + "LoadMethods.AtRunTime is reporting connector.Initialized"); if (report != null) { report("true"); } } yield break; }
/// <summary> /// Use this for initialization /// </summary> public void Start() { _connector = GetComponent<OCConnectorSingleton>() as OCConnectorSingleton; _feelingTextureMap = new Dictionary<string, UnityEngine.Texture2D>(); System.Console.WriteLine(OCLogSymbol.DETAILEDINFO +gameObject.name + " is started."); }