コード例 #1
0
        public bool Inspect()
        {
            bool changed = false;


            if (dataExplorer.inspectedTag == -1)
            {
                this.inspect_Name();
                if (Cfg != null && dataExplorer.tag.Length > 0 && icon.Save.Click("Save To Assets", ref changed))
                {
                    QcFile.SaveUtils.SaveBytesToAssetsByRelativePath(Mgmt.fileFolderHolder, dataExplorer.tag, dataExplorer.data);
                    QcUnity.RefreshAssetDatabase();
                }

                pegi.nl();

                if (Cfg != null)
                {
                    if (dataExplorer.tag.Length == 0)
                    {
                        dataExplorer.tag = Cfg.GetNameForInspector() + " config";
                    }

                    "Save To:".edit(50, ref Mgmt.fileFolderHolder).changes(ref changed);

                    var uObj = Cfg as UnityEngine.Object;

                    if (uObj && icon.Done.Click("Use the same directory as current object.", ref changed))
                    {
                        Mgmt.fileFolderHolder = QcUnity.GetAssetFolder(uObj);
                    }

                    uObj.ClickHighlight().nl(ref changed);
                }


                "Comment:".editBig(ref comment).nl(ref changed);
            }

            dataExplorer.Nested_Inspect().changes(ref changed);

            return(changed);
        }
