コード例 #1
0
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        public void OnGUI(Rect a_position)
        {
            if (m_data == null)
            {
                MxMSettings settings = MxMSettings.Instance();
                if (settings != null)
                {
                    m_data = settings.ActiveBlendSpace;

                    if (m_data != null)
                    {
                        SetData(m_data);
                    }
                }
            }

            if (m_data != null)
            {
                Event evt = Event.current;

                float labelWidth = EditorGUIUtility.labelWidth;

                if (evt.type == EventType.Repaint)
                {
                    if (m_queueDeleteIndex >= 0 && m_queueDeleteIndex < m_spClips.arraySize)
                    {
                        if (m_selectId == m_queueDeleteIndex)
                        {
                            m_selectId = -1;
                        }

                        if (m_spClips.GetArrayElementAtIndex(m_queueDeleteIndex).objectReferenceValue != null)
                        {
                            m_spClips.DeleteArrayElementAtIndex(m_queueDeleteIndex);
                        }

                        m_spClips.DeleteArrayElementAtIndex(m_queueDeleteIndex);
                        m_spPositions.DeleteArrayElementAtIndex(m_queueDeleteIndex);

                        m_queueDeleteIndex = -1;
                    }
                }

                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));

                EditorGUI.BeginChangeCheck();
                m_previewActive = GUILayout.Toggle(m_previewActive, "Preview", EditorStyles.toolbarButton, GUILayout.Width(60f));
                if (EditorGUI.EndChangeCheck())
                {
                    if (m_previewActive)
                    {
                        BeginPreview();
                    }
                    else
                    {
                        EndPreview();
                    }
                }



                if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                {
                    EditorGUIUtility.labelWidth = 20f;

                    EditorGUI.BeginChangeCheck();
                    m_previewPos.x = EditorGUILayout.FloatField("X: ", m_previewPos.x, EditorStyles.toolbarTextField);
                    m_previewPos.y = EditorGUILayout.FloatField("Y: ", m_previewPos.y, EditorStyles.toolbarTextField);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_previewPos.x = Mathf.Clamp(m_previewPos.x, -1f, 1f);
                        m_previewPos.y = Mathf.Clamp(m_previewPos.y, -1f, 1f);

                        CalculateBlendWeights();
                        ApplyBlendWeights();
                    }
                    EditorGUIUtility.labelWidth = labelWidth;

                    UpdatePreview();
                    MxMAnimConfigWindow.Inst().Repaint();
                }

                GUILayout.FlexibleSpace();

                m_spNormalizeTime.boolValue = GUILayout.Toggle(m_spNormalizeTime.boolValue, "Normalize Time",
                                                               EditorStyles.toolbarButton, GUILayout.Width(90f));

                EditorGUILayout.LabelField("Type:", GUILayout.Width(40f));
                m_spScatterSpace.enumValueIndex = (int)(EBlendSpaceType)EditorGUILayout.EnumPopup(
                    (EBlendSpaceType)m_spScatterSpace.enumValueIndex, GUILayout.Width(70f));
                GUILayout.Space(5f);

                switch ((EBlendSpaceType)m_spScatterSpace.enumValueIndex)
                {
                case EBlendSpaceType.Standard:
                {
                    EditorGUILayout.LabelField("Magnitude ", GUILayout.Width(62f));
                    m_spMagnitude.vector2Value = EditorGUILayout.Vector2Field("", m_spMagnitude.vector2Value, GUILayout.Width(100f));
                    EditorGUILayout.LabelField("Smoothing ", GUILayout.Width(65f));
                    m_spSmoothing.vector2Value = EditorGUILayout.Vector2Field("", m_spSmoothing.vector2Value, GUILayout.Width(100f));
                }
                break;

                case EBlendSpaceType.Scatter:
                {
                    EditorGUILayout.LabelField("Spacing", GUILayout.Width(50f));
                    m_spScatterSpacing.vector2Value = EditorGUILayout.Vector2Field("", m_spScatterSpacing.vector2Value, GUILayout.Width(100f));
                }
                break;

                case EBlendSpaceType.ScatterX:
                {
                    EditorGUILayout.LabelField("Spacing X", GUILayout.Width(60f));
                    float spacingX = EditorGUILayout.FloatField(m_spScatterSpacing.vector2Value.x, GUILayout.Width(35f));

                    m_spScatterSpacing.vector2Value = new Vector2(spacingX, m_spScatterSpacing.vector2Value.y);
                }
                break;

                case EBlendSpaceType.ScatterY:
                {
                    EditorGUILayout.LabelField("Spacing Y", GUILayout.Width(60f));
                    float spacingY = EditorGUILayout.FloatField(m_spScatterSpacing.vector2Value.y, GUILayout.Width(35f));

                    m_spScatterSpacing.vector2Value = new Vector2(m_spScatterSpacing.vector2Value.x, spacingY);
                }
                break;
                }



                GUILayout.Space(2f);
                m_showClipNames = GUILayout.Toggle(m_showClipNames, "Show Clips", EditorStyles.toolbarButton, GUILayout.Width(80f));
                GUILayout.Space(5f);
                m_snapActive = GUILayout.Toggle(m_snapActive, "Snap", EditorStyles.toolbarButton, GUILayout.Width(40f));

                if (m_snapActive)
                {
                    m_snapInterval = EditorGUILayout.FloatField(m_snapInterval, EditorStyles.toolbarTextField, GUILayout.Width(30f));
                }

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

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Height(20f), GUILayout.ExpandWidth(true));

                if (m_selectId >= 0 && m_selectId < m_spClips.arraySize)
                {
                    AnimationClip      clip       = m_spClips.GetArrayElementAtIndex(m_selectId).objectReferenceValue as AnimationClip;
                    SerializedProperty spPosition = m_spPositions.GetArrayElementAtIndex(m_selectId);

                    if (clip != null && spPosition != null)
                    {
                        EditorGUILayout.LabelField(clip.name, GUILayout.Width(GUI.skin.label.CalcSize(new GUIContent(clip.name)).x + 4f));

                        EditorGUI.BeginChangeCheck();
                        spPosition.vector2Value = EditorGUILayout.Vector2Field("", spPosition.vector2Value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                            {
                                CalculateBlendWeights();
                                ApplyBlendWeights();
                            }
                        }
                    }
                }

                EditorGUILayout.LabelField("Require", GUILayout.Width(50f));
                MxMPreProcessData preProcessData = m_spTargetPreProcessData.objectReferenceValue as MxMPreProcessData;
                AnimationModule   animModule     = m_spTargetAnimModule.objectReferenceValue as AnimationModule;

                if (preProcessData != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(preProcessData.TagNames.ToArray(), m_spGlobalTags, 100f);
                }
                else if (animModule != null && animModule.TagNames != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(animModule.TagNames.ToArray(), m_spGlobalTags, 100f);
                }
                else
                {
                    m_spGlobalTags.intValue = (int)(ETags)EditorGUILayout.EnumFlagsField((ETags)m_spGlobalTags.intValue);
                }

                EditorGUILayout.LabelField("Favour", GUILayout.Width(45f));

                if (preProcessData != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(preProcessData.FavourTagNames.ToArray(), m_spGlobalFavourTags, 100f);
                }
                else if (animModule != null && animModule.FavourTagNames != null)
                {
                    EditorFunctions.DrawTagFlagFieldWithCustomNames(animModule.FavourTagNames.ToArray(), m_spGlobalFavourTags, 100f);
                }
                else
                {
                    m_spGlobalFavourTags.intValue = (int)(ETags)EditorGUILayout.EnumFlagsField((ETags)m_spGlobalFavourTags.intValue);
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(new GUIContent("Open Timeline"), EditorStyles.toolbarButton))
                {
                    MxMTaggingWindow.ShowWindow();
                }

                GUILayout.Space(5f);

                if (m_spTargetPreProcessData.objectReferenceValue != null ||
                    m_spTargetAnimModule.objectReferenceValue != null)
                {
                    if (GUILayout.Button(EditorGUIUtility.IconContent("back").image, EditorStyles.toolbarButton))
                    {
                        LastBlendSpace();
                    }

                    if (GUILayout.Button(EditorGUIUtility.IconContent("forward").image, EditorStyles.toolbarButton))
                    {
                        NextBlendSpace();
                    }
                }

                EditorGUI.BeginDisabledGroup(true);

                EditorGUIUtility.labelWidth = 110f;
                if (preProcessData != null)
                {
                    EditorGUILayout.ObjectField(m_spTargetPreProcessData, new GUIContent("Target PreProcess"));
                }
                else if (animModule != null)
                {
                    EditorGUILayout.ObjectField(m_spTargetAnimModule, new GUIContent("Target Anim Module"));
                }

                EditorGUIUtility.labelWidth = 95f;
                EditorGUILayout.ObjectField(m_spTargetPrefab, new GUIContent("Preview Prefab"));

                EditorGUI.EndDisabledGroup();

                EditorGUIUtility.labelWidth = labelWidth;

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

                Rect blendSpaceRect = new Rect(30f, 40f, a_position.width - 60f, a_position.height - 90f);

                GUI.Box(blendSpaceRect, "");

                Rect labelRect = new Rect(blendSpaceRect.x - 18f, blendSpaceRect.y, 18f, 18f);

                GUI.Label(labelRect, "1");
                labelRect.y += blendSpaceRect.height / 2f - 9f;
                GUI.Label(labelRect, "0");
                labelRect.y = blendSpaceRect.y + blendSpaceRect.height - 18f;
                GUI.Label(labelRect, "-1");
                labelRect.y += labelRect.height;
                labelRect.x += labelRect.width;
                GUI.Label(labelRect, "-1");
                labelRect.x += blendSpaceRect.width / 2f - 9f;
                GUI.Label(labelRect, "0");
                labelRect.x = blendSpaceRect.x + blendSpaceRect.width - 18f;
                GUI.Label(labelRect, "1");

                float spacingH = blendSpaceRect.width / 10f;
                float spacingV = blendSpaceRect.height / 10f;

                float top    = blendSpaceRect.y;
                float bottom = blendSpaceRect.y + blendSpaceRect.height;
                float left   = blendSpaceRect.x;
                float right  = blendSpaceRect.x + blendSpaceRect.width;

                Handles.color = Color.grey;
                for (int i = 1; i < 10; ++i)
                {
                    float horizontal = i * spacingH + blendSpaceRect.x;
                    float vertical   = i * spacingV + blendSpaceRect.y;

                    Handles.DrawLine(new Vector3(horizontal, top), new Vector3(horizontal, bottom));
                    Handles.DrawLine(new Vector3(left, vertical), new Vector3(right, vertical));
                }

                Handles.color = Color.black;
                Handles.DrawLine(new Vector3(blendSpaceRect.x + blendSpaceRect.width / 2f, top),
                                 new Vector3(blendSpaceRect.x + blendSpaceRect.width / 2f, bottom));

                Handles.DrawLine(new Vector3(left, blendSpaceRect.y + blendSpaceRect.height / 2f),
                                 new Vector3(right, blendSpaceRect.y + blendSpaceRect.height / 2f));

                Rect    animDrawRect    = new Rect(0f, 0f, 18f, 18f);
                Vector2 blendSpaceRatio = new Vector2(2f / blendSpaceRect.width, 2f / blendSpaceRect.height);

                Texture blendKey         = EditorGUIUtility.IconContent("blendKey").image;
                Texture blendKeySelected = EditorGUIUtility.IconContent("blendKeySelected").image;
                Texture previewPointTex  = EditorGUIUtility.IconContent("d_P4_AddedLocal").image;

                Vector2 centerPos = blendSpaceRect.position;
                centerPos.x += blendSpaceRect.width / 2f;
                centerPos.y += blendSpaceRect.height / 2f;

                //Draw Points
                for (int i = 0; i < m_spClips.arraySize; ++i)
                {
                    Vector2 normalizedPos = m_spPositions.GetArrayElementAtIndex(i).vector2Value;
                    normalizedPos.y *= -1f;

                    animDrawRect.position = (normalizedPos / blendSpaceRatio) + centerPos;

                    animDrawRect.size = new Vector2(14f, 14f);

                    if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                    {
                        float size = 9f + 5f * m_blendWeights[i];
                        animDrawRect.size = new Vector2(size, size);
                    }
                    else
                    {
                        animDrawRect.size = new Vector2(14f, 14f);
                    }

                    animDrawRect.position -= (animDrawRect.size / 2f);

                    if (m_selectId == i)
                    {
                        GUI.DrawTexture(animDrawRect, blendKeySelected);
                    }
                    else
                    {
                        GUI.DrawTexture(animDrawRect, blendKey);
                    }

                    if (m_showClipNames)
                    {
                        AnimationClip clip = m_spClips.GetArrayElementAtIndex(i).objectReferenceValue as AnimationClip;

                        Vector2 labelSize = GUI.skin.label.CalcSize(new GUIContent(clip.name));

                        Rect clipNameRect = new Rect(animDrawRect.x + (animDrawRect.width / 2f) - labelSize.x / 2f,
                                                     animDrawRect.y - labelSize.y, labelSize.x, labelSize.y);

                        GUI.Label(clipNameRect, clip.name);
                    }

                    if (evt.type == EventType.MouseDown && evt.button == 0)
                    {
                        if (animDrawRect.Contains(evt.mousePosition))
                        {
                            m_selectId       = i;
                            m_dragging       = true;
                            m_cumulativeDrag = m_spPositions.GetArrayElementAtIndex(i).vector2Value;

                            if (evt.clickCount >= 2)
                            {
                                EditorGUIUtility.PingObject(m_spClips.GetArrayElementAtIndex(i).objectReferenceValue);
                            }

                            evt.Use();
                            MxMAnimConfigWindow.Inst().Repaint();
                        }
                    }
                }

                //Draw Preview Point
                if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                {
                    Vector3 previewDrawPos = m_previewPos;
                    previewDrawPos.y *= -1f;

                    animDrawRect.size     = new Vector2(18f, 18f);
                    animDrawRect.position = (previewDrawPos / blendSpaceRatio) + centerPos - (animDrawRect.size / 2f);

                    GUI.DrawTexture(animDrawRect, previewPointTex);
                }

                switch (evt.type)
                {
                case EventType.MouseDown:
                {
                    if (m_previewActive && blendSpaceRect.Contains(evt.mousePosition) && MxMPreviewScene.IsSceneLoaded)
                    {
                        Vector2 blendSpacePos = evt.mousePosition - (blendSpaceRect.position + (blendSpaceRect.size / 2f));
                        m_previewPos    = blendSpacePos * blendSpaceRatio;
                        m_previewPos.y *= -1f;

                        m_previewPos.x = Mathf.Clamp(m_previewPos.x, -1f, 1f);
                        m_previewPos.y = Mathf.Clamp(m_previewPos.y, -1f, 1f);

                        CalculateBlendWeights();
                        ApplyBlendWeights();


                        m_draggingPreview = true;
                    }

                    m_dragging = false;
                    m_selectId = -1;
                    evt.Use();
                }
                break;

                case EventType.MouseUp:
                {
                    if (m_dragging || m_draggingPreview)
                    {
                        m_draggingPreview = false;
                        m_dragging        = false;
                        m_cumulativeDrag  = Vector2.zero;
                        evt.Use();
                    }
                }
                break;

                case EventType.MouseDrag:
                {
                    if (m_dragging)
                    {
                        if (m_selectId >= 0 && m_selectId < m_spPositions.arraySize)
                        {
                            SerializedProperty spPosition = m_spPositions.GetArrayElementAtIndex(m_selectId);
                            Vector2            moveDelta  = evt.delta;
                            moveDelta.y *= -1f;

                            if (m_snapActive)
                            {
                                m_cumulativeDrag += moveDelta * blendSpaceRatio;

                                m_cumulativeDrag.x = Mathf.Clamp(m_cumulativeDrag.x, -1f, 1f);
                                m_cumulativeDrag.y = Mathf.Clamp(m_cumulativeDrag.y, -1f, 1f);

                                spPosition.vector2Value = m_cumulativeDrag;
                                SnapClip(m_selectId);
                            }
                            else
                            {
                                Vector2 newPos = spPosition.vector2Value + moveDelta * blendSpaceRatio;

                                newPos.x = Mathf.Clamp(newPos.x, -1f, 1f);
                                newPos.y = Mathf.Clamp(newPos.y, -1f, 1f);
                                spPosition.vector2Value = newPos;
                            }

                            if (m_previewActive && MxMPreviewScene.IsSceneLoaded)
                            {
                                CalculateBlendWeights();
                                ApplyBlendWeights();
                            }

                            evt.Use();
                        }
                        else
                        {
                            m_dragging = false;
                        }
                    }
                    else if (m_previewActive && m_draggingPreview && MxMPreviewScene.IsSceneLoaded)
                    {
                        Vector2 blendSpacePos = evt.mousePosition - (blendSpaceRect.position + (blendSpaceRect.size / 2f));
                        m_previewPos    = blendSpacePos * blendSpaceRatio;
                        m_previewPos.y *= -1f;

                        m_previewPos.x = Mathf.Clamp(m_previewPos.x, -1f, 1f);
                        m_previewPos.y = Mathf.Clamp(m_previewPos.y, -1f, 1f);

                        CalculateBlendWeights();
                        ApplyBlendWeights();

                        if (m_snapActive)
                        {
                            SnapPreview();
                        }

                        evt.Use();
                    }
                }
                break;

                case EventType.KeyDown:
                {
                    if (m_selectId >= 0 && m_selectId < m_spClips.arraySize)
                    {
                        if (evt.keyCode == KeyCode.Delete)
                        {
                            m_queueDeleteIndex = m_selectId;
                            MxMAnimConfigWindow.Inst().Repaint();
                            evt.Use();
                        }
                    }
                }
                break;
                }

                DragDropAnimations(blendSpaceRect);

                if (m_soData != null)
                {
                    m_soData.ApplyModifiedProperties();
                }
            }
            else
            {
                GUILayout.Space(18f);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField("No Blend Space Selected.", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
        }
コード例 #2
0
        void AssetFieldWithCreateButton(
            Rect r, SerializedProperty property, bool warnIfNull, string defaultName)
        {
            // Collect all the eligible asset types
            Type type = EmbeddedAssetType(property);

            if (mAssetTypes == null)
            {
                mAssetTypes = ReflectionHelpers.GetTypesInAllDependentAssemblies(
                    (Type t) => type.IsAssignableFrom(t) && !t.IsAbstract).ToArray();
            }

            float iconSize = r.height + 4;

            r.width -= iconSize;

            GUIContent label = new GUIContent(property.displayName, property.tooltip);

            if (warnIfNull && property.objectReferenceValue == null)
            {
                label.image = EditorGUIUtility.IconContent("console.warnicon.sml").image;
            }
            EditorGUI.PropertyField(r, property, label);

            r.x += r.width; r.width = iconSize; r.height = iconSize;
            if (GUI.Button(r, EditorGUIUtility.IconContent("_Popup"), GUI.skin.label))
            {
                GenericMenu menu = new GenericMenu();
                if (property.objectReferenceValue != null)
                {
                    menu.AddItem(new GUIContent("Edit"), false, ()
                                 => Selection.activeObject = property.objectReferenceValue);
                    menu.AddItem(new GUIContent("Clone"), false, () =>
                    {
                        ScriptableObject copyFrom = property.objectReferenceValue as ScriptableObject;
                        if (copyFrom != null)
                        {
                            string title           = "Create New " + copyFrom.GetType().Name + " asset";
                            ScriptableObject asset = CreateAsset(
                                copyFrom.GetType(), copyFrom, defaultName, title);
                            if (asset != null)
                            {
                                property.objectReferenceValue = asset;
                                property.serializedObject.ApplyModifiedProperties();
                            }
                        }
                    });
                    menu.AddItem(new GUIContent("Locate"), false, ()
                                 => EditorGUIUtility.PingObject(property.objectReferenceValue));
                }

                RebuildPresetList();
                int i = 0;
                foreach (var a in mAssetPresets)
                {
                    menu.AddItem(mAssetPresetNames[i++], false, () =>
                    {
                        property.objectReferenceValue = a;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                }

                foreach (var t in mAssetTypes)
                {
                    menu.AddItem(new GUIContent("New " + InspectorUtility.NicifyClassName(t.Name)), false, () =>
                    {
                        string title           = "Create New " + t.Name + " asset";
                        ScriptableObject asset = CreateAsset(t, null, defaultName, title);
                        if (asset != null)
                        {
                            property.objectReferenceValue = asset;
                            property.serializedObject.ApplyModifiedProperties();
                        }
                    });
                }
                menu.ShowAsContext();
            }
        }
コード例 #3
0
        private void OnInspectorGUI_Map()
        {
            EditorGUILayout.Space();

            if (GUILayout.Button("Refresh Map", GUILayout.MaxWidth(125)))
            {
                tileMap.Refresh(true, true, true, true);
            }
            if (GUILayout.Button("Clear Map", GUILayout.MaxWidth(125)))
            {
                if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to clear the map?\nThis action will remove all children objects under the tilemap", "Yes", "No"))
                {
                    Undo.RegisterFullObjectHierarchyUndo(tileMap.gameObject, "Clear Map " + tileMap.name);
                    tileMap.is_undo_enabled = true;
                    tileMap.ClearMap();
                    tileMap.is_undo_enabled = false;
                }
            }

            using (new EditorGUILayoutBeginVerticalScope(EditorStyles.helpBox))
            {
                using (new EditorGUILayoutBeginHorizontalScope())
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("cell_size"));
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        serializedObject.FindProperty("cell_size").vector2Value = tileMap.tileSet.tile_pixel_size / tileMap.tileSet.pixels_per_unit;
                    }
                }
                EditorGUILayout.PropertyField(serializedObject.FindProperty("is_show_grid"), new GUIContent("is_show_grid", "Show the tilemap grid."));
            }
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(string.Format("Map Size ({0},{1})", tileMap.GridWidth, tileMap.GridHeight));

            //Display Map Bounds
            using (new EditorGUILayoutBeginVerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.LabelField("Map Bounds (in tiles):", EditorStyles.boldLabel);
                is_toggle_map_bounds_edit = EditorGUIUtil.ToggleIconButton("Edit Map Bounds", is_toggle_map_bounds_edit, EditorGUIUtility.IconContent("EditCollider"));

                float saved_label_width = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 80;
                using (new EditorGUIIndentLevelScope(2))
                {
                    using (var check = new EditorGUIBeginChangeCheckScope())
                    {
                        using (new EditorGUILayoutBeginHorizontalScope())
                        {
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("min_grid_x"), new GUIContent("Left"));
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("min_grid_y"), new GUIContent("Bottom"));
                        }
                        using (new EditorGUILayoutBeginHorizontalScope())
                        {
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("max_grid_x"), new GUIContent("Right"));
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("max_grid_y"), new GUIContent("Top"));
                        }
                        if (check.IsChanged)
                        {
                            serializedObject.ApplyModifiedProperties();
                            tileMap.RecalculateMapBounds();
                        }
                    }
                }
                EditorGUIUtility.labelWidth = saved_label_width;
            }

            EditorGUILayout.Space();

            tileMap.is_allow_painting_out_of_bounds = EditorGUILayout.ToggleLeft("is_allow_painting_out_of_bounds", tileMap.is_allow_painting_out_of_bounds);

            EditorGUILayout.Space();

            if (GUILayout.Button("Shrink to Visible Area", GUILayout.MaxWidth(150)))
            {
                tileMap.ShrinkMapBoundsToVisibleArea();
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("is_auto_shrink"));

            EditorGUILayout.Space();
            using (new EditorGUILayoutBeginVerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.LabelField("Advanced Options", EditorStyles.boldLabel);
                using (var check = new EditorGUIBeginChangeCheckScope())
                {
                    bool is_tileMapChunks_visible = IsTileMapChunksVisible();
                    is_tileMapChunks_visible = EditorGUILayout.Toggle(new GUIContent("is_tileMapChunks_visible", "Show tilemap chunk objects for debugging or other purposes. Hiding will be refreshed after collapsing the tilemap."), is_tileMapChunks_visible);
                    if (check.IsChanged)
                    {
                        SetTileMapChunkHideFlag(HideFlags.HideInHierarchy, !is_tileMapChunks_visible);
                    }
                }
                EditorGUILayout.PropertyField(serializedObject.FindProperty("is_enable_undo_while_painting"), new GUIContent("Enable Undo", "Disable Undo when painting on big maps to improve performance."));
            }
        }
