예제 #1
0
    ReorderableList CreateList(string listPropertyName, string listTitle)
    {
        var list = new ReorderableList(serializedObject,
                                       serializedObject.FindProperty(listPropertyName),
                                       true, true, true, true);

        list.drawHeaderCallback = (Rect rect) =>
        {
            EditorGUI.LabelField(rect, listTitle);
        };

        list.elementHeightCallback = (index) =>
        {
            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            return(3.0f * EditorGUI.GetPropertyHeight(element));
        };

        list.drawElementCallback =
            (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            rect.y += 2;

            var cellSize = rect.width / (float)propNames.Length;
            var offset   = new RectOffset(2, 5, 0, 0);
            //var dataItem = element.objectReferenceValue as System.Object as ZEventCreationData;

            //find all properties associated with the type
            int        enumIndex = element.FindPropertyRelative("eventType").enumValueIndex;
            ZEventType eType     = (ZEventType)enumIndex;
            Type       compType  = Type.GetType(eType.ToString());


            //draw
            for (int i = 0; i < propNames.Length; i++)
            {
                var cellRect = new Rect(rect.x + i * cellSize, rect.y, cellSize / 2, EditorGUIUtility.singleLineHeight);
                cellRect = offset.Remove(cellRect);
                EditorGUI.LabelField(cellRect, propNames[i]);

                cellRect = new Rect(rect.x + i * cellSize + cellSize / 2, rect.y, cellSize / 2, EditorGUIUtility.singleLineHeight);
                cellRect = offset.Remove(cellRect);
                EditorGUI.PropertyField(
                    cellRect, element.FindPropertyRelative(propNames[i]), GUIContent.none);
            }
        };

        return(list);
    }
예제 #2
0
    private void PaletteDrawOnGUI()
    {
        GUIStyle b = new GUIStyle(GUI.skin.button);

        b.normal.background = EditorGUIUtility.whiteTexture;
        Color c = GUI.color;

        for (int i = 0; i < pixelAsset.Palette.Colors.Length; i++)
        {
            int x = i % 4;
            int y = i / 4;
            GUI.color = pixelAsset.Palette.Colors[i];
            RectOffset ro = new RectOffset(1, 1, 1, 1);
            Rect       r  = new Rect(x * 16, y * 16, 16, 16);
            if (i == paletteIndex)
            {
                pixelAsset.Palette.Colors[i] = EditorGUI.ColorField(ro.Add(ro.Add(r)), GUIContent.none, pixelAsset.Palette.Colors[i], false, false, false);
            }
            else
            {
                if (GUI.Button(ro.Remove(r), EditorGUIUtility.whiteTexture, b))
                {
                    paletteIndex = i;
                }
            }
        }
    }
예제 #3
0
        private bool HandlePanelResize(Rect rect)
        {
            resizeRect.x      = lockMode == SplitMode.Vertical ? rect.x + splitterValue - barSize / 2 : rect.x;
            resizeRect.y      = lockMode == SplitMode.Vertical ? rect.y : rect.y + splitterValue - barSize / 2;
            resizeRect.width  = lockMode == SplitMode.Vertical ? barSize : rect.width;
            resizeRect.height = lockMode == SplitMode.Vertical ? rect.height : barSize;
            EditorGUIUtility.AddCursorRect(resizeRect, mouseCursor);

            float clampMax            = lockMode == SplitMode.Vertical ? rect.width - lockValues : rect.height - lockValues;
            float targetSplitterValue = lockMode == SplitMode.Vertical ? rect.width : rect.height;

            if (Event.current.type == EventType.MouseDown && resizeRect.Contains(Event.current.mousePosition))
            {
                resize = true;
            }
            if (Event.current.type == EventType.MouseUp)
            {
                resize = false;
            }
            if (resize && Event.current.type == EventType.MouseDrag)
            {
                float targetValue = lockMode == SplitMode.Vertical ? Event.current.mousePosition.x : Event.current.mousePosition.y;
                float diffValue   = lockMode == SplitMode.Vertical ? rect.width : rect.height;
                ratio = targetValue / diffValue;
            }
            else if ((Event.current.type != EventType.Layout) && (Event.current.type != EventType.used))
            {
                ratio = (targetSplitterValue * ratio) / targetSplitterValue;
            }
            splitterValue = Mathf.Clamp(targetSplitterValue * ratio, lockValues, clampMax);

            EditorGUI.DrawRect(rectOffset.Remove(resizeRect), SPLITTER_COLOR);

            return(resize);
        }
예제 #4
0
        internal virtual bool BeginNonLayout()
        {
            var isGroupValid = Parent.QueryEntry(RequestedSize.x, RequestedSize.y, out Rect requestedRect);

            if (!isGroupValid)
            {
                return(false);
            }

            // Content & container rects
            ContentRectInternal   = ContentOffset.Remove(requestedRect);
            ContainerRectInternal = ContentRectInternal.Intersection(Parent.ContainerRectInternal);

            CalculateNonLayoutData();
            return(true);
        }
