Beispiel #1
0
        public static bool DestroyOBJBtn <T>(T obj, string fieldName, params GUILayoutOption[] options) where T : class
        {
            bool bResult = false;

            if (obj != null)
            {
                CustomEditorGUI.DrawSeperator();
                EditorGUILayout.ObjectField(fieldName, obj as Object, typeof(T), allowSceneObjects: true);
                if (GUILayout.Button("Destroy", options))
                {
                    Object.DestroyImmediate(obj as Object);
                    bResult = true;
                }
                GUILayout.Space(8);
            }
            return(bResult);
        }
        public static void Iso2DObjectField(SerializedObject _Iso2DSerializedObject)
        {
            _Iso2DSerializedObject.Update();

            SerializedProperty vScaler  = _Iso2DSerializedObject.FindProperty("localScale");
            SerializedProperty vRotator = _Iso2DSerializedObject.FindProperty("localRotation");

            Iso2DObject    _Iso2D      = (Iso2DObject)_Iso2DSerializedObject.targetObject;
            IsoTile        _parentTile = _Iso2D.GetComponentInParent <IsoTile>();
            SpriteRenderer sprr        = _Iso2D.GetComponent <SpriteRenderer>();

            //_Iso2D._Type = (Iso2DObject.Type) EditorGUILayout.EnumPopup("Type", _Iso2D._Type);

            EditorGUI.indentLevel = 0;
            Undo_Iso2DSpriteField(_Iso2D, Color.cyan);
            EditorGUILayout.LabelField("Type : " + _Iso2D._Type);

            float iWidth = EditorGUIUtility.currentViewWidth / 2 - 4;

            EditorGUILayout.BeginHorizontal();
            using (new EditorGUILayout.VerticalScope(
                       GUILayout.MaxWidth(iWidth)))
            {
                GUILayout.Space(5);

                Iso2DObjectEditor.Max_Slider = Mathf.Max(new float[] { 1f, vScaler.vector3Value.x, vScaler.vector3Value.y,
                                                                       EditorGUILayout.FloatField("Cap of Scale Slider", Iso2DObjectEditor.Max_Slider) });

                vScaler.vector3Value = Vector3Slider(vScaler.vector3Value, Vector3.one, "[Scale]",
                                                     -Iso2DObjectEditor.Max_Slider * Vector3.one, Iso2DObjectEditor.Max_Slider * Vector3.one, iWidth);
                // vScaler.vector3Value = EditorGUILayout.Vector3Field("",vScaler.vector3Value, GUILayout.MaxWidth(iWidth));
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField("Flip", GUILayout.MaxWidth(iWidth * 0.3f));
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.MaxWidth(iWidth * 0.3f)))
                    {
                        vScaler.vector3Value = Vector3.Scale(vScaler.vector3Value, new Vector3(-1, 1, 1));
                    }
                    if (GUILayout.Button("Y", EditorStyles.miniButton, GUILayout.MaxWidth(iWidth * 0.3f)))
                    {
                        vScaler.vector3Value = Vector3.Scale(vScaler.vector3Value, new Vector3(1, -1, 1));
                    }
                }
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.ToggleLeft(
                    string.Format("Use Global PPU Scale(x{0:0.00})", _Iso2D.PPURefScale),
                    _Iso2D.bApplyPPUScale, GUILayout.MaxWidth(iWidth));
                if (EditorGUI.EndChangeCheck())
                {
                    _Iso2D.Toggle_ApplyPPUScale();
                }
                EditorGUI.indentLevel++;
                EditorGUILayout.HelpBox("Global PPU Scale = Source PPU / Ref PPU", MessageType.None);
                EditorGUILayout.LabelField(
                    "Image Source PPU " + sprr.sprite.pixelsPerUnit,
                    GUILayout.MaxWidth(iWidth));
                EditorGUILayout.LabelField(
                    "IsoMap Reference PPU " + IsoMap.instance.ReferencePPU,
                    GUILayout.MaxWidth(iWidth));
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                Util.CustomEditorGUI.NewParagraph("[Rotation]");
                EditorGUILayout.LabelField("Tile local rotation adjustment", GUILayout.MaxWidth(iWidth));
                vRotator.vector3Value = EditorGUILayout.Vector3Field("", vRotator.vector3Value, GUILayout.MaxWidth(iWidth));
                EditorGUILayout.LabelField(
                    string.Format("+ global tile rotation(X {0}, Y {1})",
                                  IsoMap.instance.TileAngle.x,
                                  IsoMap.instance.TileAngle.y), GUILayout.MaxWidth(iWidth));
                EditorGUILayout.Separator();

                //EditorGUILayout.EndVertical();
                //GUILayout.EndArea();
            }
            drawPackedTexture(_Iso2D, Mathf.Min(125f, iWidth * 0.75f));
            EditorGUILayout.EndHorizontal();

            if (_parentTile != null && _Iso2D.gameObject != _parentTile.gameObject)
            {
                EditorGUILayout.Separator();
                Util.CustomEditorGUI.NewParagraph("[Object Selector]");
                if (_Iso2D.RC != null)
                {
                    Util.CustomEditorGUI.ComSelector <RegularCollider>(_Iso2D.RC, "GO Controller");
                }
                else
                {
                    CustomEditorGUI.ComSelector <SubColliderHelper>(_Iso2D.SC, "GO SubCollider");
                }
                Util.CustomEditorGUI.ComSelector <IsoTile>(_parentTile, "GO IsoTile");
            }

            _Iso2DSerializedObject.ApplyModifiedProperties();
        }
        public static void ColliderControlHelperGUI(Object[] objects)
        {
            SubColliderHelper[] _cols = objects.Where(r => r is SubColliderHelper).Cast <SubColliderHelper>().ToArray();

            bool bHasBC       = _cols.All(r => r.GetComponent <BoxCollider>() != null);
            bool isNotIsoTile = _cols.All(r => r.GetComponent <IsoTile>() == null);

            if (isNotIsoTile)
            {
                Util.CustomEditorGUI.NewParagraph("[Object Selector]");
                Util.CustomEditorGUI.ComSelector <IsoTile>(Selection.activeGameObject.GetComponentInParent <IsoTile>(), "GO IsoTile");
                var _iso2Ds = Selection.activeGameObject.GetComponentsInChildren <Iso2DObject>();
                foreach (var one in _iso2Ds)
                {
                    Util.CustomEditorGUI.ComSelector <Iso2DObject>(one, "GO Iso2D");
                }
                CustomEditorGUI.DrawSeperator();
            }

            if (bHasBC || isNotIsoTile)
            {
                NewParagraph("[Collider Control]");
                float fRayCastHeight = 10f * IsoMap.instance.gGrid.TileSize.y;
                if (bHasBC && GUILayout.Button(string.Format("Drop to the floor collider[Max({0:0.0})]", fRayCastHeight)))
                {
                    foreach (var _col in _cols)
                    {
                        if (_col.BC != null)
                        {
                            float fDropHeight = _col.BC.DropToFloor(_col.gameObject, fRayCastHeight);
                            if (fDropHeight > 0)
                            {
                                Debug.Log(string.Format("{0} fell {1} high.", _col.gameObject.name, fDropHeight));
                            }
                            else if (fDropHeight < 0)
                            {
                                Debug.Log(string.Format("{0} went up to {1} height because there is no floor within {2} range.",
                                                        _col.gameObject.name, -fDropHeight, fRayCastHeight));
                            }
                            else
                            {
                                Debug.Log(string.Format("There is no floor within {0} height.", fRayCastHeight));
                            }
                        }
                    }
                }
                if (isNotIsoTile && GUILayout.Button(string.Format("Change Parent to the nearest tile.", fRayCastHeight)))
                {
                    foreach (var _col in _cols)
                    {
                        _col.ReParent(0.5f);
                    }
                }
                if (isNotIsoTile && GUILayout.Button("Sync Light to Tile."))
                {
                    foreach (var _col in _cols)
                    {
                        var _tile = _col.GetComponentInParent <IsoTile>();
                        _tile.SyncIsoLight(_col.gameObject);
                    }
                }
                CustomEditorGUI.DrawSeperator();
            }

            if (isNotIsoTile && (bFoldout_ColliderControlGUI = !NewParagraphWithHideToggle("[Etc Control]", "Hide", !bFoldout_ColliderControlGUI)))
            {
                List <Iso2DObject> Iso2Ds = new List <Iso2DObject>();
                foreach (var _col in _cols)
                {
                    Iso2Ds.AddRange(_col.GetComponentsInChildren <Iso2DObject>());
                }
                if (Iso2Ds.Count > 0)
                {
                    Iso2Ds = Iso2Ds.Distinct().ToList();
                    GUILayoutOption heightLayout = GUILayout.Height(EditorGUIUtility.singleLineHeight * 3);
                    Iso2Ds.ForEach(r => Iso2DDrawer.Drawer(EditorGUILayout.GetControlRect(heightLayout), r.gameObject));
                }
            }
        }
        static void AttachmentField <T>(Object owner, T attachment) where T : class, IGameObject, IAttachment, IFloatValue, new()
        {
            const int cellSize   = 44;
            const int fudgeWidth = 175;
            const int border     = 2;

            Transform      _transform   = attachment.gameObject.transform;
            SpriteRenderer _sprr        = attachment.gameObject.GetComponent <SpriteRenderer>();
            float          _fDepthFudge = attachment.FloatValue;
            int            IndentLevel  = attachment.IndentLevel;

            Color borderColor = Selection.activeObject == _transform.gameObject
                ? CustomEditorGUI.Color_LightYellow : Color.gray;

            Rect rect              = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(GUILayout.Height(cellSize + border * 2)));
            Rect rect_inside       = new Rect(rect.xMin + border, rect.yMin + border, rect.width - border * 2, rect.height - border * 2);
            Rect rect_preview      = new Rect(rect_inside.xMin, rect_inside.yMin, cellSize, rect_inside.height);
            Rect rect_info_name    = new Rect(rect_preview.xMax, rect_inside.yMin, rect_inside.width - cellSize - fudgeWidth, rect_inside.height * 0.5f);
            Rect rect_Fudge        = new Rect(rect_info_name.xMax, rect_inside.yMin, fudgeWidth, rect_inside.height * 0.5f - border);
            Rect rect_info_Sub     = new Rect(rect_info_name.xMin, rect_info_name.yMin + cellSize * 0.5f, rect_info_name.width, rect_inside.height - rect_info_name.height);
            Rect rect_select_reset = new Rect(rect_inside.xMax - cellSize * 3.1f, rect_info_Sub.yMin, cellSize * 1.5f, rect_info_Sub.height);
            Rect rect_select_go    = new Rect(rect_inside.xMax - cellSize * 1.5f, rect_info_Sub.yMin, cellSize * 1.5f, rect_info_Sub.height);

            CustomEditorGUI.DrawBordereddRect(rect, borderColor, rect_inside, Color.clear);
            if (_sprr != null)
            {
                CustomEditorGUI.DrawSprite(rect_preview, _sprr.sprite, Color.white, false, false);
            }
            else
            {
                EditorGUI.LabelField(rect_preview, "Trans\nform\nNode");
            }

            int iLv = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;
            EditorGUI.LabelField(rect_info_name, _transform.name, EditorStyles.boldLabel);

            float _fNewDepthFudge = CustomEditorGUI.FloatSlider(rect_Fudge, "Depth", _fDepthFudge, -1f, 1f);


            // 서브 인포 출력
            //using (new EditorGUILayout.HorizontalScope())
            {
                float            _fMinSize = Mathf.Min(rect_info_Sub.width, rect_info_Sub.height);
                SpriteRenderer[] _sprrList = _transform.GetComponentsInChildren <SpriteRenderer>();

                for (int i = 0; i < _sprrList.Length; ++i)
                {
                    if (_sprrList[i].sprite != null && _sprrList[i] != _sprr)
                    {
                        Rect _rt = EditorGUI.IndentedRect(rect_info_Sub);
                        _rt.width           = _rt.height = _fMinSize;
                        rect_info_Sub.xMin += _fMinSize;
                        CustomEditorGUI.DrawSprite(_rt, _sprrList[i].sprite, _sprrList[i].color, true, true);
                    }
                }
            }
            using (new GUIBackgroundColorScope(Util.CustomEditorGUI.Color_LightMagenta))
            {
                if (GUI.Button(rect_select_reset, "Depth 0"))
                {
                    _fNewDepthFudge = 0;
                }
            }

            using (new GUIBackgroundColorScope(Util.CustomEditorGUI.Color_LightYellow))
            {
                if (GUI.Button(rect_select_go, "Select"))
                {
                    Selection.activeGameObject = _transform.gameObject;
                }
            }

            if (_fNewDepthFudge != _fDepthFudge)
            {
                Undo.RecordObject(_transform, "Transform : LocalOffset");
                _transform.position = _transform.position - IsoMap.vDepthFudge(_fDepthFudge) + IsoMap.vDepthFudge(_fNewDepthFudge);

                Undo.RecordObject(owner, "DepthFudge changed");
                attachment.FloatValue = _fNewDepthFudge;
            }

            EditorGUI.indentLevel = iLv;
        }