コード例 #4
0
    /// <summary>
    /// Draws info box of the provided scene
    /// </summary>
    private void DrawSceneInfoGUI(Rect position, BuildUtils.BuildScene buildScene, int sceneControlID)
    {
        bool   readOnly        = BuildUtils.IsReadOnly();
        string readOnlyWarning = readOnly ? "\n\nWARNING: Build Settings is not checked out and so cannot be modified." : "";

        // Label Prefix
        GUIContent iconContent  = new GUIContent();
        GUIContent labelContent = new GUIContent();

        // Missing from build scenes
        if (buildScene.buildIndex == -1)
        {
            iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_close");
            labelContent.text    = "NOT In Build";
            labelContent.tooltip = "This scene is NOT in build settings.\nIt will be NOT included in builds.";
        }
        // In build scenes and enabled
        else if (buildScene.scene.enabled)
        {
            iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_max");
            labelContent.text    = "BuildIndex: " + buildScene.buildIndex;
            labelContent.tooltip = "This scene is in build settings and ENABLED.\nIt will be included in builds." + readOnlyWarning;
        }
        // In build scenes and disabled
        else
        {
            iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_min");
            labelContent.text    = "BuildIndex: " + buildScene.buildIndex;
            labelContent.tooltip = "This scene is in build settings and DISABLED.\nIt will be NOT included in builds.";
        }

        // Left status label
        using (new EditorGUI.DisabledScope(readOnly))
        {
            Rect labelRect = DrawUtils.GetLabelRect(position);
            Rect iconRect  = labelRect;
            iconRect.width   = iconContent.image.width + padSize;
            labelRect.width -= iconRect.width;
            labelRect.x     += iconRect.width;
            EditorGUI.PrefixLabel(iconRect, sceneControlID, iconContent);
            EditorGUI.PrefixLabel(labelRect, sceneControlID, labelContent);
        }

        // Right context buttons
        Rect buttonRect = DrawUtils.GetFieldRect(position);

        buttonRect.width = (buttonRect.width) / 3;

        string tooltipMsg = "";

        using (new EditorGUI.DisabledScope(readOnly))
        {
            // NOT in build settings
            if (buildScene.buildIndex == -1)
            {
                buttonRect.width *= 2;
                int addIndex = EditorBuildSettings.scenes.Length;
                tooltipMsg = "Add this scene to build settings. It will be appended to the end of the build scenes as buildIndex: " + addIndex + "." + readOnlyWarning;
                if (DrawUtils.ButtonHelper(buttonRect, "Add...", "Add (buildIndex " + addIndex + ")", EditorStyles.miniButtonLeft, tooltipMsg))
                {
                    BuildUtils.AddBuildScene(buildScene);
                }
                buttonRect.width /= 2;
                buttonRect.x     += buttonRect.width;
            }
            // In build settings
            else
            {
                bool   isEnabled   = buildScene.scene.enabled;
                string stateString = isEnabled ? "Disable" : "Enable";
                tooltipMsg = stateString + " this scene in build settings.\n" + (isEnabled ? "It will no longer be included in builds" : "It will be included in builds") + "." + readOnlyWarning;

                if (DrawUtils.ButtonHelper(buttonRect, stateString, stateString + " In Build", EditorStyles.miniButtonLeft, tooltipMsg))
                {
                    BuildUtils.SetBuildSceneState(buildScene, !isEnabled);
                }
                buttonRect.x += buttonRect.width;

                tooltipMsg = "Completely remove this scene from build settings.\nYou will need to add it again for it to be included in builds!" + readOnlyWarning;
                if (DrawUtils.ButtonHelper(buttonRect, "Remove...", "Remove from Build", EditorStyles.miniButtonMid, tooltipMsg))
                {
                    BuildUtils.RemoveBuildScene(buildScene);
                }
            }
        }

        buttonRect.x += buttonRect.width;

        tooltipMsg = "Open the 'Build Settings' Window for managing scenes." + readOnlyWarning;
        if (DrawUtils.ButtonHelper(buttonRect, "Settings", "Build Settings", EditorStyles.miniButtonRight, tooltipMsg))
        {
            BuildUtils.OpenBuildSettings();
        }
    }