コード例 #2
0
ファイル: RoundedGraphic.cs プロジェクト: Vytek/Tools
        public bool Inspect()
        {
            inspected = this;

            pegi.toggleDefaultInspector(this);

            info.fullWindowDocumentationClickOpen("About Rounded Graphic").nl();

            var mat = material;

            var can = canvas;

            var shad = mat.shader;

            var changed = false;

            var expectedScreenPosition = false;

            var expectedAtlasedPosition = false;

            if (!_showModules)
            {
                bool gotPixPerfTag = false;

                bool mayBeDefaultMaterial = true;

                bool expectingPosition = false;

                bool possiblePositionData = false;

                bool possibleFadePosition = false;

                bool needThirdUv = false;

                #region Material Tags
                if (mat)
                {
                    var pixPfTag = mat.Get(ShaderTags.PixelPerfectUi);

                    gotPixPerfTag = !pixPfTag.IsNullOrEmpty();

                    if (!gotPixPerfTag)
                    {
                        "{0} doesn't have {1} tag".F(shad.name, ShaderTags.PixelPerfectUi.NameForDisplayPEGI()).writeWarning();
                    }
                    else
                    {
                        mayBeDefaultMaterial = false;

                        expectedScreenPosition = pixPfTag.Equals(ShaderTags.PixelPerfectUis.Position.NameForDisplayPEGI());

                        if (!expectedScreenPosition)
                        {
                            expectedAtlasedPosition = pixPfTag.Equals(ShaderTags.PixelPerfectUis.AtlasedPosition.NameForDisplayPEGI());

                            if (!expectedAtlasedPosition)
                            {
                                possibleFadePosition = pixPfTag.Equals(ShaderTags.PixelPerfectUis.FadePosition.NameForDisplayPEGI());
                            }
                        }

                        needThirdUv = expectedAtlasedPosition || (possibleFadePosition && feedPositionData);

                        expectingPosition = expectedAtlasedPosition || expectedScreenPosition;

                        possiblePositionData = expectingPosition || possibleFadePosition;

                        if (!can)
                        {
                            "No Canvas".writeWarning();
                        }
                        else
                        {
                            if ((can.additionalShaderChannels & AdditionalCanvasShaderChannels.TexCoord1) == 0)
                            {
                                "Material requires Canvas to pass Edges data trough Texture Coordinate 1 data channel"
                                .writeWarning();
                                if ("Fix Canvas Texture Coordinate 1".Click().nl())
                                {
                                    can.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord1;
                                }
                            }

                            if (possiblePositionData && feedPositionData)
                            {
                                if ((can.additionalShaderChannels & AdditionalCanvasShaderChannels.TexCoord2) == 0)
                                {
                                    "Material requires Canvas to pass Position Data trough Texcoord2 channel"
                                    .writeWarning();
                                    if ("Fix Canvas ".Click().nl())
                                    {
                                        can.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord2;
                                    }
                                }
                                else if (needThirdUv && (can.additionalShaderChannels & AdditionalCanvasShaderChannels.TexCoord3) == 0)
                                {
                                    "Material requires Canvas to pass Texoord3 channel".writeWarning();
                                    if ("Fix Canvas".Click().nl())
                                    {
                                        can.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord3;
                                    }
                                }
                            }

                            if (can.renderMode == RenderMode.WorldSpace)
                            {
                                "Rounded UI isn't always working on world space UI yet.".writeWarning();
                                if ("Change to Overlay".Click())
                                {
                                    can.renderMode = RenderMode.ScreenSpaceOverlay;
                                }
                                if ("Change to Camera".Click())
                                {
                                    can.renderMode = RenderMode.ScreenSpaceCamera;
                                }
                                pegi.nl();
                            }
                        }
                    }
                }
                #endregion

                var linked = LinkedCorners;

                if (mat && (linked == mat.IsKeywordEnabled(UNLINKED_VERTICES)))
                {
                    mat.SetShaderKeyword(UNLINKED_VERTICES, !linked);
                }

                if (pegi.toggle(ref linked, icon.Link, icon.UnLinked).changes(ref changed))
                {
                    LinkedCorners = linked;
                }

                for (var i = 0; i < _roundedCorners.Length; i++)
                {
                    var crn = _roundedCorners[i];

                    if ("Corner{0}".F(linked ? "s" : (" " + i)).edit(70, ref crn, 0, 1f).nl(ref changed))
                    {
                        _roundedCorners[i] = crn;
                    }
                }

                pegi.nl();

                if (mat)
                {
                    var needLink = ShaderTags.PerEdgeData.Get(mat);
                    if (!needLink.IsNullOrEmpty())
                    {
                        if (ShaderTags.PerEdgeRoles.LinkedCourners.Equals(needLink))
                        {
                            if (!linked)
                            {
                                "Material expects edge data to be linked".writeWarning();
                                if ("FIX".Click(ref changed))
                                {
                                    LinkedCorners = true;
                                }
                            }
                        }
                        else
                        {
                            if (linked)
                            {
                                "Material expects edge data to be Unlinked".writeWarning();
                                if ("FIX".Click(ref changed))
                                {
                                    LinkedCorners = false;
                                }
                            }
                        }
                    }
                }

                pegi.nl();

                QcUnity.RemoveEmpty(_compatibleMaterials);

                if (mat && gotPixPerfTag)
                {
                    _compatibleMaterials.AddIfNew(mat);
                }

                bool showingSelection = false;

                var cmpCnt = _compatibleMaterials.Count;
                if (cmpCnt > 0 && ((cmpCnt > 1) || (!_compatibleMaterials[0].Equals(mat))))
                {
                    showingSelection = true;

                    if (pegi.select(ref mat, _compatibleMaterials, allowInsert: !mayBeDefaultMaterial))
                    {
                        material = mat;
                    }
                }

                if (mat)
                {
                    if (!Application.isPlaying)
                    {
                        var path = QcUnity.GetAssetFolder(mat);
                        if (path.IsNullOrEmpty())
                        {
                            pegi.nl();
                            "Material is not saved as asset. Click COPY next to it to save as asset. Or Click 'Refresh' to find compatible materials in your assets ".writeHint();
                            pegi.nl();
                        }
                        else
                        {
                            mayBeDefaultMaterial = false;
                        }
                    }

                    if (!showingSelection && !mayBeDefaultMaterial)
                    {
                        var n = mat.name;
                        if ("Rename Material".editDelayed("Press Enter to finish renaming.", 120, ref n))
                        {
                            mat.RenameAsset(n);
                        }
                    }
                }

                if (pegi.edit(ref mat, 60).changes(ref changed) ||
                    (!Application.isPlaying && pegi.ClickDuplicate(ref mat, gameObject.name).changes(ref changed)))
                {
                    material = mat;
                    if (mat)
                    {
                        _compatibleMaterials.AddIfNew(mat);
                    }
                }

                if (!Application.isPlaying && icon.Refresh.Click("Find All Compatible Materials in Assets"))
                {
                    _compatibleMaterials = ShaderTags.PixelPerfectUi.GetTaggedMaterialsFromAssets();
                }


                pegi.nl();

                if (mat && !mayBeDefaultMaterial)
                {
                    if (shad)
                    {
                        shad.ClickHighlight();
                    }

                    if ("Shaders".select(60, ref shad, CompatibleShaders, false, true).changes(ref changed))
                    {
                        mat.shader = shad;
                    }

                    var sTip = mat.Get(QuizCannersUtilities.ShaderTags.ShaderTip);

                    if (!sTip.IsNullOrEmpty())
                    {
                        sTip.fullWindowDocumentationClickOpen("Tip from shader tag");
                    }

                    if (icon.Refresh.Click("Refresh compatible Shaders list"))
                    {
                        _compatibleShaders = null;
                    }
                }

                pegi.nl();

                var col = color;
                if (pegi.edit(ref col).nl(ref changed))
                {
                    color = col;
                }

                #region Position Data

                if (possiblePositionData || feedPositionData)
                {
                    "Position Data".toggleIcon(ref feedPositionData, true).changes(ref changed);

                    if (feedPositionData)
                    {
                        "Position: ".editEnum(60, ref _positionDataType).changes(ref changed);

                        "Shaders that use position data often don't look right in the scene view."
                        .fullWindowDocumentationClickOpen("Camera dependancy warning");

                        pegi.nl();
                    }
                    else if (expectingPosition)
                    {
                        "Shader expects Position data".writeWarning();
                    }

                    if (gotPixPerfTag)
                    {
                        if (feedPositionData)
                        {
                            switch (_positionDataType)
                            {
                            case PositionDataType.ScreenPosition:

                                if (expectedAtlasedPosition)
                                {
                                    "Shader is expecting Atlased Position".writeWarning();
                                }

                                break;

                            case PositionDataType.AtlasPosition:
                                if (expectedScreenPosition)
                                {
                                    "Shader is expecting Screen Position".writeWarning();
                                }
                                else if (sprite && sprite.packed)
                                {
                                    if (sprite.packingMode == SpritePackingMode.Tight)
                                    {
                                        "Tight Packing is not supported by rounded UI".writeWarning();
                                    }
                                    else if (sprite.packingRotation != SpritePackingRotation.None)
                                    {
                                        "Packing rotation is not supported by Rounded UI".writeWarning();
                                    }
                                }

                                break;

                            case PositionDataType.FadeOutPosition:

                                "Fade out at".edit(ref faeOutUvPosition).nl(ref changed);

                                break;
                            }
                        }
                    }

                    pegi.nl();
                }

                if (gotPixPerfTag && feedPositionData)
                {
                    if (!possiblePositionData)
                    {
                        "Shader doesn't have any PixelPerfectUI Position Tags. Position updates may not be needed".writeWarning();
                    }
                    else
                    {
                        pegi.nl();

                        /*
                         * if (rectTransform.pivot != Vector2.one * 0.5f)
                         * {
                         *  "Pivot is expected to be in the center for position processing to work".writeWarning();
                         *  pegi.nl();
                         *  if ("Set Pivot to 0.5,0.5".Click().nl(ref changed))
                         *      rectTransform.SetPivotTryKeepPosition(Vector2.one * 0.5f);
                         * }
                         *
                         * if (rectTransform.localScale != Vector3.one)
                         * {
                         *  "Scale deformation can interfear with some shaders that use position".writeWarning();
                         *  pegi.nl();
                         *  if ("Set local scale to 1".Click().nl(ref changed))
                         *      rectTransform.localScale = Vector3.one;
                         * }
                         *
                         * if (rectTransform.localRotation != Quaternion.identity)
                         * {
                         *  "Rotation can compromise calculations in shaders that need position".writeWarning();
                         *  if ("Reset Rotation".Click().nl(ref changed))
                         *      rectTransform.localRotation = Quaternion.identity;
                         *
                         * }*/
                    }

                    // if (_positionDataType == PositionDataType.AtlasPosition) {
                    //  "UV:".edit(ref atlasedUVs).nl(ref changed);
                    //   pegi.edit01(ref atlasedUVs).nl(ref changed);
                    // }
                }

                #endregion

                var rt = raycastTarget;
                if ("Click-able".toggleIcon("Is RayCast Target", ref rt).nl(ref changed))
                {
                    raycastTarget = rt;
                }

                if (rt)
                {
                    "On Click".edit_Property(() => OnClick, this).nl(ref changed);
                }

                var spriteTag = mat ? mat.Get(ShaderTags.SpriteRole) : null;

                var noTag = spriteTag.IsNullOrEmpty();

                if (noTag || !spriteTag.SameAs(ShaderTags.SpriteRoles.Hide.NameForDisplayPEGI()))
                {
                    if (noTag)
                    {
                        spriteTag = "Sprite";
                    }

                    var sp = sprite;
                    if (spriteTag.edit(90, ref sp).changes(ref changed))
                    {
                        sprite = sp;
                    }

                    if (sp)
                    {
                        var tex = sp.texture;

                        var rct = SpriteRect;

                        if (tex && (rct.width != rectTransform.rect.width || rct.height != rectTransform.rect.height) &&
                            icon.Size.Click("Set Native Size").nl())
                        {
                            rectTransform.sizeDelta = SpriteRect.size;
                            this.SetToDirty();
                        }
                    }

                    pegi.nl();
                }
            }

            if ("Modules".enter_List(ref _modules, ref _inspectedModule, ref _showModules).nl(ref changed))
            {
                this.SaveCfgData();
            }



            if (changed)
            {
                SetVerticesDirty();
            }

            return(changed);
        }