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
1
Question by SquarePieStudios · Jun 29, 2015 at 09:17 PM · c#scripting problemassetsdependencies

How to check if other Asset exists?

Hey all. I tried posting this in the Scripting and the Asset Store forum, but wasn't able to find a good answer, so I thought I would try here instead. I have a problem that I would like to resolve but am not sure exactly where to start. Essentially I have an asset that I'm working on that has extra behaviour supported if another one of my assets is included. Essentially I've boiled it down to the following example.

Asset 1:

 namespace Package1 {
     //The class that I want to extend from in my new asset
     public class Class_A {
         public int IntField;
     }
 }

Asset 2:

 namespace Package2 {
     public interface SomeInterface {
         void DoAThing();
     }
 
     public class Class_B : SomeInterface {
         public void DoAThing() {
             Debug.Log("Does A Thing");
         }
     }
 
     //This will cause compile errors if the user does not also have Package1.
     public class SomeClass_A : Package1.Class_A, SomeInterface {
         public void DoAThing() {
             Debug.Log(IntField);
         }
     }
 }

My question is essentially, how can I resolve the issue of determining if the user has Package1 or not? Essentially, I want to provide bonus functionality for people who have Package1, but it shouldn't cause compile errors if someone only wants Package2. I know that some people have added support for other assets such as PlayMaker and I want to know how to do similar, but for my own packages.

Thanks for any help!

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 Dave-Carlile · Jun 29, 2015 at 09:17 PM

You should be able to use Reflection for this.

From this Stackoverflow answer...

 var instances = from t in Assembly.GetExecutingAssembly().GetTypes()
             where t.GetInterfaces().Contains(typeof(ISomething))


That will get all of the types in the executing assembly, then get a list of interfaces to see if any of them are a specific interface type. This probably isn't exactly what you're looking for, but it kind of gives you a good place to start exploring.

Comment
Add comment · Show 3 · 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 SquarePieStudios · Jun 29, 2015 at 09:19 PM 0
Share

I can't declare a class and extend another type by way of reflection.

avatar image Dave-Carlile · Jun 29, 2015 at 09:24 PM 0
Share

Yeah, that would be difficult, but do you need to extend the class? Your new class can hold a reference to an instance of the other object and call methods in it. Your new class becomes kind of a wrapper around the old one, rather than a descendent.

avatar image SquarePieStudios · Jun 29, 2015 at 09:35 PM 0
Share

Because I have specialized editor script for Class_A from the first package and unfortunately because of how awful Unity handles generalized classes, you can't use:

 public ExampleGeneric<T> ExampleField;

ins$$anonymous$$d you have to do something like this:

 [Serializeable]
 public class ConcreteIntVersion : ExampleGeneric<int> { }
 public ConcreteIntVersion ExampleIntVersion;

So if I want to create for my 2nd package a class that includes a version of that uses Package2.CustomType as the type for ExampleGeneric, I have to do it like this:

 public class ConcreteCustomVersion : ExampleGeneric<Package2.CustomType> { }

But of course I don't want to do this if it's going to cause compile errors when the user of Package2 isn't using Package1 which includes ExampleGeneric.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Unloading Broken Assembly | How to solve this !? 2 Answers

how to keep track of Lean Tween function? 0 Answers

Mirror : How to Sync child objects active status on join? 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