/// <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.");
        }
        private string ParseDMessage(string inputLine)
        {
            UnityEngine.Debug.Log("OCMessageHandler::ParseDMessage");

            string answer = null;

            string contents = inputLine.Substring(1);

            if (_state == READING_MESSAGES)
            {
                if (_lineCount > 0)
                {
                    _message.Append("\n");
                }
                _message.Append(contents);
                _lineCount++;
            }
            else
            {
                OCLogger.Error("onLine: Unexpected dataline. Discarding line [" +
                               inputLine + "]");
                answer = OCNetworkElement.FAILED_MESSAGE;
            }

            return(answer);
        }
        public void UpdateMessagesSync(System.Net.Sockets.Socket workSocket)
        {
            UnityEngine.Debug.Log("OCMessageHandler::UpdateMessagesSync");

            StreamReader reader = null;
            StreamWriter writer = null;

            try
            {
                Stream s = new NetworkStream(workSocket);
                reader = new StreamReader(s);
                writer = new StreamWriter(s);
            }
            catch (IOException ioe)
            {
                workSocket.Close();
                OCLogger.Error("An I/O error occured.  [" + ioe.Message + "].");
            }

            bool endInput = false;

            while (!endInput)
            {
                try
                {
                    //@TODO Make some tests to judge the read time.
                    string line = reader.ReadLine();

                    if (line != null)
                    {
                        UnityEngine.Debug.Log("Parsing line: " + line);

                        string answer = Parse(line);
                    }
                    else
                    {
                        endInput = true;
                    }
                }
                catch (IOException ioe)
                {
                    UnityEngine.Debug.Log("An I/O error occured.  [" + ioe.Message + "].");
                    endInput = true;
                }
            }

            try
            {
                reader.Close();
                writer.Close();
                workSocket.Close();
            }
            catch (IOException ioe)
            {
                UnityEngine.Debug.Log("Something went wrong: " + ioe.Message);
                //OCLogger.Error("An I/O error occured.  [" + ioe.Message + "].");
                endInput = true;
            }
        }
예제 #4
0
        //---------------------------------------------------------------------------

        #endregion

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

        #region Public Member Functions

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

        void Start()
        {
            _face = transform.Find("robotG/mainG/head_GEO");
            if (!_face)
            {
                OCLogger.Error("Face of the robot is not found");
            }
        }
예제 #5
0
 /// <summary>
 /// Notify a number of new messages from router.
 /// </summary>
 /// <param name="newMessagesNum">number of new arriving messages</param>
 public void NotifyNewMessages(int newMessagesNum)
 {
     OCLogger.Debugging("Notified about new messages in Router.");
     lock (_unreadMessagesLock)
     {
         _unreadMessagesCount += newMessagesNum;
         OCLogger.Debugging("Unread messages [" + _unreadMessagesCount + "]");
     }
 }