예제 #5
0
    public static string CreateObjectThumbnail(GameObject obj)
    {
        var pivot = GameObject.Find("Pivot");

        if (pivot == null)
        {
            Debug.Log("Pivot object not found. Try running Initialize.");
            return("");
        }

        //turn off the UI
        var controls = GameObject.Find("Controls");

        if (controls != null)
        {
            controls.SetActive(false);
        }

        //store the orignal pivot values
        var orgPos = pivot.transform.position;
        var orgRot = pivot.transform.localRotation;

        //move pivot to obj position
        pivot.transform.position      = obj.transform.position;
        pivot.transform.localRotation = obj.transform.localRotation;

        //create the screenshot
        var dirPath = "Assets/Resources/Thumbnails";

        if (!AssetDatabase.IsValidFolder(dirPath))
        {
            AssetDatabase.CreateFolder("Assets/Resources", "Thumbnails");
        }
        var filePath = dirPath + "/" + obj.name + "_preview.png";

        Camera.main.Render();
        var       camRect = Camera.main.pixelRect;
        var       offset  = new RectOffset(10, 10, 50, 50);
        var       newRect = offset.Remove(camRect);
        Texture2D tex     = new Texture2D((int)newRect.width, (int)newRect.height, TextureFormat.ARGB32, false);

        tex.ReadPixels(newRect, 0, 0);
        tex.Apply();

        var data = tex.EncodeToPNG();

        System.IO.File.WriteAllBytes(filePath, data);
        AssetDatabase.Refresh();

        //move cam back and trun UI back on
        pivot.transform.position      = orgPos;
        pivot.transform.localRotation = orgRot;
        if (controls != null)
        {
            controls.SetActive(true);
        }

        return(filePath);
    }
예제 #6
0
    public static void SecondField(Rect drawRect, SerializedProperty prop)
    {
        RectOffset offset = new RectOffset(-(int)EditorGUIUtility.labelWidth, 0, 0, 0);

        drawRect = offset.Add(drawRect);
        EditorGUI.PropertyField(drawRect, prop, GUIContent.none);
        drawRect = offset.Remove(drawRect);
    }
예제 #7
0
        public static void Box(string content)
        {
            Rect       r      = EditorGUILayout.BeginVertical();
            RectOffset offset = new RectOffset((int)indentSpace * EditorGUI.indentLevel, 0, 0, 0);

            GUI.Box(offset.Remove(r), "");
            EditorGUILayout.LabelField(content, WordWrapItalicLabel);
            EditorGUILayout.EndVertical();
        }
예제 #8
0
        public void SetRect(Rect rect)
        {
            panelRect = rect;
            menuRect  = new Rect(panelRect.x, panelRect.y, panelRect.width, 18);

            int        padding       = 1;
            RectOffset paddingOffset = new RectOffset(padding, padding, ((int)menuRect.height) + padding, padding);

            contentRect = paddingOffset.Remove(panelRect);
        }
