• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

242 Neutral

About hojjatjafary

  • Rank
  1. FMOD C# api crash

    Found my solution, I was iterating through a generic List of string containing music cue names to get cue iterator, a List<string> musicCueNames, like this : ERRCHECK(musicSystem.getCues(ref iter, musicCueNames[i])); // Crash! I changed it to something like this :   string cueName = musicCueNames[i]; ERRCHECK(musicSystem.getCues(ref iter, cueName)); // Works! and now everything works properly, but don't know exactly why.
  2. FMOD C# api crash

    Hi, I'm trying to implement an interactive music system using FMOD Designer C# api, I used the event system without any problem, but when I try to get music cues it crashes. FMOD.RESULT result; ERRCHECK(result = eventsystem.getMusicSystem(ref musicSystem)); FMOD.MUSIC_ITERATOR iter = new FMOD.MUSIC_ITERATOR(); ERRCHECK(musicSystem.getCues(ref iter, "myFilter")); // Crash !!! Is there anyone master in P/Invoke that can help me to find a solution to this annoying problem?
  3. Rogue Legacy Random Level

    Thanx Álvaro, I was wondering about expanding rooms according to their doors in a DFS like manner but I didn't know how depth should I go into or should I expand rooms in Breadth. For this case I'm trying to build a random BSP tree and putting the rooms at the leaf of the tree and match the doors, this will reduce the number of trial and errors.
  4. Hi, I'm trying to implement a random level generator from premade rooms, something very similar to Rogue Legacy, As you may know this is not a procedurally generated level so doors can be in some predefined locations of rooms. There is no open ground between rooms, there is no corridors that connects rooms, rooms only connected to each other by their doors. The generation algorithm should be fast and generate levels without dead locks. All rooms are accessible from each other, some rooms may make a loop. Should I use a trial and error algorithm like Depth First Search?    
  5. C++ Plugin Debug Log with Unity

    Hi, I don't like C# so much but this is not the reason, it is not a missing feature in Unity, some times you have some existing C++ code that you like to use them in Unity or you need to use another external plugin like Steam, you can also write plugins to gain performance improvements, here you can find more detail, they gained 25x improvements by writing C++ plugins.
  6. C++ Plugin Debug Log with Unity

    Hi ivan, Thank you for the points you mensioned, I added a paragraph at the start of article that I think make many things clear,   "You can write a function in C# that takes a string as it's argument and print it into the Unity's console window, and then pass a pointer of this function to C++ dll, so you can call the function from C++ by it's pointer, this will redirect your strings from C++ to log window."   log messages need not be always hard coded, but often are, strings like "plugin inited.", "initialization faild" or so on, but you can use sprintf or any method you know to prepare a log string and then print it, I wrote only a string to show how to use that function pointer.   GL, Hojjat.
  7. When I was writing a C++ plugin for Unity in our upcoming iOS game (Shadow Blade), I was thinking that it would be very good if I could write some debug logs into the Unity console. After going on and progressing the plugin without logs, suddenly an idea came to my mind! This is an explanation of how to redirect some debug text from a C++ plugin to Unity's console. The method is based on Delegates in C#, Delegates can be treated as a typedef of a function pointers in C/C++ and you can call them from unmanaged code. You can write a function in C# that takes a string as it's argument and print it into the Unity's console window, and then pass a pointer of this function to C++ dll, so you can call the function from C++ by it's pointer, this will redirect your strings from C++ to log window. First of all define a delegate like this: using System.Runtime.InteropServices; ... [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void MyDelegate(string str); ... This is a delegate of type a function that has a string argument and returns nothing. Take care of your calling conventions, by default calling conventions of a C++ project in Visual Studio are __cdecl (/Gd) you can find it in the project properties -> C/C++ -> Advanced options. Then write a method that you will call it from C++ to print the log string, this is a member function of a Unity script file (a mono script): static void CallBackFunction(string str) { Debug.Log("::CallBaaaaaaack : " + str); } In the Start() function of your Unity script instantiate the defined delegate: MyDelegate callback_delegate = new MyDelegate( CallBackFunction ); // Convert callback_delegate into a function pointer that can be // used in unmanaged code. IntPtr intptr_delegate = Marshal.GetFunctionPointerForDelegate(callback_delegate); // Call the API passing along the function pointer. SetDebugFunction( intptr_delegate ); The SetDebugFunction is a method that assigns the function pointer to a pointer that you defined in your C++ code: typedef void (*FuncPtr)( const char * ); FuncPtr Debug; You can access this pointer in other source code by an extern modifier or any global access method you know such as writing a singleton class. extern "C" { EXPORT_API void SetDebugFunction( FuncPtr fp ) { Debug = fp; } } Don't forget to import it in your C# code: [DllImport ("UnityPlugin")] public static extern void SetDebugFunction( IntPtr fp ); Now you can call this function everywhere in your C++ plugin: ... Debug( "String From C++ Dll" ); ... And the resault: (I called a function from my plugin that logs a string into console window)
  • Advertisement