예제 #6
0
        /// <summary>
        /// Use this for initialization
        /// </summary>
        public void Start()
        {
            Input.eatKeyPressOnTextFieldFocus = false;


            _panelHeight = Screen.height * 0.30f;


            // TODO: Re-enable line below
            //_inputController = (GameObject.FindWithTag("OCInputController") as GameObject).GetComponent<OCInputController>();

            // TODO: Disable line below
            //_inputController = (GameObject.FindWithTag("CharacterInputController") as GameObject).GetComponent<CharacterInputController>();

            _player = GameObject.FindGameObjectWithTag("Player");
            //_inputController = OpenCog.Character.OCInputController.Instance;


            // Initialise position
            _currentYPosition = -_panelHeight;
            _panelRect        = new Rect(0, _currentYPosition, Screen.width, _panelHeight);
            // If user has made console visible using public property then ensure
            // it starts appearing
            if (_isShown)
            {
                this._movementState = Movement.APPEARING;
            }

            // TODO: Removed this, may need checking.
            //OCActionController.globalActionCompleteEvent += new ActionCompleteHandler (notifyActionComplete);

            // Initialise support
            _consoleEntries = new ArrayList();
            _inputHistory   = new LinkedList <string>();
            if (_defaultCommand == null || _defaultCommand == "")
            {
                if (_commandTable.Contains("say"))
                {
                    _defaultCommand = "say";
                }
            }
            _completionPossibilities = new ArrayList();

            // add history of commands here... good way of storing test cases
            _inputHistory.AddFirst("/do Avatar self MoveToObject \"Soccer Ball\"");
            _inputHistory.AddFirst("/do Avatar \"Soccer Ball\" Kick 3000");
            _inputHistory.AddFirst("/do Avatar \"Soccer Ball\" PickUp");
            _inputHistory.AddFirst("/do Avatar \"Soccer Ball\" Drop");
            _inputHistory.AddFirst("/list Avatar");
            _inputHistory.AddFirst("/load AGI_Robot");

            OCLogger.Fine(gameObject.name + " is started.");
        }
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            if (_dirty)
            {
                Build();
                _dirty = _lightDirty = false;
            }
            if (_lightDirty)
            {
                BuildLighting();
                _lightDirty = false;
            }

            OCLogger.Fine(gameObject.name + " is updated.");
        }
        //---------------------------------------------------------------------------

        #endregion

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

        #region Accessors and Mutators

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



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

        #endregion

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

        #region Public Member Functions

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

        public static int AllocatePort()
        {
            int port = MIN_PORT_NUMBER;

            while (_usedPorts.Contains(port) && port < 65535)
            {
                port++;
            }

            if (port >= 65535)     // No ports are available
            {
                OCLogger.Error("No more ports available between " + MIN_PORT_NUMBER + " and " + port + ".");
                return(-1);
            }

            _usedPorts.Add(port);
            return(port);
        }
        /// <summary>
        /// Use this for initialization
        /// </summary>
        public void Start()
        {
            Transform reticule = gameObject.transform.Find("Reticule");

            if (reticule == null)
            {
                Debug.LogError("No \"Reticule\" game object found");
            }
            _reticuleTexture            = reticule.gameObject.GetComponent <GUITexture>();
            _reticuleTexture.pixelInset = new Rect(Screen.width / 2, Screen.height / 2, 16, 16);

            _feelingTextureMap = new Dictionary <string, Texture2D>();
            _demandTextureMap  = new Dictionary <string, Texture2D>();

            ConstructForceTexture();

            OCLogger.Fine(gameObject.name + " is started.");
        }
        private string ParseCMessage(string inputLine)
        {
            UnityEngine.Debug.Log("OCMessageHandler::ParseCMessage");

            string contents = inputLine.Substring(1);
            string answer   = null;

            string[]    tokenArr = contents.Split(' ');
            IEnumerator token    = tokenArr.GetEnumerator();

            token.MoveNext();
            string command = token.Current.ToString();

            if (command.Equals("NOTIFY_NEW_MESSAGE"))
            {
                answer = ParseNotifyNewMessage(token);
            }
            else if (command.Equals("UNAVAILABLE_ELEMENT"))
            {
                answer = ParseUnavailableElement(token);
            }
            else if (command.Equals("AVAILABLE_ELEMENT"))
            {
                answer = ParseAvailableElement(token);
            }
            else if (command.Equals("START_MESSAGE"))    // Parse a common message
            {
                answer = ParseStartMessage(inputLine, command, token);
            }
            else if (command.Equals("NO_MORE_MESSAGES"))
            {
                answer = ParseNoMoreMessages(inputLine, command, token);
            }
            else
            {
                OCLogger.Error("onLine: Unexpected command [" + command + "]. Discarding line [" + inputLine + "]");
                answer = OCNetworkElement.FAILED_MESSAGE;
            }     // end processing command.

            return(answer);
        }