コード例 #5
0
        private void DrawIconSpriteEditor(bool showComponents, ButtonIconSet iconSet)
        {
            if (showComponents)
            {
                EditorGUILayout.PropertyField(iconSpriteRendererProp);
            }

            Sprite currentIconSprite = null;

            if (iconQuadTextureProp.objectReferenceValue != null)
            {
                currentIconSprite = iconSpriteProp.objectReferenceValue as Sprite;
            }
            else
            {
                if (iconSpriteRendererProp.objectReferenceValue != null)
                {
                    currentIconSprite = ((SpriteRenderer)iconSpriteRendererProp.objectReferenceValue).sprite;
                }
                else
                {
                    EditorGUILayout.HelpBox("This button has no icon quad renderer assigned.", MessageType.Warning);
                    return;
                }
            }

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(iconSetProp);

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(EditorGUIUtility.IconContent("d_Refresh"), EditorStyles.miniButtonRight, GUILayout.Width(24f)))
            {
                iconSet.UpdateSpriteIconTextures();
            }
            EditorGUILayout.EndHorizontal();
            if (iconSet == null)
            {
                EditorGUILayout.HelpBox("No icon set assigned. You can specify custom icons manually by assigning them to the field below:", MessageType.Info);
                EditorGUILayout.PropertyField(iconQuadTextureProp);
                return;
            }
            if (iconSet.SpriteIcons == null || iconSet.SpriteIcons.Length == 0)
            {
                EditorGUILayout.HelpBox("No sprite icons assigned to the icon set. You can specify custom icons manually by assigning them to the field below:", MessageType.Info);
                EditorGUILayout.PropertyField(iconQuadTextureProp);
                return;
            }

            Sprite newIconSprite;
            bool   foundSprite;

            if (iconSet.EditorDrawSpriteIconSelector(currentIconSprite, out foundSprite, out newIconSprite, 1))
            {
                iconSpriteProp.objectReferenceValue = newIconSprite;
                cb.SetSpriteIcon(newIconSprite);
            }

            if (!foundSprite)
            {
                EditorGUILayout.HelpBox(missingIconWarningMessage, MessageType.Warning);
                EditorGUILayout.PropertyField(iconSpriteProp);
            }
        }
コード例 #6
0
    //内部ウィンドウ処理
    void DrawObjectFieldWindow(int id)
    {
        //IDの処理をしないとエラーが起きるので注意(デリゲートの場合はなくていい)
        int      idW   = GUIUtility.GetControlID(FocusType.Passive, _objFieldSize);
        GUIStyle style = EditorStyles.objectFieldThumb;

        style.fontSize  = 15;
        style.fontStyle = FontStyle.Bold;
        if (Event.current.type == EventType.Repaint)
        {
            if (CharacterPrefab == null)
            {
                style.Draw(_objFieldSize, new GUIContent("  CharacterObject", EditorGUIUtility.IconContent("UnityLogo").image), idW);
            }

            else if (CharacterPrefab != null)
            {
                style.Draw(_objFieldSize, new GUIContent("  " + CharacterPrefab.name, EditorGUIUtility.IconContent("PreMatCube").image), idW);
            }
        }

        //ドラッグアンドドロップ処理
        if (_objFieldSize.Contains(Event.current.mousePosition))
        {
            switch (Event.current.type)
            {
            //ドラッグ終了 = ドロップ
            case EventType.DragExited:
                DragAndDrop.activeControlID = idW;
                //ドロップしているのが参照可能なオブジェクトの場合
                if (DragAndDrop.objectReferences.Length == 1)
                {
                    var reference = DragAndDrop.objectReferences[0] as GameObject;
                    if (reference != null)
                    {
                        CharacterPrefab = reference;
                        HandleUtility.Repaint();
                        //ここでEv.Use()するとその後の処理が出来ずヒエラルキーに表示されないオブジェクトが作成されたので注意
                    }
                    HandleUtility.Repaint();
                }
                break;

            //ドラッグ中
            case EventType.DragUpdated:
            case EventType.DragPerform:

                //ドラッグしているのが参照可能なオブジェクトの場合
                if (DragAndDrop.objectReferences.Length == 1)
                {
                    //オブジェクトを受け入れる
                    DragAndDrop.AcceptDrag();
                }
                //ドラッグしているものを現在のコントロール ID と紐付ける
                DragAndDrop.activeControlID = idW;
                //カーソルの見た目を変える
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                Event.current.Use();    //
                break;
            }
        }
    }
コード例 #7
0
ファイル: TimelineWindow.cs プロジェクト: 0geova0/Jam
        public static void CreateNewTimeline()
        {
            var icon = EditorGUIUtility.IconContent("TimelineAsset Icon").image as Texture2D;

            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance <DoCreateTimeline>(), "New Timeline.playable", icon, null);
        }
コード例 #8
0
        private void OnGUI()
        {
            if (EditorApplication.isCompiling)
            {
                this.ShowNotification(new GUIContent("Compiling Scripts", EditorGUIUtility.IconContent("BuildSettings.Editor").image));
            }
            else
            {
                this.RemoveNotification();
            }



            /*
             * tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
             * tex.SetPixel(0, 0, new Color(0.55f, 0.55f, 0.55f));
             * tex.Apply();
             *
             * GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), tex, ScaleMode.StretchToFill);
             */

            // Add The Banner
            Texture2D welcomeImage     = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/SciFi_Spherical_FX/Resources/SciFiFXSphericalPack.png", typeof(Texture2D));
            Rect      welcomeImageRect = new Rect(0, 0, 512, 128);

            UnityEngine.GUI.DrawTexture(welcomeImageRect, welcomeImage);

            GUILayout.Space(20);

            GUILayout.BeginArea(new Rect(EditorGUILayout.GetControlRect().x + 10, 200, WelcomeWindowWidth - 20, WelcomeWindowHeight));

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Have fun with ''SciFi Spheric FX PACK'' !! \n", LargeTextStyle);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Subscribe to OrangedKeys Newsletter to be updated about our Next Assets Releases/Updates. \n", RegularTextStyle);
            EditorGUILayout.Space();



            // subscribe

            email = EditorGUILayout.TextField("E-mail : ", email, GUILayout.MaxWidth(480f));
            EditorGUILayout.Space();
            if (GUILayout.Button(new GUIContent(" SUBSCRIBE ", EditorGUIUtility.IconContent("TimelineClipBG").image), GUILayout.MaxWidth(480)))
            {
                SendToMailChimp(email);
            }

            // WEBSITE

            if (GUILayout.Button(new GUIContent("  www.OrangedKeys.com  ", EditorGUIUtility.IconContent("BuildSettings.Web.Small").image), GUILayout.MaxWidth(480)))
            {
                Application.OpenURL(WEB_URL);
            }

            // YOUTUBE

            if (GUILayout.Button(new GUIContent("  YouTube Channel  ", EditorGUIUtility.IconContent("Animation.Record").image), GUILayout.MaxWidth(480)))
            {
                Application.OpenURL(YOUTUBE_URL);
            }



            GUILayout.EndArea();

            Rect areaRect = new Rect(0, WelcomeWindowHeight - 20, WelcomeWindowWidth, WelcomeWindowHeight - 20);

            GUILayout.BeginArea(areaRect);
            EditorGUILayout.LabelField("Copyright © 2019 OrangedKeys", FooterTextStyle);
            GUILayout.EndArea();
        }
    static GUIContent IconContent(string name, string tooltip)
    {
        var builtinIcon = EditorGUIUtility.IconContent(name);

        return(new GUIContent(builtinIcon.image, tooltip));
    }
