#StackBounty: #unity #data-structure #text #localization How to store and update presentation strings describing effects with parameters?

Bounty: 50

Consider this spell:

Drain Life

As you can see in my design a Spell is a composition of one or more Effects. An Effect has properties on it like value, range, etc. So, I can say that the Spell Description is an aggregate description of the composition of effects.

Presentation Layer

In my presentation, I want to decorate part of the description string in HTML tags and display as rich text. I also want to ensure that my string’s numeric values come from data.

Solution 1

Simply hard code the string. In this case the spell description would look like: Choose a target within <#f4b350>4</color> squares. Deal <#f33613>4</color> damage to that target and restore your HP by <#3cf73c>50%</color> of the damage done.

This approach has some obvious issues, namely:

  • Changing the color value of a particular tag would be a nightmare when there are hundreds of abilities
  • Changing the damage value of a spell means updating it in two places, the string and the data

Solution 2

Create a tag series separated by _ that indicates various properties. I could for example, do something like Deal {subtractive_value} damage to that target with the idea that when I go to parse the string, subtractive could be a tag indicating a red color, and value can be a tag indicating that its the effect’s value that should go there.

This is all fine except that a spell can have multiple effects. I need a way to associate the part of the description with the specific effect that drives it.

Modification to Solution 2

So then I suppose I could just add IDs to the spell effects such that the string defined in data becomes:

Choose a target within {neutral_damageEffect_range} squares. Deal {subtractive_damageEffect_value} damage to that target and restore your HP by {additive_healEffect_value}.

But now you see that its getting a bit cumbersome and I’m dubious of how scalable that solution is.

Non-Goal

Lastly I figured I’d mention a non-goal. If you take my approach thus far to its ultimate conclusion, you would probably end up with trying to find a way to generate your description text from the effect themselves. While this is an interesting idea, I think it’s a bit too ambitious, so I’m specifically not trying to do that. That said, if you feel like that’s easier than I think it is, feel free to make that suggestion!

Question

So, given what I’ve tried and the problem I’m trying to solve, there’s no way this is a unique problem to me. Is there a battle-tested solution to this problem? What’s a good way to go about it or some patterns to use I might not know about?

EDIT

Some have asked for some code, it is lengthy though so I can just link to a gist here:
https://gist.github.com/jsandersr/ef6d560ad95f1d63b1f8e3b2099038a5


Get this bounty!!!

#StackBounty: #unity #c# #python How to make Unity' hidden dot folders visible?

Bounty: 50

My problem is that I have some plugin files inside a folder ".lib" that I need to read in my script, I keep getting errors because the script can’t find the ".lib" folder.
Apparently unity hides folders that starts with a dot.
is there a way around this ?.

Edit :
I’m running a python script using ironpyton, I got some packages in the project, the error happens when it gets to import ‘python package name’ in the python script, due to the missing folder, I can clearly see the folder ‘.lib’ in the file explorer but completely invisible in the project. to clarify things I didn’t set the path manually, one of the python packages causes this error when it can’t find the folder.

the error I got in the console :

OSException: cannot load library C:UsersSaiDocumentsWorkUnityUnity-Python-Demo-masterAssetsStreamingAssetsLibsite-packagesnumpy.libslibopenblas.SVHFG5YE3RK3Z27NVFUDAPL2O3W6IMXW.gfortran-win32.dll

This is my code :

        var engine = Python.CreateEngine();
        ICollection<string> searchPaths = engine.GetSearchPaths();
#if UNITY_STANDALONE_WIN
        searchPaths.Add(Application.dataPath);
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Lib");
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Libsite-packages");
        engine.SetSearchPaths(searchPaths);
        dynamic py = engine.ExecuteFile(Application.dataPath + @"StreamingAssets" + @"Pythonpt.py");
        test = py.CTScan("Codemaker"); //"Codemaker"

My python script :

from time import sleep
from System.Collections.Generic import *

import scipy



