Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Cross Asset Dependency

Discussion in 'Scripting' started by SquarePieStudios, Jun 27, 2015.

  1. SquarePieStudios

    SquarePieStudios

    Joined:
    Apr 22, 2015
    Posts:
    33
    Hey all. 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:
    Code (CSharp):
    1. namespace Package1 {
    2.     //The class that I want to extend from in my new asset
    3.     public class Class_A {
    4.         public int IntField;
    5.     }
    6. }
    Asset 2:
    Code (CSharp):
    1.  
    2. namespace Package2 {
    3.     public interface SomeInterface {
    4.         void DoAThing();
    5.     }
    6.  
    7.     public class Class_B : SomeInterface {
    8.         public void DoAThing() {
    9.             Debug.Log("Does A Thing");
    10.         }
    11.     }
    12.  
    13.     //This will cause compile errors if the user does not also have Package1.
    14.     public class SomeClass_A : Package1.Class_A, SomeInterface {
    15.         public void DoAThing() {
    16.             Debug.Log(IntField);
    17.         }
    18.     }
    19. }
    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.

    Thanks for any help!
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Sounds like a job for some reflection. Not sure exactly how to do it, but that's the place to start. Reflection lets you look through an assembly and see what is available.
     
  3. SquarePieStudios

    SquarePieStudios

    Joined:
    Apr 22, 2015
    Posts:
    33
    As far as I know, there's no possible way to extend by a type using reflection.
     
  4. SquarePieStudios

    SquarePieStudios

    Joined:
    Apr 22, 2015
    Posts:
    33
    Bump, still lookin for help on this one. I know I'm not the only one that's run into this issue as I've seen several plugins on the asset store that have support for the PlayMaker asset