Example #1
0
        void BuildConstructorExtensions()
        {
            uiConstructor     = new UiImgConstructor();
            spriteConstructor = new SpriteConstructor();

            Type targetType = typeof(IPsdConstructor);
            Type sprType    = typeof(SpriteConstructor);
            Type uiType     = typeof(UiImgConstructor);

            Type[] constructorTypes = AppDomain.CurrentDomain.GetAssemblies()
                                      .SelectMany(s => s.GetTypes())
                                      .Where(p => targetType.IsAssignableFrom(p) && p.IsClass &&
                                             !(p == sprType || p == uiType))
                                      .ToArray();

            List <IPsdConstructor> constructors   = new List <IPsdConstructor>();
            List <GUIContent>      constructNames = new List <GUIContent>();

            foreach (Type t in constructorTypes)
            {
                IPsdConstructor constructor = Activator.CreateInstance(t) as IPsdConstructor;
                if (constructor == null)
                {
                    continue;
                }

                constructors.Add(constructor);
                constructNames.Add(new GUIContent(constructor.MenuName));
            }

            constructorExtensions = constructors.ToArray();
            constructorNames      = constructNames.ToArray();
        }
        public GameObject CreateGameObject(string name, GameObject parent)
        {
            GameObject go = SpriteConstructor.GOFactory(name, parent);

            // Unity UI objects need Rect Transforms,
            // add the component after creating the base object
            go.AddComponent <RectTransform>();
            return(go);
        }