示例#1
0
        private void AddRegistryObjectDependency(UTinyModule module)
        {
            if (null == module)
            {
                return;
            }

            foreach (var m in module.EnumerateDependencies())
            {
                var path = UTinyPersistence.GetLocation(m);

                // Core or sample module/project don't need to be packaged, they will be included from the manifest.
                if (ShouldPackage(path))
                {
                    AddFileElements(path, false);
                }

                foreach (var asset in AssetIterator.EnumerateAssets(m))
                {
                    if (ShouldPackage(asset.AssetPath))
                    {
                        AddFileElements(asset.AssetPath, false);
                    }
                }
            }
        }
        private void ShowTypeMissing(UTinyObject tinyObject, bool isRoot, UTinyModule mainModule, UTinyModule moduleContainingType)
        {
            using (new EditorGUILayout.HorizontalScope(UTinyStyles.TypeMissingStyle))
            {
                if (isRoot)
                {
                    Foldout(false, tinyObject.Name + " (Missing)", false, null);
                }
                else
                {
                    EditorGUILayout.LabelField($"Type '{tinyObject.Type.Name}' is missing.");
                }

                ShowRemoveComponent(tinyObject.Type);
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button($"Add '{moduleContainingType.Name}' module"))
                {
                    mainModule.AddExplicitModuleDependency((UTinyModule.Reference)moduleContainingType);
                }
                GUILayout.FlexibleSpace();
            }
            GUILayout.Space(5.0f);
        }
        private static void CreateAssetExportInfo <TSettings>(UTinyProject project, UTinyModule module, UTinyAssetInfo assetInfo)
            where TSettings : UTinyAssetExportSettings, ICopyable <TSettings>, new()
        {
            var asset    = module.GetAsset(assetInfo.Object) ?? module.AddAsset(assetInfo.Object);
            var settings = asset.CreateExportSettings <TSettings>();

            settings.CopyFrom(UTinyUtility.GetAssetExportSettings(project, assetInfo.Object) as TSettings);
        }
 private static void SetPropertyValue(UTinyModule module, IEnumerable <UTinyAssetInfo> assetInfos, string property, object value)
 {
     foreach (var assetInfo in assetInfos)
     {
         var a        = module.GetAsset(assetInfo.Object);
         var settings = a?.ExportSettings as IPropertyContainer;
         settings?.PropertyBag.FindProperty(property)?.SetObjectValue(settings, value);
     }
 }
