Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Leslie-Young · Jun 08, 2013 at 08:52 AM · c#asset store

Detecting another author's lib/package/classes

This has to do with packages/assets being released for the Asset Store.

I've been discussing this with a friend today as we want to collaborate in a way. The new tool I am working on should have the ability to, when it detects the presence of his package, allow additional features while making calls to his code to do the actual work. I was hoping it would be as simple as doing #if SOME_CLASS_NAME (C#) but I see it can't be used like that. So now I am not quite sure how one can write code that will not throw errors if the other package's classes are not present.

So far I can only think of having some unitypackage that can be imported which would add the script(s) that provide the working link between the two.

I would create a script with the needed class and function(s) that my code can call into and these functions would make calls to my friend's scripts. I distribute my tool with an "empty" version of this class, its functions will be be empty/ do nothing and thus have no code that can throw errors cause of the other package's classes not being present.

If a user then installs my friend's package and want my tool to support it he can import/extract the version of my script which has the actual working code.

Any thoughts on this? Is there a better way this could be done? I do not want my customers to really worry about what I described above. Things should just work.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Leslie-Young · Jun 13, 2013 at 09:41 AM

Since I am only targeting Unity 4 with the tool I am making I could make use of the player settings' scripting define symbols field. My friend will simply add a define to it and then I can use #if HIS_DEFINE_SYMBOL.

Here's a sample of how to add such a symbol via code in an editor script. This code will be executed whenever the code is recompiled by unity, so when the package is imported it will create the needed symbol(s).

 #if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5)
 
 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 using System.Collections.Generic;
 
 [InitializeOnLoad]
 public class SetupMyDefines
 {
     static SetupMyDefines()
     {
         // run through all the build targets and add the define symbol if needed
         foreach (BuildTargetGroup btg in System.Enum.GetValues(typeof(BuildTargetGroup)))
         {
             // extract existing defines to check if the ones to be added
             // does not allready exist before adding the new defines
 
             string defines_field = PlayerSettings.GetScriptingDefineSymbolsForGroup(btg);
             List<string> defines = new List<string>(defines_field.Split(';'));
             if (!defines.Contains("SOME_DEFINE_FOR_MY_PACKAGE"))
             {
                 defines.Add("SOME_DEFINE_FOR_MY_PACKAGE");
                 PlayerSettings.SetScriptingDefineSymbolsForGroup(btg, string.Join(";", defines.ToArray()));
             }
         }
     }
 }
 #endif
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Leslie-Young · Jun 13, 2013 at 09:42 AM 0
Share

I think it would be nice if more asset store publishers can do this kind of thing for their code related packages so that other who wish to support these packages in whatever way have an easy way of detecting the presence of the package.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can anyone help me with a simple CSharp error 1 Answer

targetting dont work 0 Answers

Whats wrong with this code? im new 1 Answer

help my code has error CS8205 :parsing error how can I fix? 2 Answers

Is there any way to use CSharpCodeProvider in build? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges