示例#1
0
        public bool DrawLayout()
        {
            if (m_Dirty)
            {
                m_Dirty = false;
                Reload();
            }

            m_AssetNames = Model.GetAssetInfos().Select(a => a.Name).ToList();

            GUILayout.Space(2);

            var rect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            // Support dropping scene objects
            var objects = UTinyEditorUtility.DoDropField(rect, s_DropFieldHash, objs => objs.ToArray(), UTinyStyles.DropField);

            if (null != objects)
            {
                foreach (var @object in objects)
                {
                    Model.MainModule.Dereference(Model.Registry).AddAsset(@object);
                    SetDirty();
                }
            }

            OnGUI(rect);

            return(false);
        }
        private void DrawCullingMask(UTinyObject tinyObject)
        {
            var cullingMask = tinyObject.Properties.PropertyBag.FindProperty("layerMask") as IProperty <UTinyObject.PropertiesContainer, int>;

            EditorGUI.BeginChangeCheck();
            var mixed = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue = HasMixedValues <int>(tinyObject.Properties, cullingMask);
            var isOverriden = (cullingMask as IUTinyValueProperty)?.IsOverridden(tinyObject.Properties) ?? true;

            UTinyEditorUtility.SetEditorBoldDefault(isOverriden);
            try
            {
                var container  = tinyObject.Properties;
                var layerNames = GetLayerNames();
                var newLayer   = EditorGUILayout.MaskField("cullingMask", GetCurrentEditorLayer(layerNames, cullingMask.GetValue(container)), layerNames.ToArray());
                if (EditorGUI.EndChangeCheck())
                {
                    cullingMask.SetValue(container, GetLayers(layerNames, newLayer));
                    PushChange(container, cullingMask);
                }
            }
            finally
            {
                UTinyEditorUtility.SetEditorBoldDefault(false);
                EditorGUI.showMixedValue = mixed;
            }
        }
示例#3
0
        private void DrawText(UTinyObject tinyObject)
        {
            var textProperty = tinyObject.Properties.PropertyBag.FindProperty("text") as IProperty <UTinyObject.PropertiesContainer, string>;

            EditorGUI.BeginChangeCheck();
            var mixed = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue = HasMixedValues <string>(tinyObject.Properties, textProperty);
            var isOverriden = (textProperty as IUTinyValueProperty)?.IsOverridden(tinyObject.Properties) ?? true;

            UTinyEditorUtility.SetEditorBoldDefault(isOverriden);
            try
            {
                var container = tinyObject.Properties;
                var newText   = EditorGUILayout.TextField(textProperty.Name, textProperty.GetValue(container));

                if (EditorGUI.EndChangeCheck())
                {
                    textProperty.SetValue(container, newText);
                    PushChange(container, textProperty);
                }
            }
            finally
            {
                UTinyEditorUtility.SetEditorBoldDefault(false);
                EditorGUI.showMixedValue = mixed;
            }
        }
        protected bool DoField <TContainer, TValue>(ref TContainer container, ref VisitContext <TValue> context,
                                                    Func <GUIContent, TValue, TValue> onGUI)
            where TContainer : IPropertyContainer
        {
            var property = context.Property;

            // Well, we must be in a list.
            if (context.Index >= 0 && null != CurrentListProperty)
            {
                var label = ConstructLabel(CurrentListProperty);
                label.text = context.Index.ToString();

                EditorGUILayout.BeginHorizontal();
                context.Value = onGUI(label, context.Value);
                if (GUILayout.Button("x", GUILayout.Width(16.0f), GUILayout.Height(16.0f)))
                {
                    RemoveAtIndex = context.Index;
                }

                EditorGUILayout.EndHorizontal();
                return(true);
            }

            if (property == null || ShouldHide(property))
            {
                return(false);
            }

            PushEnabledState();
            var isReadOnly = IsReadOnly(property);

            GUI.enabled &= !isReadOnly;

            if (HasHeader(property))
            {
                DrawHeader(property);
            }

            var mixed = EditorGUI.showMixedValue;

            var isOverridden = (property as Tiny.IUTinyValueProperty)?.IsOverridden(container) ?? true;

            UTinyEditorUtility.SetEditorBoldDefault(isOverridden);

            try
            {
                EditorGUI.showMixedValue = HasMixedValues <TValue>(container, context.Property);
                context.Value            = onGUI(ConstructLabel(property), context.Value);
            }
            finally
            {
                EditorGUI.showMixedValue = mixed;
                UTinyEditorUtility.SetEditorBoldDefault(false);
            }

            PopEnabledState();
            return(true);
        }
