Exemple #1
0
        // LANGUAGES: --------------------------------------------------------------------------------------------------

        private void PaintLanguages()
        {
            EditorGUILayout.BeginVertical(this.styleLanguagesPadding);
            this.languages.DoLayoutList();
            EditorGUILayout.EndVertical();
        }
        /// <summary>
        /// Generate warning report for object.
        /// </summary>
        /// <param name="obj">Target Object</param>
        /// <param name="dirty">Is Object Dirty?</param>
        static void InspectWarnings(SceneTrackObject obj, ref bool dirty)
        {
            if (_warnings == null || _warnings.Count == 0)
            {
                return;
            }

            if (_warnings != null && _warnings.Count > 0)
            {
                GUILayout.Label(String.Format("{0} Issues", _warnings.Count), EditorStyles.boldLabel);
            }

            foreach (var warning in _warnings)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                switch (warning)
                {
                case Warnings.NoRootBone:
                    GUILayout.Label("\u2022 No Root Bone is attached the Skinned Mesh Renderer");
                    break;

                case Warnings.DisabledMeshRecording:
                    GUILayout.Label("\u2022 Mesh recording is disabled");
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Suggested Fix:");
                    if (GUILayout.Button("Enable Mesh Recording", EditorStyles.miniButton))
                    {
                        obj.TrackMeshRenderer = true;
                        dirty = true;
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    break;

                case Warnings.NoMesh:
                    GUILayout.Label("\u2022 No Mesh is attached to the MeshFilter");
                    break;

                case Warnings.NoSkinnedMesh:
                    GUILayout.Label("\u2022 No Mesh is attached to the Skinned Mesh Filter");
                    break;

                case Warnings.NoBones:
                    GUILayout.Label("\u2022 There are no Bones assigned to this Skinned Mesh Renderer");
                    break;

                case Warnings.ScaledSkinnedMeshRenderer:
                    GUILayout.Label("LocalScale is not [1, 1, 1]", EditorStyles.boldLabel);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Suggested Fix:");
                    if (GUILayout.Button("Reset Scale", EditorStyles.miniButton, GUILayout.MaxWidth(100)))
                    {
                        obj.transform.localScale = Vector3.one;
                        dirty = true;
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    break;

                case Warnings.NotAllBonesHaveObjects:
                    GUILayout.Label("\u2022 Some Bones do not have Trackers attached");
                    if (_missingObjectsOnBones != null && _missingObjectsOnBones.Count > 0)
                    {
                        ListChildren(_missingObjectsOnBones);
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Suggested Fix:");
                        if (GUILayout.Button("Add Trackers to Bones", EditorStyles.miniButton))
                        {
                            foreach (var bone in _missingObjectsOnBones)
                            {
                                SceneTrackObject boneObject = bone.gameObject.AddComponent <SceneTrackObject>();
                                EditorUtility.SetDirty(boneObject);
                                EditorUtility.SetDirty(bone.gameObject);
                            }
                            dirty = true;
                        }
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.EndHorizontal();
                    }
                    break;

                case Warnings.NoMaterial:
                    GUILayout.Label("\u2022 No Material is assigned", EditorStyles.boldLabel);
                    break;

                case Warnings.NoMaterialMainTexture:
                    GUILayout.Label("\u2022 No Main Texture was assigned to the material");
                    break;

                case Warnings.NoMeshRenderer:
                    GUILayout.Label("\u2022 No Mesh Renderer attached", EditorStyles.boldLabel);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Suggested Fix:");
                    if (GUILayout.Button("Add Mesh Renderer Component", EditorStyles.miniButton))
                    {
                        var mr = obj.gameObject.AddComponent <MeshRenderer>();
                        EditorUtility.SetDirty(mr);
                        dirty = true;
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    break;

                case Warnings.NoRendererButWantsRecording:
                    obj.TrackMeshRenderer = false;
                    dirty = true;
                    break;

                case Warnings.DisabledButChildTracking:
                    GUILayout.Label("\u2022 Tracking is disabled, but child objects are tracking");
                    ListChildren(_enabledChildren);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Suggested Fixes:");

                    if (GUILayout.Button("Turn off tracking for Children", EditorStyles.miniButton))
                    {
                        foreach (var childObj in _enabledChildren)
                        {
                            childObj.TrackObject = false;
                            EditorUtility.SetDirty(childObj);
                        }
                        dirty = true;
                    }

                    GUILayout.Label(" or ");

                    if (GUILayout.Button("Enable Object Tracking", EditorStyles.miniButton))
                    {
                        obj.TrackObject = true;
                        dirty           = true;
                    }

                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    break;

                case Warnings.MissingExportPoseMesh:
                    GUILayout.Label("\u2022 Export Pose Mesh Missing", EditorStyles.boldLabel);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Suggested Fix:");
                    if (GUILayout.Button("Set As Export Pose", EditorStyles.miniButton))
                    {
                        SetExportPose(obj, obj.GetComponent <SkinnedMeshRenderer>());
                        dirty = true;
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                    break;
                }

                EditorGUILayout.EndVertical();
                GUILayout.Space(5);
            }

            if (_warnings != null && _warnings.Count > 0)
            {
                EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
            }
        }
    public override void OnInspectorGUI()
    {
        GUIStyle boldCenteredLabel = new GUIStyle(EditorStyles.boldLabel)
        {
            alignment = TextAnchor.MiddleCenter
        };

        EditorStyles.textField.wordWrap = true;

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        EditorGUILayout.BeginVertical("Box", GUILayout.Width(90 * Screen.width / 100));
        EditorGUILayout.LabelField(new GUIContent(TopDownIcon), boldCenteredLabel, GUILayout.ExpandWidth(true), GUILayout.Height(32));
        EditorGUILayout.LabelField("- TOP DOWN RPG -", boldCenteredLabel);
        EditorGUILayout.LabelField("Npc Name and Health Bar", boldCenteredLabel);
        EditorGUILayout.HelpBox("If this is enabled it will place name and health over NPC that you put your mouse cursor over.", MessageType.Info);
        EditorGUILayout.EndVertical();
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        EditorGUILayout.BeginVertical("Box", GUILayout.Width(90 * Screen.width / 100));
        EditorGUILayout.Space();

        td_target.placeBarOverHead = EditorGUILayout.Toggle("Put bar over head?", td_target.placeBarOverHead);

        if (td_target.placeBarOverHead == true)
        {
            EditorGUILayout.LabelField("Offset on Y Axis");
            td_target.yOffsetOverHead = EditorGUILayout.FloatField(td_target.yOffsetOverHead);
            EditorGUILayout.HelpBox("An offset that will put text in place on Y axis.", MessageType.Info);
        }
        else
        {
            EditorGUILayout.LabelField("Offset on Y Axis");
            td_target.yOffset = EditorGUILayout.FloatField(td_target.yOffset);
            EditorGUILayout.HelpBox("An offset that will put text in place on Y axis.", MessageType.Info);
        }
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("UI Elements");
        EditorGUILayout.HelpBox("Here setup your UI elements. Text component for name and Image component for health bar.", MessageType.Info);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Health Bar Image Component");
        td_target.healthBar = (Image)EditorGUILayout.ObjectField(string.Empty, td_target.healthBar, typeof(Image), true);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Energy Bar Image Component");
        td_target.energyBar = (Image)EditorGUILayout.ObjectField(string.Empty, td_target.energyBar, typeof(Image), true);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Portrait Image Component");
        td_target.portraitImage = (Image)EditorGUILayout.ObjectField(string.Empty, td_target.portraitImage, typeof(Image), true);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Name Text Component");
        td_target.nameText = (Text)EditorGUILayout.ObjectField(string.Empty, td_target.nameText, typeof(Text), true);
        EditorGUILayout.EndVertical();
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();
    }
Exemple #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();


            MalbersEditor.DrawDescription("All the selector actions and animations are managed here");

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical(MalbersEditor.StyleGray);
            {
                MalbersEditor.DrawScript(script);

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                {
                    M.FocusedItemIndex = EditorGUILayout.IntField(new GUIContent("Focused Item", "Index of the first Item to appear on Focus (Zero Index Based)"), M.FocusedItemIndex);

                    if (M.FocusedItemIndex == -1)
                    {
                        EditorGUILayout.HelpBox("-1 Means no item is selected", MessageType.Info);
                    }
                    if (M.FocusedItemIndex < -1)
                    {
                        M.FocusedItemIndex = -1;
                    }

                    EditorGUILayout.PropertyField(RestoreTime, new GUIContent("Restore Time", "Time to restore the previuous item to his original position"));
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginHorizontal();
                {
                    AnimateSelection.boolValue = GUILayout.Toggle(AnimateSelection.boolValue, new GUIContent("Animate Selection", "Animate the selection between items"), EditorStyles.toolbarButton);
                    SoloSelection.boolValue    = !AnimateSelection.boolValue;

                    SoloSelection.boolValue    = GUILayout.Toggle(SoloSelection.boolValue, new GUIContent("Solo Selection", "Animate the selection between items"), EditorStyles.toolbarButton);
                    AnimateSelection.boolValue = !SoloSelection.boolValue;
                }
                EditorGUILayout.EndHorizontal();

                if (AnimateSelection.boolValue)
                {
                    EditorGUILayout.BeginVertical(MalbersEditor.StyleGreen);
                    EditorGUILayout.HelpBox("The Selector Controller will move and rotate to center the selected Item", MessageType.None);
                    EditorGUILayout.EndVertical();


                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    {
                        EditorGUILayout.PropertyField(SelectionTime, new GUIContent("Selection Time", "Time between the selection among the objects"));

                        if (SelectionTime.floatValue < 0)
                        {
                            SelectionTime.floatValue = 0;                               //Don't put time below zero;
                        }
                        if (SelectionTime.floatValue != 0)
                        {
                            EditorGUILayout.PropertyField(SelectionCurve, new GUIContent("Selection Curve", "Timing of the selection animation"));
                        }


                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.PropertyField(DragSpeed, new GUIContent("Drag Speed", "Swipe speed when swiping  :)"));
                            if (DragSpeed.floatValue != 0)
                            {
                                dragHorizontal.boolValue = GUILayout.Toggle(dragHorizontal.boolValue, new GUIContent(dragHorizontal.boolValue ? "Horizontal" : "Vertical", "Drag/Swipe type from the mouse/touchpad "), EditorStyles.popup);
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        if (DragSpeed.floatValue == 0)
                        {
                            EditorGUILayout.HelpBox("Drag is disabled", MessageType.Info);
                        }
                    }
                    EditorGUILayout.EndVertical();

                    if (DragSpeed.floatValue != 0)
                    {
                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                        EditorGUILayout.PropertyField(inertia, new GUIContent("Inertia", "Add inertia when Draging is enabled and the mouse is released"));

                        if (inertia.boolValue)
                        {
                            EditorGUILayout.PropertyField(inertiaTime, new GUIContent("Inertia Time", "The time on inertia when the Drag is released"));
                            EditorGUILayout.PropertyField(minInertiaSpeed, new GUIContent("Inertia Min Speed", "Min Speed to apply inertia"));
                            EditorGUILayout.PropertyField(inertiaCurve, new GUIContent("Inertia Curve", "the Curve for the time inertia"));
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        EditorGUILayout.PropertyField(UseSelectionZone, new GUIContent("Use Selection Zone", "Add inertia when Draging is enabled and the mouse is released"));

                        if (UseSelectionZone.boolValue)
                        {
                            EditorGUI.BeginChangeCheck();

                            EditorGUILayout.PropertyField(serializedObject.FindProperty("ZMinX"), new GUIContent("Min X", "Region enableed for the Dragging/Swapping"));
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("ZMaxX"), new GUIContent("Max X", "Region enableed for the Dragging/Swapping"));
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("ZMinY"), new GUIContent("Min Y", "Region enableed for the Dragging/Swapping"));
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("ZMaxY"), new GUIContent("Max Y", "Region enableed for the Dragging/Swapping"));
                        }
                        EditorGUILayout.EndVertical();
                    }
                }

                if (SoloSelection.boolValue)
                {
                    EditorGUILayout.BeginVertical(MalbersEditor.StyleGreen);
                    EditorGUILayout.HelpBox("The Selector Controller will not move", MessageType.None);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    EditorGUILayout.PropertyField(Hover, new GUIContent("Hover Selection", "Select by hovering the mouse over an item"));
                    EditorGUILayout.EndVertical();
                }


                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                EditorGUI.indentLevel++;
                EditorIdleAnims.boolValue = EditorGUILayout.Foldout(EditorIdleAnims.boolValue, "Idle Animations");
                EditorGUI.indentLevel--;

                if (EditorIdleAnims.boolValue)
                {
                    EditorGUILayout.BeginHorizontal();
                    MoveIdle.boolValue   = GUILayout.Toggle(MoveIdle.boolValue, new GUIContent("Move", "Repeating moving motion for the focused item"), EditorStyles.miniButton);
                    RotateIdle.boolValue = GUILayout.Toggle(RotateIdle.boolValue, new GUIContent("Rotate", "Turning table for the focused item"), EditorStyles.miniButton);
                    ScaleIdle.boolValue  = GUILayout.Toggle(ScaleIdle.boolValue, new GUIContent("Scale", "Repeating scale motion for the focused item"), EditorStyles.miniButton);
                    EditorGUILayout.EndHorizontal();

                    if (MoveIdle.boolValue)
                    {
                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        EditorGUILayout.PropertyField(MoveIdleAnim, new GUIContent("Move Idle", "Idle Move Animation when is on focus"));
                        EditorGUILayout.EndVertical();
                    }
                    if (M.RotateIdle)
                    {
                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        EditorGUILayout.PropertyField(ItemRotationSpeed, new GUIContent("Speed", "How fast the focused Item will rotate"));
                        EditorGUILayout.PropertyField(TurnTableVector, new GUIContent("Rotation Vector", "Choose your desire vector to rotate around"));
                        EditorGUILayout.EndVertical();
                    }

                    if (M.ScaleIdle)
                    {
                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        EditorGUILayout.PropertyField(ScaleIdleAnim, new GUIContent("Scale Idle", "Idle Scale Animation when is on focus"));
                        EditorGUILayout.EndVertical();
                    }
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.PropertyField(LockMaterial, new GUIContent("Lock Material", "Material choosed for the locked objects"));

                EditorGUILayout.BeginHorizontal();
                EditorGUIUtility.labelWidth = 95;

                if (E && E.SelectorCamera)
                {
                    EditorGUILayout.PropertyField(frame_Camera, new GUIContent("Frame Camera", " Auto Adjust the camera position by the size of the object"), GUILayout.MinWidth(20));
                    if (frame_Camera.boolValue)
                    {
                        EditorGUIUtility.labelWidth = 55;
                        EditorGUILayout.PropertyField(frame_Multiplier, new GUIContent("Multiplier", "Distance Mupltiplier for the camera frame"), GUILayout.MaxWidth(100));
                    }
                }
                EditorGUIUtility.labelWidth = 0;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();


                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUI.indentLevel++;
                EditorAdvanced.boolValue = EditorGUILayout.Foldout(EditorAdvanced.boolValue, "Advanced");

                if (EditorAdvanced.boolValue)
                {
                    if (!Hover.boolValue)
                    {
                        EditorGUILayout.PropertyField(ClickToFocus, new GUIContent("Click to Focus", "If a another item is touched/clicked, focus on it"));
                    }

                    EditorGUILayout.PropertyField(ChangeOnEmptySpace, new GUIContent("Change on Empty Space", "If there's a Click/Touch on an empty space change to the next/previous item"));
                    EditorGUILayout.PropertyField(Threshold, new GUIContent("Threshold", "Max Threshold to identify if is a click/touch or a drag/swipe"));
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUI.indentLevel++;
                EditorShowEvents.boolValue = EditorGUILayout.Foldout(EditorShowEvents.boolValue, "Events");
                EditorGUI.indentLevel--;

                if (EditorShowEvents.boolValue)
                {
                    EditorGUILayout.PropertyField(OnClickOnItem, new GUIContent("On Click/Touch an Item"));
                    //  EditorGUILayout.PropertyField(OnItemFocused, new GUIContent("On Item Focused"));
                    if (AnimateSelection.boolValue)
                    {
                        EditorGUILayout.PropertyField(OnIsChangingItem, new GUIContent("Is Changing Item"));
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();


            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Selector Controller Inspector");
                //EditorUtility.SetDirty(target);
            }
            serializedObject.ApplyModifiedProperties();
        }
Exemple #5
0
        private void DrawSpritesWithThumbs()
        {
            // Get a copy of the sprites list
            List <SPSpriteInfo> sprites = this.m_SPInstance.copyOfSprites;

            sprites.Sort();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            EditorGUILayout.BeginVertical();

            RectOffset padding                 = this.paddingStyle.padding;
            RectOffset thumbnailPadding        = new RectOffset(6, 6, 6, 3);
            float      thumbnailMaxHeight      = EditorPrefs.GetFloat(SPTools.Settings_ThumbsHeightKey);
            float      labelHeight             = 20f;
            float      selectedExtensionHeight = 27f;

            GUIStyle labelStyle = new GUIStyle(EditorStyles.label);

            labelStyle.fontStyle = FontStyle.Normal;
            labelStyle.alignment = TextAnchor.MiddleCenter;

            // Draw the sprites
            foreach (SPSpriteInfo info in sprites)
            {
                bool  isSelected = this.IsSelected(info.GetHashCode());
                Color boxColor   = (isSelected ? SPInstanceEditor.spriteBoxHighlightColor : SPInstanceEditor.spriteBoxNormalColor);

                GUILayout.Space(6f);
                EditorGUILayout.BeginHorizontal(this.paddingStyle);

                if (info.targetSprite != null)
                {
                    // Determine the control height
                    float thumbnailHeight = (info.targetSprite.rect.height > thumbnailMaxHeight) ? thumbnailMaxHeight : info.targetSprite.rect.height;

                    // Apply the thumb padding to the height
                    float thumbnailHeightWithPadding = thumbnailHeight + thumbnailPadding.top + thumbnailPadding.bottom;

                    // Generate a working rect for the control
                    Rect controlRect = GUILayoutUtility.GetRect(0.0f, (thumbnailHeightWithPadding + labelHeight + (isSelected ? (selectedExtensionHeight + padding.top) : 0f)), GUILayout.ExpandWidth(true));

                    // Determine the click rect
                    Rect clickRect = new Rect(controlRect.x, controlRect.y, controlRect.width, (controlRect.height - (isSelected ? (selectedExtensionHeight + padding.top) : 0f)));

                    // Sprite box background
                    GUI.color = boxColor;
                    GUI.Box(new Rect(controlRect.x - padding.left, controlRect.y - padding.top, controlRect.width + (padding.left + padding.right), controlRect.height + (padding.top + padding.bottom)), "", this.boxStyle);
                    GUI.color = Color.white;

                    // Draw the thumbnail
                    if (info.targetSprite.texture != null)
                    {
                        this.DrawThumbnail(info, thumbnailHeight, controlRect, thumbnailPadding);
                    }

                    // Draw the sprite name label
                    GUI.Label(new Rect(controlRect.x, (controlRect.y + thumbnailHeightWithPadding + 1f), controlRect.width, labelHeight), info.targetSprite.name + " (" + info.targetSprite.rect.width + "x" + info.targetSprite.rect.height + ")", labelStyle);

                    // Remove button
                    if (GUI.Button(new Rect((controlRect.width - 9f), (controlRect.y + thumbnailHeightWithPadding + 2f), 18f, 18f), "X"))
                    {
                        this.m_SPInstance.QueueAction_RemoveSprite(info);
                    }
                    // Detect sprite clicks
                    else if (Event.current.type == EventType.MouseUp && clickRect.Contains(Event.current.mousePosition))
                    {
                        EditorGUIUtility.PingObject(info.targetSprite);

                        // Remove the focus of the focused control
                        GUI.FocusControl("");

                        // Set as selected
                        if (!isSelected)
                        {
                            this.SetSelected(info.GetHashCode());
                        }
                    }

                    // Draw the selected extension
                    if (isSelected)
                    {
                        Rect extensionRect = new Rect((controlRect.x - padding.left),
                                                      (controlRect.y + thumbnailHeightWithPadding + labelHeight + padding.top),
                                                      (controlRect.width + (padding.left + padding.right)),
                                                      selectedExtensionHeight);

                        // Box that looks like a separator
                        if (Event.current.type == EventType.Repaint)
                        {
                            GUI.color = boxColor;
                            this.boxStyle.Draw(new Rect(extensionRect.x, extensionRect.y, extensionRect.width, 1f), GUIContent.none, 0);
                            GUI.color = Color.white;
                        }

                        // Draw the source label
                        GUI.Label(new Rect(extensionRect.x + padding.left + 2f, extensionRect.y + padding.top + 3f, 60f, 20f), "Source:", EditorStyles.label);

                        Rect sourceFieldRect = new Rect((extensionRect.x + 60f), (extensionRect.y + padding.top + 3f), (extensionRect.width - 66f), 18f);

                        // Draw the sprite source field
                        EditorGUI.BeginChangeCheck();
                        Object source = EditorGUI.ObjectField(sourceFieldRect, info.source, typeof(Object), false);
                        if (EditorGUI.EndChangeCheck())
                        {
                            this.m_SPInstance.ChangeSpriteSource(info, source);
                        }
                    }
                }

                EditorGUILayout.EndHorizontal();
            }
            GUILayout.Space(6f);

            EditorGUILayout.EndVertical();
            GUILayout.Space(6f);
            EditorGUILayout.EndHorizontal();
        }
Exemple #6
0
        private void HotResMoveGUI()
        {
            EditorGUILayout.BeginHorizontal();

            //EditorGUILayout.BeginVertical();
            //string abDirInAssets = _cfg.abHotResDir;
            //string abDirInBackup = FileSystem.CombineDirs(false, HOT_RES_BACKUP_ROOT, _cfg.abHotResDir);

            //if (Directory.Exists(abDirInAssets))
            //{
            //    EditorGUILayout.LabelField(string.Format("目录移动:{0} >>> {1}", abDirInAssets, abDirInBackup));
            //    if (GUILayout.Button("排除AssetBundle热更资源"))
            //    {
            //        if (false == Directory.Exists(abDirInBackup))
            //        {
            //            Directory.CreateDirectory(abDirInBackup);
            //        }
            //        FileUtil.ReplaceDirectory(abDirInAssets, abDirInBackup);
            //        FileUtil.DeleteFileOrDirectory(abDirInAssets);
            //        AssetDatabase.Refresh();
            //    }
            //}
            //else
            //{
            //    EditorGUILayout.LabelField(string.Format("目录移动:{0} >>> {1}", abDirInBackup, abDirInAssets));
            //    if (GUILayout.Button("复原AssetBundle热更资源"))
            //    {
            //        if (false == Directory.Exists(abDirInAssets))
            //        {
            //            Directory.CreateDirectory(abDirInAssets);
            //        }
            //        FileUtil.ReplaceDirectory(abDirInBackup, abDirInAssets);
            //        FileUtil.DeleteFileOrDirectory(abDirInBackup);
            //        AssetDatabase.Refresh();
            //    }
            //}
            //EditorGUILayout.EndVertical();

            //GUILayout.Space(20);

            EditorGUILayout.BeginVertical();

            if (Directory.Exists(_model.DllDirInAssets))
            {
                EditorGUILayout.LabelField(string.Format("目录移动:{0} >>> {1}", _model.DllDirInAssets, _model.DllDirInBackup));
                if (GUILayout.Button("排除Dll热更资源"))
                {
                    _model.ExcludeDllCodes();
                }
            }
            else
            {
                EditorGUILayout.LabelField(string.Format("目录移动:{0} >>> {1}", _model.DllDirInBackup, _model.DllDirInAssets));
                if (GUILayout.Button("复原Dll热更资源"))
                {
                    _model.IncludeDllCodes();
                }
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();
        }
Exemple #7
0
    public override void OnInspectorGUI()
    {
        // Setting the GUI Styles
        guiStyleBox         = new GUIStyle(GUI.skin.box);
        guiStyleBox.margin  = new RectOffset(0, 20, 10, 0);
        guiStyleBox.padding = new RectOffset(20, 20, 10, 10);

        guiStyleLabel          = new GUIStyle(GUI.skin.label);
        guiStyleLabel.richText = true;

        guiStyleButton         = new GUIStyle(GUI.skin.button);
        guiStyleButton.margin  = new RectOffset(0, 20, 10, 0);
        guiStyleButton.padding = new RectOffset(10, 10, 5, 5);


        // Draw chain's properties
        EditorGUILayout.Space(10);

        chain.trigger = (EventChain.EventTrigger)EditorGUILayout.EnumPopup("Trigger", chain.trigger);
        chain.radius  = EditorGUILayout.FloatField("Radius", chain.radius);
        if (chain.trigger != EventChain.EventTrigger.Interact)
        {
            chain.groundedOnly = EditorGUILayout.Toggle("Grounded Only", chain.groundedOnly);
        }

        EditorGUILayout.Space(10);

        // For every event in the chain
        for (int i = 0; i < chain.events.Count; i++)
        {
            EditorGUILayout.BeginVertical(guiStyleBox);

            // Draw Event header
            EditorGUILayout.BeginHorizontal(guiStyleLabel);

            string label = (i + 1) + " - " + chain.events[i].GetEventName();
            //if (GUILayout.Button(chain.events[i].visible? "<b>" + label + "</b>" : label, guiStyleLabel))
            //    chain.events[i].visible = !chain.events[i].visible;


            chain.events[i].visible = EditorGUILayout.Foldout(chain.events[i].visible, label);
            EditorGUILayout.EndHorizontal();

            // Draw Event content
            if (chain.events[i].visible)
            {
                // Call the expecific event's editor
                EditorGUILayout.BeginVertical();

                CreateEditor(chain.events[i]).OnInspectorGUI();

                EditorGUILayout.EndVertical();

                EditorGUILayout.Space(10);

                // Event actions
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Move Up"))
                {
                    chain.MoveEventUp(i);
                }

                if (GUILayout.Button("Move Down"))
                {
                    chain.MoveEventDown(i);
                }

                if (GUILayout.Button("Duplicate"))
                {
                    chain.DuplicateEvent(i);
                }

                if (GUILayout.Button("Delete"))
                {
                    chain.DeleteEvent(i);
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
        }

        // Draw the event type dropdown
        EditorGUILayout.Separator();
        selectedEvent = (Events)EditorGUILayout.EnumPopup("Event Type", selectedEvent);

        // Draw Add event button
        if (GUILayout.Button("Add Event", guiStyleButton))
        {
            chain.AddEvent(GetEventType());
        }

        EditorGUILayout.Space(10);
    }
        public override void DrawInspector()
        {
            base.DrawInspector();
            if (!isOpen)
            {
                return;
            }
            List <SplineSampleModifier.Key> keys = module.GetKeys();

            if (keys.Count > 0)
            {
                drawAllKeys = EditorGUILayout.Toggle("Draw all Modules", drawAllKeys);
            }
            for (int i = 0; i < keys.Count; i++)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (selected == i)
                {
                    EditorGUI.BeginChangeCheck();
                    KeyGUI(keys[i]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        user.Rebuild();
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(i + " [" + (Mathf.Round((float)keys[i].start * 10) / 10f) + " - " + (Mathf.Round((float)keys[i].end * 10) / 10f) + "]");
                }
                EditorGUILayout.EndVertical();
                Rect lastRect = GUILayoutUtility.GetLastRect();
                if (lastRect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.MouseDown)
                    {
                        if (Event.current.button == 0)
                        {
                            selected = i;
                            editor.Repaint();
                        }
                        else if (Event.current.button == 1)
                        {
                            int         index = i;
                            GenericMenu menu  = new GenericMenu();
                            menu.AddItem(new GUIContent("Delete"), false, delegate
                            {
                                keys.RemoveAt(index);
                                module.SetKeys(keys);
                                editor.Repaint();
                                user.Rebuild();
                            });
                            menu.ShowAsContext();
                        }
                    }
                }
            }

            EditorGUILayout.Space();
            if (keys.Count > 0)
            {
                module.blend = EditorGUILayout.Slider("Blend", module.blend, 0f, 1f);
            }
        }
Exemple #9
0
	public static void ShowUni2DPreferences( )
	{
		GUILayoutOption oMaxWidthOption = GUILayout.MaxWidth( 135.0f );
		GUILayoutOption oMaxColorPickedWidthOption = GUILayout.MaxWidth( 100.0f );

		//EditorGUILayout.HelpBox( "Uni2D Beta", MessageType.Warning, true );
		
		EditorGUILayout.BeginVertical( );
		{			
			// Header
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Bone Gizmo State", EditorStyles.boldLabel, oMaxWidthOption );
				EditorGUILayout.LabelField( "Bone", EditorStyles.boldLabel, oMaxColorPickedWidthOption );
				EditorGUILayout.LabelField( "Root Bone", EditorStyles.boldLabel, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
			
			// Unselected
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Unselected", oMaxWidthOption );
				Uni2DEditorPreferences.UnselectedBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.UnselectedBoneGizmoColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.UnselectedRootBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.UnselectedRootBoneGizmoColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
			
			// Selected
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Selected", oMaxWidthOption );
				Uni2DEditorPreferences.SelectedBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.SelectedBoneGizmoColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.SelectedRootBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.SelectedRootBoneGizmoColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
			
			// Editable
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Editable", oMaxWidthOption );
				Uni2DEditorPreferences.EditableBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.EditableBoneGizmoColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.EditableRootBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.EditableRootBoneGizmoColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
	
			// Active
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Active", oMaxWidthOption );
				Uni2DEditorPreferences.ActiveBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.ActiveBoneGizmoColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.ActiveRootBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.ActiveRootBoneGizmoColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );

			EditorGUILayout.Space( );

			// Header
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Disc Handle", EditorStyles.boldLabel, oMaxWidthOption );
				EditorGUILayout.LabelField( "Bone", EditorStyles.boldLabel, oMaxColorPickedWidthOption );
				EditorGUILayout.LabelField( "Root Bone", EditorStyles.boldLabel, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );

			// Inner disc handle
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Inner", oMaxWidthOption );
				Uni2DEditorPreferences.InnerBoneDiscHandleColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.InnerBoneDiscHandleColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.InnerRootBoneDiscHandleColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.InnerRootBoneDiscHandleColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
	
			// Outer disc handle
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Outer", oMaxWidthOption );
				Uni2DEditorPreferences.OuterBoneDiscHandleColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.OuterBoneDiscHandleColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.OuterRootBoneDiscHandleColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.OuterRootBoneDiscHandleColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
	
			// Selected disc handle outline
			EditorGUILayout.BeginHorizontal( );
			{
				EditorGUILayout.LabelField( "Outline (when selected)", oMaxWidthOption );
				Uni2DEditorPreferences.SelectedBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.SelectedBoneDiscHandleOutlineColor, oMaxColorPickedWidthOption );
				Uni2DEditorPreferences.SelectedRootBoneGizmoColor = EditorGUILayout.ColorField( Uni2DEditorPreferences.SelectedRootBoneDiscHandleOutlineColor, oMaxColorPickedWidthOption );
			}
			EditorGUILayout.EndHorizontal( );
	
			EditorGUILayout.Space( );
	
		}
		EditorGUILayout.EndVertical( );

		Uni2DEditorPreferences.SmoothBindingDefaultSkinQuality = (SkinQuality) EditorGUILayout.EnumPopup( "Default Skin Quality", Uni2DEditorPreferences.SmoothBindingDefaultSkinQuality );

		EditorGUILayout.Space( );	
	
		EditorGUILayout.BeginHorizontal( );
		{
			if( GUILayout.Button( "Use Default" ) )
			{
				Uni2DEditorPreferences.RestoreDefaults( );
			}
			GUILayout.FlexibleSpace( );
		}
		EditorGUILayout.EndHorizontal( );

		EditorGUILayout.Space( );

		// Asset table rebuild
		EditorGUILayout.BeginVertical( );
		{
			EditorGUILayout.LabelField( "Rebuild the Uni2D asset table if you think Uni2D is not handling your assets properly.", EditorStyles.wordWrappedLabel );
			
			if( GUILayout.Button( "Rebuild Uni2D Asset Table" ) )
			{
				Uni2DEditorAssetTable rAssetTable = Uni2DEditorAssetTable.Instance;
				rAssetTable.Rebuild( );
			}
		}
		EditorGUILayout.EndVertical( );
	}
	public void OnGUI()
	{
		//dialogue("" + anyToPush);

		if (headerStyle == null)
			CreateStyles();

		bool haveChanges = changes.Length > 0;
		//        bool anyToPush = execute("git", "log @{u}.. -n 1 --pretty=format:\"%h;%an;%ar;%s\"").Trim() != "";

		scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
		GUI.backgroundColor = defaultBackgroundColor;

		GUILayout.Space(8);
		GUILayout.Label(_name, headerStyle);
		GUILayout.Label(version, EditorStyles.miniLabel);
		GUILayout.Space(16);
		int branchID = Array.IndexOf(branches, currentBranch);

		if (currentBranch == null)
		{
			GUILayout.Label("Initializing. No branch selected.");
		}
		else
		{
			int newBranchID = EditorGUILayout.Popup("Branch", branchID, branches);
			if (newBranchID != branchID)
			{
				checkout(branches[newBranchID]);
			}
			commitMessage = GUILayout.TextArea(commitMessage, GUILayout.Height(70.0f));
			if (haveChanges)
			{
				if (GUILayout.Button("Commit"))
				{
					CreateCommit();
				}

			}
			else
			{
				GUILayout.BeginHorizontal();

				if (GUILayout.Button("Push"))
				{
					push();
				}
				if (GUILayout.Button("Pull"))
				{
					pull();
				}

				GUILayout.EndHorizontal();
			}

		} // now fold out

		if (changesFoldedOut = EditorGUILayout.Foldout(changesFoldedOut, "View Changes"))
		{
			GUILayout.BeginVertical("box");
			if (haveChanges)
			{
				foreach (string change in changes)
				{
					string str = change.Trim();
					if (str.StartsWith("M"))
						GUI.color = modifiedColor;
					if (str.StartsWith("A"))
						GUI.color = addedColor;
					if (str.StartsWith("D"))
						GUI.color = deletedColor;
					GUILayout.Label(change.Trim(), EditorStyles.miniLabel);
					GUI.color = defaultColor;
				}
			}
			else
			{
				GUILayout.Label("You are up to date!", EditorStyles.miniLabel);
			}
			GUILayout.EndVertical();
		}

		#region commit history
		if (historyFoldedOut = EditorGUILayout.Foldout(historyFoldedOut, "Commit History"))
		{
			//			EditorGUILayout.BeginVertical ("box");
			if (history == null)
			{
				EditorGUILayout.BeginVertical("box");
				GUILayout.Label("Loading commits...");
				EditorGUILayout.EndVertical();
			}
			else
			{
				maxCommits = EditorGUILayout.IntField("History Length", maxCommits);
				//				int hashWidth = 60;
				//				float subjectWidth = (EditorGUIUtility.fieldWidth / 2) - hashWidth - 24;
				//				log (EditorGUIUtility.currentViewWidth);
				//				subjectWidth = 100;
				foreach (Commit commit in history)
				{
					if (commit.local)
					{
						GUI.backgroundColor = Color.Lerp(Color.grey, defaultBackgroundColor, 0.5f);
					}
					else
					{
						GUI.backgroundColor = defaultBackgroundColor;
					}
					EditorGUILayout.BeginVertical("box");
					//					EditorGUILayout.BeginHorizontal ();
					//					GUILayout.Label (commit.subject, EditorStyles.largeLabel, GUILayout.Width(subjectWidth));
					//					GUILayout.Label (commit.hash, monospaced, GUILayout.Width(hashWidth));
					GUILayout.Label(commit.subject, EditorStyles.largeLabel, GUILayout.Width(position.width - 20));
					//					EditorGUILayout.EndHorizontal ();
					GUILayout.Label(commit.date + " by " + commit.author, EditorStyles.miniLabel);
					EditorGUILayout.EndVertical();
				}
				GUI.backgroundColor = defaultBackgroundColor;
			}
			//			EditorGUILayout.EndVertical ();
		}
		#endregion

		if (advancedOptions = EditorGUILayout.Foldout(advancedOptions, "Advanced/Expirimental Options"))
		{
			EditorGUI.indentLevel = 1;
			if (creatingBranch = EditorGUILayout.Foldout(creatingBranch, "Create New Branch"))
			{
				newBranchName = EditorGUILayout.TextField("Branch Name", newBranchName);
				GUILayout.Button("Create New Branch");
				EditorGUI.indentLevel = 0;
			}
			if (enableDebug = GUILayout.Toggle(enableDebug, "Enable Debug Panels"))
			{
				if (debugPanel = EditorGUILayout.Foldout(debugPanel, "Debug Event Triggers"))
				{
					GUILayout.BeginVertical("box");
					if (GUILayout.Button("refreshChanges()"))
						refreshChanges();
					if (GUILayout.Button("RefreshInformation()"))
						refreshInformation();
					if (GUILayout.Button("CreateStyles()"))
						CreateStyles();
					if (GUILayout.Button("push()"))
						push();
					if (GUILayout.Button("resetBusiness()"))
						business.Clear();
					GUILayout.EndVertical();

				}

				if (busnessDisplay = EditorGUILayout.Foldout(busnessDisplay, "Debug Business Array"))
				{
					GUILayout.BeginVertical("box");
					foreach (StringPointer strp in business)
					{
						GUILayout.Label(strp.ToString());
					}
					GUILayout.EndVertical();
				}
			}
		}







		EditorGUILayout.EndScrollView();

	}
Exemple #11
0
 public static void BrandField()
 {
     EditorGUILayout.BeginVertical();
     EditorGUILayout.LabelField(new GUIContent(brand), EditorStyles.centeredGreyMiniLabel, GUILayout.ExpandWidth(true), GUILayout.MinHeight(75));
     EditorGUILayout.EndVertical();
 }
        void GUI_Wall()
        {
            EditorGUILayout.BeginVertical(style_box_marginleft);

            foreach (KeyValuePair <int, BuildWallConfig> kvp in War.model.buildWallConfigs)
            {
                BuildWallConfig wallConfig = kvp.Value;

                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();

                GUILayout.Label(wallConfig.id + "", style_label_wall_id, GUILayout.Width(50), GUILayout.Height(100));

                AvatarConfig avatarConfig = Goo.avatar.GetConfig(wallConfig.avatarId);
                GameObject   prefab       = null;
                if (avatarConfig != null)
                {
                    prefab = WarRes.GetPrefab(avatarConfig.model);
                }

                if (prefab)
                {
                    SpriteAvatar spriteAvatar = prefab.GetComponent <SpriteAvatar>();
                    Sprite       sprite       = spriteAvatar.avatarData.avatarActions[0].GetSpriteAnimationClip(wallConfig.angle).frames[0];


                    Texture2D tex = null;
                    if (!wall_icon_dict.TryGetValue(sprite, out tex))
                    {
                        tex = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height, TextureFormat.RGBA32, false);

                        Color[] pixels = sprite.texture.GetPixels((int)sprite.rect.xMin, (int)sprite.rect.yMin,
                                                                  (int)sprite.rect.width, (int)sprite.rect.height);
                        tex.SetPixels(pixels);
                        tex.Apply();
                        wall_icon_dict.Add(sprite, tex);
                    }

                    if (GUILayout.Button(tex, GUILayout.Width(100), GUILayout.Height(100)))
                    {
                        Click_Wall(wallConfig);
                    }
                }
                else
                {
                    GUILayout.Button("没有资源", GUILayout.Width(100), GUILayout.Height(100));

                    if (avatarConfig != null)
                    {
                        WarEditor.LoadRes(avatarConfig.model);
                    }
                }


                GUILayout.Label(wallConfig.name, style_label_wall_line, GUILayout.Width(100), GUILayout.Height(100));
                GUILayout.Label(wallConfig.wallType == WallType.Cube ? "立方体" : "球", style_label_wall_line, GUILayout.Width(50), GUILayout.Height(100));
                if (wallConfig.wallType == WallType.Cube)
                {
                    GUILayout.Label("角度:" + wallConfig.angle, style_label_wall_line, GUILayout.Width(100), GUILayout.Height(100));
                    GUILayout.Label("大小:" + wallConfig.size.x + "x" + wallConfig.size.z, style_label_wall_line, GUILayout.Width(100), GUILayout.Height(100));
                }
                else
                {
                    GUILayout.Label("半径:" + wallConfig.radius, style_label_wall_line, GUILayout.Width(100), GUILayout.Height(100));
                }


                EditorGUILayout.EndHorizontal();
                GUILayout.Space(10);
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
            }
            EditorGUILayout.EndVertical();
        }
        void GUI_Build(int buildTypeValue, string name)
        {
            EditorGUILayout.BeginVertical(style_box_marginleft);
            buildSwitchs[buildTypeValue] = GUILayout.Toggle(buildSwitchs[buildTypeValue], name, style_label_type, GUILayout.ExpandWidth(true));
            if (buildSwitchs[buildTypeValue])
            {
                GUIContent iconContent = new GUIContent("");
                GUILayout.BeginHorizontal(iconContent, style_box_key);
                int column = 0;
                for (int i = 0; i < colorEnables.Length; i++)
                {
                    if (colorEnables[i])
                    {
                        GUILayout.Space(10);
                        GUILayout.Label(colorNames[i], style_box_key, GUILayout.Width(100), GUILayout.Height(18));
                        GUILayout.Space(10);
                        column++;
                    }
                }
                GUILayout.EndHorizontal();


                foreach (KeyValuePair <int, BuildConfig> kvp in War.model.buildConfigs)
                {
                    BuildConfig buildConfig = kvp.Value;

                    if ((int)buildConfig.buildType != buildTypeValue + 1)
                    {
                        continue;
                    }

                    GUILayout.Space(20);

                    foreach (KeyValuePair <int, BuildLevelConfig> levelKVP in buildConfig.levels)
                    {
                        BuildLevelConfig levelConfig = levelKVP.Value;
                        if (levelEnables[levelConfig.level - 1] == false)
                        {
                            continue;
                        }

                        EditorGUILayout.BeginHorizontal(GUILayout.Width(column * 120));
                        for (int i = 0; i < colorEnables.Length; i++)
                        {
                            if (colorEnables[i])
                            {
                                AvatarConfig avatarConfig = Goo.avatar.GetConfig(levelConfig.avatarId);
                                string       file         = avatarConfig.GetModelPath(colorIds[i]);

                                GameObject prefab = WarRes.GetPrefab(file);
                                if (prefab)
                                {
                                    GUILayout.Space(10);
                                    EditorGUILayout.BeginVertical();
                                    SpriteAvatar spriteAvatar = prefab.GetComponent <SpriteAvatar>();
                                    Sprite       sprite       = spriteAvatar.avatarData.avatarActions[0].clips[0].frames[0];
                                    if (GUILayout.Button(sprite.texture, GUILayout.Width(100), GUILayout.Height(100)))
                                    {
                                        Click_Build(colorIds[i], levelConfig.level, buildConfig);
                                    }
                                    GUILayout.Label(buildConfig.id + " " + levelConfig.name, style_label_icon_hasbg, GUILayout.Width(100));

                                    if (levelConfig.basepropId > 0)
                                    {
                                        GUILayout.Label("<color=#55AAAA><b>#" + levelConfig.basepropId + " 基本属性</b></color>", style_label_prop);
                                        foreach (Prop prop in levelConfig.basepropConfig.props)
                                        {
                                            GUILayout.Label("<color=#88AAAA>" + prop.id + " " + prop.Name + ":" + prop.ValueStr + "</color>", style_label_prop, GUILayout.Width(150));
                                        }
                                    }

                                    if (levelConfig.produceId > 0)
                                    {
                                        GUILayout.Space(5);
                                        GUILayout.Label("<color=#55AA55><b>#" + levelConfig.produceId + " 生产属性</b></color>", style_label_prop);
                                        foreach (Prop prop in levelConfig.produceConfig.props)
                                        {
                                            GUILayout.Label("<color=#88AA88>" + prop.id + " " + prop.Name + ":" + prop.ValueStr + "</color>", style_label_prop, GUILayout.Width(150));
                                        }
                                    }

                                    if (levelConfig.turretId > 0)
                                    {
                                        GUILayout.Space(5);
                                        GUILayout.Label("<color=#AA5555><b>#" + levelConfig.turretId + " 箭塔属性</b></color>", style_label_prop);
                                        foreach (Prop prop in levelConfig.turretConfig.props)
                                        {
                                            GUILayout.Label("<color=#AA8888>" + prop.id + " " + prop.Name + ":" + prop.ValueStr + "</color>", style_label_prop, GUILayout.Width(150));
                                        }
                                    }

                                    if (levelConfig.spotId > 0)
                                    {
                                        GUILayout.Space(5);
                                        GUILayout.Label("<color=#5555AA><b>#" + levelConfig.spotId + " 据点属性</b></color>", style_label_prop);
                                        foreach (Prop prop in levelConfig.spotConfig.props)
                                        {
                                            GUILayout.Label("<color=#8888AA>" + prop.id + " " + prop.Name + ":" + prop.ValueStr + "</color>", style_label_prop, GUILayout.Width(150));
                                        }
                                    }

                                    EditorGUILayout.EndVertical();
                                    GUILayout.Space(10);
                                }
                                else
                                {
                                    GUILayout.Space(10);
                                    GUILayout.Button("没有资源", GUILayout.Width(100), GUILayout.Height(100));
                                    GUILayout.Space(10);

                                    WarEditor.LoadRes(file);
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }


                    GUILayout.Space(20);
                }
            }
            EditorGUILayout.EndVertical();
        }
        void GUIHandle()
        {
//			if(style_box_key == null)
//			{
            InitStyle();
//			}


            fold_filter = EditorGUILayout.Foldout(fold_filter, "过滤器");
            if (fold_filter)
            {
                EditorGUILayout.BeginVertical(style_box_marginleft);
                GUILayout.Label("单位", style_key);
                EditorGUILayout.BeginHorizontal();
                for (int i = 0; i < unitEnables.Length; i++)
                {
                    GUILayout.Space(20);
                    unitEnables[i] = EditorGUILayout.ToggleLeft(unitNames[i], unitEnables[i], GUILayout.Width(50));
                }
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(10);


                if (unitGroupEnabled && unitEnables[0])
                {
                    GUILayout.Label("颜色", style_key);
                    EditorGUILayout.BeginHorizontal();
                    for (int i = 0; i < colorEnables.Length; i++)
                    {
                        GUILayout.Space(20);
                        colorEnables[i] = EditorGUILayout.ToggleLeft(colorNames[i], colorEnables[i], GUILayout.Width(50));
                    }
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(10);


                    GUILayout.Label("建筑", style_key);
                    EditorGUILayout.BeginHorizontal();
                    for (int i = 0; i < buildEnableds.Length; i++)
                    {
                        GUILayout.Space(20);
                        buildEnableds[i] = EditorGUILayout.ToggleLeft(buildTypeNames[i], buildEnableds[i], GUILayout.Width(50));
                    }
                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(10);

                    GUILayout.Label("等级", style_key);
                    EditorGUILayout.BeginHorizontal();

                    for (int i = 0; i < levelEnables.Length; i++)
                    {
                        GUILayout.Space(20);
                        levelEnables[i] = EditorGUILayout.ToggleLeft(levelNames[i], levelEnables[i], GUILayout.Width(50));
                    }
                    EditorGUILayout.EndHorizontal();
                }


                EditorGUILayout.EndVertical();
                GUILayout.Space(20);
            }


            scrollPos_build = EditorGUILayout.BeginScrollView(scrollPos_build);
            if (buildGroupEnabled && unitGroupEnabled && unitEnables[0])
            {
                fold_build = EditorGUILayout.Foldout(fold_build, "建筑");
                if (fold_build)
                {
                    for (int i = 0; i < buildEnableds.Length; i++)
                    {
                        if (buildEnableds[i])
                        {
                            GUI_Build(i, buildTypeNames[i]);

                            GUILayout.Space(20);
                        }
                    }
                }
            }

            if (unitGroupEnabled && unitEnables[1])
            {
                fold_wall = EditorGUILayout.Foldout(fold_wall, "路障");
                if (fold_wall)
                {
                    GUI_Wall();
                }
            }
            EditorGUILayout.EndScrollView();
        }
Exemple #15
0
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.EndHorizontal();

            SplitterGUILayoutBridge.BeginVerticalSplit(splitter);
            EditorGUILayout.BeginVertical();
            targetScroll = GUILayout.BeginScrollView(targetScroll);

            // var focused = EditorGUILayout.TextField("focus", GUI.GetNameOfFocusedControl());
            var focused = GUI.GetNameOfFocusedControl();

            if (string.IsNullOrEmpty(focused))
            {
                focusedRefs = null;
                focusedDeps = null;
            }
            else
            {
                var chunks = focused.Split(',');
                if (chunks.Length == 2)
                {
                    focusedObjectPath = chunks[1];
                    if (chunks[0] == "Result")
                    {
                        focusedRefs = GetOrNull(references, focusedObjectPath);
                        focusedDeps = GetOrNull(dependencies, focusedObjectPath);
                    }
                    else if (chunks[0] == "Target")
                    {
                        focusedDeps = GetOrNull(dependencies, focusedObjectPath);
                    }
                }
            }

            Targets = Targets ?? new List <UnityObject>();
            if (Targets.Count == 0)
            {
                Targets.Add(null);
            }
            targetList.Clear();
            targetList.AddRange(Targets.Select(AssetDatabase.GetAssetPath));
            var backgroundColor = GUI.backgroundColor;

            targetList.Draw();

            if (isAutoSelect)
            {
                if (Selection.objects != null && Selection.objects.Length > 0 && !Selection.objects.SequenceEqual(Targets))
                {
                    var o = Selection.objects[0];
                    if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(o)))
                    {
                        Targets = Selection.objects.ToList();
                    }
                }
            }

            if (Targets[0] == null)
            {
                guid = null;
            }
            EditorGUILayout.TextField("GUIDs", guid ?? "");

            if (Targets[0] != null && (prevTargets == null || !Targets.SequenceEqual(prevTargets)))
            {
                prevTargets = Targets;
                ListDependencies(Targets);
            }

            GUILayout.EndScrollView();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
            EditorGUILayout.LabelField(string.Format("dependencies: {0}", objectList.Count));

            objectList.Draw();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("SelectAll"))
            {
                SelectAll();
            }
            if (GUILayout.Button("DeselectAll"))
            {
                DeselectAll();
            }
            if (GUILayout.Button("History"))
            {
                ShowHistory();
            }
            if (GUILayout.Button("DuplicateDeps"))
            {
                Duplicate();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            SplitterGUILayoutBridge.EndVerticalSplit();

            var ev = Event.current;

            if (ev.type == EventType.KeyDown)
            {
                OnKeyDown(ev.keyCode);
            }
        }
Exemple #16
0
    public override void OnInspectorGUI()
    {
        GUI.changed = false;

        modifier = target as VJBaseModifier;

        if (!modifier.isModifierEnabled)
        {
            EditorGUILayout.HelpBox("Diabled from On-Off Switch", MessageType.None);
        }

        VJAbstractManager[] managers = UnityEngine.Object.FindObjectsOfType(typeof(VJAbstractManager)) as VJAbstractManager[];
        if (managers.Length > 0)
        {
            string[] options_managers = new string[managers.Length];
            for (int i = 0; i < managers.Length; ++i)
            {
                options_managers[i] = managers[i].gameObject.name;
                if (modifier.manager == managers[i])
                {
                    index = i;
                }
            }

            index = EditorGUILayout.Popup(
                "Manager:",
                index,
                options_managers);

            modifier.manager = managers[index];
            //EditorUtility.SetDirty(target);

            GameObject             go      = managers[index].gameObject;
            VJAbstractDataSource[] sources = go.GetComponents <VJAbstractDataSource>() as VJAbstractDataSource[];
            if (sources.Length > 0)
            {
                string[] options_sources = new string[sources.Length];
                for (int i = 0; i < sources.Length; ++i)
                {
                    options_sources[i] = sources[i].sourceName;
                    if (modifier.source == sources[i])
                    {
                        index_src = i;
                    }
                }

                index_src = EditorGUILayout.Popup(
                    "DatSource:",
                    index_src,
                    options_sources);

                modifier.source = sources[index_src];
                //EditorUtility.SetDirty(target);
            }
            else
            {
                EditorGUILayout.LabelField("No DataSource found");
            }
        }
        else
        {
            EditorGUILayout.LabelField("No VJManager found");
        }

        base.OnInspectorGUI();

//		modifier.multiple = EditorGUILayout.Toggle("Multiple", modifier.multiple);
//		if(modifier.multiple) {
////			Rect r = GUILayoutUtility.GetLastRect();
////			r.x += 8;
////			r.width -= 16;
////			r.y += 20;
////			r.height = 16;
//			//GUILayout.Space(72.0f);
//			EditorGUILayout.PropertyField (serializedObject.FindProperty ("targets"), GUIContent.none);
//		}

        if (GUILayout.Button("Target Children"))
        {
            modifier.multiple = true;
            modifier.SetVisibleChildrenAsTarget();
        }

        //EditorGUILayout.Space();
        Rect r = GUILayoutUtility.GetLastRect();

        r.x     += 8;
        r.width -= 16;
        r.y     += 20;
        r.height = 16;
        EditorGUILayout.BeginVertical();
        GUILayout.Space(32.0f);
        EditorGUI.ProgressBar(r, modifier.lastReturnedValue / VJAbstractDataSource.s_prog_max, "value:" + modifier.lastReturnedValue);
        EditorGUILayout.EndVertical();


        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
        public override void OnInspectorGUI()
        {
            if (_decorator == null)
            {
                return;
            }

            bool requestChanges = false;

            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Group", GUILayout.Width(120));
            int oldGroup = _decorator.GUIGroupIndex;

            _decorator.GUIGroupIndex = EditorGUILayout.Popup(_decorator.GUIGroupIndex, groupNames, GUILayout.MaxWidth(200));
            if (_decorator.GUIGroupIndex != oldGroup || decoratorGroup == null)
            {
                decoratorGroup = _decorator.GetDecoratorGroup(_decorator.GUIGroupIndex, true);
            }

            if (GUILayout.Button("Clear"))
            {
                _decorator.ClearDecoratorGroup(_decorator.GUIGroupIndex);
                if (decorator != null)
                {
                    decorator.isNew = true;
                }
                ReloadGroupNames();
                _decorator.ReloadCountryNames();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Enabled", GUILayout.Width(120));
            decoratorGroup.active = EditorGUILayout.Toggle(decoratorGroup.active, GUILayout.Width(20));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            // country selector
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Country", GUILayout.Width(120));
            if (_decorator.lastCountryCount != _map.countries.Length)
            {
                _decorator.ReloadCountryNames();
            }
            int selection = EditorGUILayout.Popup(_decorator.GUICountryIndex, _decorator.countryNames);

            if (selection != _decorator.GUICountryIndex)
            {
                SetCountryFromCombo(selection);
            }

            bool prevc = _decorator.groupByContinent;

            GUILayout.Label("Grouped");
            _decorator.groupByContinent = EditorGUILayout.Toggle(_decorator.groupByContinent, GUILayout.Width(20));
            if (_decorator.groupByContinent != prevc)
            {
                _decorator.ReloadCountryNames();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(120));
            DrawWarningLabel("(Click on SceneView to select a country)");
            EditorGUILayout.EndHorizontal();

            // type of decoration
            if (_decorator.GUICountryName.Length > 0)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(120));
                if (GUILayout.Button("Toggle Zoom"))
                {
                    ToggleZoomState();
                }
                EditorGUILayout.EndHorizontal();

                CountryDecorator existingDecorator = _decorator.GetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                if (existingDecorator != null)
                {
                    decorator = existingDecorator;
                }
                else if (decorator == null || !decorator.countryName.Equals(_decorator.GUICountryName))
                {
                    decorator = new CountryDecorator(_decorator.GUICountryName);
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Persistent", "The attributes set by this decorator will replace any other change done at runtime"), GUILayout.Width(120));
                decorator.isPersistent = EditorGUILayout.Toggle(decorator.isPersistent);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Hidden", GUILayout.Width(120));
                bool prevHidden = decorator.hidden;
                decorator.hidden = EditorGUILayout.Toggle(decorator.hidden);
                if (prevHidden != decorator.hidden)
                {
                    requestChanges = true;
                }
                EditorGUILayout.EndHorizontal();

                if (!decorator.hidden)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Label Visible", GUILayout.Width(120));
                    bool prevLabelVisible = decorator.labelVisible;
                    decorator.labelVisible = EditorGUILayout.Toggle(decorator.labelVisible);
                    if (prevLabelVisible != decorator.labelVisible)
                    {
                        requestChanges = true;
                    }
                    EditorGUILayout.EndHorizontal();

                    if (decorator.labelVisible)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Label", GUILayout.Width(120));
                        decorator.labelOverride = EditorGUILayout.Toggle(decorator.labelOverride, GUILayout.Width(40));
                        if (decorator.labelOverride)
                        {
                            GUILayout.Label("Text", GUILayout.Width(40));
                            string prevLabel = decorator.customLabel;
                            decorator.customLabel = EditorGUILayout.TextField(decorator.customLabel);
                            if (!prevLabel.Equals(decorator.customLabel))
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Font", GUILayout.Width(120));
                        Font prevFont = decorator.labelFontOverride;
                        decorator.labelFontOverride = (Font)EditorGUILayout.ObjectField(decorator.labelFontOverride, typeof(Font), false);
                        if (decorator.labelFontOverride != prevFont)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Color", GUILayout.Width(120));
                        decorator.labelOverridesColor = EditorGUILayout.Toggle(decorator.labelOverridesColor, GUILayout.Width(40));
                        if (decorator.labelOverridesColor)
                        {
                            GUILayout.Label("Color", GUILayout.Width(40));
                            Color prevColor = decorator.labelColor;
                            decorator.labelColor = EditorGUILayout.ColorField(decorator.labelColor, GUILayout.Width(50));
                            if (prevColor != decorator.labelColor)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Size", GUILayout.Width(120));
                        decorator.labelOverridesFontSize = EditorGUILayout.Toggle(decorator.labelOverridesFontSize, GUILayout.Width(40));
                        if (decorator.labelOverridesFontSize)
                        {
                            GUILayout.Label("Size", GUILayout.Width(40));
                            float prevSize = decorator.labelFontSize;
                            decorator.labelFontSize = Mathf.Max(0.01f, EditorGUILayout.FloatField(decorator.labelFontSize));
                            if (prevSize != decorator.labelFontSize)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();


                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Offset", GUILayout.Width(120));
                        Vector2 prevLabelOffset = decorator.labelOffset;
                        decorator.labelOffset = EditorGUILayout.Vector2Field("", decorator.labelOffset);
                        if (prevLabelOffset != decorator.labelOffset)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Rotation", GUILayout.Width(120));
                        float prevLabelRotation = decorator.labelRotation;
                        decorator.labelRotation = EditorGUILayout.Slider(decorator.labelRotation, 0, 359);
                        if (prevLabelRotation != decorator.labelRotation)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();
                    }


                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Colorized", GUILayout.Width(120));
                    bool prevColorized = decorator.isColorized;
                    decorator.isColorized = EditorGUILayout.Toggle(decorator.isColorized);
                    if (prevColorized != decorator.isColorized)
                    {
                        requestChanges = true;
                    }
                    if (decorator.isColorized)
                    {
                        GUILayout.Label("Fill Color", GUILayout.Width(120));
                        Color prevColor = decorator.fillColor;
                        decorator.fillColor = EditorGUILayout.ColorField(decorator.fillColor, GUILayout.Width(50));
                        if (prevColor != decorator.fillColor)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Include All Regions", GUILayout.Width(120));
                        bool prevIncludeAllRegions = decorator.includeAllRegions;
                        decorator.includeAllRegions = EditorGUILayout.Toggle(decorator.includeAllRegions);
                        if (prevIncludeAllRegions != decorator.includeAllRegions)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Texture", GUILayout.Width(120));
                        Texture2D prevTexture = decorator.texture;
                        decorator.texture = (Texture2D)EditorGUILayout.ObjectField(decorator.texture, typeof(Texture2D), false);
                        if (decorator.texture != prevTexture)
                        {
                            requestChanges = true;
                        }

                        if (decorator.texture != null)
                        {
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Include All Regions", GUILayout.Width(120));
                            prevIncludeAllRegions = decorator.applyTextureToAllRegions;
                            decorator.applyTextureToAllRegions = EditorGUILayout.Toggle(decorator.applyTextureToAllRegions);
                            if (prevIncludeAllRegions != decorator.applyTextureToAllRegions)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Scale", GUILayout.Width(120));
                            Vector2 prevVector = decorator.textureScale;
                            decorator.textureScale = EditorGUILayout.Vector2Field("", decorator.textureScale);
                            if (prevVector != decorator.textureScale)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Offset", GUILayout.Width(120));
                            prevVector = decorator.textureOffset;
                            decorator.textureOffset = EditorGUILayout.Vector2Field("", decorator.textureOffset);
                            if (prevVector != decorator.textureOffset)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Rotation", GUILayout.Width(120));
                            float prevFloat = decorator.textureRotation;
                            decorator.textureRotation = EditorGUILayout.Slider(decorator.textureRotation, 0, 360);
                            if (prevFloat != decorator.textureRotation)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.BeginHorizontal();
                if (decorator.isNew)
                {
                    if (GUILayout.Button("Assign"))
                    {
                        _decorator.SetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName, decorator);
                        ReloadGroupNames();
                        _decorator.ReloadCountryNames();
                    }
                }
                else if (GUILayout.Button("Remove"))
                {
                    decorator = null;
                    _decorator.RemoveCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                    ReloadGroupNames();
                    _decorator.ReloadCountryNames();
                }
                EditorGUILayout.EndHorizontal();

                if (!decoratorGroup.active)
                {
                    DrawWarningLabel("Enable the decoration group to activate changes");
                }
            }


            EditorGUILayout.EndVertical();

            if (requestChanges)
            {
                _decorator.ForceUpdateDecorators();
                SceneView.RepaintAll();
                EditorUtility.SetDirty(_map);
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
            }
        }
    /// <summary>
    /// Custom Inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        // Start custom Inspector
        serializedObject.Update();
        EditorGUI.BeginChangeCheck();
        m_target.layerIndex = m_reorderableTilemapLayerList.index;

        if (m_target.toolIndex > 0 && m_target.toolIndex < 5)
        {
            Tools.hidden = true;
        }
        else
        {
            Tools.hidden = false;
        }
        //
        // References
        //
        m_showReferencesGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showReferencesGroup.isExpanded, "References");
        if (m_showReferencesGroup.isExpanded)
        {
            GUILayout.Space(1);
            // Standard diffuse shader
            GUI.color = m_greenColor;
            if (!m_legacyShader.objectReferenceValue)
            {
                GUI.color = m_redColor;
            }
            EditorGUILayout.PropertyField(m_legacyShader, m_guiContent[7]);

            // Universal diffuse shader
            GUI.color = m_greenColor;
            if (!m_universalShader.objectReferenceValue)
            {
                GUI.color = m_redColor;
            }
            EditorGUILayout.PropertyField(m_universalShader, m_guiContent[8]);
            GUI.color = Color.white;
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Settings
        //
        m_showSettingsGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showSettingsGroup.isExpanded, "Settings");
        if (m_showSettingsGroup.isExpanded)
        {
            GUILayout.Space(1);
            // Render pipeline
            EditorGUILayout.PropertyField(m_renderPipeline, m_guiContent[9]);
            if (m_target.renderPipeline == TilemapSystemPipeline.Universal)
            {
                EditorGUILayout.HelpBox("Universal Render Pipeline is still a work in progress and is not fully functional.", MessageType.Info);
            }

            // Tilemap size
            EditorGUILayout.IntPopup(m_tilesetSize, m_tilesetSizeContentArray, m_tilesetSizeArray, m_guiContent[16]);

            // Grid size
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField(m_guiContent[0]);
            m_gridMapSize.x = EditorGUILayout.IntField(m_guiContent[1], (int)m_target.gridMapSize.x);
            m_gridMapSize.y = EditorGUILayout.IntField(m_guiContent[2], (int)m_target.gridMapSize.y);
            EditorGUILayout.EndVertical();

            // Layer list
            m_reorderableTilemapLayerList.DoLayoutList();
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Data
        //
        m_showDataGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showDataGroup.isExpanded, "Data");
        if (m_showDataGroup.isExpanded)
        {
            GUILayout.Space(1);
            if (m_reorderableTilemapLayerList.count > 0)
            {
                EditorGUI.BeginDisabledGroup(true);
                // Tilemap data
                if (!m_tilemapData.objectReferenceValue)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_tilemapData, m_guiContent[6]);
                GUI.color = Color.white;
                // Tilemap texture field
                if (!m_target.tilemapTexture)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[13], m_target.tilemapTexture, typeof(Texture3D), false);
                GUI.color = Color.white;
                // Tileset texture field
                if (!m_target.tilesetTexture)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[15], m_target.tilesetTexture, typeof(Texture3D), false);
                GUI.color = Color.white;
                // Array texture field
                if (!m_target.layerArrayTexture)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[17], m_target.layerArrayTexture, typeof(Texture2D), false);
                GUI.color = Color.white;
                // Render material field
                if (!m_target.renderMaterial)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[14], m_target.renderMaterial, typeof(Material), false);
                GUI.color = Color.white;
                EditorGUI.EndDisabledGroup();

                // Button
                if (GUILayout.Button("Generate Tilemap Data"))
                {
                    m_target.GenerateTilemapData();
                    if (m_target.tilemapData)
                    {
                        TilePalette[] palettes   = new TilePalette[m_target.tilemapLayerList.Count];
                        int[]         tilesCount = new int[m_target.tilemapLayerList.Count];
                        for (int i = 0; i < palettes.Length; i++)
                        {
                            palettes[i] = m_target.tilemapLayerList[i].tilePalette;
                            if (palettes[i])
                            {
                                tilesCount[i] = m_target.tilemapLayerList[i].tilePalette.tilesCount;
                            }
                            else
                            {
                                tilesCount[i] = 0;
                            }
                        }

                        m_target.tilemapData.settingsState  = new TilemapSettings(m_target.tilemapLayerList.Count, tilesCount, palettes, (int)m_gridMapSize.x, (int)m_gridMapSize.y, m_tilesetSize.intValue);
                        m_target.tilemapData.layerIntensity = new float[m_target.tilemapLayerList.Count];
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Painting
        //
        m_showPantingGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showPantingGroup.isExpanded, "Painting");
        if (m_showPantingGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    // Tile palette field
                    EditorGUILayout.BeginVertical("Box");
                    m_tilePalette = m_reorderableTilemapLayerList.serializedProperty.GetArrayElementAtIndex(m_target.layerIndex).FindPropertyRelative("tilePalette");
                    GUI.color     = m_greenColor;
                    if (!m_tilePalette.objectReferenceValue)
                    {
                        GUI.color = m_redColor;
                    }
                    EditorGUILayout.PropertyField(m_tilePalette, m_guiContent[5]);
                    GUI.color = Color.white;
                    EditorGUILayout.EndVertical();

                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        // Painting mode
                        EditorGUILayout.BeginVertical("Box");
                        EditorGUILayout.PropertyField(m_paintingMode, m_guiContent[10]);

                        // Auto tile layout popup
                        if (m_target.paintingMode == TilemapSystemPaintingMode.AutoTiles)
                        {
                            m_autoTileElements = GetAutoTileElements();

                            if (m_autoTileElements.Length > 0)
                            {
                                m_autoTileLayoutIndex          = m_reorderableTilemapLayerList.serializedProperty.GetArrayElementAtIndex(m_target.layerIndex).FindPropertyRelative("layoutIndex");
                                m_autoTileLayoutIndex.intValue = EditorGUILayout.Popup(m_guiContent[17], m_autoTileLayoutIndex.intValue, m_autoTileElements);
                            }
                            else
                            {
                                EditorGUILayout.HelpBox("The Auto Tile list is empty. Please, set some auto tile layout first.", MessageType.Error);
                            }
                        }
                        EditorGUILayout.EndVertical();
                        GUILayout.Space(-3);

                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            EditorGUILayout.BeginVertical("Box");
                            if (m_target.tilesetTexture)
                            {
                                if (CanPaint())
                                {
                                    // Reset layer button
                                    if (GUILayout.Button("Reset This Layer Using the Selected Tile"))
                                    {
                                        // Register the texture in the undo stack
                                        Undo.RegisterCompleteObjectUndo(m_target.tilemapTexture, "Tilemap Change");
                                        m_target.ResetLayer(m_target.layerIndex);
                                    }

                                    // Toolbar
                                    EditorGUILayout.BeginHorizontal();
                                    m_isPicking = m_target.toolIndex == 1 ? true : false;
                                    if (GUILayout.Toggle(m_isPicking, m_paintingToolIcons[0], EditorStyles.miniButtonLeft))
                                    {
                                        m_target.toolIndex = 1;
                                    }
                                    else if (m_target.toolIndex == 1)
                                    {
                                        m_target.toolIndex = 0;
                                    }

                                    m_isPainting = m_target.toolIndex == 2 ? true : false;
                                    if (GUILayout.Toggle(m_isPainting, m_paintingToolIcons[1], EditorStyles.miniButtonMid))
                                    {
                                        m_target.toolIndex = 2;
                                    }
                                    else if (m_target.toolIndex == 2)
                                    {
                                        m_target.toolIndex = 0;
                                    }

                                    m_isFilling = m_target.toolIndex == 3 ? true : false;
                                    if (GUILayout.Toggle(m_isFilling, m_paintingToolIcons[2], EditorStyles.miniButtonMid))
                                    {
                                        m_target.toolIndex = 3;
                                    }
                                    else if (m_target.toolIndex == 3)
                                    {
                                        m_target.toolIndex = 0;
                                    }

                                    m_isErasing = m_target.toolIndex == 4 ? true : false;
                                    if (GUILayout.Toggle(m_isErasing, m_paintingToolIcons[3], EditorStyles.miniButtonRight))
                                    {
                                        m_target.toolIndex = 4;
                                    }
                                    else if (m_target.toolIndex == 4)
                                    {
                                        m_target.toolIndex = 0;
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                else
                                {
                                    EditorGUILayout.HelpBox("It looks like you have changed some settings. Please, regenerate the Tilemap Data to update the 3D Textures.", MessageType.Error);
                                }
                            }
                            else
                            {
                                EditorGUILayout.HelpBox("There is no Tileset Texture yet. Please, regenerate the Tilemap Data again to create the 3D Tileset texture so you can start painting.", MessageType.Error);
                            }

                            // Tile grid
                            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos);
                            EditorGUILayout.LabelField("", GUILayout.Width(442));
                            GUILayout.Space(-20);
                            m_buttonIndex = 0;

                            // Start the selectable loop
                            for (int vertical = 0; vertical < 256;)
                            {
                                m_controlRect = EditorGUILayout.GetControlRect(GUILayout.Width(24), GUILayout.Height(24));

                                EditorGUILayout.BeginHorizontal();
                                for (int horizontal = 0; horizontal < 16; horizontal++)
                                {
                                    // Get the tile texture
                                    m_tileTexture = m_target.tilemapLayerList[m_target.layerIndex].tilePalette.temporaryTileTextureArray[vertical] ? m_target.tilemapLayerList[m_target.layerIndex].tilePalette.temporaryTileTextureArray[vertical] : emptyIconTexture;

                                    // Draw the selectable button
                                    m_isSelected = m_target.tileIndex == m_buttonIndex ? true : false;
                                    if (GUI.Toggle(m_controlRect, m_isSelected, GUIContent.none, GUI.skin.button))
                                    {
                                        m_target.tileIndex = m_buttonIndex;
                                    }

                                    // Draw the tile texture
                                    if (m_isSelected)
                                    {
                                        GUI.color = m_selectedTileColor;
                                    }
                                    GUI.DrawTexture(m_controlRect, m_tileTexture, ScaleMode.StretchToFill, true, 0);
                                    GUI.color = Color.white;

                                    m_controlRect.x += 28;
                                    vertical++;
                                    m_buttonIndex++;
                                }

                                EditorGUILayout.EndHorizontal();
                            }

                            EditorGUILayout.EndScrollView();
                            EditorGUILayout.EndVertical();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Auto tiles
        //
        m_showAutoTileGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showAutoTileGroup.isExpanded, "Auto Tiles");
        if (m_showAutoTileGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                            GUILayout.Space(3);
                            m_autoTileDictionary[m_target.layerIndex].DoLayoutList();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Random tile painting
        //
        EditorGUI.BeginDisabledGroup(true);
        m_showRandomTilePaintingGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showRandomTilePaintingGroup.isExpanded, "Random Tile Painting");
        if (m_showRandomTilePaintingGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();

        // Random tiles
        m_showRandomizeTileGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showRandomizeTileGroup.isExpanded, "Randomize Tiles");
        if (m_showRandomizeTileGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();

        // Tile brushes
        m_showTileBrushesGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showTileBrushesGroup.isExpanded, "Tile Brushes");
        if (m_showTileBrushesGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        EditorGUI.EndDisabledGroup();

        // About group
        m_showAboutGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showAboutGroup.isExpanded, "About");
        if (m_showAboutGroup.isExpanded)
        {
            EditorGUILayout.HelpBox("3D Tilemap System v1.0.1 by Seven Stars Games", MessageType.None);
            if (GUILayout.Button(m_guiContent[18]))
            {
                Application.OpenURL("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S8AB7CVH5VMZS&source=url");
            }
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("My other assets you may like:");
            if (GUILayout.Button(m_guiContent[19]))
            {
                Application.OpenURL("https://assetstore.unity.com/packages/tools/particles-effects/azure-sky-dynamic-skybox-36050");
            }
            if (GUILayout.Button(m_guiContent[20]))
            {
                Application.OpenURL("https://assetstore.unity.com/packages/vfx/shaders/azure-sky-lite-89858");
            }
        }

        // Update layer intensity when there is a change in the Inspector
        if (m_target.tilemapData)
        {
            if (NeedUpdateLayerIntensity())
            {
                m_target.UpdateLayerSettings();
                m_target.tilemapData.layerIntensity = new float[m_target.tilemapLayerList.Count];
                for (int i = 0; i < m_target.tilemapLayerList.Count; i++)
                {
                    m_target.tilemapData.layerIntensity[i] = m_target.tilemapLayerList[i].intensity;
                }
            }
        }

        // End custom Inspector
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(m_target, "3D Tilemap System");
            serializedObject.ApplyModifiedProperties();
            m_target.gridMapSize = m_gridMapSize;
            m_target.UpdateMaterialSettings();
        }
    }
Exemple #19
0
        void OnGUI()
        {
            EditorGUILayout.BeginVertical();

            GUILayout.Label(new GUIContent("gmcs or mcs path"));
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.TextField(_gmcsPath);
                if (GUILayout.Button(new GUIContent("..."), GUILayout.MaxWidth(50)))
                {
                    string path = EditorUtility.OpenFilePanel("gmcs or mcs", "", "*.*");
                    if (path.Length > 0)
                    {
                        _gmcsPath = path;
                        EditorPrefs.SetString("Pie_ScriptEncrypter_GMCSPath", _gmcsPath);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
            GUILayout.Label(new GUIContent("Dependent library paths"));
            for (int i = 0; i < _dllPaths.Count; ++i)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.TextField(_dllPaths[i]);
                if (GUILayout.Button(new GUIContent("X"), GUILayout.MaxWidth(50)))
                {
                    _dllPaths.Remove(_dllPaths[i]);
                    SaveLibraryList();
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.TextField(_dllAdder);

                if (GUILayout.Button(new GUIContent("..."), GUILayout.MaxWidth(50)))
                {
                    string path = EditorUtility.OpenFilePanel("Dependent Library", "", "dll");
                    if (path.Length > 0)
                    {
                        _dllAdder = path;
                    }
                }

                if (GUILayout.Button(new GUIContent("Add"), GUILayout.MaxWidth(50)))
                {
                    if (!_dllAdder.Equals(string.Empty))
                    {
                        _dllPaths.Add(_dllAdder);
                        _dllAdder = "";
                        SaveLibraryList();
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Label(new GUIContent("Script path"));
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.TextField(_scriptPath);
                if (GUILayout.Button(new GUIContent("..."), GUILayout.MaxWidth(50)))
                {
                    string path = EditorUtility.OpenFilePanel("Script Path", Application.dataPath, "cs");
                    if (path.Length > 0)
                    {
                        _scriptPath = path;
                        _scriptName = path.Substring(path.LastIndexOf('/') + 1);
                        _scriptName = _scriptName.Substring(0, _scriptName.LastIndexOf('.'));
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Label(new GUIContent("Save path"));
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.TextField(_savePath);
                if (GUILayout.Button(new GUIContent("..."), GUILayout.MaxWidth(50)))
                {
                    string path = EditorUtility.SaveFolderPanel("Save Path", Application.dataPath, "");
                    if (path.Length > 0)
                    {
                        _savePath = path;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Label("Key & IV");
            GUILayout.TextArea(_sslKey);
            if (GUILayout.Button("Copy"))
            {
                EditorGUIUtility.systemCopyBuffer = _sslKey;
            }

            GUILayout.Label("You must install OpenSSL (https://www.openssl.org/)");

            if (GUILayout.Button(new GUIContent("Encrypt")))
            {
                _sslKey = "";
                CreateDLL();
                Rc2Encrypt();
                Base64Encrypt();
                AssetDatabase.Refresh();
                MessageBox.Show("UnityPie", "Finish Script Encrypt!\nMust take note of the key and IV\nThen delete the original script", new Vector2(320, 100));
            }

            EditorGUILayout.EndVertical();
        }
        void DrawMopubSettings()
        {
            EditorGUILayout.Space();
            DrawUppercaseSection("MOPUB_ADS_SETUP_FOLDOUT_KEY", "MOPUB ADS", () =>
            {
                    #if !EM_MOPUB
                EditorGUILayout.HelpBox(MoPubImportInstruction, MessageType.Warning);
                if (GUILayout.Button("Download MoPub Plugin", GUILayout.Height(EM_GUIStyleManager.buttonHeight)))
                {
                    EM_ExternalPluginManager.DownloadMoPubPlugin();
                }
                    #else
                EditorGUILayout.HelpBox(MoPubAvailMsg, MessageType.Info);
                if (GUILayout.Button("Download MoPub Plugin", GUILayout.Height(EM_GUIStyleManager.buttonHeight)))
                {
                    EM_ExternalPluginManager.DownloadMoPubPlugin();
                }

                // Default placements.
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Default Placement", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(AdProperties.mopubDefaultBannerAdId.property, AdProperties.mopubDefaultBannerAdId.content, true);
                EditorGUILayout.PropertyField(AdProperties.mopubDefaultInterstitialAdId.property, AdProperties.mopubDefaultInterstitialAdId.content, true);
                EditorGUILayout.PropertyField(AdProperties.mopubDefaultRewardedAdId.property, AdProperties.mopubDefaultRewardedAdId.content, true);
                EditorGUI.indentLevel--;

                // Custom placements.
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Custom Placements", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(AdProperties.mopubCustomBannerAdIds.property, AdProperties.mopubCustomBannerAdIds.content, true);
                EditorGUILayout.PropertyField(AdProperties.mopubCustomInterstitialAdIds.property, AdProperties.mopubCustomInterstitialAdIds.content, true);
                EditorGUILayout.PropertyField(AdProperties.mopubCustomRewardedAdIds.property, AdProperties.mopubCustomRewardedAdIds.content, true);
                EditorGUI.indentLevel--;

                if (AdProperties.mopubReportAppOpen.property.boolValue)
                {
                    /// We only need to provide app ID on IOS,
                    /// on Android the report app open feature can be called without any parameter.
                        #if UNITY_IOS
                    EditorGUILayout.PropertyField(AdProperties.mopubITuneAppID.property, AdProperties.mopubITuneAppID.content, true);
                        #else
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    EditorGUILayout.LabelField("App ID is only required on iOS.", EditorStyles.miniBoldLabel);
                    EditorGUILayout.EndVertical();
                        #endif
                    EditorGUILayout.Space();
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Advanced Settings", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(AdProperties.mopubEnableLocationPassing.property, AdProperties.mopubEnableLocationPassing.content);

                EditorGUILayout.PropertyField(AdProperties.mopubEnableAdvancedSetting.property, AdProperties.mopubEnableAdvancedSetting.content);
                if (AdProperties.mopubEnableAdvancedSetting.property.boolValue)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    DrawEnumArrayProperty(AdProperties.mopubInitNetworks.property, typeof(MoPubSettings.MoPubInitNetwork), "Initialize Networks");
                    DrawEnumArrayProperty(AdProperties.mopubAdvancedBidders.property, typeof(MoPubSettings.MoPubAdvancedBidder), "Advanced Bidders");
                    DrawMediationSettingProperty(AdProperties.mopubMediationSettings.property, "Mediation Settings");
                    EditorGUILayout.EndVertical();
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("GDPR Consent", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(AdProperties.mopubAutoRequestConsent.property, AdProperties.mopubAutoRequestConsent.content);
                EditorGUILayout.PropertyField(AdProperties.mopubForceGdprApplicable.property, AdProperties.mopubForceGdprApplicable.content);
                    #endif
            });
        }
        //Draws Track inspector
        public override void OnInspectorGUI()
        {
            //Updates the SFXManager object
            serializedObject.Update();
            CreateStyles();

            //Banner display
            Rect BannerRect = GUILayoutUtility.GetRect(0.0f, 0.0f);

            BannerRect.height = Screen.width * 250 / 1600;
            GUILayout.Space(BannerRect.height);
            GUI.Label(BannerRect, Banner);

            //Preview
            GUILayout.BeginVertical(BackgroundStyles[0], GUILayout.Height(EditorGUIUtility.singleLineHeight * 2));
            EditorGUILayout.BeginHorizontal();
            GUI.enabled = SFXManager.Main;
            EditorGUILayout.LabelField(new GUIContent("Preview", "Preview options for the SFXManager. Only available at runtime."));
            if (GUILayout.Button(new GUIContent("Stop All", "Stops all sound currently being played.")))
            {
                SFXManager.Main.StopAll();
            }
            if (SFXManager.Main)
            {
                GUI.enabled = true;
                if (SFXManager.Main.Paused)
                {
                    if (GUILayout.Button(new GUIContent("Unpause", "Unpauses the SFXManager.")))
                    {
                        SFXManager.Main.UnPause();
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent("Pause", "Pauses the SFXManager.")))
                    {
                        SFXManager.Main.Pause();
                    }
                }
            }
            else
            {
                GUI.enabled = false;
                GUILayout.Button(new GUIContent("Pause", "Pauses the SFXManager."));
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = MusicManager.Main;
            SMInstance.SetVolume(EditorGUILayout.Slider(new GUIContent("Volume", "Global volume of the SFXManager"), SMInstance.MasterVolume, 0, 1));
            SMInstance.Muted = EditorGUILayout.Toggle(new GUIContent("Muted", "If the SFXManager is muted"), SMInstance.Muted);
            EditorGUILayout.LabelField(new GUIContent("Current Voice Count: " + (SMInstance ? SMInstance.CurrentAudioSourceCount.ToString() : "0"), "The number of active playing voices in the SFXManager."));
            GUI.enabled = true;
            EditorGUILayout.EndVertical();

            //Basic Settings
            GUILayout.BeginVertical(BackgroundStyles[1], GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.PropertyField(Mixer, new GUIContent("Mixer", "(Optional) Audio mixer to set as the output of all audio handled by SFXManager."));
            EditorGUILayout.PropertyField(ScenePersistent, new GUIContent("Scene Persistent", "Marks the GameObject as DontDestroyOnLoad to provide the manager with scene persistence(Note: manager must be present on a root GameObject for this functionality to work)."));
            GUILayout.EndVertical();

            //Updates SFXManager
            CollapseObjectLibrary.boolValue = EditorGUILayout.Foldout(CollapseObjectLibrary.boolValue, new GUIContent("SFXObject Library", "Library of SFXObjects stored on the SFXManager so that SFXObjects can be started by name without needing a reference to the SFXObject."));
            if (CollapseObjectLibrary.boolValue)
            {
                SFXObjectListDisplay.DoLayoutList();
            }
            CollapseGroupLibrary.boolValue = EditorGUILayout.Foldout(CollapseGroupLibrary.boolValue, new GUIContent("SFXGroup Library", "Library of SFXGroups stored on the SFXManager so that SFXGroups can be started by name without needing a reference to the SFXGroup."));
            if (CollapseGroupLibrary.boolValue)
            {
                SFXGroupListDisplay.DoLayoutList();
            }
            serializedObject.ApplyModifiedProperties();
        }
        /// <summary>
        /// Used by motors and other inspectors/editors to render out a list of bones that
        /// the user can edit.
        /// </summary>
        /// <param name="rBones"></param>
        /// <param name="rSelectedBones">Bones that are selected in the scene</param>
        /// <param name="rSelectedBoneIndex">Bone index that is selected in the bone list</param>
        /// <returns></returns>
        protected bool RenderBoneList(List <BoneControllerBone> rBones, ref int rSelectedBoneIndex, ref BoneControllerBone rSceneSelectedBone, bool rIncludeChildren, int rMaxBones)
        {
            bool lIsDirty = false;

#if UNITY_EDITOR
            // Force the selected bone based on the input list
            BoneControllerBone lSelectedBone = (rSceneSelectedBone != null ? rSceneSelectedBone : (rSelectedBoneIndex < 0 ? null : rBones[rSelectedBoneIndex]));
            int lSelectedBoneIndex           = (rSelectedBoneIndex >= 0 ? rSelectedBoneIndex : rBones.IndexOf(lSelectedBone));

            // List of bones that represent the chain (head->neck->etc)
            if (rBones.Count == 0)
            {
                EditorGUILayout.HelpBox("Select a bone in the scene view and press '+' to make it part of the motor", MessageType.Info);
            }
            else
            {
                for (int i = 0; i < rBones.Count; i++)
                {
                    EditorGUILayout.BeginVertical(GUI.skin.box);

                    // If this bone is selected, we'll highlight the title
                    bool lIsSelected = (i == lSelectedBoneIndex);

                    GUIStyle lRowStyle = (lIsSelected ? BoneController.SelectedRowStyle : BoneController.TitleRowStyle);

                    // Display the title
                    EditorGUILayout.BeginHorizontal(lRowStyle);

                    if (GUILayout.Button(new GUIContent(BoneController.ItemSelector), GUI.skin.label, GUILayout.Width(16)))
                    {
                        lSelectedBoneIndex = i;
                        lSelectedBone      = rBones[i];
                    }

                    string lCleanName = "Select a bone";
                    if (rBones[i] != null)
                    {
                        lCleanName = rBones[i].CleanName + (rBones[i].Parent == null ? "" : " (from " + rBones[i].Parent.CleanName + ")");
                    }
                    EditorGUILayout.LabelField(lCleanName);

                    EditorGUILayout.EndHorizontal();

                    // Search based on the bone name
                    string lOldBoneName = (rBones[i] == null ? "" : rBones[i].Name);
                    string lNewBoneName = EditorGUILayout.TextField(new GUIContent("Bone Name", "Name of the bone to search for and pose."), lOldBoneName);
                    if (lNewBoneName != lOldBoneName)
                    {
                        lIsDirty = true;

                        BoneControllerBone lBone = mSkeleton.GetBone(lNewBoneName) as BoneControllerBone;
                        if (lBone != null)
                        {
                            rBones[i]          = lBone;
                            lSelectedBone      = lBone;
                            lSelectedBoneIndex = i;
                        }
                    }

                    // Select based on the transform
                    Transform lOldBoneTransform = (rBones[i] == null ? null : rBones[i].Transform);
                    Transform lNewBoneTransform = EditorGUILayout.ObjectField(new GUIContent("Bone Transform", "Bone transform we are posing."), lOldBoneTransform, typeof(Transform), true) as Transform;
                    if (lNewBoneTransform != lOldBoneTransform)
                    {
                        lIsDirty = true;

                        BoneControllerBone lBone = mSkeleton.GetBone(lNewBoneTransform) as BoneControllerBone;
                        if (lBone != null)
                        {
                            rBones[i]          = lBone;
                            lSelectedBone      = lBone;
                            lSelectedBoneIndex = i;
                        }
                    }

                    // Render out the motor specific bone details
                    bool lIsBoneDirty = RenderBone(i, rBones[i]);
                    if (lIsBoneDirty)
                    {
                        lSelectedBoneIndex = i;
                        lSelectedBone      = rBones[i];

                        lIsDirty = true;
                    }

                    EditorGUILayout.EndVertical();
                }
            }

            // Control buttons
            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(new GUIContent("Clear", "Clears all the bones"), EditorStyles.miniButton, GUILayout.Width(50)))
            {
                if (EditorUtility.DisplayDialog("Bone Controller", "Delete all bones from the motor?", "Yes", "No"))
                {
                    lIsDirty = true;
                    ClearBones();
                }
            }

            if (rMaxBones <= 0 || mBones.Count < rMaxBones)
            {
                if (GUILayout.Button(new GUIContent("+", "Add Bone"), EditorStyles.miniButtonLeft, GUILayout.Width(20)))
                {
                    if (!rBones.Contains(lSelectedBone))
                    {
                        lIsDirty           = true;
                        lSelectedBoneIndex = rBones.Count;

                        AddBone(lSelectedBone, rIncludeChildren);
                    }
                    else
                    {
                        lIsDirty = true;

                        lSelectedBone      = null;
                        lSelectedBoneIndex = rBones.Count;

                        AddBone(lSelectedBone, rIncludeChildren);
                    }
                }
            }

            if (GUILayout.Button(new GUIContent("-", "Delete Bone"), EditorStyles.miniButtonRight, GUILayout.Width(20)))
            {
                if (lSelectedBoneIndex >= 0)
                {
                    if (EditorUtility.DisplayDialog("Bone Controller", "Delete this bone (and its children) from the motor?", "Yes", "No"))
                    {
                        lIsDirty = true;

                        RemoveBone(lSelectedBoneIndex, rIncludeChildren);

                        if (lSelectedBoneIndex >= rBones.Count)
                        {
                            lSelectedBoneIndex = rBones.Count - 1;
                        }
                        lSelectedBone = (lSelectedBoneIndex < 0 ? null : rBones[lSelectedBoneIndex]);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            // Send back the index of the currently selected bone
            rSceneSelectedBone = lSelectedBone;
            rSelectedBoneIndex = lSelectedBoneIndex;
#endif

            return(lIsDirty);
        }
Exemple #23
0
        private void DrawCurrentSprites()
        {
            if (this.m_SPInstance == null)
            {
                return;
            }

            Rect controlRect = EditorGUILayout.GetControlRect();

            GUI.Label(controlRect, "Sprites (" + this.m_SPInstance.sprites.Count.ToString() + ")", EditorStyles.boldLabel);

            GUI.Label(new Rect(controlRect.width - 120f, controlRect.y, 70f, 20f), "Scrollview");

            GUI.changed = false;
            bool sv = GUI.Toggle(new Rect(controlRect.width - 55f, controlRect.y + 1f, 20f, 20f), EditorPrefs.GetBool(SPTools.Settings_UseScrollViewKey), " ");

            if (GUI.changed)
            {
                EditorPrefs.SetBool(SPTools.Settings_UseScrollViewKey, sv);
            }

            GUI.Label(new Rect(controlRect.width - 40f, controlRect.y, 40f, 20f), "Show");

            GUI.changed = false;
            bool ss = GUI.Toggle(new Rect(controlRect.width - 2f, controlRect.y + 1f, 20f, 20f), EditorPrefs.GetBool(SPTools.Settings_ShowSpritesKey), " ");

            if (GUI.changed)
            {
                EditorPrefs.SetBool(SPTools.Settings_ShowSpritesKey, ss);
            }

            if (EditorPrefs.GetBool(SPTools.Settings_ShowSpritesKey))
            {
                if (this.m_SPInstance.sprites.Count == 0)
                {
                    this.DrawMessage("The atlas does not contain sprites.");
                    return;
                }

                EditorGUILayout.BeginVertical(this.boxStyle);

                if (EditorPrefs.GetBool(SPTools.Settings_UseScrollViewKey))
                {
                    this.scrollViewOffset = EditorGUILayout.BeginScrollView(this.scrollViewOffset, GUILayout.Height(EditorPrefs.GetFloat(SPTools.Settings_ScrollViewHeightKey)));
                }

                if (EditorPrefs.GetBool(SPTools.Settings_UseSpriteThumbsKey))
                {
                    this.DrawSpritesWithThumbs();
                }
                else
                {
                    this.DrawSpritesSimple();
                }

                if (EditorPrefs.GetBool(SPTools.Settings_UseScrollViewKey))
                {
                    EditorGUILayout.EndScrollView();
                }

                EditorGUILayout.EndVertical();
            }
        }
    /// <summary>
    /// Raises the inspector GUI event. Defines a custom inspector for the Object Pool
    /// </summary>
    public override void OnInspectorGUI()
    {
        // Cache useful references
        ObjectPoolManager pool = (ObjectPoolManager)target;

        m_lib   = pool.PoolLibrary;
        m_nodes = m_lib.Nodes;

        // Begin preliminary GUI work
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField("Default Settings", EditorStyles.boldLabel);
        EditorGUILayout.Space();

        // Define toggles
        EditorGUILayout.HelpBox("Enabling \"Use Debug\" will allow the Object Pool to produce debug messages in the console. These areas of code are removed through the use of preprocessor directives when the game is compiled.", MessageType.None);
        pool.UseDebug = EditorGUILayout.Toggle("Use Debug", pool.UseDebug);
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Enabling \"Persistent\" will allow the Object Pool to persist through scene load.", MessageType.None);
        pool.Persistent = EditorGUILayout.Toggle("Persistent", pool.Persistent);
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Enabling \"Enforce Pooling\" will ensure that the Object Pool never instantiates or destroys objects when an object cannot normally be acquired. If disabled, the pool will create (and destroy) instances of pooled objects when they cannot normally be acquired.", MessageType.None);
        pool.EnforcePooling = EditorGUILayout.Toggle("Enforce Pooling", pool.EnforcePooling);
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Enabling \"Allow Instantiation\" will allow the Object Pool to instantiate non-pooled objects through calls to Instantiate. The name argument is treated as a path in the resource folder.", MessageType.None);
        pool.AllowInstantiation = EditorGUILayout.Toggle("Allow Instantiation", pool.AllowInstantiation);
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Enabling \"Detatch in Hierarchy\" will cause the Object Pool to move acquired objects to the root of the scene hierarchy. Useful for organization and debugging.", MessageType.None);
        pool.Detatch = EditorGUILayout.Toggle("Detatch in Hierarchy", pool.Detatch);
        EditorGUILayout.Space();

        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField("Pool Presets", EditorStyles.boldLabel);
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Enabling \"Use Presets\" will cause the Object Pool to load its pool list from a Scriptable Object in the Assets folder.", MessageType.None);
        pool.UsePreset = EditorGUILayout.Toggle("Use Presets", pool.UsePreset);
        EditorGUILayout.Space();

        // Define Pool Library structure
        if (pool.UsePreset)
        {
            EditorGUILayout.Space();

            EditorGUILayout.HelpBox("The buttons below will allow you to add references to pool presets in the Asset library.", MessageType.None);
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Add Preset"))
            {
                pool.Presets.Add(null);
            }

            if (GUILayout.Button("Remove Preset"))
            {
                if (pool.Presets.Count > 0)
                {
                    pool.Presets.RemoveAt(pool.Presets.Count - 1);
                }

                else
                {
                    Debug.LogWarning("There aren't any presets to remove!");
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            for (int i = 0; i < pool.Presets.Count; i++)
            {
                pool.Presets[i] = (ObjectPoolPreset)EditorGUILayout.ObjectField("Preset", pool.Presets[i], typeof(ScriptableObject), true);
            }
            EditorGUILayout.Space();
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField("Pool Library", EditorStyles.boldLabel);
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("Objects can be added or removed from the Pool Library below. Simply specify a number of objects to create at the start of the scene (maximum can be changed in the inspector code), set a unique name for the object, then link its prefab. The pool handles the rest.", MessageType.None);
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Add Object"))
        {
            m_nodes.Add(new PoolLibraryNode());
        }

        if (GUILayout.Button("Remove Object"))
        {
            if (m_nodes.Count > 0)
            {
                m_nodes.RemoveAt(m_nodes.Count - 1);
            }

            else
            {
                Debug.LogWarning("There aren't any nodes to remove!");
            }
        }
        EditorGUILayout.EndHorizontal();

        for (int i = 0; i < m_nodes.Count; i++)
        {
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            PoolLibraryNode node = m_nodes[i];
            node.Maximum = EditorGUILayout.IntSlider("Amount to Pool", node.Maximum, 0, 100);
            node.Name    = EditorGUILayout.TextField("Object Name", node.Name);
            node.Prefab  = (GameObject)EditorGUILayout.ObjectField("Prefab", node.Prefab, typeof(GameObject), true);
        }

        if (m_nodes.Count > 0)
        {
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUI.backgroundColor = Color.cyan;
            EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb);
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Preset Generation", EditorStyles.boldLabel);
            EditorGUILayout.Space();

            EditorGUILayout.HelpBox("Clicking \"Create Preset\" will create a (Whisper) Object Pool preset that can be used in other pools. The user can specify a name for the preset.", MessageType.None);
            EditorGUILayout.BeginHorizontal();
            m_presetName = EditorGUILayout.TextField("Preset Name", m_presetName);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Create Preset", GUILayout.Width(120)))
            {
                ObjectPoolPreset preset = ScriptableObject.CreateInstance <ObjectPoolPreset> ();

                preset.Library       = m_lib;
                preset.Library.Nodes = m_nodes;

                string path = "Assets/";
                AssetDatabase.CreateAsset(preset, path + m_presetName + ".asset");
                AssetDatabase.SaveAssets();
                Debug.Log("Object Pool Preset instantiated!");
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
    }
Exemple #25
0
        private void DrawPendingActions()
        {
            if (this.m_SPInstance == null)
            {
                return;
            }

            EditorGUILayout.LabelField("Pending Actions", EditorStyles.boldLabel);

            float labelWidth = 90f;

            if (this.m_SPInstance.pendingActions.Count == 0)
            {
                this.DrawMessage("There are no pending actions.");
                return;
            }

            EditorGUILayout.BeginVertical();

            List <SPAction> unqueueList = new List <SPAction>();

            // Draw the actions
            foreach (SPAction action in this.m_SPInstance.pendingActions)
            {
                switch (action.actionType)
                {
                case SPAction.ActionType.Sprite_Add:
                {
                    GUI.color = SPInstanceEditor.green;
                    EditorGUILayout.BeginHorizontal(this.boxStyle);
                    GUI.color = Color.white;

                    EditorGUILayout.LabelField("Add Sprite", GUILayout.Width(labelWidth));
                    EditorGUILayout.ObjectField(action.resource, action.resource.GetType(), false);

                    // Remove action button
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
                    {
                        unqueueList.Add(action);
                    }

                    EditorGUILayout.EndHorizontal();
                    break;
                }

                case SPAction.ActionType.Sprite_Remove:
                {
                    GUI.color = SPInstanceEditor.red;
                    EditorGUILayout.BeginHorizontal(this.boxStyle);
                    GUI.color = Color.white;

                    EditorGUILayout.LabelField("Remove Sprite", GUILayout.Width(labelWidth));
                    EditorGUILayout.ObjectField(action.spriteInfo.targetSprite, typeof(Sprite), false);

                    // Remove action button
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
                    {
                        unqueueList.Add(action);
                    }

                    EditorGUILayout.EndHorizontal();
                    break;
                }
                }
            }

            // Unqueue actions in the list
            foreach (SPAction a in unqueueList)
            {
                this.m_SPInstance.UnqueueAction(a);
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();
        }
        void OnGUI()
        {
            ResizeScrollView();
            Rect viewportRect = new Rect(0, 0, position.width - sidePanelWidth, position.height);

            EditorGUI.DrawRect(viewportRect, bgColor);
            bool repaint = false;

            foreach (var obj in Selection.objects)
            {
                if (obj is StateMachineDefinition)
                {
                    def = (StateMachineDefinition)obj;
                    break;
                }
            }

            if (def != null)
            {
                bool showSide = true;

                Event cur = Event.current;

                if (op != null)
                {
                    if (def != op.definition)
                    {
                        op.Cancel();
                        op = null;
                    }
                    else
                    {
                        op.Update();

                        if (op.done)
                        {
                            op      = null;
                            repaint = true;
                            EditorUtility.SetDirty(def);
                            dirty = true;
                        }
                    }
                }
                else
                {
                    var selected   = def.SelectState(cur.mousePosition + scrollPos);
                    var selectedTr = def.SelectTransition(cur.mousePosition + scrollPos);

                    if (selected == null)
                    {
                        if (selectedTr.t2 != lastSelectedTr)
                        {
                            repaint        = true;
                            lastSelectedTr = selectedTr.t2;
                        }

                        if (lastSelectedState != null)
                        {
                            lastSelectedState = null;
                            repaint           = true;
                        }
                    }
                    else
                    {
                        if (selected != lastSelectedState)
                        {
                            repaint           = true;
                            lastSelectedState = selected;
                        }

                        if (lastSelectedTr != null)
                        {
                            lastSelectedTr = null;
                            repaint        = true;
                        }
                    }

                    if (viewportRect.Contains(cur.mousePosition))
                    {
                        if (cur.type == EventType.MouseDown)
                        {
                            if (cur.button == 0)
                            {
                                if (selected != null)
                                {
                                    editingState         = selected;
                                    editingTransition.t1 = null;
                                    editingTransition.t2 = null;
                                    repaint  = true;
                                    showSide = false;


                                    if (cur.clickCount == 1)
                                    {
                                        op = new MoveStateOperation(def, this, selected);
                                    }
                                    else if (cur.clickCount == 2)
                                    {
                                        op = new RenameStateOperation(def, this, selected);
                                    }
                                }
                                else if (selectedTr.t1 != null)
                                {
                                    editingTransition = selectedTr;
                                    editingState      = null;
                                    repaint           = true;
                                    showSide          = false;
                                }
                                else
                                {
                                    editingState         = null;
                                    editingTransition.t1 = null;
                                    editingTransition.t2 = null;
                                    repaint  = true;
                                    showSide = false;
                                }
                            }
                            else if (cur.button == 1)
                            {
                                if (selected == null && lastSelectedTr == null)
                                {
                                    GenericMenu menu = new GenericMenu();

                                    menu.AddItem(new GUIContent("Create State"), false, () => {
                                        var s      = def.AddState();
                                        s.position = cur.mousePosition + scrollPos;
                                        MoveStateOperation.Snap(ref s.position);
                                        op = new RenameStateOperation(def, this, s);
                                        EditorUtility.SetDirty(def);
                                        dirty = true;
                                    });

                                    menu.ShowAsContext();
                                }
                                else if (selected != null)
                                {
                                    GenericMenu menu = new GenericMenu();

                                    menu.AddItem(new GUIContent("Delete State"), false, () => {
                                        def.RemoveState(selected);
                                        EditorUtility.SetDirty(def);
                                        dirty   = true;
                                        repaint = true;
                                    });

                                    menu.AddItem(new GUIContent("Add Transition"), false, () => {
                                        op = new MakeTransitionOperation(def, this, selected);
                                    });

                                    if (selected.name != def.defaultState)
                                    {
                                        menu.AddItem(new GUIContent("Make Default State"), false, () => {
                                            def.defaultState = selected.name;
                                            dirty            = true;
                                            repaint          = true;
                                        });
                                    }

                                    menu.ShowAsContext();
                                }
                                else if (selectedTr.t1 != null)
                                {
                                    GenericMenu menu = new GenericMenu();

                                    menu.AddItem(new GUIContent("Remove Transition"), false, () => {
                                        selectedTr.t1.RemoveTransition(selectedTr.t2);
                                        EditorUtility.SetDirty(def);
                                        dirty   = true;
                                        repaint = true;
                                    });

                                    menu.ShowAsContext();
                                }
                            }
                        }
                        else if (cur.type == EventType.MouseDrag && cur.button == 2)
                        {
                            scrollPos -= cur.delta;
                            repaint    = true;
                        }
                        else if (cur.type == EventType.KeyDown && cur.keyCode == KeyCode.F)
                        {
                            var state = def.GetState(def.defaultState);
                            if (state == null && def.states.Count > 0)
                            {
                                state = def.states[0];
                            }

                            if (state != null)
                            {
                                scrollPos = state.position - viewportRect.size / 2;
                                repaint   = true;
                            }
                        }
                    }
                }

                if (Event.current.type != EventType.Repaint && (repaint || (op != null && op.repaint)))
                {
                    Repaint();
                }

                Handles.BeginGUI();

                Handles.color = lineColor;
                for (float x = -scrollPos.x % MoveStateOperation.snap; x < viewportRect.width; x += MoveStateOperation.snap)
                {
                    Handles.DrawLine(new Vector3(x, 0), new Vector3(x, viewportRect.height));
                }

                for (float y = -scrollPos.y % MoveStateOperation.snap; y < viewportRect.height; y += MoveStateOperation.snap)
                {
                    Handles.DrawLine(new Vector3(0, y), new Vector3(viewportRect.width, y));
                }

                if (def.states != null)
                {
                    foreach (var from in def.states)
                    {
                        if (from.transitions != null)
                        {
                            foreach (var tr in from.transitions)
                            {
                                if (tr != lastSelectedTr && tr != editingTransition.t2)
                                {
                                    Handles.color = Color.black;
                                }
                                else
                                {
                                    Handles.color = Color.blue;
                                }

                                if (def.GetState(tr.to) != null)
                                {
                                    var     line = def.GetTransitionPoints(from, tr);
                                    Vector2 src  = line.t1 - scrollPos;
                                    Vector2 dest = line.t2 - scrollPos;

                                    Vector2 v     = (dest - src).normalized;
                                    Vector2 ortho = new Vector2(v.y, -v.x);

                                    Vector2 arrow = ortho - v;
                                    Vector2 mid   = (src + dest) / 2;

                                    Handles.DrawAAPolyLine(3, src, dest);
                                    Handles.DrawAAPolyLine(3, mid + v * 5, mid + arrow * 10);
                                }
                            }
                        }
                    }

                    foreach (var state in def.states)
                    {
                        if (op == null || op.state != state || op.showBaseGUI)
                        {
                            string s = state.name;
                            if (def.defaultState == s)
                            {
                                s += "\n<default state>";
                            }

                            Rect rect = state.rect;
                            rect.position -= scrollPos;

                            if (state != lastSelectedState && state != editingState)
                            {
                                GUI.Button(rect, s);
                            }
                            else
                            {
                                GUI.Button(rect, "");

                                var centeredStyle = new GUIStyle(GUI.skin.label);
                                centeredStyle.alignment        = TextAnchor.MiddleCenter;
                                centeredStyle.normal.textColor = Color.blue;
                                centeredStyle.fontStyle        = FontStyle.Bold;

                                GUI.Label(rect, s, centeredStyle);
                            }
                        }

                        if (op != null && op.state == state)
                        {
                            op.OnGUI();
                        }
                    }
                }

                Handles.EndGUI();

                if (showSide)
                {
                    EditorGUI.DrawRect(new Rect(position.width - sidePanelWidth, 0, sidePanelWidth, position.height), panelColor);


                    float padding = 20;
                    GUILayout.BeginArea(new Rect(position.width - sidePanelWidth + padding, padding, sidePanelWidth - padding * 2, position.height - padding * 2));
                    EditorGUILayout.BeginVertical();
                    float w = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 1;

                    if (GUILayout.Button(dirty ? "Save *" : "Save"))
                    {
                        AssetDatabase.SaveAssets();
                        dirty = false;
                        StateMachineClassGenerator.GenerateAbstractClass(def);
                    }

                    if (GUILayout.Button("New Impl Class..."))
                    {
                        var path = EditorUtility.SaveFilePanelInProject("Save new class", def.name + "Impl.cs", "cs", "Enter a name for the new impl class");
                        if (path.Length > 0)
                        {
                            StateMachineClassGenerator.GenerateImplClass(def, path);
                        }
                    }

                    if (types == null)
                    {
                        types = typeof(StateMachine).Assembly.GetTypes()
                                .Where(p => !p.IsGenericType && typeof(StateMachine).IsAssignableFrom(p))
                                .Select(t => t.FullName).ToArray();
                    }

                    int index = Array.IndexOf(types, def.baseClass);
                    if (index < 0)
                    {
                        index = Array.IndexOf(types, typeof(StateMachine).FullName);
                    }
                    int prev = index;

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Base Class");
                    index = EditorGUILayout.Popup(index, types);

                    if (prev != index)
                    {
                        dirty = true;
                    }

                    EditorGUILayout.EndHorizontal();
                    def.baseClass = types[index];

                    if (editingState != null)
                    {
                        EditorGUILayout.LabelField("State " + editingState.name);
                        EditorGUILayout.LabelField("State Events", EditorStyles.boldLabel);

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Enter: ");
                        bool enter = EditorGUILayout.Toggle(editingState.hasEnter);
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("During: ");
                        bool during = EditorGUILayout.Toggle(editingState.hasDuring);
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Exit: ");
                        bool exit = EditorGUILayout.Toggle(editingState.hasExit);
                        EditorGUILayout.EndHorizontal();


                        if (enter != editingState.hasEnter || during != editingState.hasDuring || exit != editingState.hasExit)
                        {
                            editingState.hasEnter  = enter;
                            editingState.hasDuring = during;
                            editingState.hasExit   = exit;

                            dirty = true;
                            EditorUtility.SetDirty(def);
                        }
                    }
                    else if (editingTransition.t1 != null)
                    {
                        EditorGUILayout.LabelField("Transition From " + editingTransition.t1.name + " To " + editingTransition.t2.to);
                        EditorGUILayout.LabelField("Transition Events", EditorStyles.boldLabel);

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Notify: ");
                        bool notify = EditorGUILayout.Toggle(editingTransition.t2.hasNotify);
                        EditorGUILayout.EndHorizontal();

                        if (notify != editingTransition.t2.hasNotify)
                        {
                            editingTransition.t2.hasNotify = notify;

                            dirty = true;
                            EditorUtility.SetDirty(def);
                        }
                    }

                    EditorGUILayout.EndVertical();
                    EditorGUIUtility.labelWidth = w;

                    GUILayout.EndArea();
                }
            }
            else if (op != null)
            {
                op.Cancel();
                op = null;
            }
        }
Exemple #27
0
        /// <summary>
        /// Draws the specified array object.
        /// </summary>
        /// <param name="guiContent">The GUIContent to draw with the associated object.</param>
        /// <param name="type">The type of object to draw.</param>
        /// <param name="parent">The parent of the value.</param>
        /// <param name="value">The value of the object.</param>
        /// <param name="name">The name of the object being drawn.</param>
        /// <param name="hashPrefix">The prefix of the hash from the parent class. This value will prevent collisions with similarly named objects.</param>
        /// <param name="valuePositionMap">A map between the value hash and the position within the positions array.</param>
        /// <param name="serialization">The serialized data.</param>
        /// <param name="fieldProperty">A reference to the field or property that is being drawn.</param>
        /// <param name="drawFields">Should the fields be drawn? If false the properties will be drawn.</param>
        /// <returns>The drawn object.</returns>
        private static object DrawArrayObject(GUIContent guiContent, Type type, object parent, object value, string name, int hashPrefix, Dictionary <int, int> valuePositionMap, Serialization serialization, object fieldProperty, bool drawFields)
        {
            // Arrays and lists operate differently when retrieving the element type.
            Type elementType;

            if (type.IsArray)
            {
                elementType = type.GetElementType();
            }
            else
            {
                var baseFieldType = type;
                while (!baseFieldType.IsGenericType)
                {
                    baseFieldType = baseFieldType.BaseType;
                }
                elementType = baseFieldType.GetGenericArguments()[0];
            }

            // Create the list value if it is null. The list cannot be null.
            IList list;

            if (value == null)
            {
                if (type.IsGenericType || type.IsArray)
                {
                    list = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType), true) as IList;
                }
                else
                {
                    list = Activator.CreateInstance(type, true) as IList;
                }
                if (type.IsArray)
                {
                    // Copy to an array so SetValue will accept the new value.
                    var array = Array.CreateInstance(elementType, list.Count);
                    list.CopyTo(array, 0);
                    list = array;
                }
            }
            else
            {
                list = (IList)value;
            }

            EditorGUILayout.BeginVertical();
            if (InspectorUtility.Foldout(list, guiContent))
            {
                EditorGUI.indentLevel++;
                var hash = hashPrefix + (parent != null ? parent.GetHashCode() : 0) + Serialization.StringHash(type.FullName) + Serialization.StringHash(name);
                // s_EditingArray is static so s_FocusHash is necessary so the array that is being modified can be identified.
                if (s_EditingArray && s_FocusHash == hash && (s_KeybordControl != GUIUtility.keyboardControl || Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    s_EditingArray = false;
                    var newArray    = Array.CreateInstance(elementType, s_ArraySize);
                    var origElement = -1;
                    // Copy all of the old values to the new array.
                    for (int i = 0; i < s_ArraySize; ++i)
                    {
                        if (i < list.Count)
                        {
                            origElement = i;
                        }
                        if (origElement == -1)
                        {
                            break;
                        }

                        var listValue = list[origElement];
                        if (i >= list.Count && !typeof(UnityEngine.Object).IsAssignableFrom(elementType) && !typeof(string).IsAssignableFrom(elementType))
                        {
                            // Do not copy by reference.
                            listValue = Activator.CreateInstance(list[origElement].GetType(), true);
                        }

                        newArray.SetValue(listValue, i);
                    }
                    if (type.IsArray)
                    {
                        list = (IList)newArray;
                    }
                    else
                    {
                        if (type.IsGenericType)
                        {
                            list = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType), true) as IList;
                        }
                        else
                        {
                            list = Activator.CreateInstance(type, true) as IList;
                        }
                        for (int i = 0; i < newArray.Length; ++i)
                        {
                            list.Add(newArray.GetValue(i));
                        }
                    }
                    // Mark the GUI as changed so the object will be serialized.
                    GUI.changed = true;
                }
                var size = EditorGUILayout.IntField("Size", list.Count);
                if (size != list.Count)
                {
                    if (!s_EditingArray)
                    {
                        s_EditingArray   = true;
                        s_KeybordControl = GUIUtility.keyboardControl;
                        s_FocusHash      = hash;
                    }
                    s_ArraySize = size;
                }

                hash = hashPrefix + Serialization.StringHash(type.FullName) + Serialization.StringHash(name);
                for (int i = 0; i < list.Count; ++i)
                {
                    GUILayout.BeginHorizontal();
                    if (list[i] == null && !typeof(UnityEngine.Object).IsAssignableFrom(elementType) && elementType != typeof(string))
                    {
                        list[i] = Activator.CreateInstance(elementType);
                    }
                    guiContent.text = "Element " + i;
                    list[i]         = DrawObject(guiContent, elementType, parent, list[i], name, hash / (i + 2), valuePositionMap, serialization, fieldProperty, drawFields);
                    GUILayout.Space(6);
                    GUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndVertical();
            return(list);
        }
        //-----------------------------------------------------------------------------------
        protected void RenderTitle(bool isEditable, bool drawEnabledToggle = true, bool drawVisibleToggle = true, bool isDebugRender = false)
        {
            currentFocusedControlName_ = GUI.GetNameOfFocusedControl();

            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();

            string title;

            if (Data.NeedsUpdate)
            {
                title = Data.Name + "(*)";
            }
            else
            {
                title = Data.Name;
            }

            GUILayout.Space(5f);
            Rect iconRect = GUILayoutUtility.GetRect(30f, 30f);

            GUI.Label(iconRect, new GUIContent(TexIcon));
            EditorGUI.BeginDisabledGroup(!Data.IsNodeEnabledInHierarchy);
            GUILayout.Label(new GUIContent(title), styleTitle);
            EditorGUI.EndDisabledGroup();

            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginVertical();
            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();

            EditorGUI.BeginDisabledGroup(!(isEditable));
            float width = ((Data.IsNodeEnabled == Data.IsNodeEnabledInHierarchy) && (Data.IsNodeVisible == Data.IsNodeVisibleInHierarchy)) ? 100f : 170f;

            if (drawEnabledToggle)
            {
                string nameEnabled = (Data.IsNodeEnabled == Data.IsNodeEnabledInHierarchy) ? "Enabled" : "Enabled (Overidden to off)";
                Enabled = EditorGUILayout.ToggleLeft(nameEnabled, Data.IsNodeEnabled, GUILayout.Width(width));
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(!(isEditable || isDebugRender));
            if (drawVisibleToggle)
            {
                string nameVisible = (Data.IsNodeVisible == Data.IsNodeVisibleInHierarchy) ? "Visible" : "Visible (Overidden to off)";
                Visible = EditorGUILayout.ToggleLeft(nameVisible, Data.IsNodeVisible, GUILayout.Width(width));
            }
            EditorGUI.EndDisabledGroup();

            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }

            EditorGUILayout.EndVertical();
            GUILayout.EndHorizontal();

            CRGUIUtils.Splitter();

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty id             = property.FindPropertyRelative("ID");
            SerializedProperty title          = property.FindPropertyRelative("Title");
            SerializedProperty speaker        = property.FindPropertyRelative("speakerIndex");
            SerializedProperty isEnd          = property.FindPropertyRelative("isEnd");
            SerializedProperty text           = property.FindPropertyRelative("Text");
            SerializedProperty onEnter        = property.FindPropertyRelative("OnEnter");
            SerializedProperty onExit         = property.FindPropertyRelative("OnExit");
            SerializedProperty cutsceneEvents = property.FindPropertyRelative("cutsceneEvents");
            SerializedProperty transitions    = property.FindPropertyRelative("transitions");
            SerializedProperty responsesList  = property.FindPropertyRelative("Responses");
            SerializedProperty response;
            SerializedObject   parent = property.serializedObject;//TODO instead use serialized property, and get conversation from that

            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("ID: ");
            EditorGUILayout.SelectableLabel(id.intValue.ToString());
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.PropertyField(title);
            // Display possible speakers as popup
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Speaker: ");
            speaker.intValue = EditorGUILayout.Popup(speaker.intValue, (parent.targetObject as Conversation).Speakers.ToArray());
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.PropertyField(isEnd);
            EditorGUILayout.PropertyField(text);
            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(onEnter, true);
            EditorGUILayout.PropertyField(onExit, true);
            EditorGUILayout.PropertyField(cutsceneEvents, true);
            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(transitions, true);

            EditorGUILayout.Separator();

            // Responses list area
            int         responsesSize = responsesList.arraySize;
            ListActions action        = ListActions.Nothing;
            int         selectedIndex = -1;

            responsesList.isExpanded = EditorGUILayout.Foldout(responsesList.isExpanded, "Responses", true, EditorStyles.boldLabel);
            if (responsesList.isExpanded)
            {
                // Display each response
                for (int i = 0; i < responsesSize; ++i)
                {
                    response = responsesList.GetArrayElementAtIndex(i);

                    string responseTitle = response.FindPropertyRelative("Text").stringValue;
                    if (string.IsNullOrEmpty(responseTitle))
                    {
                        responseTitle = "Response " + i.ToString();
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.BeginVertical();
                    // Display response details if expanded
                    response.isExpanded = EditorGUILayout.Foldout(response.isExpanded, responseTitle);
                    if (response.isExpanded)
                    {
                        EditorGUILayout.PropertyField(response, new GUIContent(responseTitle), true); //TODO get text from response, use as label
                    }
                    EditorGUILayout.EndVertical();
                    // Buttons for moving or deleting response
                    bool moveUp = false, moveDown = false, deleteResponse = false;
                    using (new EditorGUI.DisabledScope(i <= 0))     // Disable if first in array
                    {
                        moveUp = GUILayout.Button("^", GUILayout.Width(MOVE_BUTTON_WIDTH));
                    }
                    using (new EditorGUI.DisabledScope(i + 1 >= responsesSize))
                    {
                        moveDown = GUILayout.Button("v", GUILayout.Width(MOVE_BUTTON_WIDTH));
                    }
                    deleteResponse = GUILayout.Button("X", GUILayout.Width(MOVE_BUTTON_WIDTH));
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Separator();
                    // Set button action based on buttons clicked
                    if (moveUp)
                    {
                        action        = ListActions.MoveUp;
                        selectedIndex = i;
                    }
                    else if (moveDown)
                    {
                        action        = ListActions.MoveDown;
                        selectedIndex = i;
                    }
                    else if (deleteResponse)
                    {
                        action        = ListActions.Delete;
                        selectedIndex = i;
                    }
                }
                GUILayout.BeginHorizontal();
                bool addItem    = GUILayout.Button("Add Response");
                bool clearItems = GUILayout.Button("Clear Responses");
                GUILayout.EndHorizontal();
                // Perform action based on buttons clicked
                if (addItem)
                {
                    responsesList.InsertArrayElementAtIndex(responsesSize);
                }
                if (clearItems)
                {
                    responsesList.arraySize = 0;
                }
                switch (action)
                {
                case ListActions.MoveUp:
                    if (selectedIndex > 0)
                    {
                        responsesList.MoveArrayElement(selectedIndex, selectedIndex - 1);
                    }
                    break;

                case ListActions.MoveDown:
                    if (selectedIndex >= 0 && selectedIndex < (responsesSize - 1))
                    {
                        responsesList.MoveArrayElement(selectedIndex, selectedIndex + 1);
                    }
                    break;

                case ListActions.Delete:
                    if (selectedIndex >= 0 && selectedIndex < (responsesSize))
                    {
                        responsesList.DeleteArrayElementAtIndex(selectedIndex);
                    }
                    break;

                case ListActions.Nothing:
                default:
                    break;
                }
            }
            else
            {
                responsesList.isExpanded = GUILayout.Button("Show");
            }

            EditorGUILayout.EndVertical();
        }
Exemple #30
0
        protected void DrawSharedElements(ActionList _target)
        {
            if (UnityVersionHandler.IsPrefabFile(_target.gameObject) && _target.source == ActionListSource.InScene)
            {
                EditorGUILayout.HelpBox("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info);
                return;
            }

            int numActions = 0;

            if (_target.source != ActionListSource.AssetFile)
            {
                numActions = _target.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;
                    AC.Action newAction = ActionList.GetDefaultAction();
                    _target.actions.Add(newAction);
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();

            if (_target.source == ActionListSource.AssetFile)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(_target, "Expand actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = true;
                }
            }
            if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(_target, "Collapse actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = false;
                }
            }

            GUI.enabled = true;

            if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
            {
                if (_target.source == ActionListSource.AssetFile)
                {
                    if (_target.assetFile != null)
                    {
                        ActionListEditorWindow.Init(_target.assetFile);
                    }
                }
                else
                {
                    ActionListEditorWindow.Init(_target);
                }
            }
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
            {
                _target.Interact();
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (_target.source == ActionListSource.AssetFile)
            {
                return;
            }

            ActionListEditor.ResetList(_target);

            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
                return;
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                if (_target.actions[i] == null)
                {
                    ACDebug.LogWarning("An empty Action was found, and was deleted");
                    _target.actions.RemoveAt(i);
                    continue;
                }

                _target.actions[i].AssignParentList(_target);

                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.BeginHorizontal();
                int    typeIndex   = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]);
                string actionLabel = " (" + (i).ToString() + ") " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel();
                actionLabel = actionLabel.Replace("\r\n", "");
                actionLabel = actionLabel.Replace("\n", "");
                actionLabel = actionLabel.Replace("\r", "");
                if (actionLabel.Length > 40)
                {
                    actionLabel = actionLabel.Substring(0, 40) + "..)";
                }

                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f));
                }

                if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                {
                    ActionSideMenu(i);
                }

                _target.actions[i].isAssetFile = false;

                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isBreakPoint)
                {
                    EditorGUILayout.HelpBox("Break point", MessageType.None);
                }

                if (_target.actions[i].isDisplayed)
                {
                    GUI.enabled = _target.actions[i].isEnabled;

                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type has been disabled in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");
                            _target.actions[i] = ActionListEditor.RebuildAction(_target.actions[i], newTypeIndex, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene);
                        }

                        if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0)
                        {
                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                GUI.enabled = true;

                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new action"))
            {
                Undo.RecordObject(_target, "Create action");
                numActions += 1;
            }

            _target.actions = ActionListEditor.ResizeList(_target.actions, numActions);
        }