예제 #11
0
        public void Stop()
        {
            _shouldStop = true;

            if (_listener == null)
            {
                UnityEngine.Debug.Log("_listener == null, nothing to call Stop on...");
            }
            else
            {
                try
                {
                    _listener.Stop();
                    _listener = null;
                }
                catch (SocketException se)
                {
                    OCLogger.Error(se.Message);
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            if (_isEstablished)
            {
                if (!_isListening)
                {
                    StartListening();
                }
                else if (_listener.IsReady && !_isHandlingMessages)
                {
                    StartHandling();
                    Pulse();
                }
                else
                {
                    Pulse();
                }
            }


            OCLogger.Fine(this.name + " is updated.");
        }
        /// <summary>
        /// Parse a text line from message received.
        /// </summary>
        /// <param name='inputLine'>
        /// The raw data that received by server socket.
        /// </param>
        /// <returns>
        /// An 'OK' string if the line was successfully parsed,
        /// a 'FAILED' string if something went wrong,
        /// null if there is still more to parse.
        /// </returns>
        private string Parse(string inputLine)
        {
            UnityEngine.Debug.Log("OCMessageHandler::Parse (" + inputLine + ")");

            string answer = null;

            if (_networkElement == null)
            {
                _networkElement = OCNetworkElement.Instance;
            }

            UnityEngine.Debug.Log("_networkElement == null? I wonder..." + ((_networkElement == null) ? "yes...it is..." : "no...it isn't"));

//		if (_networkElement != null) {
//			//UnityEngine.Debug.Log ("OCMessageHandler is using a NetworkElement with ID " + _networkElement.VerificationGuid + "...");
//		}
//		else {
//			//UnityEngine.Debug.Log("_networkElement == null");
//		}

            char selector = inputLine[0];

            if (selector == 'c')
            {
                answer = ParseCMessage(inputLine);
            }
            else if (selector == 'd')
            {
                answer = ParseDMessage(inputLine);
            }
            else
            {
                OCLogger.Error("onLine: Invalid selector [" + selector
                               + "]. Discarding line [" + inputLine + "].");
                answer = OCNetworkElement.FAILED_MESSAGE;
            }

            return(answer);
        }
        private string ParseAvailableElement(IEnumerator token)
        {
            UnityEngine.Debug.Log("OCMessageHandler::ParseAvailableElement");

            string answer = null;

            if (token.MoveNext())    // Has more elements
            {
                string id = token.Current.ToString();

                OCLogger.Debugging("onLine: Available element message received for [" +
                                   id + "].");
                _networkElement.MarkAsAvailable(id);
                answer = OCNetworkElement.OK_MESSAGE;
            }
            else
            {
                answer = OCNetworkElement.FAILED_MESSAGE;
            }

            return(answer);
        }
        private string ParseNotifyNewMessage(IEnumerator token)
        {
            UnityEngine.Debug.Log("OCMessageHandler::ParseNotifyNewMessage");

            string answer = null;

            if (token.MoveNext())    // Has more elements
            {
                // Get new message number.
                int numberOfMessages = int.Parse(token.Current.ToString());

                _networkElement.NotifyNewMessages(numberOfMessages);
                answer = OCNetworkElement.OK_MESSAGE;

                OCLogger.Debugging("onLine: Notified about [" +
                                   numberOfMessages + "] messages in Router.");
            }
            else
            {
                answer = OCNetworkElement.FAILED_MESSAGE;
            }

            return(answer);
        }
예제 #16
0
        public void LoadFromFile(string fileName)
        {
            System.IO.StreamReader reader = new System.IO.StreamReader(fileName);
            char[] separator  = { '=', ' ' };
            int    linenumber = 0;

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                linenumber++;

                // not a commentary or an empty line
                if (line.Length > 0 && line[0] != '#')
                {
                    string[] tokens = line.Split(separator, System.StringSplitOptions.RemoveEmptyEntries);
                    if (tokens.Length < 2)
                    {
                        // TODO: Debug.isDebugBuild??
                        //if (Debug.isDebugBuild)
                        OCLogger.Debugging("Invalid format at line " + linenumber + ": '" + line + "'");
                    }
                    if (table.ContainsKey(tokens[0]))
                    {
                        //if (Debug.isDebugBuild) Debug.Log(tokens[0] + "=" + tokens[1]);
                        table[tokens[0]] = tokens[1];
                    }
                    else
                    {
                        OCLogger.Debugging("Ignoring unknown parameter name '" + tokens[0] + "' at line "
                                           + linenumber + ".");
                    }
                }
            }

            reader.Close();
        }
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            _reticuleTexture.pixelInset = new Rect(Screen.width / 2, Screen.height / 2, 16, 16);

            OCLogger.Fine(gameObject.name + " is updated.");
        }
        private string ParseStartMessage(string inputLine, string command, IEnumerator token)
        {
            UnityEngine.Debug.Log("OCMessageHandler::ParseStartMessage");

            string answer = null;

            if (_state == READING_MESSAGES)
            {
                // A previous message was already read.
                OCLogger.Debugging("onLine: From [" + _messageFrom +
                                   "] to [" + _messageTo +
                                   "] Type [" + _messageType + "]");

                OCMessage message = OCMessage.CreateMessage(_messageFrom,
                                                            _messageTo,
                                                            _messageType,
                                                            _message.ToString());
                if (message == null)
                {
                    OCLogger.Error("Could not factory message from the following string: " +
                                   _message.ToString());
                }
                if (_useMessageBuffer)
                {
                    _messageBuffer.Add(message);
                    if (_messageBuffer.Count > _maxMessagesInBuffer)
                    {
                        _networkElement.PullMessage(_messageBuffer);
                        _messageBuffer.Clear();
                    }
                }
                else
                {
                    _networkElement.PullMessage(message);
                }

                _lineCount   = 0;
                _messageTo   = "";
                _messageFrom = "";
                _messageType = OCMessage.MessageType.NONE;
                _message.Remove(0, _message.Length);
            }
            else
            {
                if (_state == DOING_NOTHING)
                {
                    // Enter reading state from idle state.
                    _state = READING_MESSAGES;
                }
                else
                {
                    OCLogger.Error("onLine: Unexepcted command [" +
                                   command + "]. Discarding line [" +
                                   inputLine + "]");
                }
            }

            if (token.MoveNext())
            {
                _messageFrom = token.Current.ToString();

                if (token.MoveNext())
                {
                    _messageTo = token.Current.ToString();
                    if (token.MoveNext())
                    {
                        _messageType = (OCMessage.MessageType) int.Parse(token.Current.ToString());
                    }
                    else
                    {
                        answer = OCNetworkElement.FAILED_MESSAGE;
                    }
                }
                else
                {
                    answer = OCNetworkElement.FAILED_MESSAGE;
                }
            }
            else
            {
                answer = OCNetworkElement.FAILED_MESSAGE;
            }
            _lineCount = 0;

            return(answer);
        }