Beispiel #5
0
        private static bool OverrideColoredTexture2D(Texture2D source, Rect sourceRect, ref Texture2D destination, Color color, bool bAccumulate)
        {
            int s_x      = Mathf.RoundToInt(sourceRect.x);
            int s_y      = Mathf.RoundToInt(sourceRect.y);
            int s_width  = Mathf.RoundToInt(sourceRect.width);
            int s_height = Mathf.RoundToInt(sourceRect.height);

            if (destination == null)
            {
                destination = new Texture2D(s_width, s_height, TextureFormat.RGBA32, false);
                destination.alphaIsTransparency = true;
                destination.filterMode          = FilterMode.Point;
            }
            else
            {
                s_width  = Mathf.Min(s_width, destination.width);
                s_height = Mathf.Min(s_height, destination.height);
            }

            int d_width  = destination.width;
            int d_height = destination.height;
            int d_x      = (d_width - s_width) / 2;
            int d_y      = (d_height - s_height) / 2;

            Texture2D sourceForRead = source;
            // if (source is compressed)
            {
                RenderTexture rt = new RenderTexture(source.width, source.height, 0, RenderTextureFormat.ARGB32);
                RenderTexture.active = rt;
                Graphics.Blit(source, rt);

                sourceForRead = new Texture2D(source.width, source.height, TextureFormat.RGBA32, false);
                sourceForRead.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0, false);
            }

            var rawdata = sourceForRead.GetRawTextureData();

            Color32[] destColor = bAccumulate ? destination.GetPixels32() : null;
            Color32[] newcolors = new Color32[s_width * s_height];
            Color     col;
            int       index_new_color;
            int       index_source_raw;
            int       index_dest_raw;

            for (int _y = 0; _y < s_height; ++_y)
            {
                for (int _x = 0; _x < s_width; _x++)
                {
                    index_new_color  = _x + _y * s_width;
                    index_source_raw = 4 * ((s_x + _x) + (s_y + _y) * sourceForRead.width);
                    index_dest_raw   = (d_x + _x) + (d_y + _y) * d_width;

                    col = new Color32(rawdata[index_source_raw], rawdata[index_source_raw + 1], rawdata[index_source_raw + 2], rawdata[index_source_raw + 3]) * color;
                    newcolors[index_new_color] = bAccumulate ? CustomEditorGUI.Color_AlphaBlend(col, destColor[index_dest_raw]) : col;
                }
            }

            destination.SetPixels32(d_x, d_y, s_width, s_height, newcolors);
            destination.Apply();
            return(newcolors.Length > 0);
        }