コード例 #10
0
        private void List_drawElementCallback(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused)
        {
            var keyValueProp = KeysValues.GetArrayElementAtIndex(index);
            var keyProp      = KeysProp.GetArrayElementAtIndex(index);
            var valueProp    = ValuesProp.GetArrayElementAtIndex(index);

            if (!selected)
            {
                Color color = Color.grey * 0.75f;
                color.a = 1;

                DrawRect(rect, color);
            }

            rect.height = lineHeight;

            Rect keyRect   = new Rect(rect.x + 50, rect.y, rect.width - 50, rect.height);
            Rect valueRect = keyRect;

            valueRect.y      = keyRect.yMax + 3;
            valueRect.x     -= 20;
            valueRect.width += 20;

            //Special case for generic types
            if (valueProp.propertyType == SerializedPropertyType.Generic)
            {
                //Key field
                keyValueProp.isExpanded = EditorGUI.Foldout(new Rect(rect.x + 15, rect.y, 20, rect.height), keyValueProp.isExpanded, idContent, true);

                GUI.SetNextControlName("CheckGenericFocus" + index);
                EditorGUI.BeginProperty(rect, GUIContent.none, keyValueProp);

                switch (keyValueProp.propertyType)
                {
                case SerializedPropertyType.Quaternion:
                    EditorGUI.BeginChangeCheck();
                    var newV4 = EditorGUI.Vector4Field(keyRect, GUIContent.none, QuaternionToVector4(keyValueProp.quaternionValue));

                    if (EditorGUI.EndChangeCheck())
                    {
                        keyValueProp.quaternionValue = ConvertToQuaternion(newV4);
                    }
                    break;

                case SerializedPropertyType.Enum:
                    string[] names       = keyValueProp.enumDisplayNames;
                    var      selectedVal = names[keyValueProp.enumValueIndex];

                    //Draw button with dropdown style
                    if (GUI.Button(keyRect, selectedVal, EditorStyles.layerMaskField))
                    {
                        GenericMenu menu = new GenericMenu();

                        //Erase the string of the values that are already being used
                        for (int i = 0; i < KeysValues.arraySize; i++)
                        {
                            var currentEnumIndex = KeysValues.GetArrayElementAtIndex(i).enumValueIndex;

                            if (selectedVal.Equals(names[currentEnumIndex]))
                            {
                                continue;
                            }

                            names[currentEnumIndex] = "";
                        }

                        //Add all the menu items
                        for (int i = 0; i < names.Length; i++)
                        {
                            int nameIndex = i;

                            //Skip the erased values
                            if (string.IsNullOrEmpty(names[nameIndex]))
                            {
                                continue;
                            }

                            menu.AddItem(new GUIContent(names[nameIndex]), selectedVal == names[nameIndex], () =>
                            {
                                keyValueProp.enumValueIndex = nameIndex;
                                keyValueProp.serializedObject.ApplyModifiedProperties();
                            });
                        }

                        //Show menu under mouse position
                        menu.ShowAsContext();

                        Event.current.Use();
                    }
                    break;

                default:
                    EditorGUI.PropertyField(keyRect, keyValueProp, GUIContent.none, false);
                    break;
                }
                EditorGUI.EndProperty();

                //Old key value
                var oldId = GetKeyValue(keyProp);
                //New key value
                var newId = GetKeyValue(keyValueProp);

                //Notify if the key is empty or null
                if ((keyProp.propertyType == SerializedPropertyType.String && string.IsNullOrEmpty(newId.ToString())) || newId == null)
                {
                    GUIContent content = EditorGUIUtility.IconContent("console.warnicon.sml");
                    content.tooltip = "ID cannot be left empty";

                    GUI.Button(new Rect(keyRect.x - 15, keyRect.y, 30, 30), content, GUIStyle.none);
                }
                //Check if the key value has been changed
                else if (!oldId.Equals(newId))
                {
                    //Be sure that the dictionary doesn't contain an element with this key
                    if (ContainsId(newId, index))
                    {
                        //Check if this key is still focused
                        if (GUI.GetNameOfFocusedControl().Equals("CheckGenericFocus" + index))
                        {
                            //Notify the user that this key already exists
                            GUIContent content = EditorGUIUtility.IconContent("console.erroricon.sml");
                            content.tooltip = "Dictionary already has this id, this id cannot be used";

                            GUI.Button(new Rect(keyRect.x - 15, keyRect.y, 30, 30), content, GUIStyle.none);
                        }
                        else
                        {
                            //If it's not set the correct key back. This is to avoid having multiple errors with ids
                            SetValue(keyValueProp, oldId);
                        }
                    }
                    else
                    {
                        //Set the value
                        SetGenericValue(keyProp, valueProp, newId);
                    }
                }

                EditorGUI.BeginChangeCheck();
                rect.y += EditorGUIUtility.singleLineHeight;
                //Value field
                if (keyValueProp.isExpanded)
                {
                    EditorGUI.BeginProperty(valueRect, GUIContent.none, valueProp);
                    if (valueProp.propertyType == SerializedPropertyType.Quaternion)
                    {
                        EditorGUI.BeginChangeCheck();
                        var newV4 = EditorGUI.Vector4Field(new Rect(rect.x + 15, rect.y, keyRect.width + 35, rect.height), GUIContent.none, QuaternionToVector4(valueProp.quaternionValue));

                        if (EditorGUI.EndChangeCheck())
                        {
                            valueProp.quaternionValue = ConvertToQuaternion(newV4);
                        }
                    }
                    else
                    {
                        EditorGUI.PropertyField(new Rect(rect.x + 15, rect.y, keyRect.width + 35, rect.height), valueProp, valueContent, true);
                    }
                    EditorGUI.EndProperty();
                }

                if (EditorGUI.EndChangeCheck())
                {
                    //This is used to apply the changes to modifier
                    ValuesProp.serializedObject.ApplyModifiedProperties();
                }
            }
            else
            {
                //Key field
                EditorGUI.BeginProperty(rect, GUIContent.none, keyValueProp);

                keyValueProp.isExpanded = EditorGUI.Foldout(new Rect(rect.x + 15, rect.y, 20, rect.height), keyValueProp.isExpanded, idContent, true);

                GUI.SetNextControlName("CheckNonGenericFocus" + index);
                switch (keyValueProp.propertyType)
                {
                case SerializedPropertyType.Quaternion:
                    EditorGUI.BeginChangeCheck();
                    var newV4 = EditorGUI.Vector4Field(keyRect, GUIContent.none, QuaternionToVector4(keyValueProp.quaternionValue));

                    if (EditorGUI.EndChangeCheck())
                    {
                        keyValueProp.quaternionValue = ConvertToQuaternion(newV4);
                    }
                    break;

                case SerializedPropertyType.Enum:
                    string[] names       = keyValueProp.enumDisplayNames;
                    var      selectedVal = names[keyValueProp.enumValueIndex];

                    //Draw button with dropdown style
                    if (GUI.Button(keyRect, selectedVal, EditorStyles.layerMaskField))
                    {
                        GenericMenu menu = new GenericMenu();

                        //Erase the string of the values that are already being used
                        for (int i = 0; i < KeysValues.arraySize; i++)
                        {
                            var currentEnumIndex = KeysValues.GetArrayElementAtIndex(i).enumValueIndex;

                            if (selectedVal.Equals(names[currentEnumIndex]))
                            {
                                continue;
                            }

                            names[currentEnumIndex] = "";
                        }

                        //Add all the menu items
                        for (int i = 0; i < names.Length; i++)
                        {
                            int nameIndex = i;

                            //Skip the erased values
                            if (string.IsNullOrEmpty(names[nameIndex]))
                            {
                                continue;
                            }

                            menu.AddItem(new GUIContent(names[nameIndex]), selectedVal == names[nameIndex], () =>
                            {
                                keyValueProp.enumValueIndex = nameIndex;
                                keyValueProp.serializedObject.ApplyModifiedProperties();
                            });
                        }

                        //Show menu under mouse position
                        menu.ShowAsContext();

                        Event.current.Use();
                    }
                    break;

                default:
                    EditorGUI.PropertyField(keyRect, keyValueProp, GUIContent.none, false);
                    break;
                }
                EditorGUI.EndProperty();

                //New key value
                var oldId = GetKeyValue(keyProp);
                var newId = GetKeyValue(keyValueProp);

                //Value field
                if (keyValueProp.isExpanded)
                {
                    valueRect.x     -= 10;
                    valueRect.width += 10;

                    EditorGUI.BeginProperty(valueRect, GUIContent.none, valueProp);

                    EditorGUI.PrefixLabel(valueRect, valueContent);
                    if (valueProp.propertyType == SerializedPropertyType.Quaternion)
                    {
                        EditorGUI.BeginChangeCheck();
                        var newV4 = EditorGUI.Vector4Field(new Rect(valueRect.x + 45, valueRect.y, valueRect.width - 45, valueRect.height), GUIContent.none, QuaternionToVector4(valueProp.quaternionValue));

                        if (EditorGUI.EndChangeCheck())
                        {
                            valueProp.quaternionValue = ConvertToQuaternion(newV4);
                        }
                    }
                    else
                    {
                        EditorGUI.PropertyField(new Rect(valueRect.x + 45, valueRect.y, valueRect.width - 45, valueRect.height), valueProp, GUIContent.none, true);
                    }
                    EditorGUI.EndProperty();
                }

                //Notify if the key is empty or null
                if (keyProp.propertyType == SerializedPropertyType.String && string.IsNullOrEmpty(newId.ToString()) || newId == null)
                {
                    GUIContent content = EditorGUIUtility.IconContent("console.warnicon.sml");
                    content.tooltip = "ID cannot be left empty";

                    GUI.Button(new Rect(keyRect.x - 15, keyRect.y, 30, 30), content, GUIStyle.none);
                }
                //Check if the key value has been changed
                else if (oldId == null || !oldId.Equals(newId))
                {
                    //Be sure that the dictionary doesn't contain an element with this key
                    if (ContainsId(newId, index))
                    {
                        //Check if this key is still focused
                        if (GUI.GetNameOfFocusedControl().Equals("CheckNonGenericFocus" + index))
                        {
                            //Notify the user that this key already exists
                            GUIContent content = EditorGUIUtility.IconContent("console.erroricon.sml");
                            content.tooltip = "Dictionary already has this id, this id cannot be used";

                            GUI.Button(new Rect(keyRect.x - 15, keyRect.y, 30, 30), content, GUIStyle.none);
                        }
                        else
                        {
                            //If it's not set the correct key back. This is to avoid having multiple errors with ids
                            SetValue(keyValueProp, oldId);
                        }
                    }
                    else
                    {
                        //Set the value
                        SetValue(keyProp, newId);
                    }
                }
            }
        }
コード例 #11
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            if (GUI.changed)
            {
                Debug.Log("Button changed");
            }
            UIEditor.DrawImage("UIButtonLabel");

            GUILayout.BeginVertical("Box");
            GUILayout.Label("UI Button Properties", UIStyle.LabelBold);
            GUILayout.BeginVertical("HelpBox");
            EditorGUI.indentLevel++;
            _openSelectable = EditorGUILayout.Foldout(_openSelectable, new GUIContent("Selectable"), true, UIStyle.FoldoutBoldMini);
            if (_openSelectable)
            {
                base.OnInspectorGUI();
            }
            EditorGUI.indentLevel--;
            GUILayout.EndVertical();

            GUILayout.EndVertical();
            GUILayout.BeginVertical("Box");
            /////////////////////////////////
            GUILayout.BeginHorizontal();
            GUILayout.Label("UI Button Actions", UIStyle.LabelBold);
            if (GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Minus"), "selectionRect"))
            {
                SetAllOpen(false);
            }
            if (GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Plus"), "selectionRect"))
            {
                SetAllOpen(true);
            }

            EditorGUILayout.EndHorizontal();
            ///////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnClick_FieldsOpen.target = GUILayout.Toggle(m_OnClick_FieldsOpen.target, "Actions On Click()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnClickActions_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnClickActions_SerializedObject.isOpen.boolValue = m_OnClick_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnClick_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnClickActions_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnClick_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            ///////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnDoubleClick_FieldsOpen.target = GUILayout.Toggle(m_OnDoubleClick_FieldsOpen.target, "Actions On Double Click()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnDoubleClick_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnDoubleClick_SerializedObject.isOpen.boolValue = m_OnDoubleClick_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnDoubleClick_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnDoubleClick_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnDoubleClick_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            ///////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnLongClick_FieldsOpen.target = GUILayout.Toggle(m_OnLongClick_FieldsOpen.target, "Actions On Long Click()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnLongClick_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnLongClick_SerializedObject.isOpen.boolValue = m_OnLongClick_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnLongClick_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnLongClick_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnLongClick_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            /////////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnPointEnter_FieldsOpen.target = GUILayout.Toggle(m_OnPointEnter_FieldsOpen.target, "Actions On Pointer Enter()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnPointerEnter_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnPointerEnter_SerializedObject.isOpen.boolValue = m_OnPointEnter_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnPointEnter_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnPointerEnter_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnPointEnter_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            /////////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnPointExit_FieldsOpen.target = GUILayout.Toggle(m_OnPointExit_FieldsOpen.target, "Actions On Pointer Exit()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnPointerExit_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnPointerExit_SerializedObject.isOpen.boolValue = m_OnPointExit_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnPointExit_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnPointerExit_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnPointExit_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            ///////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnPointDown_FieldsOpen.target = GUILayout.Toggle(m_OnPointDown_FieldsOpen.target, "Actions On Pointer Down()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnPointerDown_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnPointerDown_SerializedObject.isOpen.boolValue = m_OnPointDown_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnPointDown_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnPointerDown_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnPointDown_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            ///////////////////////////////////
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginVertical("HelpBox");
            GUI.backgroundColor = Color.white;
            EditorGUILayout.BeginHorizontal();
            m_OnPointUp_FieldsOpen.target = GUILayout.Toggle(m_OnPointUp_FieldsOpen.target, "Actions On Pointer Up()", UIStyle.ButtonMini);
            DrawActionMiniIcon(p_OnPointerUp_SerializedObject);
            EditorGUILayout.EndHorizontal();
            p_OnPointerUp_SerializedObject.isOpen.boolValue = m_OnPointUp_FieldsOpen.target;
            using (var group = new EditorGUILayout.FadeGroupScope(m_OnPointUp_FieldsOpen.faded))
            {
                if (group.visible)
                {
                    DrawActionSetup(p_OnPointerUp_SerializedObject);
                }
            }
            GUILayout.EndVertical();
            if (m_OnPointUp_FieldsOpen.target)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
            /////////////////////////////////



            GUILayout.EndVertical();
            EditorGUILayout.Space();
            serializedObject.ApplyModifiedProperties();
        }
コード例 #12
0
        protected override void OnDefaultEnable()
        {
            base.OnDefaultEnable();

            _addGC            = new GUIContent();
            _addGC.image      = EditorGUIUtility.IconContent("d_Toolbar Plus More").image;
            _addGC.tooltip    = "Add a new define";
            _removeGC         = new GUIContent();
            _removeGC.image   = EditorGUIUtility.IconContent("d_Toolbar Minus").image;
            _removeGC.tooltip = "Remove select define";

            _entityList = new ReorderableList(Target.DefineEntityNames, typeof(string), true, true, false, false);
            _entityList.elementHeight      = 45;
            _entityList.drawHeaderCallback = (Rect rect) =>
            {
                Rect sub = rect;
                sub.Set(rect.x, rect.y, 200, rect.height);
                GUI.Label(sub, "Define Entity:");

                if (!EditorApplication.isPlaying)
                {
                    sub.Set(rect.x + rect.width - 40, rect.y - 2, 20, 20);
                    if (GUI.Button(sub, _addGC, "InvisibleButton"))
                    {
                        Target.DefineEntityNames.Add("<None>");
                        Target.DefineEntityTargets.Add(null);
                        HasChanged();
                    }

                    sub.Set(rect.x + rect.width - 20, rect.y - 2, 20, 20);
                    GUI.enabled = _entityList.index >= 0 && _entityList.index < Target.DefineEntityNames.Count;
                    if (GUI.Button(sub, _removeGC, "InvisibleButton"))
                    {
                        Target.DefineEntityNames.RemoveAt(_entityList.index);
                        Target.DefineEntityTargets.RemoveAt(_entityList.index);
                        HasChanged();
                    }
                    GUI.enabled = true;
                }
            };
            _entityList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (index >= 0 && index < Target.DefineEntityNames.Count)
                {
                    Rect subrect = rect;

                    subrect.Set(rect.x, rect.y + 2, 50, 16);
                    GUI.Label(subrect, "Type");
                    if (isActive)
                    {
                        subrect.Set(rect.x + 50, rect.y + 2, rect.width - 50, 16);
                        if (GUI.Button(subrect, Target.DefineEntityNames[index], EditorGlobalTools.Styles.MiniPopup))
                        {
                            GenericMenu gm    = new GenericMenu();
                            List <Type> types = ReflectionToolkit.GetTypesInRunTimeAssemblies(type =>
                            {
                                return(type.IsSubclassOf(typeof(EntityLogicBase)) && !type.IsAbstract);
                            });
                            for (int m = 0; m < types.Count; m++)
                            {
                                int j = index;
                                int n = m;
                                if (Target.DefineEntityNames.Contains(types[n].FullName))
                                {
                                    gm.AddDisabledItem(new GUIContent(types[n].FullName));
                                }
                                else
                                {
                                    gm.AddItem(new GUIContent(types[n].FullName), Target.DefineEntityNames[j] == types[n].FullName, () =>
                                    {
                                        Target.DefineEntityNames[j] = types[n].FullName;
                                        HasChanged();
                                    });
                                }
                            }
                            gm.ShowAsContext();
                        }
                    }
                    else
                    {
                        subrect.Set(rect.x + 50, rect.y + 2, rect.width - 50, 16);
                        GUI.Label(subrect, Target.DefineEntityNames[index]);
                    }

                    subrect.Set(rect.x, rect.y + 22, 50, 16);
                    GUI.Label(subrect, "Entity");
                    subrect.Set(rect.x + 50, rect.y + 22, rect.width - 50, 16);
                    GameObject entity = EditorGUI.ObjectField(subrect, Target.DefineEntityTargets[index], typeof(GameObject), false) as GameObject;
                    if (entity != Target.DefineEntityTargets[index])
                    {
                        Target.DefineEntityTargets[index] = entity;
                        HasChanged();
                    }
                }
            };
            _entityList.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (Event.current.type == EventType.Repaint)
                {
                    GUIStyle gUIStyle = (index % 2 != 0) ? "CN EntryBackEven" : "CN EntryBackodd";
                    gUIStyle    = (!isActive && !isFocused) ? gUIStyle : "RL Element";
                    rect.x     += 2;
                    rect.width -= 6;
                    gUIStyle.Draw(rect, false, isActive, isActive, isFocused);
                }
            };
            _entityList.onReorderCallbackWithDetails = (ReorderableList list, int oldIndex, int newIndex) =>
            {
                GameObject entity = Target.DefineEntityTargets[oldIndex];
                Target.DefineEntityTargets.RemoveAt(oldIndex);
                Target.DefineEntityTargets.Insert(newIndex, entity);
                HasChanged();
            };
        }
コード例 #13
0
        void CellGUI(Rect cellRect, TreeViewItem item, ConnectionDropDownColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);
            ConnectionDropDownItem cddi = null;

            if (item is ConnectionDropDownItem downItem)
            {
                cddi = downItem;
            }

            switch (column)
            {
            case ConnectionDropDownColumns.DisplayName:
                if (cddi != null)
                {    //actual connections
                    var rect = cellRect;
                    rect.x += GetContentIndent(item) - foldoutWidth;

                    EditorGUI.BeginChangeCheck();
                    rect.width = ConnectionDropDownStyles.ToggleRectWidth;
                    var isConnected = cddi.m_Connected?.Invoke() ?? false;
                    GUI.Label(rect, (isConnected ? EditorGUIUtility.IconContent("Valid") : GUIContent.none));
                    rect.x += ConnectionDropDownStyles.ToggleRectWidth;
                    if (cddi.IsDevice)
                    {
                        EditorGUI.LabelField(new Rect(rect.x, rect.y, rowHeight, rowHeight), cddi.IconContent);
                        rect.x += rowHeight;
                    }
                    var textRect = cellRect;
                    textRect.x     = rect.x;
                    textRect.width = cellRect.width - (textRect.x - cellRect.x);

                    GUI.Label(textRect, ConnectionUIHelper.TruncateString(cddi.DisplayName, ConnectionDropDownStyles.sTVLine, textRect.width));
                    if (EditorGUI.EndChangeCheck())
                    {
                        cddi.m_OnSelected.Invoke();
                    }
                }
                else
                {
                    var r = cellRect;
                    if (item.depth <= 0)
                    {    // major group headers
                        if (args.row != 0)
                        {
                            EditorGUI.DrawRect(new Rect(r.x, r.y, args.rowRect.width, 1f), ConnectionDropDownStyles.SeparatorColor);
                        }
                        r.x    += GetContentIndent(item);
                        r.width = args.rowRect.width - GetContentIndent(item);
                        GUI.Label(r, item.displayName, EditorStyles.boldLabel);
                    }
                    else
                    {    // sub group headers
                        r.x += GetContentIndent(item);
                        EditorGUI.LabelField(new Rect(r.x, r.y, rowHeight, rowHeight), ConnectionUIHelper.GetIcon(item.displayName));
                        GUI.Label(new Rect(r.x + rowHeight, r.y, r.width - rowHeight, r.height), item.displayName, EditorStyles.miniBoldLabel);
                    }
                }
                break;

            case ConnectionDropDownColumns.ProjectName:
                if (item.depth > 1)
                {
                    DrawVerticalSeparatorLine(cellRect);
                    GUI.Label(cellRect, ConnectionUIHelper.TruncateString(cddi.ProjectName, ConnectionDropDownStyles.sTVLine, cellRect.width));
                }
                break;

            case ConnectionDropDownColumns.IP:
                if (item.depth > 1)
                {
                    DrawVerticalSeparatorLine(cellRect);
                    GUI.Label(cellRect, ConnectionUIHelper.TruncateString(cddi.IP, ConnectionDropDownStyles.sTVLine, cellRect.width));
                }
                break;

            case ConnectionDropDownColumns.Port:
                if (item.depth > 1)
                {
                    DrawVerticalSeparatorLine(cellRect);
                    GUI.Label(cellRect, ConnectionUIHelper.TruncateString(cddi.Port, ConnectionDropDownStyles.sTVLine, cellRect.width));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(column), column, null);
            }
        }
コード例 #14
0
 public static GUIContent GetIcon(string name, string tooltip)
 {
     return(new GUIContent(EditorGUIUtility.IconContent(name, tooltip).image, tooltip));
 }
コード例 #15
0
ファイル: TaskPointBase.cs プロジェクト: sambsp/HTFramework
        protected void TaskGameObjectField(ref TaskGameObject taskGameObject, string name, float nameWidth)
        {
            if (taskGameObject == null)
            {
                taskGameObject = new TaskGameObject();
            }

            GUILayout.BeginHorizontal();

            GUIContent gUIContent = new GUIContent(name);

            gUIContent.tooltip = "GUID: " + taskGameObject.GUID;
            GUILayout.Label(gUIContent, GUILayout.Width(nameWidth));

            GUI.color = taskGameObject.AgentEntity ? Color.white : Color.gray;
            GameObject newEntity = EditorGUILayout.ObjectField(taskGameObject.AgentEntity, typeof(GameObject), true, GUILayout.Width(Anchor.width - nameWidth - 35)) as GameObject;

            if (newEntity != taskGameObject.AgentEntity)
            {
                if (newEntity != null)
                {
                    TaskTarget target = newEntity.GetComponent <TaskTarget>();
                    if (!target)
                    {
                        target = newEntity.AddComponent <TaskTarget>();
                    }
                    if (target.GUID == "<None>")
                    {
                        target.GUID = Guid.NewGuid().ToString();
                    }
                    taskGameObject.AgentEntity = newEntity;
                    taskGameObject.GUID        = target.GUID;
                    taskGameObject.Path        = newEntity.transform.FullName();
                }
            }
            GUI.color = Color.white;

            if (taskGameObject.AgentEntity == null && taskGameObject.GUID != "<None>")
            {
                taskGameObject.AgentEntity = GameObject.Find(taskGameObject.Path);
                if (taskGameObject.AgentEntity == null)
                {
                    TaskTarget[] targets = FindObjectsOfType <TaskTarget>();
                    foreach (TaskTarget target in targets)
                    {
                        if (taskGameObject.GUID == target.GUID)
                        {
                            taskGameObject.AgentEntity = target.gameObject;
                            taskGameObject.Path        = target.transform.FullName();
                            break;
                        }
                    }
                }
                else
                {
                    TaskTarget target = taskGameObject.AgentEntity.GetComponent <TaskTarget>();
                    if (!target)
                    {
                        target      = taskGameObject.AgentEntity.AddComponent <TaskTarget>();
                        target.GUID = taskGameObject.GUID;
                    }
                }
            }

            gUIContent         = EditorGUIUtility.IconContent("TreeEditor.Trash");
            gUIContent.tooltip = "Delete";
            GUI.enabled        = taskGameObject.GUID != "<None>";
            if (GUILayout.Button(gUIContent, "InvisibleButton", GUILayout.Width(20), GUILayout.Height(20)))
            {
                taskGameObject.AgentEntity = null;
                taskGameObject.GUID        = "<None>";
                taskGameObject.Path        = "";
            }
            GUI.enabled = true;

            GUILayout.EndHorizontal();
        }
コード例 #16
0
        public override void OnInspectorGUI()
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            serializedObject.Update();

            var bs = NavMesh.GetSettingsByID(m_AgentTypeID.intValue);

            if (bs.agentTypeID != -1)
            {
                // Draw image
                const float diagramHeight    = 80.0f;
                Rect        agentDiagramRect = EditorGUILayout.GetControlRect(false, diagramHeight);
                NavMeshEditorHelpers.DrawAgentDiagram(agentDiagramRect, bs.agentRadius, bs.agentHeight, bs.agentClimb, bs.agentSlope);
            }
            NavMeshComponentsGUIUtility.AgentTypePopup("Agent Type", m_AgentTypeID);

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(m_CollectObjects);
            if ((CollectObjects)m_CollectObjects.enumValueIndex == CollectObjects.Volume)
            {
                EditorGUI.indentLevel++;

                EditMode.DoEditModeInspectorModeButton(EditMode.SceneViewEditMode.Collider, "Edit Volume",
                                                       EditorGUIUtility.IconContent("EditCollider"), GetBounds, this);
                EditorGUILayout.PropertyField(m_Size);
                EditorGUILayout.PropertyField(m_Center);

                EditorGUI.indentLevel--;
            }
            else
            {
                if (editingCollider)
                {
                    EditMode.QuitEditMode();
                }
            }

            EditorGUILayout.PropertyField(m_LayerMask, s_Styles.m_LayerMask);
            EditorGUILayout.PropertyField(m_UseGeometry);

            EditorGUILayout.Space();

            EditorGUILayout.Space();

            m_OverrideVoxelSize.isExpanded = EditorGUILayout.Foldout(m_OverrideVoxelSize.isExpanded, "Advanced");
            if (m_OverrideVoxelSize.isExpanded)
            {
                EditorGUI.indentLevel++;

                NavMeshComponentsGUIUtility.AreaPopup("Default Area", m_DefaultArea);

                // Override voxel size.
                EditorGUILayout.PropertyField(m_OverrideVoxelSize);

                using (new EditorGUI.DisabledScope(!m_OverrideVoxelSize.boolValue || m_OverrideVoxelSize.hasMultipleDifferentValues))
                {
                    EditorGUI.indentLevel++;

                    EditorGUILayout.PropertyField(m_VoxelSize);

                    if (!m_OverrideVoxelSize.hasMultipleDifferentValues)
                    {
                        if (!m_AgentTypeID.hasMultipleDifferentValues)
                        {
                            float voxelsPerRadius = m_VoxelSize.floatValue > 0.0f ? (bs.agentRadius / m_VoxelSize.floatValue) : 0.0f;
                            EditorGUILayout.LabelField(" ", voxelsPerRadius.ToString("0.00") + " voxels per agent radius", EditorStyles.miniLabel);
                        }
                        if (m_OverrideVoxelSize.boolValue)
                        {
                            EditorGUILayout.HelpBox("Voxel size controls how accurately the navigation mesh is generated from the level geometry. A good voxel size is 2-4 voxels per agent radius. Making voxel size smaller will increase build time.", MessageType.None);
                        }
                    }
                    EditorGUI.indentLevel--;
                }

                // Override tile size
                EditorGUILayout.PropertyField(m_OverrideTileSize);

                using (new EditorGUI.DisabledScope(!m_OverrideTileSize.boolValue || m_OverrideTileSize.hasMultipleDifferentValues))
                {
                    EditorGUI.indentLevel++;

                    EditorGUILayout.PropertyField(m_TileSize);

                    if (!m_TileSize.hasMultipleDifferentValues && !m_VoxelSize.hasMultipleDifferentValues)
                    {
                        float tileWorldSize = m_TileSize.intValue * m_VoxelSize.floatValue;
                        EditorGUILayout.LabelField(" ", tileWorldSize.ToString("0.00") + " world units", EditorStyles.miniLabel);
                    }

                    if (!m_OverrideTileSize.hasMultipleDifferentValues)
                    {
                        if (m_OverrideTileSize.boolValue)
                        {
                            EditorGUILayout.HelpBox("Tile size controls the how local the changes to the world are (rebuild or carve). Small tile size allows more local changes, while potentially generating more data in overal.", MessageType.None);
                        }
                    }
                    EditorGUI.indentLevel--;
                }


                // Height mesh
                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUILayout.PropertyField(m_BuildHeightMesh);
                }

                EditorGUILayout.Space();
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.Space();

            serializedObject.ApplyModifiedProperties();

            var hadError        = false;
            var multipleTargets = targets.Length > 1;

            foreach (NavMeshSurface2d navSurface in targets)
            {
                var settings = navSurface.GetBuildSettings();
                // Calculating bounds is potentially expensive when unbounded - so here we just use the center/size.
                // It means the validation is not checking vertical voxel limit correctly when the surface is set to something else than "in volume".
                var bounds = new Bounds(Vector3.zero, Vector3.zero);
                if (navSurface.collectObjects == CollectObjects2d.Volume)
                {
                    bounds = new Bounds(navSurface.center, navSurface.size);
                }

                var errors = settings.ValidationReport(bounds);
                if (errors.Length > 0)
                {
                    if (multipleTargets)
                    {
                        EditorGUILayout.LabelField(navSurface.name);
                    }
                    foreach (var err in errors)
                    {
                        EditorGUILayout.HelpBox(err, MessageType.Warning);
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(EditorGUIUtility.labelWidth);
                    if (GUILayout.Button("Open Agent Settings...", EditorStyles.miniButton))
                    {
                        NavMeshEditorHelpers.OpenAgentSettings(navSurface.agentTypeID);
                    }
                    GUILayout.EndHorizontal();
                    hadError = true;
                }
            }

            if (hadError)
            {
                EditorGUILayout.Space();
            }

            using (new EditorGUI.DisabledScope(Application.isPlaying || m_AgentTypeID.intValue == -1))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUIUtility.labelWidth);
                if (GUILayout.Button("Clear"))
                {
                    foreach (NavMeshSurface2d s in targets)
                    {
                        ClearSurface(s);
                    }
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button("Bake"))
                {
                    // Remove first to avoid double registration of the callback
                    EditorApplication.update -= UpdateAsyncBuildOperations;
                    EditorApplication.update += UpdateAsyncBuildOperations;

                    foreach (NavMeshSurface2d surf in targets)
                    {
                        var oper = new AsyncBakeOperation();

                        oper.bakeData      = InitializeBakeData(surf);
                        oper.bakeOperation = surf.UpdateNavMesh(oper.bakeData);
                        oper.surface       = surf;

                        s_BakeOperations.Add(oper);
                    }
                }

                GUILayout.EndHorizontal();
            }

            // Show progress for the selected targets
            for (int i = s_BakeOperations.Count - 1; i >= 0; --i)
            {
                if (!targets.Contains(s_BakeOperations[i].surface))
                {
                    continue;
                }

                var oper = s_BakeOperations[i].bakeOperation;
                if (oper == null)
                {
                    continue;
                }

                var p = oper.progress;
                if (oper.isDone)
                {
                    SceneView.RepaintAll();
                    continue;
                }

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Cancel", EditorStyles.miniButton))
                {
                    var bakeData = s_BakeOperations[i].bakeData;
                    UnityEngine.AI.NavMeshBuilder.Cancel(bakeData);
                    s_BakeOperations.RemoveAt(i);
                }

                EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(), p, "Baking: " + (int)(100 * p) + "%");
                if (p <= 1)
                {
                    Repaint();
                }

                GUILayout.EndHorizontal();
            }
        }
