Unity script runs in editor but fails to build - unity3d

I am using Unity 2019.2.10f1 and have encountered a weird bug when trying to build the game. Error message I get is:
error CS0246: The type or namespace name 'StaticEditorFlags' could not be found (are you missing a using directive or an assembly reference?)
I tried to reimport all, and I definitely have UnityEditor use directive for that script.
The following code is used to mark objects as static for optimization purposes and is only executed from the Editor:
private StaticEditorFlags staticFlags = StaticEditorFlags.ContributeGI | StaticEditorFlags.OccluderStatic | StaticEditorFlags.BatchingStatic | StaticEditorFlags.NavigationStatic | StaticEditorFlags.OffMeshLinkGeneration | StaticEditorFlags.ReflectionProbeStatic;
public void StaticLock()
{
lockChanges = true;
Transform renderRoot = transform.Find("Renders");
Transform collidersRoot = transform.Find("Colliders");
if (renderRoot != null)
{
int count = renderRoot.childCount;
for (int i = 0; i < count; i++)
GameObjectUtility.SetStaticEditorFlags(renderRoot.GetChild(i).gameObject, staticFlags);
}
if (collidersRoot != null)
{
int count = collidersRoot.childCount;
for (int i = 0; i < count; i++)
GameObjectUtility.SetStaticEditorFlags(collidersRoot.GetChild(i).gameObject, staticFlags);
}
}

First, UnityEditor libraries are not included in the builds, so you should get that error.
But in order to not include that script to builds you should put that script in a folder called Editor, so Unity will automatically remove scripts inside that folder from builds.
You can create Editor folders everywhere. everything inside will be ignored.

Related

How to import other person's package?

import CtCILibrary.*;
public class RotateMatrix {
public static boolean rotate (int [][]matrix) {
if ( matrix.length == 0 || matrix.length != matrix[0].length) {
return false;
}
int n = matrix.length;
for ( int layer = 0 ; layer < n / 2 ; layer++ ) {
int first = layer;
int last = n - 1 - first;
for ( int i = first ; i < last; i++ ) {
int offset = i - first;
int top = matrix[first][i];
//left-> top
matrix[first][i] = matrix [last-offset][first];
//bottom -> left
matrix[last-offset][first] = matrix [last][last-offset];
//right -> bottom
matrix[last][last-offset]= matrix[i][last];
//top->right
matrix[i][last]=top;
}
}
return true;
}
Hi there, I'm trying to import the CtCI library to solve the problem but there's an error message. And from her GitHub, that was how she imported this class. I know we can import the class from java built-in library. But I'm not sure how import works when trying to import from someone else. Could someone explain it to me?
If you are doing serious programming for a long term app, and by import you refer to libraries/dependencies, I highly recommend you using maven for it.
If you don't use maven yet, you can just add the .jar files from you IDE to your project path, but with maven is way better.
If you mean importing a .java file written by someone else, to use part of it in your code, just put the file at your project path, you probably need to adapt its libraries and imports, and once ready you can just use its methods ans stuff. Just make sure you have tipped at the top of your current file the import sentence of that file.

Project Browser not updating with Package Deletion Script

The following method deletes a package. The problem is that the Project Browser is never refreshed. Calling Repository.RefreshModelView(0) forces the update, but it reopens the model and kills script execution.
Here is the method:
function clearPackage( pkg ) {
var parent as EA.Package;
parent = Repository.GetPackageByID(pkg.ParentID);
var pkgList as EA.Collection;
pkgList = parent.Packages;
for (var i = 0; i < pkgList.Count; i++) {
var p as EA.Package;
p = pkgList.GetAt(i);
if (p.PackageGUID == pkg.PackageGUID) {
pkgList.Delete(i);
pkgList.Refresh();
parent.Update(); // have tried with and without
return;
}
}
}
Inspecting pkgList.Count before and after pkgList.Refresh does show a change in size. Again, the problem seems limited to the Project Browser.
Any ideas on how to refresh the Project Browser?
Cross posted on Sparx Forums.
To delete a package you just need to delete the package itself. Sorry for the Perl, but thats my donkey :-)
my $p = $rep->GetTreeSelectedObject();
my $par = $rep->GetPackageByID ($p->ParentID);
my $idx = 0;
for my $sp (in $par->Packages) {
if ($sp->PackageID == $p->PackageID) {
$par->Packages->DeleteAt ($idx, 1);
last;
}
$idx++;
}
$rep->RefreshModelView ($par->PackageID);
Try
Repository.RefreshModelView(parent.PackageID);
That will refresh only the contents of the parent package, not the whole model.

Diagnosing netlogo extension command error