예제 #19
0
 /// <summary>
 /// Use this for initialization
 /// </summary>
 public void Start()
 {
     OCLogger.Fine(gameObject.name + " is started.");
 }
        //---------------------------------------------------------------------------

        #endregion

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

        #region Public Member Functions

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


//	public IEnumerator StartProcessing(System.Net.Sockets.Socket workSocket)
//	{
//		UnityEngine.Debug.Log ("OCMessageHandler::StartProcessing");
//		yield return StartCoroutine(UpdateMessages(workSocket));
////		UnityEngine.Debug.Log ("BALLS!");
////		yield return null;
//	}

        public IEnumerator UpdateMessages(System.Net.Sockets.Socket workSocket)
        {
            UnityEngine.Debug.Log("OCMessageHandler::UpdateMessages");

            StreamReader reader = null;
            StreamWriter writer = null;

            try
            {
                Stream s = new NetworkStream(workSocket);
                reader = new StreamReader(s);
                writer = new StreamWriter(s);
            }
            catch (IOException ioe)
            {
                workSocket.Close();
                OCLogger.Error("An I/O error occured.  [" + ioe.Message + "].");
            }

            bool endInput = false;

            while (true)
            {
                while (!endInput)
                {
                    try
                    {
                        //@TODO Make some tests to judge the read time.
                        string line = reader.ReadLine();

                        if (line != null)
                        {
                            string answer = Parse(line);

                            //UnityEngine.Debug.Log ("Just parsed '" + line + "'");
                        }
                        else
                        {
                            UnityEngine.Debug.Log("No more input, line == null");

                            endInput = true;

                            //					UnityEngine.Debug.Log ("Setting OCNetworkElement.IsHandling to false...");
                            //
                            //					OCNetworkElement.Instance.IsHandlingMessages = false;
                        }
                    }
                    catch (IOException ioe)
                    {
                        UnityEngine.Debug.Log("An I/O error occured.  [" + ioe.Message + "].");
                        endInput = true;
                    }
                    catch (System.Exception ex)
                    {
                        UnityEngine.Debug.Log("A general error occured.  [" + ex.Message + "].");
                        endInput = true;
                    }

                    yield return(new UnityEngine.WaitForSeconds(0.1f));
                }

                if (endInput)
                {
                    yield return(new UnityEngine.WaitForSeconds(0.5f));

                    endInput = false;
                }
            }

            try
            {
                reader.Close();
                writer.Close();
                workSocket.Close();
            }
            catch (IOException ioe)
            {
                UnityEngine.Debug.Log("Something went wrong: " + ioe.Message);
                //OCLogger.Error("An I/O error occured.  [" + ioe.Message + "].");
                endInput = true;
            }

            yield return(null);
        }
        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"));
            }
        }
예제 #22
0
 /// <summary>
 /// Use this for initialization
 /// </summary>
 public new void Start()
 {
     base.Start();
     OCLogger.Fine(gameObject.name + " is started.");
 }