コード例 #17
0
 public static Texture GetUnityIcon(string iconName)
 {
     return(EditorGUIUtility.IconContent(iconName).image);
 }
コード例 #18
0
ファイル: TemplateGenerator.cs プロジェクト: malering/ET
 static Texture2D GetIcon()
 {
     return(EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D);
 }
コード例 #19
0
 private void OnEnable()
 {
     titleContent      = EditorGUIUtility.IconContent("Settings");
     titleContent.text = "Settings";
 }
コード例 #20
0
        public void EventLineGUI(Rect rect, AnimationWindowState state)
        {
            //  We only display and manipulate animation events from the main
            //  game object in selection.  If we ever want to update to handle
            //  a multiple selection, a single timeline might not be sufficient...
            AnimationClip clip     = state.activeAnimationClip;
            GameObject    animated = state.activeRootGameObject;

            GUI.BeginGroup(rect);
            Color backupCol = GUI.color;

            Rect eventLineRect = new Rect(0, 0, rect.width, rect.height);

            float mousePosTime = Mathf.Max(Mathf.RoundToInt(state.PixelToTime(Event.current.mousePosition.x, rect) * state.frameRate) / state.frameRate, 0.0f);

            // Draw events
            if (clip != null)
            {
                AnimationEvent[] events      = AnimationUtility.GetAnimationEvents(clip);
                Texture          eventMarker = EditorGUIUtility.IconContent("Animation.EventMarker").image;

                // Calculate rects
                Rect[] hitRects   = new Rect[events.Length];
                Rect[] drawRects  = new Rect[events.Length];
                int    shared     = 1;
                int    sharedLeft = 0;
                for (int i = 0; i < events.Length; i++)
                {
                    AnimationEvent evt = events[i];

                    if (sharedLeft == 0)
                    {
                        shared = 1;
                        while (i + shared < events.Length && events[i + shared].time == evt.time)
                        {
                            shared++;
                        }
                        sharedLeft = shared;
                    }
                    sharedLeft--;

                    // Important to take floor of positions of GUI stuff to get pixel correct alignment of
                    // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.
                    float keypos       = Mathf.Floor(state.FrameToPixel(evt.time * clip.frameRate, rect));
                    int   sharedOffset = 0;
                    if (shared > 1)
                    {
                        float spread = Mathf.Min((shared - 1) * (eventMarker.width - 1), (int)(state.FrameDeltaToPixel(rect) - eventMarker.width * 2));
                        sharedOffset = Mathf.FloorToInt(Mathf.Max(0, spread - (eventMarker.width - 1) * (sharedLeft)));
                    }

                    Rect r = new Rect(
                        keypos + sharedOffset - eventMarker.width / 2,
                        (rect.height - 10) * (float)(sharedLeft - shared + 1) / Mathf.Max(1, shared - 1),
                        eventMarker.width,
                        eventMarker.height);

                    hitRects[i]  = r;
                    drawRects[i] = r;
                }

                // Store tooptip info
                if (m_DirtyTooltip)
                {
                    if (m_HoverEvent >= 0 && m_HoverEvent < hitRects.Length)
                    {
                        m_InstantTooltipText  = AnimationWindowEventInspector.FormatEvent(animated, events[m_HoverEvent]);
                        m_InstantTooltipPoint = new Vector2(hitRects[m_HoverEvent].xMin + (int)(hitRects[m_HoverEvent].width / 2) + rect.x - 30, rect.yMax);
                    }
                    m_DirtyTooltip = false;
                }

                bool[] selectedEvents = new bool[events.Length];

                Object[] selectedObjects = Selection.objects;
                foreach (Object selectedObject in selectedObjects)
                {
                    AnimationWindowEvent awe = selectedObject as AnimationWindowEvent;
                    if (awe != null)
                    {
                        if (awe.eventIndex >= 0 && awe.eventIndex < selectedEvents.Length)
                        {
                            selectedEvents[awe.eventIndex] = true;
                        }
                    }
                }

                Vector2 offset = Vector2.zero;
                int     clickedIndex;
                float   startSelection, endSelection;

                // TODO: GUIStyle.none has hopping margins that need to be fixed
                HighLevelEvent hEvent = EditorGUIExt.MultiSelection(
                    rect,
                    drawRects,
                    new GUIContent(eventMarker),
                    hitRects,
                    ref selectedEvents,
                    null,
                    out clickedIndex,
                    out offset,
                    out startSelection,
                    out endSelection,
                    GUIStyle.none
                    );

                if (hEvent != HighLevelEvent.None)
                {
                    switch (hEvent)
                    {
                    case HighLevelEvent.BeginDrag:
                        m_EventsAtMouseDown = events;
                        m_EventTimes        = new float[events.Length];
                        for (int i = 0; i < events.Length; i++)
                        {
                            m_EventTimes[i] = events[i].time;
                        }
                        break;

                    case HighLevelEvent.SelectionChanged:
                        state.ClearKeySelections();
                        EditEvents(animated, clip, selectedEvents);
                        break;

                    case HighLevelEvent.Delete:
                        DeleteEvents(clip, selectedEvents);
                        break;

                    case HighLevelEvent.DoubleClick:

                        if (clickedIndex != -1)
                        {
                            EditEvents(animated, clip, selectedEvents);
                        }
                        else
                        {
                            EventLineContextMenuAdd(new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents));
                        }
                        break;

                    case HighLevelEvent.Drag:
                        for (int i = events.Length - 1; i >= 0; i--)
                        {
                            if (selectedEvents[i])
                            {
                                AnimationEvent evt = m_EventsAtMouseDown[i];
                                evt.time = m_EventTimes[i] + offset.x * state.PixelDeltaToTime(rect);
                                evt.time = Mathf.Max(0.0F, evt.time);
                                evt.time = Mathf.RoundToInt(evt.time * clip.frameRate) / clip.frameRate;
                            }
                        }
                        int[] order = new int[selectedEvents.Length];
                        for (int i = 0; i < order.Length; i++)
                        {
                            order[i] = i;
                        }
                        System.Array.Sort(m_EventsAtMouseDown, order, new EventComparer());
                        bool[]  selectedOld = (bool[])selectedEvents.Clone();
                        float[] timesOld    = (float[])m_EventTimes.Clone();
                        for (int i = 0; i < order.Length; i++)
                        {
                            selectedEvents[i] = selectedOld[order[i]];
                            m_EventTimes[i]   = timesOld[order[i]];
                        }

                        // Update selection to reflect new order.
                        EditEvents(animated, clip, selectedEvents);

                        Undo.RegisterCompleteObjectUndo(clip, "Move Event");
                        AnimationUtility.SetAnimationEvents(clip, m_EventsAtMouseDown);
                        m_DirtyTooltip = true;
                        break;

                    case HighLevelEvent.ContextClick:
                        GenericMenu menu                = new GenericMenu();
                        var         contextData         = new EventLineContextMenuObject(animated, clip, events[clickedIndex].time, clickedIndex, selectedEvents);
                        int         selectedEventsCount = selectedEvents.Count(selected => selected);

                        menu.AddItem(
                            EditorGUIUtility.TrTextContent("Add Animation Event"),
                            false,
                            EventLineContextMenuAdd,
                            contextData);
                        menu.AddItem(
                            new GUIContent(selectedEventsCount > 1 ? "Delete Animation Events" : "Delete Animation Event"),
                            false,
                            EventLineContextMenuDelete,
                            contextData);
                        menu.ShowAsContext();

                        // Mouse may move while context menu is open - make sure instant tooltip is handled
                        m_InstantTooltipText = null;
                        m_DirtyTooltip       = true;
                        state.Repaint();
                        break;
                    }
                }

                CheckRectsOnMouseMove(rect, events, hitRects);

                // Create context menu on context click
                if (Event.current.type == EventType.ContextClick && eventLineRect.Contains(Event.current.mousePosition))
                {
                    Event.current.Use();
                    // Create menu
                    GenericMenu menu                = new GenericMenu();
                    var         contextData         = new EventLineContextMenuObject(animated, clip, mousePosTime, -1, selectedEvents);
                    int         selectedEventsCount = selectedEvents.Count(selected => selected);

                    menu.AddItem(
                        EditorGUIUtility.TrTextContent("Add Animation Event"),
                        false,
                        EventLineContextMenuAdd,
                        contextData);

                    if (selectedEventsCount > 0)
                    {
                        menu.AddItem(
                            new GUIContent(selectedEventsCount > 1 ? "Delete Animation Events" : "Delete Animation Event"),
                            false,
                            EventLineContextMenuDelete,
                            contextData);
                    }

                    menu.ShowAsContext();
                }
            }

            GUI.color = backupCol;
            GUI.EndGroup();
        }
コード例 #21
0
        public override void OnInspectorGUI()
        {
            var gridPlane = target as GridPlane;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            _isEditing = GUILayout.Toggle(_isEditing, EditorGUIUtility.IconContent("EditCollider"), GUI.skin.GetStyle("Button"), GUILayout.Width(35), GUILayout.Height(25));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (_isEditing)
            {
                GUILayout.BeginHorizontal();

                var hasPlant = GUILayout.Toggle(_editingUsages.HasFlag(CellUsage.Plant), "作物", GUI.skin.button);
                if (hasPlant)
                {
                    _editingUsages |= CellUsage.Plant;
                }
                else
                {
                    _editingUsages &= ~CellUsage.Plant;
                }

                var hasBuilding = GUILayout.Toggle(_editingUsages.HasFlag(CellUsage.Building), "建筑", GUI.skin.button);
                if (hasBuilding)
                {
                    _editingUsages |= CellUsage.Building;
                }
                else
                {
                    _editingUsages &= ~CellUsage.Building;
                }

                var hasFurniture = GUILayout.Toggle(_editingUsages.HasFlag(CellUsage.Furniture), "家具", GUI.skin.button);
                if (hasFurniture)
                {
                    _editingUsages |= CellUsage.Furniture;
                }
                else
                {
                    _editingUsages &= ~CellUsage.Furniture;
                }

                GUILayout.EndHorizontal();
            }


            GUILayout.BeginHorizontal();
            GUILayout.Label("Dimension");
            var row = EditorGUILayout.IntField(gridPlane.Row, GUILayout.Width(60));

            GUILayout.Label("x", GUILayout.Width(15));
            var col = EditorGUILayout.IntField(gridPlane.Column, GUILayout.Width(60));

            GUILayout.EndHorizontal();
            if (row != gridPlane.Row || col != gridPlane.Column)
            {
                Undo.RecordObject(gridPlane, "Update Grid Dimension");
                gridPlane.UpdateDimension(row, col);
            }

            serializedObject.Update();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Cell Size");
            var cellWidth = serializedObject.FindProperty("_cellSize.x");

            cellWidth.floatValue = EditorGUILayout.IntField((int)cellWidth.floatValue, GUILayout.Width(60));
            GUILayout.Label("x", GUILayout.Width(15));
            var cellHeight = serializedObject.FindProperty("_cellSize.y");

            cellHeight.floatValue = EditorGUILayout.IntField((int)cellHeight.floatValue, GUILayout.Width(60));
            GUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();
        }