class CTScan():
    COLORS = {
        "sick": "rgb(176,55,55)",
        "healthy": "rgb(128,128,128)"
    }

    OPACITY = {
        "sick": 0.3,
        "healthy": 0.2
    }

Folder is visible in the file explorer

Same folder not visible from inside the project


Get this bounty!!!

#StackBounty: #unity #c# #python How to make Unity' hidden dot folders visible?

Bounty: 50

My problem is that I have some plugin files inside a folder ".lib" that I need to read in my script, I keep getting errors because the script can’t find the ".lib" folder.
Apparently unity hides folders that starts with a dot.
is there a way around this ?.

Edit :
I’m running a python script using ironpyton, I got some packages in the project, the error happens when it gets to import ‘python package name’ in the python script, due to the missing folder, I can clearly see the folder ‘.lib’ in the file explorer but completely invisible in the project. to clarify things I didn’t set the path manually, one of the python packages causes this error when it can’t find the folder.

the error I got in the console :

OSException: cannot load library C:UsersSaiDocumentsWorkUnityUnity-Python-Demo-masterAssetsStreamingAssetsLibsite-packagesnumpy.libslibopenblas.SVHFG5YE3RK3Z27NVFUDAPL2O3W6IMXW.gfortran-win32.dll

This is my code :

        var engine = Python.CreateEngine();
        ICollection<string> searchPaths = engine.GetSearchPaths();
#if UNITY_STANDALONE_WIN
        searchPaths.Add(Application.dataPath);
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Lib");
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Libsite-packages");
        engine.SetSearchPaths(searchPaths);
        dynamic py = engine.ExecuteFile(Application.dataPath + @"StreamingAssets" + @"Pythonpt.py");
        test = py.CTScan("Codemaker"); //"Codemaker"

My python script :

from time import sleep
from System.Collections.Generic import *

import scipy



class CTScan():
    COLORS = {
        "sick": "rgb(176,55,55)",
        "healthy": "rgb(128,128,128)"
    }

    OPACITY = {
        "sick": 0.3,
        "healthy": 0.2
    }

Folder is visible in the file explorer

Same folder not visible from inside the project


Get this bounty!!!

#StackBounty: #unity #c# #python How to make Unity' hidden dot folders visible?

Bounty: 50

My problem is that I have some plugin files inside a folder ".lib" that I need to read in my script, I keep getting errors because the script can’t find the ".lib" folder.
Apparently unity hides folders that starts with a dot.
is there a way around this ?.

Edit :
I’m running a python script using ironpyton, I got some packages in the project, the error happens when it gets to import ‘python package name’ in the python script, due to the missing folder, I can clearly see the folder ‘.lib’ in the file explorer but completely invisible in the project. to clarify things I didn’t set the path manually, one of the python packages causes this error when it can’t find the folder.

the error I got in the console :

OSException: cannot load library C:UsersSaiDocumentsWorkUnityUnity-Python-Demo-masterAssetsStreamingAssetsLibsite-packagesnumpy.libslibopenblas.SVHFG5YE3RK3Z27NVFUDAPL2O3W6IMXW.gfortran-win32.dll

This is my code :

        var engine = Python.CreateEngine();
        ICollection<string> searchPaths = engine.GetSearchPaths();
#if UNITY_STANDALONE_WIN
        searchPaths.Add(Application.dataPath);
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Lib");
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Libsite-packages");
        engine.SetSearchPaths(searchPaths);
        dynamic py = engine.ExecuteFile(Application.dataPath + @"StreamingAssets" + @"Pythonpt.py");
        test = py.CTScan("Codemaker"); //"Codemaker"

My python script :

from time import sleep
from System.Collections.Generic import *

import scipy



class CTScan():
    COLORS = {
        "sick": "rgb(176,55,55)",
        "healthy": "rgb(128,128,128)"
    }

    OPACITY = {
        "sick": 0.3,
        "healthy": 0.2
    }

Folder is visible in the file explorer

Same folder not visible from inside the project