예제 #9
0
    static int Remove(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        RectOffset obj  = LuaScriptMgr.GetNetObject <RectOffset>(L, 1);
        Rect       arg0 = LuaScriptMgr.GetNetObject <Rect>(L, 2);
        Rect       o    = obj.Remove(arg0);

        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
        private void OnGUI()
        {
            Color backgroundColor  = new Color(0.76f, 0.87f, 0.71f);
            Color backgroundColor2 = new Color(0.62f, 0.77f, 0.9f);
            Rect  rect             = new Rect(0f, 0f, this.m_InstructionRect.width, this.m_InstructionRect.height);

            GUI.backgroundColor = backgroundColor;
            GUI.Box(rect, GUIContent.none, this.styles.solidColor);
            RectOffset padding  = this.m_InstructionStyle.padding;
            Rect       position = padding.Remove(rect);

            GUI.backgroundColor = backgroundColor2;
            GUI.Box(position, GUIContent.none, this.styles.solidColor);
        }
예제 #11
0
        private void DrawToolbar()
        {
            GUI.enabled = !EditorApplication.isCompiling;
            Rect       r      = EditorGUILayout.GetControlRect();
            RectOffset offset = new RectOffset(4, 4, 0, 0);

            GUI.Box(offset.Add(r), string.Empty, EditorStyles.toolbar);

            Rect       searchBoxRect   = new Rect(r.max.x - 200, r.min.y, 200, r.height);
            RectOffset searchBoxOffset = new RectOffset(0, 0, 2, 2);

            SearchString = EditorGUI.TextField(searchBoxOffset.Remove(searchBoxRect), SearchString, EditorStyles.toolbarTextField);
            GUI.enabled  = true;
        }
예제 #12
0
        public override void DrawContents()
        {
            base.DrawContents();

            Image.Width  = (int)ContentsBounds.width;
            Image.Height = (int)ContentsBounds.height;
            Image.Update();
            Image.Draw();

            RectOffset border = new RectOffset(2, 2, 2, 2);

            if (!Enabled)
            {
                SmartUI.DrawFillRect(border.Remove(Frame), new Color(0.4f, 0.4f, 0.4f, 0.66f));
            }
        }
예제 #13
0
    void OnPostRender()
    {
        if (doCapture)
        {
#if UNITY_EDITOR
            //create the screenshot
            var dirPath = "Assets/Resources/Thumbnails";
            if (!AssetDatabase.IsValidFolder(dirPath))
            {
                AssetDatabase.CreateFolder("Assets/Resources", "Thumbnails");
            }
            var currObj  = PageEventsManager.currentPage.gameObject;
            var filePath = dirPath + "/" + currObj.name + "_preview.png";

            var       camRect = Camera.main.pixelRect;
            var       offset  = new RectOffset(10, 10, 50, 50);
            var       newRect = offset.Remove(camRect);
            Texture2D tex     = new Texture2D((int)newRect.width, (int)newRect.height, TextureFormat.ARGB32, false);
            tex.ReadPixels(newRect, 0, 0);
            tex.Apply();

            var data = tex.EncodeToPNG();
            System.IO.File.WriteAllBytes(filePath, data);
            AssetDatabase.Refresh();

            TextureImporter importer = AssetImporter.GetAtPath(filePath) as TextureImporter;
            if (importer != null)
            {
                importer.spriteImportMode = SpriteImportMode.Single;
                importer.textureType      = TextureImporterType.Sprite;
                AssetDatabase.ImportAsset(filePath, ImportAssetOptions.ForceUpdate);
                AssetDatabase.Refresh();

                //link to page component (if available)
                Sprite preview = AssetDatabase.LoadAssetAtPath <Sprite>(filePath);
                var    page    = currObj.GetComponent <Page>();
                if (page != null && preview != null)
                {
                    page.pagePreview = preview;
                }
            }
#endif
            doCapture = false;
        }
    }
예제 #14
0
        private void HandlePanelResize(Rect rect)
        {
            Rect resizeActiveArea = new Rect(rect.x + m_SplitterValue - 8, rect.y, 16, rect.height);

            EditorGUIUtility.AddCursorRect(resizeActiveArea, MouseCursor.ResizeHorizontal);

            if (Event.current.type == EventType.MouseDown && resizeActiveArea.Contains(Event.current.mousePosition))
            {
                m_Resize = true;
            }

            if (m_Resize)
            {
                value = Event.current.mousePosition.x;
            }

            switch (m_LockMode)
            {
            case SplitLockMode.BothMinSize:
                m_SplitterValue = Mathf.Clamp(m_SplitterValue, m_LockValues.x, rect.width - m_LockValues.y);
                break;

            case SplitLockMode.LeftMinMax:
                m_SplitterValue = Mathf.Clamp(m_SplitterValue, m_LockValues.x, m_LockValues.y);
                break;

            case SplitLockMode.RightMinMax:
                m_SplitterValue = Mathf.Clamp(m_SplitterValue, rect.width - m_LockValues.y, rect.width - m_LockValues.x);
                break;

            default:
                break;
            }

            RectOffset o = new RectOffset(7, 8, 0, 0);

            EditorGUI.DrawRect(o.Remove(resizeActiveArea), new Color(0, 0, 0, 0.5f));
            if (Event.current.type == EventType.MouseUp)
            {
                m_Resize = false;
            }
        }
예제 #15
0
    public static int Remove(IntPtr l)
    {
        int result;

        try
        {
            RectOffset rectOffset = (RectOffset)LuaObject.checkSelf(l);
            Rect       rect;
            LuaObject.checkValueType <Rect>(l, 2, out rect);
            Rect rect2 = rectOffset.Remove(rect);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, rect2);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
예제 #16
0
        private void DrawMode(Rect r, string label, Texture icon)
        {
            GUIStyle labelStyle = EditorStyles.miniLabel;
            Rect     iconRect   = new Rect(r.min.x, r.min.y, r.height, r.height);
            Rect     labelRect  = new Rect(r.min.x + r.height + 1, r.min.y, r.width - r.height, r.height);

            GEditorCommon.DrawBodyBox(r);
            GEditorCommon.DrawHeaderBox(iconRect);
            if (icon != null)
            {
                GUI.color = labelStyle.normal.textColor;
                RectOffset offset = new RectOffset(3, 3, 3, 3);
                GUI.DrawTexture(offset.Remove(iconRect), icon);
                GUI.color = Color.white;
            }

            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            GUI.Label(labelRect, label, labelStyle);
            EditorGUI.indentLevel = indent;
        }
예제 #17
0
        void DrawTemplateDetails()
        {
            if (selectedTemplate.Scene != null)
            {
                GUILayout.Label(selectedTemplate.Name, Styles.detailsTitle);
                GUILayout.Space(16);
                GUILayout.Label(selectedTemplate.Description, Styles.detailsBody);
            }
            else
            {
                GUILayout.Label("No Template Selected");
            }

            GUILayout.FlexibleSpace();

            if (selectedTemplate.ScreenShot != null)
            {
                GUILayout.Box(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(180));
                Rect       r   = GUILayoutUtility.GetLastRect();
                RectOffset off = new RectOffset(6, 6, 6, 6);
                r = off.Remove(r);
                EditorGUI.DrawPreviewTexture(r, selectedTemplate.ScreenShot, null, ScaleMode.ScaleAndCrop);
            }
        }
예제 #18
0
        protected void DrawInspectedRect(Rect instructionRect)
        {
            Rect       rect          = GUILayoutUtility.GetRect((float)0f, (float)100f);
            int        top           = Mathf.CeilToInt(34f);
            int        bottom        = Mathf.CeilToInt(16f);
            int        right         = 100;
            RectOffset offset        = new RectOffset(50, right, top, bottom);
            Rect       position      = offset.Remove(rect);
            float      imageAspect   = instructionRect.width / instructionRect.height;
            Rect       outScreenRect = new Rect();
            Rect       outSourceRect = new Rect();

            GUI.CalculateScaledTextureRects(position, ScaleMode.ScaleToFit, imageAspect, ref outScreenRect, ref outSourceRect);
            position        = outScreenRect;
            position.width  = Mathf.Max(80f, position.width);
            position.height = Mathf.Max(26f, position.height);
            Rect rect5 = new Rect {
                height = 16f,
                width  = offset.left * 2,
                y      = position.y - offset.top
            };

            rect5.x = position.x - (rect5.width / 2f);
            Rect rect7 = new Rect {
                height = 16f,
                width  = offset.right * 2,
                y      = position.yMax
            };
            Rect rect6 = rect7;

            rect6.x = position.xMax - (rect6.width / 2f);
            rect7   = new Rect {
                x      = position.x,
                y      = rect5.yMax + 2f,
                width  = position.width,
                height = 16f
            };
            Rect rect8 = rect7;
            Rect rect9 = rect8;

            rect9.width = rect8.width / 3f;
            rect9.x     = rect8.x + ((rect8.width - rect9.width) / 2f);
            Rect rect10 = position;

            rect10.x     = position.xMax;
            rect10.width = 16f;
            Rect rect11 = rect10;

            rect11.height = 16f;
            rect11.width  = offset.right;
            rect11.y     += (rect10.height - rect11.height) / 2f;
            GUI.Label(rect5, $"({instructionRect.x},{instructionRect.y})", this.styles.centeredLabel);
            Handles.color = new Color(1f, 1f, 1f, 0.5f);
            Vector3 vector  = new Vector3(rect8.x, rect9.y);
            Vector3 vector2 = new Vector3(rect8.x, rect9.yMax);

            Handles.DrawLine(vector, vector2);
            vector.x = vector2.x = rect8.xMax;
            Handles.DrawLine(vector, vector2);
            vector.x  = rect8.x;
            vector.y  = vector2.y = Mathf.Lerp(vector.y, vector2.y, 0.5f);
            vector2.x = rect9.x;
            Handles.DrawLine(vector, vector2);
            vector.x  = rect9.xMax;
            vector2.x = rect8.xMax;
            Handles.DrawLine(vector, vector2);
            GUI.Label(rect9, instructionRect.width.ToString(), this.styles.centeredLabel);
            vector  = new Vector3(rect10.x, rect10.y);
            vector2 = new Vector3(rect10.xMax, rect10.y);
            Handles.DrawLine(vector, vector2);
            vector.y = vector2.y = rect10.yMax;
            Handles.DrawLine(vector, vector2);
            vector.x  = vector2.x = Mathf.Lerp(vector.x, vector2.x, 0.5f);
            vector.y  = rect10.y;
            vector2.y = rect11.y;
            Handles.DrawLine(vector, vector2);
            vector.y  = rect11.yMax;
            vector2.y = rect10.yMax;
            Handles.DrawLine(vector, vector2);
            GUI.Label(rect11, instructionRect.height.ToString());
            GUI.Label(rect6, $"({instructionRect.xMax},{instructionRect.yMax})", this.styles.centeredLabel);
            GUI.Box(position, GUIContent.none);
        }
예제 #19
0
        protected void DrawInspectedRect(Rect instructionRect)
        {
            Rect       rect        = GUILayoutUtility.GetRect(0f, 100f);
            int        top         = Mathf.CeilToInt(34f);
            int        bottom      = Mathf.CeilToInt(16f);
            int        right       = 100;
            RectOffset rectOffset  = new RectOffset(50, right, top, bottom);
            Rect       rect2       = rectOffset.Remove(rect);
            float      imageAspect = instructionRect.width / instructionRect.height;
            Rect       rect3       = default(Rect);
            Rect       rect4       = default(Rect);

            GUI.CalculateScaledTextureRects(rect2, ScaleMode.ScaleToFit, imageAspect, ref rect3, ref rect4);
            rect2        = rect3;
            rect2.width  = Mathf.Max(80f, rect2.width);
            rect2.height = Mathf.Max(26f, rect2.height);
            Rect position = default(Rect);

            position.height = 16f;
            position.width  = (float)(rectOffset.left * 2);
            position.y      = rect2.y - (float)rectOffset.top;
            position.x      = rect2.x - position.width / 2f;
            Rect position2 = new Rect
            {
                height = 16f,
                width  = (float)(rectOffset.right * 2),
                y      = rect2.yMax
            };

            position2.x = rect2.xMax - position2.width / 2f;
            Rect rect5 = new Rect
            {
                x      = rect2.x,
                y      = position.yMax + 2f,
                width  = rect2.width,
                height = 16f
            };
            Rect position3 = rect5;

            position3.width = rect5.width / 3f;
            position3.x     = rect5.x + (rect5.width - position3.width) / 2f;
            Rect rect6 = rect2;

            rect6.x     = rect2.xMax;
            rect6.width = 16f;
            Rect position4 = rect6;

            position4.height = 16f;
            position4.width  = (float)rectOffset.right;
            position4.y     += (rect6.height - position4.height) / 2f;
            GUI.Label(position, string.Format("({0},{1})", instructionRect.x, instructionRect.y), this.styles.centeredLabel);
            Handles.color = new Color(1f, 1f, 1f, 0.5f);
            Vector3 p  = new Vector3(rect5.x, position3.y);
            Vector3 p2 = new Vector3(rect5.x, position3.yMax);

            Handles.DrawLine(p, p2);
            p.x = (p2.x = rect5.xMax);
            Handles.DrawLine(p, p2);
            p.x  = rect5.x;
            p.y  = (p2.y = Mathf.Lerp(p.y, p2.y, 0.5f));
            p2.x = position3.x;
            Handles.DrawLine(p, p2);
            p.x  = position3.xMax;
            p2.x = rect5.xMax;
            Handles.DrawLine(p, p2);
            GUI.Label(position3, instructionRect.width.ToString(), this.styles.centeredLabel);
            p  = new Vector3(rect6.x, rect6.y);
            p2 = new Vector3(rect6.xMax, rect6.y);
            Handles.DrawLine(p, p2);
            p.y = (p2.y = rect6.yMax);
            Handles.DrawLine(p, p2);
            p.x  = (p2.x = Mathf.Lerp(p.x, p2.x, 0.5f));
            p.y  = rect6.y;
            p2.y = position4.y;
            Handles.DrawLine(p, p2);
            p.y  = position4.yMax;
            p2.y = rect6.yMax;
            Handles.DrawLine(p, p2);
            GUI.Label(position4, instructionRect.height.ToString());
            GUI.Label(position2, string.Format("({0},{1})", instructionRect.xMax, instructionRect.yMax), this.styles.centeredLabel);
            GUI.Box(rect2, GUIContent.none);
        }
예제 #20
0
        public static void DrawProperty(Rect position, SerializedProperty property, GUIContent label, bool isActive = false, bool isSelected = false)
        {
            SerializedProperty assetProperty      = property.FindPropertyRelative("Asset");
            SerializedProperty nameProperty       = property.FindPropertyRelative("Name");
            SerializedProperty pathProperty       = property.FindPropertyRelative("Path");
            SerializedProperty buildIndexProperty = property.FindPropertyRelative("BuildIndex");
            SerializedProperty includedProperty   = property.FindPropertyRelative("Included");
            SerializedProperty tagProperty        = property.FindPropertyRelative("Tag");

            // Set up our properties and settings
            boxOffset = EditorStyles.helpBox.padding;
            if (italicStyle == null)
            {
                italicStyle = new GUIStyle(EditorStyles.label);
            }
            bool lastMode        = EditorGUIUtility.wideMode;
            int  lastIndentLevel = EditorGUI.indentLevel;

            EditorGUIUtility.wideMode = true;
            EditorGUI.BeginProperty(position, label, property);

            GUI.color = isActive ? Color.gray : GUI.backgroundColor;
            GUI.color = isSelected ? Color.blue : GUI.backgroundColor;

            // Indent our rect, then reset indent to 0 so sub-properties don't get doubly indented
            position = EditorGUI.IndentedRect(position);
            //position.width = propertyWidth;
            EditorGUI.indentLevel = 0;

            // Draw a box around our item
            Rect boxPosition = position;

            boxPosition.height = (EditorGUIUtility.singleLineHeight * (DrawTagProperty ? 4 : 3)) - EditorGUIUtility.standardVerticalSpacing;
            GUI.Box(boxPosition, GUIContent.none, EditorStyles.helpBox);

            position = boxOffset.Remove(position);

            Rect iconRect = position;

            iconRect.width = iconWidth;

            Rect assetRect = position;

            assetRect.width  = position.width - iconWidth;
            assetRect.height = EditorGUIUtility.singleLineHeight;
            assetRect.x     += iconWidth;

            Rect buttonRect = position;

            buttonRect.height = EditorGUIUtility.singleLineHeight;
            buttonRect.y     += (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);

            Rect tagRect = position;

            tagRect.height = EditorGUIUtility.singleLineHeight;
            tagRect.y     += ((EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 2) + EditorGUIUtility.standardVerticalSpacing;

            bool changed = false;

            UnityEngine.Object asset = assetProperty.objectReferenceValue;

            if (!Application.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling)
            {   // This is expensive so don't refresh during play mode or while other stuff is going on
                changed = RefreshSceneInfo(asset, nameProperty, pathProperty, buildIndexProperty, includedProperty, tagProperty);
            }

            GUIContent labelContent = null;
            GUIContent iconContent  = null;

            italicStyle.fontStyle = FontStyle.Normal;
            bool buttonsDisabled = false;
            bool tagDisabled     = false;

            if (asset == null)
            {
                string missingSceneName = nameProperty.stringValue;
                if (!string.IsNullOrEmpty(missingSceneName))
                {
                    labelContent          = new GUIContent(" (" + missingSceneName + ")");
                    labelContent.tooltip  = "The scene " + missingSceneName + " is missing. It will not be available to load.";
                    italicStyle.fontStyle = FontStyle.Italic;
                    tagDisabled           = true;
                    iconContent           = EditorGUIUtility.IconContent(missingIconContent);
                }
                else
                {
                    labelContent         = new GUIContent(" (Empty)");
                    labelContent.tooltip = "This scene is empty. You should assign a scene object before building.";
                    buttonsDisabled      = true;
                    tagDisabled          = true;
                    iconContent          = EditorGUIUtility.IconContent(missingIconContent);
                }
            }
            else
            {
                if (includedProperty.boolValue)
                {
                    if (buildIndexProperty.intValue >= 0)
                    {
                        labelContent         = new GUIContent(" Build index: " + buildIndexProperty.intValue);
                        labelContent.tooltip = "This scene is in build settings at index " + buildIndexProperty.intValue;
                        iconContent          = EditorGUIUtility.IconContent(enabledIconContent);
                    }
                    else
                    {
                        labelContent         = new GUIContent(" (Disabled)");
                        labelContent.tooltip = "This scene is in build settings at index " + buildIndexProperty.intValue + ", but it has been disabled and will not be available to load.";
                        iconContent          = EditorGUIUtility.IconContent(disabledIconContent);
                    }
                }
                else
                {
                    labelContent         = new GUIContent(" (Not included in build)");
                    labelContent.tooltip = "This scene is not included in build settings and will not be available to load.";
                    iconContent          = EditorGUIUtility.IconContent(errorIconContent);
                }
            }

            // Draw our icon
            EditorGUI.LabelField(iconRect, iconContent);

            // Draw our object field
            EditorGUI.BeginDisabledGroup(Application.isPlaying);
            EditorGUIUtility.labelWidth = assetLabelWidth;
            asset = EditorGUI.ObjectField(assetRect, labelContent, assetProperty.objectReferenceValue, typeof(SceneAsset), false);
            EditorGUI.EndDisabledGroup();

            if (DrawTagProperty)
            {
                // Draw our tag field
                EditorGUI.BeginDisabledGroup(tagDisabled || Application.isPlaying);
                EditorGUIUtility.labelWidth = tagLabelWidth;
                changed |= EditorGUI.PropertyField(tagRect, tagProperty);
                EditorGUI.EndDisabledGroup();
            }

            // Draw our button
            EditorGUI.BeginDisabledGroup(buttonsDisabled || Application.isPlaying);
            if (!string.IsNullOrEmpty(pathProperty.stringValue) && asset == null)
            {
                // The scene is missing
                // This may be due to a local file ID mismatch
                // Try to find it based on guid first
                asset = AssetDatabase.LoadAssetAtPath <SceneAsset>(pathProperty.stringValue);
            }


            if (!string.IsNullOrEmpty(nameProperty.stringValue) && asset == null)
            {
                // If we still can't find it, draw a button that lets people attempt to recover it
                if (GUI.Button(buttonRect, "Search for missing scene", EditorStyles.toolbarButton))
                {
                    changed |= FindScene(nameProperty, pathProperty, ref asset);
                }
            }
            else
            {
                // It's not included in build settings
                if (!includedProperty.boolValue)
                {
                    // The scene exists but it isn't in our build settings
                    // Show a button that lets us add it
                    if (GUI.Button(buttonRect, "Add to build settings", EditorStyles.toolbarButton) && asset != null)
                    {
                        List <EditorBuildSettingsScene> scenes = new List <EditorBuildSettingsScene>(EditorBuildSettings.scenes);
                        scenes.Add(new EditorBuildSettingsScene(pathProperty.stringValue, true));
                        includedProperty.boolValue = true;
                        cachedScenes = scenes.ToArray();
                        EditorBuildSettings.scenes = cachedScenes;
                        changed = true;
                    }
                }
                else
                {
                    bool enabledInBuild = buildIndexProperty.intValue >= 0;
                    // The scene exists and is in build settings
                    // Show enable / disable toggle
                    if (GUI.Button(buttonRect, enabledInBuild ? "Disable in build settings" : "Enable in build settings", EditorStyles.toolbarButton))
                    {
                        enabledInBuild = !enabledInBuild;
                        // Find the scene in our build settings and enable / disable it
                        cachedScenes = EditorBuildSettings.scenes;
                        int sceneCount = 0;
                        int buildIndex = -1;
                        for (int i = 0; i < cachedScenes.Length; i++)
                        {
                            if (cachedScenes[i].path == pathProperty.stringValue)
                            {
                                cachedScenes[i].enabled = enabledInBuild;
                                if (cachedScenes[i].enabled)
                                {   // Only store the build index if it's enabled
                                    buildIndex = sceneCount;
                                }
                                break;
                            }

                            if (cachedScenes[i].enabled)
                            {   // Disabled scenes don't count toward scene count
                                sceneCount++;
                            }
                        }
                        EditorBuildSettings.scenes  = cachedScenes;
                        buildIndexProperty.intValue = buildIndex;
                        changed = true;
                    }
                }
            }
            EditorGUI.EndDisabledGroup();

            if (asset != assetProperty.objectReferenceValue)
            {
                assetProperty.objectReferenceValue = asset;
                changed = true;
            }

            if (changed)
            {
                property.serializedObject.ApplyModifiedProperties();
            }

            EditorGUIUtility.wideMode = lastMode;
            EditorGUI.indentLevel     = lastIndentLevel;
            EditorGUI.EndProperty();
        }
예제 #21
0
        protected void DrawInspectedRect(Rect instructionRect)
        {
            var totalRect = GUILayoutUtility.GetRect(0, 100);

            var reserveTopFieldHeight    = Mathf.CeilToInt(EditorGUI.kSingleLineHeight * 2 + EditorGUI.kControlVerticalSpacing);
            var reserveBottomFieldHeight = Mathf.CeilToInt(EditorGUI.kSingleLineHeight);
            var reserveFieldWidth        = 100;
            var fieldsArea = new RectOffset(50, reserveFieldWidth, reserveTopFieldHeight, reserveBottomFieldHeight);
            var visualRect = fieldsArea.Remove(totalRect);

            float aspectRatio  = instructionRect.width / instructionRect.height;
            var   aspectedRect = new Rect();
            var   dummy        = new Rect();

            GUI.CalculateScaledTextureRects(visualRect, ScaleMode.ScaleToFit, aspectRatio, ref aspectedRect, ref dummy);
            visualRect        = aspectedRect;
            visualRect.width  = Mathf.Max(80, visualRect.width);
            visualRect.height = Mathf.Max(EditorGUI.kSingleLineHeight + 10, visualRect.height);

            var startPointFieldRect = new Rect {
                height = EditorGUI.kSingleLineHeight, width = fieldsArea.left * 2, y = visualRect.y - fieldsArea.top
            };

            startPointFieldRect.x = visualRect.x - startPointFieldRect.width / 2f;

            var endPointFieldRect = new Rect
            {
                height = EditorGUI.kSingleLineHeight,
                width  = fieldsArea.right * 2,
                y      = visualRect.yMax
            };

            endPointFieldRect.x = visualRect.xMax - endPointFieldRect.width / 2f;

            var widthMarkersArea = new Rect
            {
                x      = visualRect.x,
                y      = startPointFieldRect.yMax + EditorGUI.kControlVerticalSpacing,
                width  = visualRect.width,
                height = EditorGUI.kSingleLineHeight
            };

            var widthFieldRect = widthMarkersArea;

            widthFieldRect.width = widthMarkersArea.width / 3;
            widthFieldRect.x     = widthMarkersArea.x + (widthMarkersArea.width - widthFieldRect.width) / 2f;

            var heightMarkerArea = visualRect;

            heightMarkerArea.x     = visualRect.xMax;
            heightMarkerArea.width = EditorGUI.kSingleLineHeight;

            var heightFieldRect = heightMarkerArea;

            heightFieldRect.height = EditorGUI.kSingleLineHeight;
            heightFieldRect.width  = fieldsArea.right;
            heightFieldRect.y      = heightFieldRect.y + (heightMarkerArea.height - heightFieldRect.height) / 2f;

            //Draw TopLeft point
            GUI.Label(startPointFieldRect, UnityString.Format("({0},{1})", instructionRect.x, instructionRect.y), Styles.centeredLabel);

            Handles.color = new Color(1, 1, 1, 0.5f);
            //Draw Width markers and value
            var startP = new Vector3(widthMarkersArea.x, widthFieldRect.y);
            var endP   = new Vector3(widthMarkersArea.x, widthFieldRect.yMax);

            Handles.DrawLine(startP, endP);

            startP.x = endP.x = widthMarkersArea.xMax;
            Handles.DrawLine(startP, endP);

            startP.x = widthMarkersArea.x;
            startP.y = endP.y = Mathf.Lerp(startP.y, endP.y, .5f);
            endP.x   = widthFieldRect.x;
            Handles.DrawLine(startP, endP);

            startP.x = widthFieldRect.xMax;
            endP.x   = widthMarkersArea.xMax;
            Handles.DrawLine(startP, endP);

            GUI.Label(widthFieldRect, instructionRect.width.ToString(CultureInfo.InvariantCulture), Styles.centeredLabel);

            //Draw Height markers and value
            startP = new Vector3(heightMarkerArea.x, heightMarkerArea.y);
            endP   = new Vector3(heightMarkerArea.xMax, heightMarkerArea.y);
            Handles.DrawLine(startP, endP);

            startP.y = endP.y = heightMarkerArea.yMax;
            Handles.DrawLine(startP, endP);

            startP.x = endP.x = Mathf.Lerp(startP.x, endP.x, .5f);
            startP.y = heightMarkerArea.y;
            endP.y   = heightFieldRect.y;
            Handles.DrawLine(startP, endP);

            startP.y = heightFieldRect.yMax;
            endP.y   = heightMarkerArea.yMax;
            Handles.DrawLine(startP, endP);

            GUI.Label(heightFieldRect, instructionRect.height.ToString(CultureInfo.InvariantCulture));

            GUI.Label(endPointFieldRect, UnityString.Format("({0},{1})", instructionRect.xMax, instructionRect.yMax), Styles.centeredLabel);

            //Draws the rect
            GUI.Box(visualRect, GUIContent.none);
        }
예제 #22
0
 public static Rect BoxedRect(Rect rect, RectOffset offset, BackgroundStyle style)
 {
     rect = offset.Add(rect);
     DrawBackground(rect, style);
     return(offset.Remove(rect));
 }
예제 #23
0
    /**
     * Calculate UV of given position on a rendered texture given the border.
     * Returned value is [(0,0)..(textureWidth,textureHeight)].
     */
    public static Vector2 PixelToUV(Rect drawRect, Rect textureRect, Vector2 position, RectOffset border = null)
    {
        position  -= drawRect.min;
        drawRect.x = 0;
        drawRect.y = 0;

        if ((border == null) || border.IsZero())
        {
            if ((drawRect.width == 0f) || (drawRect.height == 0f))
            {
                return(Vector2.zero);
            }
            Vector2 result = new Vector2();

            result.x = textureRect.x + (position.x / drawRect.width * textureRect.width);
            result.y = textureRect.y + (position.y / drawRect.height * textureRect.height);

            return(result);
        }

        Rect innerRect    = border.Remove(drawRect);
        Rect innerTexture = border.Remove(textureRect);

        float x;
        float y;

        if (position.x <= innerRect.xMin)
        {
            x = position.x;
        }
        else if (position.x >= innerRect.xMax)
        {
            x = (textureRect.xMax - (drawRect.width - position.x));
        }
        else
        {
            if (innerRect.width == 0)
            {
                x = innerTexture.xMin;
            }
            else
            {
                x = ((position.x - innerRect.xMin) / innerRect.width) * innerTexture.width + innerTexture.xMin;
            }
        }

        if (position.y <= innerRect.yMin)
        {
            y = position.y;
        }
        else if (position.y >= innerRect.yMax)
        {
            y = (textureRect.yMax - (drawRect.yMax - position.y));
        }
        else
        {
            if (innerRect.height == 0)
            {
                y = innerTexture.yMin;
            }
            else
            {
                y = ((position.y - innerRect.yMin) / innerRect.height) * innerTexture.height + innerTexture.yMin;
            }
        }

        return(new Vector2(x, y));
    }