示例#5
0
 private void Draw(UTinyObject.PropertiesContainer container, IProperty<UTinyObject.PropertiesContainer, float> property)
 {
     var isOverridden = (property as IUTinyValueProperty)?.IsOverridden(container) ?? true;
     UTinyEditorUtility.SetEditorBoldDefault(isOverridden);
     var current = property.GetValue(container);
     var value = EditorGUILayout.FloatField(property.Name, current);
     UTinyEditorUtility.SetEditorBoldDefault(false);
     if (value != current)
     {
         property.SetValue(container, value);
         PushChange(container, property);
     }
 }
        public override bool VisitStruct(UTinyObject tinyObject, GUIContent label)
        {
            var value = tinyObject.As <Color>();

            EditorGUI.BeginChangeCheck();

            UTinyEditorUtility.SetEditorBoldDefault(tinyObject.IsOverridden);
            value = EditorGUILayout.ColorField(string.IsNullOrEmpty(label.text) ? GUIContent.none : label, value);
            UTinyEditorUtility.SetEditorBoldDefault(false);
            if (EditorGUI.EndChangeCheck())
            {
                tinyObject.AssignFrom(value);
                foreach (var prop in tinyObject.Properties.PropertyBag.Properties)
                {
                    PushChange(tinyObject.Properties, prop);
                }
            }
            return(true);
        }