Get this bounty!!!

#StackBounty: #unity #c# #python How to make Unity' hidden dot folders visible?

Bounty: 50

My problem is that I have some plugin files inside a folder ".lib" that I need to read in my script, I keep getting errors because the script can’t find the ".lib" folder.
Apparently unity hides folders that starts with a dot.
is there a way around this ?.

Edit :
I’m running a python script using ironpyton, I got some packages in the project, the error happens when it gets to import ‘python package name’ in the python script, due to the missing folder, I can clearly see the folder ‘.lib’ in the file explorer but completely invisible in the project. to clarify things I didn’t set the path manually, one of the python packages causes this error when it can’t find the folder.

the error I got in the console :

OSException: cannot load library C:UsersSaiDocumentsWorkUnityUnity-Python-Demo-masterAssetsStreamingAssetsLibsite-packagesnumpy.libslibopenblas.SVHFG5YE3RK3Z27NVFUDAPL2O3W6IMXW.gfortran-win32.dll

This is my code :

        var engine = Python.CreateEngine();
        ICollection<string> searchPaths = engine.GetSearchPaths();
#if UNITY_STANDALONE_WIN
        searchPaths.Add(Application.dataPath);
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Lib");
        searchPaths.Add(Application.dataPath + @"StreamingAssets" + @"Libsite-packages");
        engine.SetSearchPaths(searchPaths);
        dynamic py = engine.ExecuteFile(Application.dataPath + @"StreamingAssets" + @"Pythonpt.py");
        test = py.CTScan("Codemaker"); //"Codemaker"

My python script :

from time import sleep
from System.Collections.Generic import *

import scipy



class CTScan():
    COLORS = {
        "sick": "rgb(176,55,55)",
        "healthy": "rgb(128,128,128)"
    }

    OPACITY = {
        "sick": 0.3,
        "healthy": 0.2
    }

Folder is visible in the file explorer

Same folder not visible from inside the project


Get this bounty!!!

#StackBounty: #unity #c# #android #xml How can I use an inherited Activity in C#?

Bounty: 250

I am using Unity. I want to set the status bar to be permanent in opaque black. I set Start in Full Screen Mode in the Player Settings to false, and call ShowStatusBar from the following code, and life is good:

using System;
using UnityEngine;

public static class AndroidUtility
{
    private const int MinStatusBarColorApi = 21;
    private const int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400;
    private const int BlackColor = 0x00000000;

    private static AndroidJavaObject activity;