When I try to execute the first-n-integers extension example:
show noise:first-n-integers 5
I receive an error "ERROR: Expected command. " in the console or in the code tab.
I have mostly copied and pasted the class examples as is, just renaming them and putting them in a different package. I wish the error was a little more descriptive, as I suspect I am making a simple error somewhere.
I'm using 5.0.4 without the JRE and a 1.7.0_45 JRE/JDK on a x64 Windows 7 machine.
My manifest.txt file with fully-qualified class-manager and crlf at the end of the version line--
Manifest-Version: 1.0
Extension-Name: noise
Class-Manager: org.xyz.extensions.NoiseExtension
NetLogo-Extension-API-Version: 5.0 <--there is a crlf here
the jar is in a subfolder with my model file
test/
test.nlogo
noise/
noise.jar
This is my Class-Manager:
package org.xyz.extensions;
import org.nlogo.api.*;
public class NoiseExtension extends DefaultClassManager {
public void load(PrimitiveManager primitiveManager) {
primitiveManager.addPrimitive(
"first-n-integers", new org.xyz.extensions.NoiseGenerator());
}
}
This is the NoiseGenerator file:
package org.xyz.extensions;
import org.nlogo.api.*;
public class NoiseGenerator extends DefaultReporter {
public Syntax getSyntax() {
return Syntax.reporterSyntax(
new int[] {Syntax.NumberType()}, Syntax.ListType());
}
public Object report(Argument args[], Context context) throws ExtensionException {
// create a NetLogo list for the result
LogoListBuilder list = new LogoListBuilder();
int n ;
// use typesafe helper method from
// org.nlogo.api.Argument to access argument
try {
n = args[0].getIntValue();
}
catch(LogoException e) {
throw new ExtensionException( e.getMessage() ) ;
}
if (n < 0) {
// signals a NetLogo runtime error to the modeler
throw new ExtensionException
("input must be positive");
}
// populate the list. note that we use Double objects; NetLogo
// numbers are always Doubles
for (int i = 0; i < n; i++) {
list.add(Double.valueOf(i));
}
return list.toLogoList();
}
}
Thanks for any help.
AJB
This was asked and answered here:
https://groups.google.com/d/msg/netlogo-devel/eIq8drflsc8/7y_Ooh6R0sgJ
The answer was to correct the spelling of getSynax to getSyntax.

How to find orphan plugins in eclipse RCPs?

Update sites with RCPs prohibits orphan plugins, otherwise plugins that are not in a feature.
If this condition is not filled, the update manager returns the following error:
Resulting configuration does not contain the platform.
Unfortunately, no way to determine which plugins are orphan.
How to find orphan plugins ?
Here's a starting point (this applies for Eclipse 3.4 and later, when the P2 repository was introduced, earlier versions store their configuration differently. IIRC you could see all the plugins and features in platform.xml).
Create a new plugin project (New->Other->Plug-in Development->Plug-in Project) with the "Hello World" template then drop this code into the run method of the SampleAction.
Run the plugin as a test Eclipse Application and select Sample Menu->Sample Action, the plugins that don't belong to a feature will be output to the parent workspace's console. When I ran this there were quite a few more than I expected, I've had a few looks through and can't spot the logic error.
Edit, found logic error, was using the wrong array index used in innermost loop. Still not quite right though.
Edit 2. (Facepalm moment) Found the problem. Be sure to run the target workspace with all workspace and enabled target plugins enabled, or it will skew your results, obviously. If you install the plugin and dress it up a little bit you won't have this problem.
//get all the plugins that belong to features
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
Map<Long, IBundleGroup> bundlesMap = new HashMap<Long, IBundleGroup>();
if (providers != null) {
for (int i = 0; i < providers.length; i++) {
IBundleGroup[] bundleGroups = providers[i].getBundleGroups();
System.out.println("Bundle groups:");
for (int j = 0; j < bundleGroups.length; j++) {
Bundle[] bundles = bundleGroups[j] == null ? new Bundle[0] : bundleGroups[j]
.getBundles();
System.out.println(bundleGroups[j].getIdentifier());
for (int k = 0; k < bundles.length; k++) {
bundlesMap.put(bundles[k].getBundleId(), bundleGroups[j]);
}
}
}
}
BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
if(bundleContext instanceof BundleContextImpl) {
Bundle[] bundles = ((BundleContextImpl)bundleContext).getBundles();
System.out.println("Orphan Bundles:");
for (int i = 0; i < bundles.length; i++) {
if(!bundlesMap.containsKey(bundles[i].getBundleId())) {
System.out.println(bundles[i].getSymbolicName());
}
}
}

Is there a tool to merge NUnit result files?

