Exemplo n.º 1
0
    protected override UniTask UpdateEditorFieldsAsync()
    {
        if (TotalyPos == 0f)
        {
            TotalyPos = position.height;
        }

        scrollbarShown = TotalyPos > position.height;
        ScrollPosition = GUI.BeginScrollView(new Rect(0, 0, EditorGUIUtility.currentViewWidth, position.height), ScrollPosition, new Rect(0, 0, EditorGUIUtility.currentViewWidth - (scrollbarShown ? scrollbarWidth : 0f), TotalyPos));

        if (Application.isPlaying && Controller.LoadState == Controller.State.Finished)
        {
            if (Settings.LoadFromMemory)
            {
                var objManager = LevelEditorData.ObjManager;

                if (objManager is Unity_ObjectManager_R1 r1)
                {
                    if (Serializer == null)
                    {
                        Serializer = new UnityWindowSerializer(LevelEditorData.MainContext, this, r1.GlobalDataForceWrite);
                    }

                    EditorGUI.BeginChangeCheck();

                    r1.GlobalData.Update(Serializer);

                    if (EditorGUI.EndChangeCheck())
                    {
                        r1.GlobalPendingEdits = true;
                    }
                }
            }
            else
            {
                EditorGUI.HelpBox(GetNextRect(ref YPos, height: 40f), "Game properties are only available when loading from memory.", MessageType.Warning);
            }
        }
        else
        {
            EditorGUI.HelpBox(GetNextRect(ref YPos, height: 40f), "Run the project in order to edit game properties.", MessageType.Warning);
        }

        TotalyPos = YPos;
        GUI.EndScrollView();

        return(UniTask.CompletedTask);
    }
Exemplo n.º 2
0
    protected override UniTask UpdateEditorFieldsAsync()
    {
        if (TotalyPos == 0f)
        {
            TotalyPos = position.height;
        }

        scrollbarShown = TotalyPos > position.height;
        ScrollPosition = GUI.BeginScrollView(new Rect(0, 0, EditorGUIUtility.currentViewWidth, position.height), ScrollPosition, new Rect(0, 0, EditorGUIUtility.currentViewWidth - (scrollbarShown ? scrollbarWidth : 0f), TotalyPos));

        if (Application.isPlaying && Controller.LoadState == Controller.State.Finished)
        {
            if (Serializer == null)
            {
                Serializer = new UnityWindowSerializer(LevelEditorData.MainContext, this, null);
            }

            var selectedObj = Controller.obj.levelController.controllerEvents.SelectedEvent;

            if (selectedObj != null)
            {
                DrawHeader("Editor fields");

                selectedObj.ObjData.CurrentUIState = EditorField("State", selectedObj.ObjData.CurrentUIState, selectedObj.ObjData.UIStateNames);

                // TODO: Add DES/ETA drop-down, add state drop-down, show cmds as string

                DrawHeader("Object data");

                var selectedObjData = selectedObj.ObjData;

                try
                {
                    EditorGUI.BeginChangeCheck();

                    if (selectedObjData is Unity_Object_R1 r1)
                    {
                        R1_CmdPanelOpen = EditorGUI.Foldout(GetNextRect(ref YPos), R1_CmdPanelOpen, "Commands");

                        if (R1_CmdPanelOpen)
                        {
                            // TODO: Cache the commands, but make sure to update if modified
                            var cmdLines = r1.EventData.Commands?.ToTranslatedStrings(r1.EventData.LabelOffsets);

                            if (cmdLines?.Any() == true)
                            {
                                // TODO: Better way to get height?
                                EditorGUI.TextArea(GetNextRect(ref YPos, height: cmdLines.Length * 15 + 2), String.Join(Environment.NewLine, cmdLines));
                            }
                        }
                    }

                    selectedObj?.ObjData?.SerializableData?.SerializeImpl(Serializer);

                    if (EditorGUI.EndChangeCheck())
                    {
                        selectedObjData.HasPendingEdits = true;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError($"{ex.Message}{Environment.NewLine}{ex}");
                }
            }
            else
            {
                EditorGUI.HelpBox(GetNextRect(ref YPos, height: 40f), "No object selected", MessageType.Info);
            }
        }
        else
        {
            EditorGUI.HelpBox(GetNextRect(ref YPos, height: 40f), "Run the project in order to edit object properties.", MessageType.Warning);
        }

        TotalyPos = YPos;
        GUI.EndScrollView();

        return(UniTask.CompletedTask);
    }