コード例 #22
0
        void SetupChildList()
        {
            float vSpace          = 2;
            float hSpace          = 3;
            float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;

            mChildList = new UnityEditorInternal.ReorderableList(
                serializedObject, FindProperty(x => x.m_ChildCameras), true, true, true, true);

            mChildList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Virtual Camera Children");
                GUIContent priorityText   = new GUIContent("Priority");
                var        textDimensions = GUI.skin.label.CalcSize(priorityText);
                rect.x    += rect.width - textDimensions.x;
                rect.width = textDimensions.x;
                EditorGUI.LabelField(rect, priorityText);
            };
            mChildList.drawElementCallback
                = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                rect.y     += vSpace;
                rect.width -= floatFieldWidth + hSpace;
                rect.height = EditorGUIUtility.singleLineHeight;
                SerializedProperty element = mChildList.serializedProperty.GetArrayElementAtIndex(index);
                if (m_ColliderState == ColliderState.ColliderOnSomeChildren ||
                    m_ColliderState == ColliderState.ColliderOnChildrenAndParent)
                {
                    bool hasCollider = ObjectHasCollider(element.objectReferenceValue);
                    if ((m_ColliderState == ColliderState.ColliderOnSomeChildren && !hasCollider) ||
                        (m_ColliderState == ColliderState.ColliderOnChildrenAndParent && hasCollider))
                    {
                        float width = rect.width;
                        rect.width = rect.height;
                        GUIContent label = new GUIContent("");
                        label.image = EditorGUIUtility.IconContent("console.warnicon.sml").image;
                        EditorGUI.LabelField(rect, label);
                        width -= rect.width; rect.x += rect.width; rect.width = width;
                    }
                }
                EditorGUI.PropertyField(rect, element, GUIContent.none);

                SerializedObject obj = new SerializedObject(element.objectReferenceValue);
                rect.x += rect.width + hSpace; rect.width = floatFieldWidth;
                SerializedProperty priorityProp = obj.FindProperty(() => Target.m_Priority);
                float oldWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = hSpace * 2;
                EditorGUI.PropertyField(rect, priorityProp, new GUIContent(" "));
                EditorGUIUtility.labelWidth = oldWidth;
                obj.ApplyModifiedProperties();
                };
            mChildList.onChangedCallback = (UnityEditorInternal.ReorderableList l) =>
            {
                if (l.index < 0 || l.index >= l.serializedProperty.arraySize)
                {
                    return;
                }
                Object o = l.serializedProperty.GetArrayElementAtIndex(
                    l.index).objectReferenceValue;
                CinemachineVirtualCameraBase vcam = (o != null)
                        ? (o as CinemachineVirtualCameraBase) : null;
                if (vcam != null)
                {
                    vcam.transform.SetSiblingIndex(l.index);
                }
            };
            mChildList.onAddCallback = (UnityEditorInternal.ReorderableList l) =>
            {
                var index = l.serializedProperty.arraySize;
                var vcam  = CinemachineMenu.CreateDefaultVirtualCamera();
                Undo.SetTransformParent(vcam.transform, Target.transform, "");
                var collider = Undo.AddComponent <CinemachineCollider>(vcam.gameObject);
                collider.m_AvoidObstacles = false;
                Undo.RecordObject(collider, "create ClearShot child");
                vcam.transform.SetSiblingIndex(index);
            };
            mChildList.onRemoveCallback = (UnityEditorInternal.ReorderableList l) =>
            {
                Object o = l.serializedProperty.GetArrayElementAtIndex(
                    l.index).objectReferenceValue;
                CinemachineVirtualCameraBase vcam = (o != null)
                        ? (o as CinemachineVirtualCameraBase) : null;
                if (vcam != null)
                {
                    Undo.DestroyObjectImmediate(vcam.gameObject);
                }
            };
        }
コード例 #23
0
        public void ObjectIconDropDown(Rect position, SerializedProperty iconProperty)
        {
            const float kDropDownArrowMargin = 2;
            const float kDropDownArrowWidth  = 12;
            const float kDropDownArrowHeight = 12;

            if (s_IconTextureInactive == null)
            {
                s_IconTextureInactive = (Material)EditorGUIUtility.LoadRequired("Inspectors/InactiveGUI.mat");
            }

            if (s_IconButtonStyle == null)
            {
                s_IconButtonStyle = new GUIStyle("IconButton")
                {
                    fixedWidth = 0, fixedHeight = 0
                }
            }
            ;

            void SelectIcon(UnityEngine.Object obj, bool isCanceled)
            {
                if (!isCanceled)
                {
                    iconProperty.objectReferenceValue = obj;
                    iconProperty.serializedObject.ApplyModifiedProperties();
                    SearchService.RefreshWindows();
                }
            }

            if (EditorGUI.DropdownButton(position, GUIContent.none, FocusType.Passive, s_IconButtonStyle))
            {
                SearchUtils.ShowIconPicker(SelectIcon);
                GUIUtility.ExitGUI();
            }

            if (Event.current.type == EventType.Repaint)
            {
                var contentPosition = position;

                contentPosition.xMin += kDropDownArrowMargin;
                contentPosition.xMax -= kDropDownArrowMargin + kDropDownArrowWidth / 2;
                contentPosition.yMin += kDropDownArrowMargin;
                contentPosition.yMax -= kDropDownArrowMargin + kDropDownArrowWidth / 2;

                Rect arrowRect = new Rect(
                    contentPosition.x + contentPosition.width - kDropDownArrowWidth / 2,
                    contentPosition.y + contentPosition.height - kDropDownArrowHeight / 2,
                    kDropDownArrowWidth, kDropDownArrowHeight);
                Texture2D icon = null;

                if (!iconProperty.hasMultipleDifferentValues)
                {
                    icon = iconProperty.objectReferenceValue as Texture2D ?? AssetPreview.GetMiniThumbnail(targets[0]);
                }
                if (icon == null)
                {
                    icon = Icons.favorite;
                }

                Vector2 iconSize = contentPosition.size;

                if (icon)
                {
                    iconSize.x = Mathf.Min(icon.width, iconSize.x);
                    iconSize.y = Mathf.Min(icon.height, iconSize.y);
                }
                Rect iconRect = new Rect(
                    contentPosition.x + contentPosition.width / 2 - iconSize.x / 2,
                    contentPosition.y + contentPosition.height / 2 - iconSize.y / 2,
                    iconSize.x, iconSize.y);

                GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit);
                if (s_IconDropDown == null)
                {
                    s_IconDropDown = EditorGUIUtility.IconContent("Icon Dropdown");
                }
                GUIStyle.none.Draw(arrowRect, s_IconDropDown, false, false, false, false);
            }
        }

        void AddProvider(ReorderableList list)
        {
            var menu = new GenericMenu();
            var disabledProviders = GetDisabledProviders().ToList();

            for (var i = 0; i < disabledProviders.Count; ++i)
            {
                var provider = disabledProviders[i];
                menu.AddItem(new GUIContent(provider.name), false, AddProvider, provider);
                if (!provider.isExplicitProvider && i + 1 < disabledProviders.Count && disabledProviders[i + 1].isExplicitProvider)
                {
                    menu.AddSeparator(string.Empty);
                }
            }
            menu.ShowAsContext();
        }

        void AddProvider(object providerObj)
        {
            if (providerObj is SearchProvider provider && !m_EnabledProviderIds.Contains(provider.id))
            {
                m_EnabledProviderIds.Add(provider.id);
                UpdateEnabledProviders();
            }
        }

        void RemoveProvider(ReorderableList list)
        {
            var index = list.index;

            if (index != -1 && index < m_EnabledProviderIds.Count)
            {
                var toRemove = SearchService.GetProvider(m_EnabledProviderIds[index]);
                if (toRemove == null)
                {
                    return;
                }
                m_EnabledProviderIds.Remove(toRemove.id);
                UpdateEnabledProviders();

                if (index >= list.count)
                {
                    list.index = list.count - 1;
                }
            }
        }

        void UpdateEnabledProviders()
        {
            m_ProvidersProperty.arraySize = m_EnabledProviderIds.Count;
            for (var i = 0; i < m_EnabledProviderIds.Count; ++i)
            {
                m_ProvidersProperty.GetArrayElementAtIndex(i).stringValue = m_EnabledProviderIds[i];
            }
            serializedObject.ApplyModifiedProperties();
            SetupContext();
        }

        void DrawProviderElement(Rect rect, int index, bool selected, bool focused)
        {
            if (index >= 0 && index < m_EnabledProviderIds.Count)
            {
                GUI.Label(rect, SearchService.GetProvider(m_EnabledProviderIds[index])?.name ?? "<unknown>");
            }
        }

        void CheckContext()
        {
            if (m_SearchContext.searchText != m_TextProperty.stringValue)
            {
                SetupContext();
            }
        }
    }
コード例 #24
0
            public Styles()
            {
                smallZoom = EditorGUIUtility.IconContent("PreTextureMipMapLow");
                largeZoom = EditorGUIUtility.IconContent("PreTextureMipMapHigh");
                alphaIcon = EditorGUIUtility.IconContent("PreTextureAlpha");
                RGBIcon   = EditorGUIUtility.IconContent("PreTextureRGB");
                playIcon  = new GUIContent(EditorGUIUtility.IconContent("d_Animation.Play"))
                {
                    tooltip = "Continuous Repaint"
                };
                                #if UNITY_2019_3_OR_NEWER
                previewButton = new GUIStyle("preButton")
                {
                    stretchHeight = true,
                    fixedHeight   = 0
                };
                scaleIcon = new GUIContent(EditorGUIUtility.IconContent(EditorGUIUtility.isProSkin ? "ScaleTool On" : "ScaleTool"))
                {
                    image = { filterMode = FilterMode.Bilinear }, tooltip = "Reset Zoom"
                };
                                #else
                previewButton = "preButton";
                scaleIcon     = new GUIContent(EditorGUIUtility.IconContent("ViewToolZoom On"))
                {
                    image = { filterMode = FilterMode.Bilinear }, tooltip = "Reset Zoom"
                };
                                #endif
                previewSlider      = "preSlider";
                previewSliderThumb = "preSliderThumb";
                previewDropDown    = "PreDropDown";

                previewButtonScale = new GUIStyle(previewButton)
                {
                    padding    = new RectOffset(0, 0, 3, 2),
                    fixedWidth = 20
                };
                previewLabel = new GUIStyle("preLabel")
                                        #if UNITY_2019_3_OR_NEWER
                ;
                if (!EditorGUIUtility.isProSkin)
                {
                    previewLabel.normal.textColor = new Color(0.22f, 0.22f, 0.22f);
                }
                                #else
                {
                    // UpperCenter centers the mip icons vertically better than MiddleCenter
                    alignment = TextAnchor.UpperCenter
                };
                                #endif
                previewButton_R = new GUIStyle(previewButton)
                {
                    padding   = new RectOffset(5, 5, 0, 0),
                    alignment = TextAnchor.MiddleCenter,
                    normal    = { textColor = new Color(1f, 0.28f, 0.33f) }
                };
                previewButton_G = new GUIStyle(previewButton_R)
                {
                    normal =
                    {
                                        #if UNITY_2019_3_OR_NEWER
                        textColor = new Color(0f,    0.698f, 0.062f)
                                        #else
                        textColor = new Color(0.45f,     1f, 0.28f)
                                        #endif
                    }
                };
                previewButton_B = new GUIStyle(previewButton_R)
                {
                    normal = { textColor = new Color(0f, 0.65f, 1f) }
                };
            }
        }