예제 #23
0
        //---------------------------------------------------------------------------

        #endregion

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

        #region Accessors and Mutators

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

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

        #endregion

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

        #region Public Member Functions

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

        /// <summary>
        /// Called when the script instance is being loaded.
        /// </summary>
        public void Awake()
        {
            Initialize();
            OCLogger.Fine(gameObject.name + " is awake.");
        }
예제 #24
0
 /// <summary>
 /// Raises the destroy event when TalkCommand is about to be destroyed.
 /// </summary>
 public void OnDestroy()
 {
     Uninitialize();
     OCLogger.Fine(gameObject.name + " is about to be destroyed.");
 }
예제 #25
0
 /// <summary>
 /// Raises the disable event when TalkCommand goes out of scope.
 /// </summary>
 public void OnDisable()
 {
     OCLogger.Fine(gameObject.name + " is disabled.");
 }
예제 #26
0
 /// <summary>
 /// Raises the enable event when TalkCommand is loaded.
 /// </summary>
 public void OnEnable()
 {
     OCLogger.Fine(gameObject.name + " is enabled.");
 }
예제 #27
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            if (UnityEngine.Screen.showCursor)
            {
                return;
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    OCLogger.Info("Sun " + " " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    OCLogger.Info("Sun " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
                    _map.SetBlockAndRecompute(new OpenCog.Map.OCBlockData(), point.Value);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(1))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue;
                    if (empty)
                    {
                        OpenCog.Map.OCBlockData block = new OpenCog.Map.OCBlockData(_selectedBlock, OpenCog.Utility.VectorUtil.Vector3ToVector3i(point.Value));
                        block.SetDirection(GetDirection(-transform.forward));
                        _map.SetBlockAndRecompute(block, point.Value);
                    }
                }
            }

            Vector3i?cursor = GetCursor(true);

            _cursor.SetActive(cursor.HasValue);
            if (cursor.HasValue)
            {
                _cursor.transform.position = cursor.Value;
            }
            OCLogger.Fine(gameObject.name + " is updated.");
        }
예제 #28
0
 /// <summary>
 /// Update is called once per frame.
 /// </summary>
 public void Update()
 {
     OCLogger.Fine(gameObject.name + " is updated.");
 }
예제 #29
0
 /// <summary>
 /// Reset this instance to its default values.
 /// </summary>
 public void Reset()
 {
     Uninitialize();
     Initialize();
     OCLogger.Fine(gameObject.name + " is reset.");
 }
예제 #30
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            _panelHeight = Screen.height * 0.30f;

            if (Input.GetKeyDown(KeyCode.BackQuote))
            {
                // If the window is already visible and isn't disappearing...
                if (_isShown && _movementState != Movement.DISAPPEARING)
                {
                    CloseChatWindow();
                    _player.GetComponent <OCInputController>().enabled = true;
                    _player.GetComponent <OCCharacterMotor>().enabled  = true;
                    _player.GetComponent <MouseLook>().enabled         = true;
                }
                else
                {
                    _isShown = true;
                    _player.GetComponent <OCInputController>().enabled = false;
                    _player.GetComponent <OCCharacterMotor>().enabled  = false;
                    _player.GetComponent <MouseLook>().enabled         = false;

                    _movementState = Movement.APPEARING;
                }
            }

            // Below this line is only relevent when console is active
            if (!this.IsActive())
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.Return) &&
                _currentInput.Length > 0)
            {     // &&
                // GUI.GetNameOfFocusedControl() == "CommandArea")
                this.ProcessConsoleLine(_currentInput);
                _currentInput        = "";   // blank input field
                _inputHistoryCurrent = null; // reset current position in input history
            }
            // Implement input history using up/down arrow
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                if (_inputHistoryCurrent == null)
                {
                    // TODO save current output so that we can push down to restore
                    // previously written text
                    _inputHistoryCurrent = _inputHistory.First;
                }
                else
                if (_inputHistoryCurrent.Next != null)
                {
                    _inputHistoryCurrent = _inputHistoryCurrent.Next;
                }
                if (_inputHistoryCurrent != null)
                {
                    _currentInput = _inputHistoryCurrent.Value;
                }
            }
            else
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                if (_inputHistoryCurrent != null && _inputHistoryCurrent.Previous != null)
                {
                    _inputHistoryCurrent = _inputHistoryCurrent.Previous;
                }
                if (_inputHistoryCurrent != null)
                {
                    _currentInput = _inputHistoryCurrent.Value;
                }
            }
            if (_isShown)
            {
                //_inputController.SetCharacterControl(false);
            }

            OCLogger.Fine(gameObject.name + " is updated.");
        }