Unity3d edit mode test cases hot to set platform
I have following code
#if UNITY_IOS && !UNITY_EDITOR
public static MyPlugin Current = new MyPluginIOS();
#elif UNITY_ANDROID && !UNITY_EDITOR
public static MyPlugin Current = new MyPluginAndroid();
#else
public static MyPlugin Current = new MyPluginEditor();
#endif
I am writing test case and want to select platform As UNITY_ANDROID how can I do this?
1 answer
-
answered 2022-05-04 19:51
hijinxbassist
You can use the following line to define the UNITY_ANDROID preprocessor directive.
#define UNITY_ADROID
From the Docs found Here
#define lets you define a symbol. By using the symbol as the expression passed to the #if directive, the expression evaluates to true.
If you need to remove/undefine that preprocessor directive, you can use
#undef UNITY_ANDROID
do you know?
how many words do you know
See also questions close to this topic
-
C# - Adding condition to func results in stack overflow exception
I have a func as part of specification class which sorts the given iqueryable
Func<IQueryable<T>, IOrderedQueryable<T>>? Sort { get; set; }
When i add more than one condition to the func like below , it results in stack overflow exception.
spec.OrderBy(sc => sc.Case.EndTime).OrderBy(sc => sc.Case.StartTime);
The OrderBy method is implemented like this
public ISpecification<T> OrderBy<TProperty>(Expression<Func<T, TProperty>> property) { _ = Sort == null ? Sort = items => items.OrderBy(property) : Sort = items => Sort(items).ThenBy(property); return this; }
Chaining or using separate lines doesn't make a difference.
This problem gets resolved if I assign a new instance of the specification and set it's func, but i don't want to be assigning to a new instance everytime. Please suggest what am i missing here and how to reuse the same instance (if possible).
-
How to projection fields for a dictionary (C#, MongdoDB)
I am trying my luck here, I have a model which is like the following
public class RowData : BaseBsonDefinition { . [BsonExtraElements] [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] public Dictionary<string, object> Rows { get; set; } = new(StringComparer.OrdinalIgnoreCase); . }
In result, the schema in the MongoDB looks like
{ "_id": { "$binary": { "base64": "HiuI1sgyT0OZmcgGUit2dw==", "subType": "03" } }, "c1": "AAA", "c8": "Fully Vac", "c10": "", }
Those c1, c8 and c10 fields are keys from the dictionary, my question is how to dynamic project those fields?
I tried
Builders<RowData>.Projection.Exclude(p => "c1")
It seems the MongoDB driver can not handle a value directly.
Anyone could point me in the correct direction?
Thanks,
-
How do I add new DataSource to an already Databinded CheckBoxList
i'm building a web form that show Database's item(Tables, Rows, FK,...)
I have a CheckBoxList of Tables (
chkListTable
) which will show a new CheckBoxList of Rows (chkListRow
) everytime I SelectedIndexChanged fromchkListTable
. The problem is i can show the items fromchkListTable
with 1 selected item. But i don't know how to showchkListRow
if multiple item fromchkListTable
are selected.Here are my codes:
aspx
:<div> <asp:Label ID="Label2" runat="server" Text="Table: "></asp:Label> <asp:CheckBoxList ID="chkListTable" runat="server" DataTextField="name" DataValueFeild="name" AutoPostBack="true" OnSelectedIndexChanged="chkListTable_SelectedIndexChanged"> </asp:CheckBoxList> </div> <div> <asp:CheckBoxList ID="chkListRow" runat="server" DataTextField="COLUMN_NAME" DataValueField="COLUMN_NAME" RepeatDirection="Horizontal"> </asp:CheckBoxList> </div>
aspx.cs
:protected void chkListTable_SelectedIndexChanged(object sender, EventArgs e) { tableName.Clear(); foreach (ListItem item in chkListTable.Items) { if(item.Selected) { tableName.Add(item.Text.Trim()); } } for(int i = 0; i < tableName.Count; i++) { String query = "USE " + dbname + " SELECT * FROM information_schema.columns" + " WHERE table_name = '" + tableName[i] + "'" + " AND COLUMN_NAME != 'rowguid'"; chkListRow.DataSource = Program.ExecSqlDataReader(query); chkListRow.DataBind(); Program.conn.Close(); } }
Program.cs
:public static bool Connect() { if (Program.conn != null && Program.conn.State == ConnectionState.Open) Program.conn.Close(); try { Program.conn.ConnectionString = Program.constr; Program.conn.Open(); return true; } catch (Exception e) { return false; } } public static SqlDataReader ExecSqlDataReader(String query) { SqlDataReader myreader; SqlCommand sqlcmd = new SqlCommand(query, Program.conn); sqlcmd.CommandType = CommandType.Text; if (Program.conn.State == ConnectionState.Closed) Program.conn.Open(); try { myreader = sqlcmd.ExecuteReader(); return myreader; myreader.Close(); } catch (SqlException ex) { Program.conn.Close(); return null; } }
I want my display to be like this:
[x]Table1 [x]Table2 [ ]Table3 [ ]Row1(Table1) [ ]Row2(Table1) [ ]Row3(Table1) [ ]Row1(Table2) [ ]Row2(Table2)
-
Access to a PhotonView component
I need to access the INT of this component.
I am using a Photon View, and I want to set a conditional if a GameObject has that "INT" value.This is the Component
-
How can I programmatically "step" through a scene playthrough for identical playback in Unity? (pixel perfect frame replay)
My objective is to take camera snapshots of the editor playmode every 150 frames. This is so that I can validate a test scene by comparing screenshots every test run to ensure they are identical. How can I ensure every 150th frame will look exactly the same?
I understand the physics / time / graphics updates all run on separate timings. Is there a way I can force the engine to sync all these timings to make sure every frame is identical during repeated playbacks?
-
error CS1061: 'Animator' does not contain a definition for 'SetInt' and no accessible extension method 'SetInt'
so I'm having this error above in Unity and I don't know how to solve it.
The error from what I understand is in the switch, it's probably not getting the animator and blocking me from setting the animation value.
I searched on google and ended up not understanding very well, if anyone can help me I would appreciate it
public class Pontos : MonoBehaviour { public static Animator BluePoint, RedPoint; public static int Score; void Start() { BluePoint = GameObject.Find("Azul_Icons").GetComponent<Animator>(); RedPoint = GameObject.Find("Vermelho_Icons").GetComponent<Animator>(); Teste(); } void Teste() { if (PlayerAzul.BlueShoot) { Score++; } } } public class Blue : Pontos { void Point() { switch (Score) { case (0): BluePoint.SetInt("AzulValor", 0); Debug.Log("Score = 0"); break; case (1): BluePoint.SetInt("AzulValor", 1); Debug.Log("Score = 1"); break; case (2): BluePoint.SetInt("AzulValor", 2); Debug.Log("Score = 2"); break; case (3): BluePoint.SetInt("AzulValor", 3); Debug.Log("Score = 3"); break; } } }
To give a better example, this code is my points table (it's not perfect because I'm still testing it).
In void Test, don't worry about "PlayerAzul" (class) and "BlueShoot" (bool) , they are from another script that is working fine.
-
C++ increment with macro
I have the following code and I want to use increment with macro:
#include <iostream> #define ABS(x) ((x) < 0 ? -(x) : (x)) int main(int argc, char** argv) { int x = 5; const int result = ABS(x++); std::cout << "R: " << result << std::endl; std::cout << "X: " << x << std::endl; return EXIT_SUCCESS; }
But output will be incorrect:
R: 6 X: 7
Is it possible to somehow use macros with an increment, or should this be abandoned altogether?
-
Conditional formatting stops macro from running all the way
I have some conditional formatting together with a module, that for some reason prevents my macros from running all the way through.
=NOT(TestColor(E8))
is my conditional format, checked off with 'Stop if true' and works together with this module;Function TestColor (MyRange As Range) As Boolean If Range (MyRange.Address).Interior.Pattern = x1None Then TestColor = True End function
This gives me the ability to manually color cells that is otherwise colored by conditional formatting. (I didn't write this specific code, it was something i found).
However, i've found out that this also prevents any macros i make (relative or not) from running all the way through, meaning if i make a macro that creates a new row and then copies the row above, it will simply just create a new row and stop there as if it's finished, with no error messages popping up either. I know that this specific conditional format is what causes my macros to not work, as they work as intended if i delete it.
Is there a way i can get macros to work without having to delete the formatting? Or is there another way to be able to manually color cells that is being colored by conditional formatting?
-
how should i implement macro in this 8086 assembly language program for counting no. of 0's and 1's in 16 bit number?
this is the source code which i am using SOURCE: https://ankurm.com/8086-assembly-program-to-count-number-of-0s-and-1s-from-a-number/
DATA SEGMENT NO DW 5648H Z DW ? O DW ? DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX, DATA MOV DS, AX MOV AX, NO MOV BX, 00H MOV CX, 10H MOV DX, 00H UP: ROL AX,1 JC ONE INC BX JMP NXT ONE: INC DX NXT: DEC CX JNZ UP MOV Z, BX MOV O, DX INT 3 CODE ENDS END START
-
How to pass preprocessor directive to MSBuild via dotnet publish
I have an ASP.NET Core 6.0 WebApi solution with SPA. The default template builds the SPA by default by running
PublishAngular
target below.WebApi.csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web"> <!-- ... --> <!-- .NET Core Web API is being build here--> <!-- ... --> <Target Name="PublishAngular" AfterTargets="ComputeFilesToPublish"> <!-- ... --> <!-- SPA is getting built here--> <!-- ... --> </Target> </Project>
I am migrating the WebApi to Docker, and want to eventually completely split off SPA from it. But it's a lengthy process, so for the time being I want to have a way to specify whether I want to build the SPA conditionally using build command line.
I am using a pre-processor directive called DOCKER_BUILD, so I do something like this in my C# files:
#if !DOCKER_BUILD services.ConfigureSpa(); #endif
My questions are:
- What's the best way of passing a parameter from the build command line to MSBuild engine to exclude/include the
PublishAngular
target in csproj file? - Can I re-use the DOCKER_BUILD preprocessor diective to accomplish that?
My build command line looks like this:
dotnet publish -c Release -o out
I tried passing in DOCKER_BUILD as:
dotnet publish -c Release -o out /p:DOCKER_BUILD
and modifying the SPA build target like this:
<Target Name="PublishAngular" AfterTargets="ComputeFilesToPublish" Condition="!DOCKER_BUILD">
but didn't have much success. What am I doing wrong?
- What's the best way of passing a parameter from the build command line to MSBuild engine to exclude/include the
-
#if Vs if constexpr
Which one is more appropriate for compile-time configurations (such as debug/release), preprocessor directives, or
if constexpr
?#define DBG #if DBG // some code #endif // --------------------------------- or inline constexpr bool DEBUG { true }; if constexpr ( DEBUG ) { // some code }
-
Conditional onTapGesture in SwiftUI
I have a navigation link and I need a different behavior when its label (
MyView
) is tapped depending on the edit mode (or any other condition):- If we are not in edit mode, I want to trigger the navigation link and show the
DetailView
with the selected model. - If we are in edit mode, I don't want to trigger the navigation link and show an
EditingView
in a modal sheet instead.
Here's a way to implement this that I came up with:
NavigationLink(tag: model, selection: $displayedItem) { DetailView(model: model) } label: { if editMode == .active { MyView() .onTapGesture { editingModel = model } } else { MyView() } } .sheet(item: $editingModel) { model in EditingView(model: model) }
The problem with this approach is that the views in the if- and the else-branch have not the same type (due to the
onTapGesture
modifier) and SwiftUI doesn't recognize them as the same view. Thus, animations cannot be interpolated and don't work properly. Also,MyView
always loses its state each timeeditMode
is toggled.(Here's a great explanation from Chris Eidhof on why that happens: https://www.objc.io/blog/2021/08/24/conditional-view-modifiers/)
So I went ahead and moved the if-statement inside the
onTapGesture
modifier as follows so that I don't have two differentMyView
s:NavigationLink(tag: model, selection: $displayedItem) { DetailView(model: model) } label: { MyView() .onTapGesture { if editMode == .active { // moved editingModel = model } // moved } } } .sheet(item: $editingModel) { model in EditingView(model: model) }
Problem with this is that now requirement #1 doesn't work anymore: The
onTapGesture
completely swallow the tap gesture and thus the navigation link is never trigged to show theDetailView
. Makes sense.Now my question is:
How can I get the desired behavior without any of these downsides?
- If we are not in edit mode, I want to trigger the navigation link and show the
-
SwiftUI Change View with Edit Mode
I try to change the view state according to edit mode, when is editing hide the view and when it's not editing show the view, when I use on change and print the edit mode value its work but its doesn't work when working with views.
struct TaskStateMark_Row: View { @ObservedObject var task: Task @Environment(\.editMode) private var editMode var body: some View { Group { // Show and hide the view according to edit mode state if let editMode = editMode?.wrappedValue { if editMode == .inactive { taskState .onTapGesture(perform: onTapAction) } } } } private var taskState: some View { Group { if task.isCompleted { completedState } else { incompletedState } } .frame(width: 44, height: 44) } private var incompletedState: some View { ZStack{ fillCircle circle } } private var circle: some View { Image(systemName: "circle") .font(.system(size: 24)) .foregroundColor(task.wrappedPriority.color) } private var fillCircle: some View { Image(systemName: "circle.fill") .font(.system(size: 24)) .foregroundColor(task.wrappedPriority.color.opacity(0.15)) } private var completedState: some View { Image(systemName: "checkmark.circle.fill") .symbolRenderingMode(.palette) .foregroundStyle(.white, task.wrappedPriority.color) .font(.system(size: 24)) } }