For unclear reasons my Nunit test fixture cannot be executed in a single run, so I'm forced to execute a few tests in separate runs. However this means that the test results are splitted over multiple output files.
Is there a tool available which can merge NUnit result XML files into a single XML file?
I've tried using the existing Nunit-summary tool, but this simply sequentially parses the XML files with the given XSL file and concatenates the result as one big file.
Instead I would like it to merge/group the results for the test cases into the right namespaces/testfixtures first and then feed it to the XSLT processor. This way all test results should be displayed by fixture even though they're not gathered in a single run.
This is probably too late to help you, but we recently encountered a similar issue and wrote a small open source tool to help out: https://github.com/15below/NUnitMerger
From the readme:
Using in MSBuild
Load the task:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0"
DefaultTargets="Build">
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\Tools\MSBuild\15below.NUnitMerger.dll" TaskName="FifteenBelow.NUnitMerger.MSBuild.NUnitMergeTask" />
...
Feed it an array of files with in a target:
<Target Name="UnitTest" DependsOnTargets="OtherThings">
... Generate the individual files here in $(TestResultsDir) ...
<ItemGroup>
<ResultsFiles Include="$(TestResultsDir)\*.xml" />
</ItemGroup>
<NUnitMergeTask FilesToBeMerged="#(ResultsFiles)" OutputPath="$(MSBuildProjectDirectory)\TestResult.xml" />
</Target>
Find the resulting combined results at OutputPath.
Using in F#
Create an F# console app and add 15below.NUnitMerger.dll, System.Xml and System.Xml.Linq as references.
open FifteenBelow.NUnitMerger.Core
open System.IO
open System.Xml.Linq
// All my files are in one directory
WriteMergedNunitResults (#"..\testdir", "*.xml", "myMergedResults.xml")
// I want files from all over the place
let myFiles = ... some filenames as a Seq
myFiles
|> Seq.map (fun fileName -> XDocument.Parse(File.ReadAllText(fileName)))
|> FoldDocs
|> CreateMerged
|> fun x -> File.WriteAllText("myOtherMergedResults.xml", x.ToString())
I was using the 15below NUnitMerger above for a while, but wanted to extend it and since my F# skills are not good enough to do it there, I inspected their mechanism and implemented the following class in C# to achieve the same thing. Here is my starting code which might help anyone who also want to do this kind of manipulation in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
namespace RunNUnitTests
{
public static class NUnitMerger
{
public static bool MergeFiles(IEnumerable<string> files, string output)
{
XElement environment = null;
XElement culture = null;
var suites = new List<XElement>();
bool finalSuccess = true;
string finalResult = "";
double totalTime = 0;
int total = 0, errors = 0, failures = 0, notrun = 0, inconclusive = 0, ignored = 0, skipped = 0, invalid = 0;
foreach (var file in files)
{
var doc = XDocument.Load(file);
var tr = doc.Element("test-results");
if (environment == null)
environment = tr.Element("environment");
if (culture == null)
culture = tr.Element("culture-info");
total += Convert.ToInt32(tr.Attribute("total").Value);
errors += Convert.ToInt32(tr.Attribute("errors").Value);
failures += Convert.ToInt32(tr.Attribute("failures").Value);
notrun += Convert.ToInt32(tr.Attribute("not-run").Value);
inconclusive += Convert.ToInt32(tr.Attribute("inconclusive").Value);
ignored += Convert.ToInt32(tr.Attribute("ignored").Value);
skipped += Convert.ToInt32(tr.Attribute("skipped").Value);
invalid += Convert.ToInt32(tr.Attribute("invalid").Value);
var ts = tr.Element("test-suite");
string result = ts.Attribute("result").Value;
if (!Convert.ToBoolean(ts.Attribute("success").Value))
finalSuccess = false;
totalTime += Convert.ToDouble(ts.Attribute("time").Value);
if (finalResult != "Failure" && (String.IsNullOrEmpty(finalResult) || result == "Failure" || finalResult == "Success"))
finalResult = result;
suites.Add(ts);
}
if (String.IsNullOrEmpty(finalResult))
{
finalSuccess = false;
finalResult = "Inconclusive";
}
var project = XElement.Parse(String.Format("<test-suite type=\"Test Project\" name=\"\" executed=\"True\" result=\"{0}\" success=\"{1}\" time=\"{2}\" asserts=\"0\" />", finalResult, finalSuccess ? "True" : "False", totalTime));
var results = XElement.Parse("<results/>");
results.Add(suites.ToArray());
project.Add(results);
var now = DateTime.Now;
var trfinal = XElement.Parse(String.Format("<test-results name=\"Merged results\" total=\"{0}\" errors=\"{1}\" failures=\"{2}\" not-run=\"{3}\" inconclusive=\"{4}\" ignored=\"{5}\" skipped=\"{6}\" invalid=\"{7}\" date=\"{8}\" time=\"{9}\" />", total, errors, failures, notrun, inconclusive, ignored, skipped, invalid, now.ToString("yyyy-MM-dd"), now.ToString("HH:mm:ss")));
trfinal.Add(new[] { environment, culture, project });
trfinal.Save(output);
return finalSuccess;
}
}
}
I read on the web that Nunit result files are XML so i guess you can merge the file with an ordinary merge software as WinMerge