    public static void ShowStatusBar(int color = BlackColor)
    {
        RunOnUiThread(() =>
            {
                using (var window = Window)
                {
                    window.Call("clearFlags", SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                    if (GetApi() >= MinStatusBarColorApi)
                    {
                        window.Call("setStatusBarColor", color);
                    }
                    else if (color != default)
                    {
                        Debug.LogWarning("Changing the status bar color is not supported on Android API lower than Lollipop.");
                    }
                }
            });
    }

    private static void RunOnUiThread(Action action)
    {
        Activity.Call("runOnUiThread", new AndroidJavaRunnable(action));
    }

    private static AndroidJavaObject Activity
    {
        get
        {
            if (activity == null)
            {
                var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            }
            return activity;
        }
    }

    private static AndroidJavaObject Window
    {
        get
        {
            return Activity.Call<AndroidJavaObject>("getWindow");
        }
    }

    private static int GetApi()
    {
        using (var version = new AndroidJavaClass("android.os.Build$VERSION"))
        {
            return version.GetStatic<int>("SDK_INT");
        }
    }
}

I then added a plugin (Firebase Messaging) which uses a custom AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.mypackage" android:versionCode="1" android:versionName="1.0">
  <application android:label="@string/app_name" android:icon="@drawable/app_icon">
    <!-- The MessagingUnityPlayerActivity is a class that extends
         UnityPlayerActivity to work around a known issue when receiving
         notification data payloads in the background. -->
    <activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <service android:name="com.google.firebase.messaging.MessageForwardingService" android:exported="false" />
  </application>
</manifest>

My AndroidUtility class no longer works! The status bar just shows up as a solid white bar. I suspect this is because I am still referencing the default UnityPlayerActivity, when I should be referencing the MessagingUnityPlayerActivity? I have tried changing the AndroidJavaClass to com.google.firebase.MessagingUnityPlayerActivity, (among other things,) but that just makes the status bar go away completely.

How can I adjust the AndroidUtility class and AndroidManifest to work with the inherited AndroidManifest.xml?

(Also, the Android Back Button no longer does anything.)


Get this bounty!!!

#StackBounty: #unity #physics #vehicle Custom steering system in Unity for braking and sliding

Bounty: 50

I am developing a game where the player controls a vehicle. But instead of using a first person view, the camera is top-down and orthographic.

I tried using Unity’s wheel collider system. While that would work just fine for a first-person view (e.g. a traditional racing game), the controls don’t work well with a top-down view (e.g. think Micromachines on the NES). The reason, I think, is that turning and acceleration need to be much more responsive with a top-down view than with a real vehicle steering simulation. You’re not racing on a track. When viewing from top-down, the vehicle needs to accelerate and turn much more quickly than a “real” vehicle ever could.

I have implemented my own steering system based on Ackermann steering, which works fine. What I am missing is a good simulation of friction and skidding. For instance, I would like my vehicle to skid and slide if the user brakes while turning.

I don’t have a background in physics or mechanics so I am not sure where to start. Can someone give me some pointers?

Here is the code I have so far for simple steering:

void Move() {
    bool isLeft = Input.GetKey (KeyCode.A);
    bool isRight = Input.GetKey (KeyCode.D);
    bool isUp = Input.GetKey (KeyCode.W);
    bool isDown = Input.GetKey (KeyCode.S);

    turn = 0;

    acceleration = 0;
    speed *= friction;

    if (isReverse != isDown && (isUp || isDown)) {
        speed *= reverseDamping;
    }

    turn += isLeft ? (int) (-angleVel * speed) : 0;
    turn += isRight ? (int) (angleVel * speed) : 0;

    acceleration += isUp ? Time.deltaTime : 0;
    acceleration += isDown ? -Time.deltaTime : 0;
    speed += acceleration;

    transform.Rotate (0, turn, 0);
    transform.Translate (Vector3.forward * speed, Space.Self);

    isReverse = isDown;
}


Get this bounty!!!

#StackBounty: #unity #textures Unity: Exporting Game creates Texture Glitches

Bounty: 50

In the editor the textures are fine, however upon exporting I’m constantly faced with glitches like these:

enter image description here

I mainly use the Built-in Standard Specular Shader and the texture that gets glitched is always the Detail Texture. When re-exporting the game multiple times the texture gets glitched exactly the same way in the same spots.

This has happened in pretty much every scene so far.

enter image description here


Get this bounty!!!

#StackBounty: #unity #steamworks SteamWorks.Net for unity and inviting a friend to a multiplayer game

Bounty: 300

I’m trying to send an invitation to a steam friend and have it that when he accepts I create a PUN 2 room for both players and they can start their match. So far I’ve done this :

 protected Steamworks.Callback<GameRichPresenceJoinRequested_t> m_GameRichPresenceJoinRequested;


private void OnEnable()
{
    m_GameRichPresenceJoinRequested = Callback<GameRichPresenceJoinRequested_t>.Create(OnGameRichPresenceJoinRequested);
}


public void InviteFriend()
{

    SteamFriends.InviteUserToGame(steamFriendData.friendSteamId, "");
}

private void OnGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t pCallback)
{
     Debug.Log(pCallback.m_rgchConnect);
    Debug.Log("<color=green>Friend accepted the invite</color> ");
}

The invite is being sent to the correct friend and when he accepts it launches the game but I get no callback from that and thus have no way to place them in a room. What am I doing wrong ?


Get this bounty!!!