Esempio n. 1
0
        private void LoadState(StateData state)
        {
            scene.Clear();

            scene.Objs   = state.Objs;
            scene.Mats   = state.Mats;
            scene.Layers = state.Layers;

            currentLayer = null;
            currentMat   = null;
            currentObj   = null;

            if (scene.Layers.Count > 0)
            {
                currentLayer = scene.Layers[0];
            }

            UpdatePaintedMats();
        }
Esempio n. 2
0
        protected override void OnInspector()
        {
            DrawNextPaint();

            if (scene == null)
            {
                scene = CreateInstance <P3dScene>();

                scene.name = "Temp";

                scene.AddLayer();

                scene.AddCloner("Mirror X", Vector3.zero, new Vector3(0.0f, 90.0f, 0.0f));
                scene.AddCloner("Mirror Y", Vector3.zero, new Vector3(90.0f, 0.0f, 0.0f));
                scene.AddCloner("Mirror Z", Vector3.zero, new Vector3(0.0f, 0.0f, 0.0f));
            }

            if (previewDrawn == true && Event.current.type == EventType.Repaint)
            {
                previewDrawn = false;

                foreach (var layer in scene.Layers)
                {
                    foreach (var images in layer.Images)
                    {
                        if (images.Preview != null)
                        {
                            images.Preview = P3dHelper.ReleaseRenderTexture(images.Preview);
                        }
                    }
                }

                pendingUpdate = true;
            }

            if (scene.Layers.Contains(currentLayer) == false)
            {
                currentLayer = null;

                if (scene.Layers.Count > 0)
                {
                    currentLayer = scene.Layers[scene.Layers.Count - 1];
                }
            }

            if (scene.Mats.Contains(currentMat) == false)
            {
                currentMat = null;

                if (scene.Mats.Count > 0)
                {
                    currentMat = scene.Mats[scene.Mats.Count - 1];
                }
            }

            if (scene.Objs.Contains(currentObj) == false)
            {
                currentObj = null;

                if (scene.Objs.Count > 0)
                {
                    currentObj = scene.Objs[scene.Objs.Count - 1];
                }
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            EditorGUI.BeginDisabledGroup(CanUndo == false);
            if (GUILayout.Button(new GUIContent("◄", "Undo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true)
            {
                Undo();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(CanRedo == false);
            if (GUILayout.Button(new GUIContent("►", "Redo"), EditorStyles.toolbarButton, GUILayout.Width(20)) == true)
            {
                Redo();
            }
            EditorGUI.EndDisabledGroup();

            if (GUILayout.Toggle(currentState == StateType.Scene, "Scene", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Scene;
            }

            if (GUILayout.Toggle(currentState == StateType.Paint, "Paint", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Paint;
            }

            if (GUILayout.Toggle(currentState == StateType.Layer, "Layer", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Layer;
            }

            if (GUILayout.Toggle(currentState == StateType.Config, "Config", EditorStyles.toolbarButton, GUILayout.Width(50)) == true)
            {
                currentState = StateType.Config;
            }

            EditorGUILayout.Separator();

            EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false);
            if (GUILayout.Button("Save", EditorStyles.toolbarButton, GUILayout.Width(40)) == true)
            {
                HandleSave();
            }
            EditorGUI.EndDisabledGroup();

            P3dHelper.BeginColor(Color.green, P3dHelper.IsAsset(scene) == false);
            if (GUILayout.Button("Save As", EditorStyles.toolbarButton, GUILayout.Width(55)) == true)
            {
                HandleSaveAs();
            }
            P3dHelper.EndColor();
            EditorGUILayout.EndHorizontal();

            if (Event.current.type == EventType.MouseUp)
            {
                dragId     = -1;
                dragHandle = -1;
            }

            switch (currentState)
            {
            case StateType.Scene:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                objectsScrollPosition = GUILayout.BeginScrollView(objectsScrollPosition, GUILayout.Width(200));
                UpdateObjectsPanel();
                GUILayout.EndScrollView();

                DrawViewport();

                materialsScrollPosition = GUILayout.BeginScrollView(materialsScrollPosition, GUILayout.Width(200));
                UpdateMaterialsPanel();
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;

            case StateType.Paint:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                GUILayout.BeginVertical(GUILayout.Width(200));
                brushesScrollPosition = GUILayout.BeginScrollView(brushesScrollPosition, GUILayout.ExpandWidth(true));
                UpdatePaintBrushesPanel(200);
                GUILayout.EndScrollView();

                dynamicsScrollPosition = GUILayout.BeginScrollView(dynamicsScrollPosition, GUILayout.ExpandWidth(true), GUILayout.Height(200));
                UpdateDynamicsPanel();
                GUILayout.EndScrollView();
                GUILayout.EndVertical();

                DrawViewport();

                paintScrollPosition = GUILayout.BeginScrollView(paintScrollPosition, GUILayout.Width(200));
                UpdatePaintMaterialsPanel(200);
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;

            case StateType.Layer:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                repeatersScrollPosition = GUILayout.BeginScrollView(repeatersScrollPosition, GUILayout.Width(200));
                UpdateClonersPanel();
                GUILayout.EndScrollView();

                DrawViewport();

                layersScrollPosition = GUILayout.BeginScrollView(layersScrollPosition, GUILayout.Width(200));
                UpdateLayersPanel();
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;

            case StateType.Config:
            {
                GUILayout.BeginHorizontal(GUILayout.ExpandHeight(true));
                sceneScrollPosition = GUILayout.BeginScrollView(sceneScrollPosition, GUILayout.Width(200));
                UpdateScenePanel();
                GUILayout.EndScrollView();

                DrawViewport();

                settingsScrollPosition = GUILayout.BeginScrollView(settingsScrollPosition, GUILayout.Width(200));
                UpdateSettingsPanel();
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }
            break;
            }

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            EditorGUILayout.LabelField("Undo state " + stateIndex + " of " + states.Count, GUILayout.Width(135));

            EditorGUILayout.Separator();

            scene = (P3dScene)EditorGUILayout.ObjectField(scene, typeof(P3dScene), false, GUILayout.MinWidth(50));

            EditorGUI.BeginDisabledGroup(P3dHelper.IsAsset(scene) == false);
            if (GUILayout.Button("Export", EditorStyles.toolbarButton, GUILayout.Width(55)) == true)
            {
                HandleExport();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            HandleDraw();

            if (pendingUpdate == true && Event.current.type == EventType.Repaint)
            {
                pendingUpdate = false;

                UpdatePaintedMats();
            }

            Repaint();
        }