示例#7
0
        private void DoLayoutToolbar()
        {
            GUILayout.Space(1);

            using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
            {
                using (var projectScope = new EditorGUILayout.HorizontalScope(GUILayout.Width(120)))
                {
                    var buttonLabel = GetProjectButtonName();

                    if (UTinyEditorApplication.IsChanged)
                    {
                        buttonLabel += " *";
                    }

                    if (GUILayout.Button(buttonLabel, EditorStyles.toolbarDropDown))
                    {
                        var menu = new GenericMenu();

                        menu.AddItem(new GUIContent("New Project"), false, NewProject);

                        menu.AddItem(new GUIContent("New Module"), false, NewModule);

                        menu.AddSeparator(string.Empty);
                        menu.AddItem(new GUIContent("Load..."), false, LoadProject);

                        menu.AddSeparator(string.Empty);

                        var save = new GUIContent("Save");
                        if (UTinyEditorApplication.Project == null)
                        {
                            menu.AddDisabledItem(save);
                        }
                        else
                        {
                            menu.AddItem(save, false, () =>
                            {
                                UTinyEditorApplication.Save();
                            });
                        }

                        var saveAs = new GUIContent("Save As...");
                        if (UTinyEditorApplication.Project == null)
                        {
                            menu.AddDisabledItem(saveAs);
                        }
                        else
                        {
                            menu.AddItem(saveAs, false, () =>
                            {
                                UTinyEditorApplication.SaveAs();
                            });
                        }

                        menu.AddSeparator(string.Empty);

                        var closeProject = new GUIContent("Close");
                        if (UTinyEditorApplication.Project == null)
                        {
                            menu.AddDisabledItem(closeProject);
                        }
                        else
                        {
                            menu.AddItem(closeProject, false, () =>
                            {
                                if (!UTinyEditorApplication.SaveChanges())
                                {
                                    return;
                                }

                                m_TabType = TabType.Settings;
                                UTinyEditorApplication.Close();
                            });
                        }

                        menu.DropDown(projectScope.rect);
                    }
                }

                GUILayout.FlexibleSpace();

                if (UTinyEditorApplication.ContextType == EditorContextType.Project)
                {
                    var project   = UTinyEditorApplication.Project;
                    var workspace = UTinyEditorApplication.EditorContext.Workspace;

                    if (null != project && null != workspace)
                    {
                        var lastBuildConfiguration = workspace.BuildConfiguration;
                        workspace.BuildConfiguration = (UTinyBuildConfiguration)EditorGUILayout.EnumPopup(workspace.BuildConfiguration, EditorStyles.toolbarDropDown, GUILayout.Width(100));
                        if (workspace.BuildConfiguration != lastBuildConfiguration)
                        {
                            UTinyEditorUtility.RepaintAllWindows();
                        }

                        if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(100)))
                        {
                            UTinyBuildPipeline.Export(project);
                        }

                        workspace.Preview = GUILayout.Toggle(
                            workspace.Preview,
                            new GUIContent(UTinyIcons.Export, "Toggles preview in browser."),
                            EditorStyles.toolbarButton,
                            GUILayout.Width(35));
                    }
                }
            }
        }
        public override bool VisitStruct(UTinyObject tinyObject, GUIContent label)
        {
            var properties = tinyObject.Properties;

            //For the rotation, we will offer Euler angles to the user.
            var tinyEuler = GetEulerAnglesObject(tinyObject);

            tinyEuler.Refresh();

            if (Screen.width < 400)
            {
                EditorGUIUtility.labelWidth = Mathf.Max(EditorGUIUtility.labelWidth - (400 - Screen.width), 70);
            }

            var mixed  = EditorGUI.showMixedValue;
            var indent = EditorGUI.indentLevel;

            UTinyEditorUtility.SetEditorBoldDefault(tinyObject.IsOverridden);
            try
            {
                EditorGUI.showMixedValue =
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("x")) ||
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("y")) ||
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("z")) ||
                    HasMixedValues <float>(properties, properties.PropertyBag.FindProperty("w"));


                EditorGUILayout.BeginHorizontal();
                if (!string.IsNullOrEmpty(label.text))
                {
                    EditorGUILayout.PrefixLabel(label);
                }

                EditorGUIUtility.labelWidth = 15;
                EditorGUIUtility.fieldWidth = 30;
                EditorGUI.indentLevel       = 0;

                EditorGUI.BeginChangeCheck();

                Draw(tinyEuler.Properties, tinyEuler.Properties.PropertyBag.FindProperty("x") as IProperty <UTinyObject.PropertiesContainer, float>);
                Draw(tinyEuler.Properties, tinyEuler.Properties.PropertyBag.FindProperty("y") as IProperty <UTinyObject.PropertiesContainer, float>);
                Draw(tinyEuler.Properties, tinyEuler.Properties.PropertyBag.FindProperty("z") as IProperty <UTinyObject.PropertiesContainer, float>);

                if (EditorGUI.EndChangeCheck())
                {
                    SetQuaternionFromEuler(tinyObject, tinyEuler);
                    PushChange(properties, properties.PropertyBag.FindProperty("x"));
                    PushChange(properties, properties.PropertyBag.FindProperty("y"));
                    PushChange(properties, properties.PropertyBag.FindProperty("z"));
                    PushChange(properties, properties.PropertyBag.FindProperty("w"));
                }
            }
            finally
            {
                UTinyEditorUtility.SetEditorBoldDefault(false);
                EditorGUILayout.EndHorizontal();
                EditorGUI.showMixedValue    = mixed;
                EditorGUI.indentLevel       = indent;
                EditorGUIUtility.fieldWidth = 0;
                EditorGUIUtility.labelWidth = 0;
            }
            return(true);
        }
