Example #1
0
		public bool InitNavMesh( out string error )
		{
			DestroyNavMesh();

			if( !EnabledInHierarchy )
			{
				error = "Is not enabled.";
				return false;
			}

			if( NavMeshData == null )
			{
				error = "No data.";
				return false;
			}

			//check version
			var reader = new ArrayDataReader( NavMeshData );
			if( reader.ReadInt32() != navMeshDataVersion )
			{
				error = "Invalid version.";
				return false;
			}

			//read data
			var dataLength = reader.ReadInt32();
			var data = new byte[ dataLength ];
			reader.ReadBuffer( data );

			if( reader.BitPosition != reader.EndBitPosition || reader.Overflow )
			{
				error = "Invalid data.";
				return false;
			}

			//init
			try
			{
				using( var memoryStream = new MemoryStream( data ) )
				{
					var serializer = new NavMeshBinarySerializer();
					tiledNavMesh = serializer.Deserialize( memoryStream );
				}
			}
			catch( Exception e )
			{
				error = e.Message;
				return false;
			}

			//!!!!
			//TempObstaclesUpdate( true );

			error = "";
			return true;
		}
Example #2
0
        internal void Execute (HyenaSqliteConnection hconnection, Connection connection)
        {
            if (finished) {
                throw new Exception ("Command is already set to finished; result needs to be claimed before command can be rerun");
            }

            execution_exception = null;
            result = null;
            int execution_ms = 0;

            string command_text = null;
            try {
                command_text = CurrentSqlText;
                ticks = System.Environment.TickCount;

                switch (CommandType) {
                    case HyenaCommandType.Reader:
                        using (var reader = connection.Query (command_text)) {
                            result = new ArrayDataReader (reader, command_text);
                        }
                        break;

                    case HyenaCommandType.Scalar:
                        result = connection.Query<object> (command_text);
                        break;

                    case HyenaCommandType.Execute:
                    default:
                        connection.Execute (command_text);
                        result = connection.LastInsertRowId;
                        break;
                }

                execution_ms = System.Environment.TickCount - ticks;
                if (log_all) {
                    Log.DebugFormat ("Executed in {0}ms {1}", execution_ms, command_text);
                } else if (Log.Debugging && execution_ms > 500) {
                    Log.WarningFormat ("Executed in {0}ms {1}", execution_ms, command_text);
                }
            } catch (Exception e) {
                Log.DebugFormat ("Exception executing command: {0}", command_text ?? command);
                Log.Exception (e);
                execution_exception = e;
            }

            // capture the text
            string raise_text = null;
            if (raise_command_executed && execution_ms >= raise_command_executed_threshold_ms) {
                raise_text = Text;
            }

            finished_event.Reset ();
            finished = true;

            if (raise_command_executed && execution_ms >= raise_command_executed_threshold_ms) {
                var handler = CommandExecuted;
                if (handler != null) {

                    // Don't raise this on this thread; this thread is dedicated for use by the db connection
                    ThreadAssist.ProxyToMain (delegate {
                        handler (this, new CommandExecutedArgs (raise_text, execution_ms));
                    });
                }
            }
        }