コード例 #25
0
        private void DrawSelectNameAndPlatform()
        {
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("This wizard will help you set up and register a simple extension service. MRTK Services are similar to traditional Monobehaviour singletons but with more robust access and lifecycle control. Scripts can access services through the MRTK's service provider interface. For more information about services, click the link below.", MessageType.Info);

            GUIContent buttonContent = new GUIContent();

            buttonContent.image   = EditorGUIUtility.IconContent("_Help").image;
            buttonContent.text    = " Services Documentation";
            buttonContent.tooltip = servicesDocumentationURL;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(buttonContent, GUILayout.MaxWidth(docLinkWidth)))
            {
                Application.OpenURL(servicesDocumentationURL);
            }

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

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Choose a name for your service.", EditorStyles.miniLabel);

            creator.ServiceName = EditorGUILayout.TextField("Service Name", creator.ServiceName);

            bool readyToProgress = creator.ValidateName(errors);

            foreach (string error in errors)
            {
                EditorGUILayout.HelpBox(error, MessageType.Error);
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Choose which platforms your service will support.", EditorStyles.miniLabel);

            creator.Platforms = (SupportedPlatforms)EditorGUILayout.EnumFlagsField("Platforms", creator.Platforms);
            readyToProgress  &= creator.ValidatePlatforms(errors);
            foreach (string error in errors)
            {
                EditorGUILayout.HelpBox(error, MessageType.Error);
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Choose a namespace for your service.", EditorStyles.miniLabel);

            creator.Namespace = EditorGUILayout.TextField("Namespace", creator.Namespace);
            readyToProgress  &= creator.ValidateNamespace(errors);
            foreach (string error in errors)
            {
                EditorGUILayout.HelpBox(error, MessageType.Error);
            }

            EditorGUILayout.Space();

            GUI.color = readyToProgress ? enabledColor : disabledColor;
            if (GUILayout.Button("Next") && readyToProgress)
            {
                creator.Stage = ExtensionServiceCreator.CreationStage.ChooseOutputFolders;
                creator.StoreState();
            }
        }
        public override void OnInspectorGUI()
        {
            // Ordinary properties
            base.OnInspectorGUI();

            // Pipeline - call this first
            UpdateInstanceData();

            foreach (CinemachineCore.Stage stage in Enum.GetValues(typeof(CinemachineCore.Stage)))
            {
                int index = (int)stage;

                // Skip pipeline stages that have no implementations
                if (sStageData[index].PopupOptions.Length <= 1)
                {
                    continue;
                }

                GUIStyle stageBoxStyle = GUI.skin.box;
                stageBoxStyle.margin.left = 16;
                EditorGUILayout.BeginVertical(stageBoxStyle);

                Rect rect = EditorGUILayout.GetControlRect(true);
                rect.height = EditorGUIUtility.singleLineHeight;

                GUI.enabled = !StageIsLocked(stage);
                GUIContent label = new GUIContent(NicifyName(stage.ToString()));
                if (m_stageError[index])
                {
                    label.image = EditorGUIUtility.IconContent("console.erroricon.sml").image;
                }
                int newSelection = EditorGUI.Popup(
                    rect, label, m_stageState[index], sStageData[index].PopupOptions);
                GUI.enabled = true;
                Type type = sStageData[index].types[newSelection];
                if (newSelection != m_stageState[index])
                {
                    SetPipelineStage(stage, type);
                    if (newSelection != 0)
                    {
                        sStageData[index].isExpanded = true;
                    }
                    UpdateInstanceData(); // because we changed it
                    return;
                }
                if (type != null)
                {
                    int  indentOffset = 6;
                    Rect stageRect    = new Rect(
                        rect.x - indentOffset, rect.y, rect.width + indentOffset, rect.height);
                    sStageData[index].isExpanded = EditorGUI.Foldout(
                        stageRect, sStageData[index].isExpanded, GUIContent.none);
                    if (sStageData[index].isExpanded)
                    {
                        // Make the editor for that stage
                        UnityEditor.Editor e = GetEditorForPipelineStage(stage);
                        if (e != null)
                        {
                            ++EditorGUI.indentLevel;
                            EditorGUILayout.Separator();
                            e.OnInspectorGUI();
                            EditorGUILayout.Separator();
                            --EditorGUI.indentLevel;
                        }
                    }
                }
                EditorGUILayout.EndVertical();
            }
        }
コード例 #27
0
        void OnGUI()
        {
            if (delayedNotiMsg != null)
            {
                ShowNotification(new GUIContent(delayedNotiMsg));
                delayedNotiMsg = null;
            }

            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Find Empty Dirs"))
                    {
                        Core.FillEmptyDirList(out emptyDirs);

                        if (hasNoEmptyDir)
                        {
                            ShowNotification(new GUIContent("No Empty Directory"));
                        }
                        else
                        {
                            RemoveNotification();
                        }
                    }


                    if (ColorButton("Delete All", !hasNoEmptyDir, Color.red))
                    {
                        Core.DeleteAllEmptyDirAndMeta(ref emptyDirs);
                        ShowNotification(new GUIContent("Deleted All"));
                    }
                }
                EditorGUILayout.EndHorizontal();


                bool cleanOnSave = GUILayout.Toggle(lastCleanOnSave, " Clean Empty Dirs Automatically On Save");
                if (cleanOnSave != lastCleanOnSave)
                {
                    lastCleanOnSave  = cleanOnSave;
                    Core.CleanOnSave = cleanOnSave;
                }

                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

                if (!hasNoEmptyDir)
                {
                    scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.ExpandWidth(true));
                    {
                        EditorGUILayout.BeginVertical();
                        {
#if UNITY_4_6   // and higher
                            GUIContent folderContent = EditorGUIUtility.IconContent("Folder Icon");
#else
                            GUIContent folderContent = new GUIContent();
#endif

                            foreach (var dirInfo in emptyDirs)
                            {
                                UnityEngine.Object assetObj = AssetDatabase.LoadAssetAtPath("Assets", typeof(UnityEngine.Object));
                                if (null != assetObj)
                                {
                                    folderContent.text = Core.GetRelativePath(dirInfo.FullName, Application.dataPath);
                                    GUILayout.Label(folderContent, GUILayout.Height(DIR_LABEL_HEIGHT));
                                }
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndScrollView();
                }
            }
            EditorGUILayout.EndVertical();
        }
コード例 #28
0
ファイル: TaskPointBase.cs プロジェクト: sambsp/HTFramework
        public virtual int OnPropertyGUI()
        {
            int height = 0;

            #region ID
            GUILayout.BeginHorizontal();
            GUILayout.Label("ID:", GUILayout.Width(50));
            if (_isEditID)
            {
                GUID = EditorGUILayout.TextField(GUID, GUILayout.Width(110));
            }
            else
            {
                GUILayout.Label(GUID, GUILayout.Width(110));
            }
            GUILayout.FlexibleSpace();
            if (_isSelected)
            {
                if (GUILayout.Button(EditorGUIUtility.IconContent("editicon.sml"), "IconButton"))
                {
                    _isEditID = !_isEditID;
                    GUI.FocusControl(null);
                }
            }
            GUILayout.EndHorizontal();
            #endregion

            height += 20;

            #region Name
            GUILayout.BeginHorizontal();
            GUILayout.Label("Name:", GUILayout.Width(50));
            if (_isEditName)
            {
                Name = EditorGUILayout.TextField(Name, GUILayout.Width(110));
            }
            else
            {
                GUILayout.Label(Name, GUILayout.Width(110));
            }
            GUILayout.FlexibleSpace();
            if (_isSelected)
            {
                if (GUILayout.Button(EditorGUIUtility.IconContent("editicon.sml"), "IconButton"))
                {
                    _isEditName = !_isEditName;
                    GUI.FocusControl(null);
                }
            }
            GUILayout.EndHorizontal();
            #endregion

            height += 20;

            #region Details
            GUILayout.BeginHorizontal();
            GUILayout.Label("Details:", GUILayout.Width(50));
            if (_isEditDetails)
            {
                Details = EditorGUILayout.TextField(Details, GUILayout.Width(110));
            }
            else
            {
                GUILayout.Label(Details, GUILayout.Width(110));
            }
            GUILayout.FlexibleSpace();
            if (_isSelected)
            {
                if (GUILayout.Button(EditorGUIUtility.IconContent("editicon.sml"), "IconButton"))
                {
                    _isEditDetails = !_isEditDetails;
                    GUI.FocusControl(null);
                }
            }
            GUILayout.EndHorizontal();
            #endregion

            height += 20;

            return(height);
        }
コード例 #29
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (logEntryStyle == null)
            {
                logEntryStyle = new GUIStyle(EditorStyles.helpBox)
                {
                    clipping = TextClipping.Clip,
                    wordWrap = false
                };

                logTextStyle = new GUIStyle
                {
                    wordWrap  = false,
                    clipping  = TextClipping.Clip,
                    font      = logEntryStyle.font,
                    fontSize  = logEntryStyle.fontSize,
                    fontStyle = logEntryStyle.fontStyle
                };
                logTextStyle.normal.textColor = logEntryStyle.normal.textColor;
                logTextStyle.contentOffset    = logEntryStyle.contentOffset;
                logTextStyle.padding          = logEntryStyle.padding;
                logTextStyle.richText         = true;

                elipsisStyle = new GUIStyle(logTextStyle);
                elipsisStyle.padding.left  = 0;
                elipsisStyle.contentOffset = new Vector2(0, elipsisStyle.contentOffset.y);

                DebugIcon   = EditorGUIUtility.IconContent("IN-AddComponentRight", "").image;
                InfoIcon    = EditorGUIUtility.IconContent("console.infoicon.sml", "").image;
                WarningIcon = EditorGUIUtility.IconContent("console.warnicon.sml", "").image;
                ErrorIcon   = EditorGUIUtility.IconContent("console.erroricon.sml", "").image;
                ConsoleIcon = EditorGUIUtility.IconContent("UnityEditor.ConsoleWindow", "").image;
                SendIcon    = EditorGUIUtility.IconContent("CollabPush", "").image;
                ReceiveIcon = EditorGUIUtility.IconContent("CollabPull", "").image;
            }

            label = new GUIContent(label.text, ConsoleIcon, label.tooltip);

            Rect headerRect = new Rect(position)
            {
                height = EditorGUIUtility.singleLineHeight
            };
            Rect viewRect = new Rect(position)
            {
                yMin = headerRect.yMax
            };

            if (log.Expandable)
            {
                EditorGUI.BeginChangeCheck();
                property.isExpanded = EditorGUI.Foldout(headerRect, property.isExpanded, label, true);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }

                if (!property.isExpanded)
                {
                    return;
                }
            }
            else
            {
                EditorGUI.LabelField(headerRect, label);
            }

            int elements = 0;

            if (log != null)
            {
                elements = log.Count;
            }
            foreach (var element in new UniformScrollController(viewRect, EditorGUIUtility.singleLineHeight, ref Offset, elements))
            {
                if (element.Index >= log.Count)
                {
                    continue;
                }
                DrawElement(element.Index, log[element.Index], element.Position);
            }
        }
コード例 #30
0
        public void LoadAndUpdate(FavouritesAsset favsAsset = null)
        {
            if (favsAsset != null)
            {
                asset = favsAsset;
            }

            // add root
            FavouritesTreeElement treeRoot = new FavouritesTreeElement()
            {
                ID = 0, Depth = -1, Name = "Root"
            };

            model = new TreeModel <FavouritesTreeElement>(new List <FavouritesTreeElement>()
            {
                treeRoot
            });

            // add categories
            List <FavouritesTreeElement> categories = new List <FavouritesTreeElement>();
            Texture2D icon = EditorGUIUtility.IconContent(Invoke_folderIconName).image as Texture2D;

            foreach (FavouritesCategory c in asset.categories)
            {
                FavouritesTreeElement ele = new FavouritesTreeElement()
                {
                    Name     = c.name,
                    Icon     = icon,
                    ID       = model.GenerateUniqueID(),
                    category = c
                };

                categories.Add(ele);
                model.QuickAddElement(ele, treeRoot);
            }

            // add favourites from project and scene(s)
            List <FavouritesElement> favs = new List <FavouritesElement>();

            favs.AddRange(asset.favs);

            // add from scene(s)
            foreach (FavouritesContainer c in FavouritesEd.Containers)
            {
                if (c == null || c.favs == null)
                {
                    continue;
                }
                favs.AddRange(c.favs);
            }

            // sort
            favs.Sort((a, b) =>
            {
                int r = a.categoryId.CompareTo(b.categoryId);
                if (r == 0 && a.obj != null && b.obj != null)
                {
                    r = a.obj.name.CompareTo(b.obj.name);
                }
                return(r);
            });

            // and add to tree
            foreach (FavouritesElement ele in favs)
            {
                if (ele == null || ele.obj == null)
                {
                    continue;
                }
                foreach (FavouritesTreeElement c in categories)
                {
                    if (c.category.id == ele.categoryId)
                    {
                        string     nm = ele.obj.name;
                        GameObject go = ele.obj as GameObject;
                        if (go != null && go.scene.IsValid())
                        {
                            nm = string.Format("{0} ({1})", nm, go.scene.name);
                        }
                        //else
                        //{
                        //	nm = string.Format("{0} ({1})", nm, AssetDatabase.GetAssetPath(ele.obj));
                        //}

                        icon = AssetPreview.GetMiniTypeThumbnail(ele.obj.GetType());

                        model.QuickAddElement(new FavouritesTreeElement()
                        {
                            Name = nm,
                            Icon = icon,
                            ID   = model.GenerateUniqueID(),
                            fav  = ele
                        }, c);

                        break;
                    }
                }
            }

            model.UpdateDataFromTree();
            Init(model);
            Reload();
            SetSelection(new List <int>());
        }