示例#9
0
        public override void Header()
        {
            var entities = Targets.Cast <UTinyEntity>();

            var firstEntity = entities.FirstOrDefault();

            if (null == firstEntity)
            {
                return;
            }

            UTinyGUI.BackgroundColor(new Rect(0, 0, Screen.width, 15 + 2 * UTinyGUIUtility.SingleLineAndSpaceHeight), UTinyColors.Inspector.HeaderBackground);
            GUILayout.Space(10);
            var name = firstEntity.Name;

            name = entities.All(entity => entity.Name == name) ? name : "-";
            var enabled     = firstEntity.Enabled;
            var sameEnabled = entities.All(tiny => tiny.Enabled == enabled);

            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUI.BeginChangeCheck();
                var mixed = EditorGUI.showMixedValue;
                EditorGUI.showMixedValue = !sameEnabled;
                enabled = EditorGUILayout.ToggleLeft(GUIContent.none, enabled, GUILayout.Width(EditorGUIUtility.singleLineHeight));
                EditorGUI.showMixedValue = mixed;
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var entity in entities)
                    {
                        entity.Enabled = enabled;
                        entity.View.gameObject.SetActive(enabled);
                    }
                    UTinyHierarchyWindow.InvalidateDataModel();
                    UTinyEditorUtility.RepaintAllWindows();
                }
                EditorGUI.BeginChangeCheck();
                name = EditorGUILayout.DelayedTextField(name, UTinyStyles.ComponentHeaderStyle);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var entity in entities)
                    {
                        entity.Name = name;
                    }
                    UTinyHierarchyWindow.InvalidateDataModel();
                    UTinyEditorUtility.RepaintAllWindows();
                }
                GUILayout.Space(EditorGUIUtility.singleLineHeight);
            }

            var layer     = firstEntity.Layer;
            var sameLayer = entities.All(tiny => tiny.Layer == layer);

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Space(50);
                EditorGUILayout.LabelField("Layer", GUILayout.Width(50));
                EditorGUI.BeginChangeCheck();
                var mixed = EditorGUI.showMixedValue;
                EditorGUI.showMixedValue = !sameLayer;
                layer = EditorGUILayout.LayerField(layer);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (var entity in entities)
                    {
                        entity.Layer = layer;
                        entity.View.gameObject.layer = layer;
                    }
                    UTinyHierarchyWindow.InvalidateDataModel();
                    UTinyEditorUtility.RepaintAllWindows();
                }
                GUILayout.Space(EditorGUIUtility.singleLineHeight);
                EditorGUI.showMixedValue = mixed;
            }
            GUILayout.Space(5);
            UTinyGUILayout.Separator(UTinyColors.Inspector.Separator, UTinyGUIUtility.ComponentHeaderSeperatorHeight);
        }
        public static UTinyBuildResults Build(UTinyBuildOptions options)
        {
            if (options?.Project == null || options.Destination == null)
            {
                throw new ArgumentException($"{UTinyConstants.ApplicationName}: invalid build options provided", nameof(options));
            }

            var buildStart = DateTime.Now;

            var           results = new UTinyBuildResults();
            IUTinyBuilder builder = null;

            switch (options.Platform)
            {
            case UTinyPlatform.HTML5:
                builder = new UTinyHTML5Builder();
                break;

            default:
                throw new ArgumentException($"{UTinyConstants.ApplicationName}: build platform not supported", nameof(options));
            }

            try
            {
                EditorUtility.DisplayProgressBar(ProgressBarTitle, "Build started for " + options.Platform.ToString(),
                                                 0.0f);

                var destFolder = options.Destination;
                destFolder.Create();

                // BUILD = <DEST>/PLATFORM/CONFIG
                var buildFolder = new DirectoryInfo(GetBuildDirectory(options.Project, options.Platform, options.Configuration));

                results.OutputFolder = buildFolder;

                UTinyBuildUtilities.PurgeDirectory(buildFolder);
                buildFolder.Create();

                options.Destination = results.BinaryFolder = buildFolder;

                var idlFile = new FileInfo(Path.Combine(buildFolder.FullName, "generated.cs"));
                UTinyIDLGenerator.GenerateIDL(options.Project, idlFile);

                var distFolder = GetRuntimeDistFolder();

                var bindGem = new FileInfo(Path.Combine(
                                               distFolder.FullName, "bindgem/BindGem/bin/Release/BindGem.exe"));

                var exeName = "\"" + bindGem.FullName + "\"";

                // always call bindgem with mono for consistency
                exeName = "mono " + exeName;

                // reference the core runtime file
                var bindReferences = $"-r \"{RuntimeDefsAssemblyPath}\"";

                UTinyBuildUtilities.RunInShell(
                    $"{exeName} -j {bindReferences} -o bind-generated {idlFile.Name}",
                    new ShellProcessArgs()
                {
                    WorkingDirectory = buildFolder,
                    ExtraPaths       = TinyPreferences.MonoDirectory.AsEnumerable()
                });

                // @TODO Perform a full refresh before building

                builder.Build(options, results);

                results.BuildReport.Update();

                Debug.Log($"{UTinyConstants.ApplicationName} project generated at: {results.BinaryFolder.FullName}");

                TinyEditorAnalytics.SendBuildEvent(options.Project, results, DateTime.Now - buildStart);
                return(results);
            }
            catch (Exception ex)
            {
                TinyEditorAnalytics.SendException("BuildPipeline.Build", ex);
                throw;
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                UTinyEditorUtility.RepaintAllWindows();
            }
        }
        private static void Update()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (null == EditorContext)
            {
                // Flush asset changes from the persistence system
                // We don't care about any changes unless we have a project loaded
                UTinyPersistence.ClearChanges();
                return;
            }

            // Poll for workspace changes
            if (null != EditorContext.Workspace && s_WorkspaceVersion != EditorContext.Workspace.Version)
            {
                UTinyEditorPrefs.SaveWorkspace(EditorContext.Workspace, EditorContext.PersistentObject.PersistenceId);
                s_WorkspaceVersion = EditorContext.Workspace.Version;
            }

            // Poll for file/asset changes
            var changes = UTinyPersistence.DetectChanges(Registry);

            if (changes.changesDetected)
            {
                var persistenceId = EditorContext.PersistentObject.PersistenceId;

                foreach (var change in changes.changedSources)
                {
                    // The currently opened project or module has been changed on disc
                    if (change.Equals(persistenceId))
                    {
                        // Ask the user if they want to keep their changes or reload from disc
                        if (EditorUtility.DisplayDialog($"{UTinyConstants.ApplicationName} assets changed", $"{UTinyConstants.ApplicationName} assets have changed on disk, would you like to reload the current project?", "Yes", "No"))
                        {
                            LoadPersistenceId(persistenceId);
                        }
                        else
                        {
                            UTinyModificationProcessor.MarkChanged();
                        }
                    }
                    else
                    {
                        // This is some other file. We assume they are in a readonly state and we silently reload the object
                        UTinyPersistence.ReloadObject(EditorContext.Registry, change);
                    }
                }

                foreach (var deletion in changes.deletedSources)
                {
                    // The currently opened project or module has been deleted on disc
                    if (deletion.Equals(persistenceId))
                    {
                        // Ask the user if they want to keep their changes or close the project
                        if (EditorUtility.DisplayDialog($"{UTinyConstants.ApplicationName} assets changed", "The current project has been deleted, would you like to close the current project?", "Yes", "No"))
                        {
                            // Force close the project
                            Close();
                        }
                        else
                        {
                            UTinyModificationProcessor.MarkChanged();
                            EditorContext.PersistentObject.PersistenceId = string.Empty;
                        }
                    }
                    else
                    {
                        // This is some other file. We assume they are in a readonly state and we silently reload the object
                        EditorContext.Registry.UnregisterAllBySource(deletion);
                    }
                }

                foreach (var moved in changes.movedSources)
                {
                    if (!moved.Equals(persistenceId))
                    {
                        continue;
                    }

                    var path  = AssetDatabase.GUIDToAssetPath(moved);
                    var asset = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
                    if (null != asset)
                    {
                        EditorContext.PersistentObject.Name = asset.name;
                    }
                }

                OnChangesDetected?.Invoke();
            }

            // Poll for module or project changes
            if (EditorContext.ContextType == EditorContextType.Project && (s_ProjectVersion != EditorContext.Project.Version || s_ModuleVersion != EditorContext.Module.Version))
            {
                EditorContext.Project.RefreshConfiguration();
                s_ProjectVersion = EditorContext.Project.Version;
                s_ModuleVersion  = EditorContext.Module.Version;
            }

            if (s_Save)
            {
                s_Save = false;

                // NOTE: It is possible that this call will fail
                Save();
            }

            if (s_Repaint)
            {
                UTinyEditorUtility.RepaintAllWindows();
                s_Repaint = false;
            }
        }
 private static void RepaintAll()
 {
     UTinyEditorUtility.RepaintAllWindows();
 }