示例#5
0
 private static void AddRequiredModuleDependencies(IRegistry registry, UTinyModule module)
 {
     foreach (UTinyModule mod in registry.FindAllByType <UTinyModule>())
     {
         if (mod.IsRequired)
         {
             module.AddExplicitModuleDependency((UTinyModule.Reference)mod);
         }
     }
 }
        public static string GetJsTypeName(UTinyModule module, UTinyRegistryObjectBase @object)
        {
            var name = @object.Name;

            if (!string.IsNullOrEmpty(module?.Namespace))
            {
                name = module.Namespace + "." + name;
            }

            var type = @object as UTinyType;

            if (type != null)
            {
                switch (type.TypeCode)
                {
                case UTinyTypeCode.Unknown:
                    break;

                case UTinyTypeCode.Int8:
                case UTinyTypeCode.Int16:
                case UTinyTypeCode.Int32:
                case UTinyTypeCode.Int64:
                case UTinyTypeCode.UInt8:
                case UTinyTypeCode.UInt16:
                case UTinyTypeCode.UInt32:
                case UTinyTypeCode.UInt64:
                case UTinyTypeCode.Float32:
                case UTinyTypeCode.Float64:
                case UTinyTypeCode.Boolean:
                case UTinyTypeCode.Char:
                case UTinyTypeCode.String:
                    return(name.ToLower());

                case UTinyTypeCode.EntityReference:
                    // @TODO remove the magic value
                    return("ut.Entity");

                case UTinyTypeCode.Configuration:
                case UTinyTypeCode.Component:
                case UTinyTypeCode.Struct:
                case UTinyTypeCode.Enum:
                case UTinyTypeCode.UnityObject:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(name);
        }
        public UTinyModule CreateModule(UTinyId id, string name)
        {
            var module = new UTinyModule(this, m_VersionStorage)
            {
                Id   = id,
                Name = name,
            };

            m_VersionStorage.MarkAsChanged(module);

            Register(module);

            return(module);
        }
示例#8
0
        public static string GetAssetName(UTinyModule module, Object @object)
        {
            if (!@object)
            {
                return(string.Empty);
            }

            var asset = module.EnumerateDependencies().Select(m => m.GetAsset(@object)).FirstOrDefault();

            if (!string.IsNullOrEmpty(asset?.Name))
            {
                return(asset.Name);
            }

            return(@object.name);
        }
示例#9
0
        public static IEnumerable <UTinyAssetInfo> EnumerateAssets(UTinyModule module)
        {
            foreach (var m in module.EnumerateDependencies())
            {
                foreach (var asset in m.Assets)
                {
                    if (!asset.Object || null == asset.Object)
                    {
                        continue;
                    }

                    var assetInfo = GetOrAddAssetInfo(s_Assets, asset.Object, asset.Name);
                    assetInfo.AddExplicitReference((UTinyModule.Reference)module);
                }
            }

            foreach (var entity in module.EnumerateDependencies().Entities())
            {
                foreach (var component in entity.Components)
                {
                    foreach (var @object in EnumerateUnityEngineObjects(component))
                    {
                        if (!@object || null == @object)
                        {
                            continue;
                        }

                        var asset = GetOrAddAssetInfo(s_Assets, @object, @object.name);
                        asset.AddImplicitReference((UTinyEntity.Reference)entity);
                    }
                }
            }

            // Return root assets
            var assets = s_Assets.Values.Where(r => r.Parent == null).ToList();

            s_Assets.Clear();
            return(assets);
        }
        private void CreateComponentTree(bool showNotIncludedModules)
        {
            m_AnimatedTree = new UTinyAnimatedTree(TreeName());
            m_AnimatedTree.OnEscapePressed += CloseWindow;
            m_AnimatedTree.OnStateChanged  += Repaint;

            m_AnimatedTree.OnAnyLeafElementClicked += elem =>
            {
                CloseWindow();
            };

            var project = Registry.FindAllByType <UTinyProject>().FirstOrDefault();

            MainModule      = project.Module.Dereference(Registry);
            IncludedModules = new HashSet <UTinyModule>(project.Module.Dereference(Registry).EnumerateDependencies());

            foreach (var module in Registry.FindAllByType <UTinyModule>().OrderBy(m => (m.Name == "Main" ? "" : m.Name)))
            {
                var included = IncludedModules.Contains(module);

                if (!showNotIncludedModules && !included)
                {
                    continue;
                }

                var allComponentTypes = GetItems(module);
                if (!allComponentTypes.Any())
                {
                    continue;
                }

                var    element = UTinyAnimatedTree.Element.MakeGroup(module.Name == "Main" && null != project ? project.Name : module.Name, MakeTooltip(module), included);
                string warning = null;
                if (!included)
                {
                    var count = module.EnumerateDependencies().Count(m => !IncludedModules.Contains(m));
                    warning =
                        $"This will include the {module.Name} module{(count <= 1 ? "" : $", along with {count - 1} dependencies.")}.";
            public override void BeginModule(UTinyModule module)
            {
                m_Module = module;

                if (module.EntityGroups.Count > 0)
                {
                    // The idea here is we want to pack the component within the runtime `entityGroup` javascript object
                    // Each group resolves to a javascript object like so `{ENTITY_GROUPS}.{NAMESPACE}.{GROUP_NAME}`
                    //
                    // The group component lives in this object with the name `Component`
                    //
                    // e.g.
                    //
                    // - "MyGroup" becomes the runtime object `entities.game.MyGroup = {}`
                    // - The generated component becomes `entities.game.MyGroup.Component = function(w, e) {...}`
                    Writer.Line();
                    Writer.Line($"/*");
                    Writer.Line($" * !!! TEMP UNITL PROPER SCENE FORMAT !!!");
                    Writer.Line($" */");
                    using (Writer.Scope($"namespace {UTinyHTML5Builder.KEntityGroupNamespace}.{module.Namespace}"))
                    {
                        foreach (var entityGroup in module.EntityGroups)
                        {
                            using (Writer.Scope($"namespace {entityGroup.Dereference(module.Registry).Name}"))
                            {
                                VisitType(new UTinyType(null, null)
                                {
                                    TypeCode = UTinyTypeCode.Component,
                                    Name     = "Component"
                                });
                            }
                        }
                    }
                }

                Writer.Line();
                m_NamespaceScope = Writer.Scope($"namespace {module.Namespace}");
            }
 protected bool IsIncluded(UTinyModule module)
 {
     return(IncludedModules.Contains(module));
 }
 protected override IEnumerable <UTinySystem> GetItems(UTinyModule module)
 {
     return(module.Systems.Deref(Registry));
 }
示例#14
0
 public virtual void BeginModule(UTinyModule module)
 {
 }
示例#15
0
 public virtual void EndModule(UTinyModule module)
 {
 }
 public override void EndModule(UTinyModule module)
 {
     m_NamespaceScope.Dispose();
     m_NamespaceScope = null;
 }
 private static void CreateNewEntityGroup(UTinyModule module)
 {
     EntityGroupManager.CreateNewEntityGroup();
 }
 protected override IEnumerable <UTinyType> GetItems(UTinyModule module)
 {
     return(module.Components.Deref(Registry));
 }
示例#19
0
 /// <summary>
 /// Sets up or migrates the initial state of a standalone module
 /// * Includes required modules
 /// * Perfrorms any migration
 /// </summary>
 /// <param name="registry"></param>
 /// <param name="module"></param>
 private static void SetupModule(IRegistry registry, UTinyModule module)
 {
     AddRequiredModuleDependencies(registry, module);
 }
        private void CellGUI(Rect cellRect, UTinyModuleTreeViewItem item, ColumnType columnType, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            using (new GUIEnabledScope(item.Status != UTinyModuleTreeViewItem.StatusType.Self &&
                                       (item.Status != UTinyModuleTreeViewItem.StatusType.IncludedRequired)))
            {
                var moduleReference = item.Module;
                var module          = item.Module.Dereference(Model.Registry);

                switch (columnType)
                {
                case ColumnType.Icon:
                {
                    GUI.DrawTexture(cellRect, null == module ? UTinyIcons.Warning : UTinyIcons.Module,
                                    ScaleMode.ScaleToFit);
                }
                break;

                case ColumnType.Name:
                {
                    var toggleRect = cellRect;
                    toggleRect.x    += GetContentIndent(item);
                    toggleRect.width = 18;

                    EditorGUI.BeginChangeCheck();

                    item.Included = EditorGUI.Toggle(toggleRect, item.Included);

                    if (EditorGUI.EndChangeCheck())
                    {
                        ShowConfigurationInspector();
                        Reload();
                    }

                    args.rowRect = cellRect;

                    using (new GUIColorScope(null == module ? Color.red : Color.white))
                    {
                        base.RowGUI(args);
                    }
                }
                break;

                case ColumnType.Status:
                {
                    string status;

                    switch (item.Status)
                    {
                    case UTinyModuleTreeViewItem.StatusType.Self:
                        status = "";
                        break;

                    case UTinyModuleTreeViewItem.StatusType.Excluded:
                        status = "Excluded";
                        break;

                    case UTinyModuleTreeViewItem.StatusType.IncludedRequired:
                        status = "Included (Required)";
                        break;

                    case UTinyModuleTreeViewItem.StatusType.IncludedExplicit:
                        status = "Included (Explicit)";
                        break;

                    case UTinyModuleTreeViewItem.StatusType.IncludedImplicit:
                        status = "Included (Implicit)";
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    using (new GUIColorScope(item.Status != UTinyModuleTreeViewItem.StatusType.Excluded
                            ? item.Status != UTinyModuleTreeViewItem.StatusType.IncludedImplicit ?
                                             Color.green
                            : Color.cyan
                            : Color.white))
                    {
                        GUI.Label(cellRect, status);
                    }
                }
                break;

                case ColumnType.Dependencies:
                {
                    var @string = "";

                    if (module != null)
                    {
                        for (var i = 0; i < module.Dependencies.Count; i++)
                        {
                            var @ref = module.Dependencies[i];
                            var m    = @ref.Dereference(Model.Registry);

                            if (i > 0)
                            {
                                @string += ", ";
                            }

                            if (null == m)
                            {
                                @string += $"{@ref.Name} (missing)";
                            }
                            else
                            {
                                @string += m.Name;
                            }
                        }
                    }

                    GUI.Label(cellRect, @string);
                }
                break;

                case ColumnType.ReferencedBy:
                {
                    var modules = UTinyModule.GetExplicitDependantModules(Model.Registry, moduleReference).Where(m => !m.IsProjectModule);
                    var @string = string.Join(", ", modules.Select(m => m.Name).ToArray());
                    GUI.Label(cellRect, @string);
                }
                break;

                case ColumnType.Description:
                {
                    if (module != null)
                    {
                        EditorGUI.LabelField(cellRect, module.Documentation.Summary);
                    }
                }
                break;
                }
            }
        }
 /// <summary>
 /// Sets up or migrates the initial state of a standalone module
 /// * Includes required modules
 /// * Perfrorms any migration
 /// </summary>
 /// <param name="registry"></param>
 /// <param name="module"></param>
 private static void SetupModule(IRegistry registry, UTinyModule module)
 {
     // Always include a dependency on core
     module.AddExplicitModuleDependency((UTinyModule.Reference)registry.FindByName <UTinyModule>("UTiny.Core"));
 }