示例#1
0
        public void DrawOriginalRuleElement(Rect rect, RuleTile.TilingRule originalRule, bool isDefault = false)
        {
            using (new EditorGUI.DisabledScope(true))
            {
                float yPos        = rect.yMin + 2f;
                float height      = rect.height - k_PaddingBetweenRules;
                float matrixWidth = k_DefaultElementHeight;

                Rect inspectorRect = new Rect(rect.xMin, yPos, rect.width - matrixWidth * 2f - 20f, height);
                Rect matrixRect    = new Rect(rect.xMax - matrixWidth * 2f - 10f, yPos, matrixWidth, k_DefaultElementHeight);
                Rect spriteRect    = new Rect(rect.xMax - matrixWidth - 5f, yPos, matrixWidth, k_DefaultElementHeight);

                RuleTileEditor ruleTileEditor = Editor.CreateEditor(overrideTile.m_Tile) as RuleTileEditor;

                if (!isDefault)
                {
                    RuleTileEditor.RuleInspectorOnGUI(inspectorRect, originalRule);
                }
                else
                {
                    RuleOriginalDefaultInspectorOnGUI(inspectorRect, originalRule);
                }
                ruleTileEditor.RuleMatrixOnGUI(overrideTile.m_Tile, matrixRect, originalRule);
                RuleTileEditor.SpriteOnGUI(spriteRect, originalRule);

                DestroyImmediate(ruleTileEditor);
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.UpdateIfRequiredOrScript();

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Tile"));
            if (overrideTile.m_InstanceTile)
            {
                SerializedObject instanceTileSerializedObject = new SerializedObject(overrideTile.m_InstanceTile);
                overrideTile.m_InstanceTile.hideFlags = HideFlags.None;
                RuleTileEditor.DrawCustomFields(overrideTile.m_InstanceTile, instanceTileSerializedObject);
                overrideTile.m_InstanceTile.hideFlags = HideFlags.NotEditable;
                instanceTileSerializedObject.ApplyModifiedProperties();
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Advanced"));
            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                UpdateInstanceTile();
                SaveTile();
            }

            if (!overrideTile.m_Advanced)
            {
                using (new EditorGUI.DisabledScope(overrideTile.m_Tile == null))
                {
                    EditorGUI.BeginChangeCheck();
                    overrideTile.GetOverrides(m_Sprites);

                    m_SpriteList.list = m_Sprites;
                    m_SpriteList.DoLayoutList();
                    if (EditorGUI.EndChangeCheck())
                    {
                        for (int i = 0; i < targets.Length; i++)
                        {
                            RuleOverrideTile tile = targets[i] as RuleOverrideTile;
                            tile.ApplyOverrides(m_Sprites);
                            SaveTile();
                        }
                    }
                }
            }
            else
            {
                using (new EditorGUI.DisabledScope(overrideTile.m_Tile == null))
                {
                    overrideTile.GetOverrides(m_Rules);

                    m_RuleList.list = m_Rules;
                    m_RuleList.DoLayoutList();
                }
            }
        }
 public void DrawCustomFields()
 {
     if (overrideTile.m_InstanceTile)
     {
         SerializedObject instanceTileSerializedObject = new SerializedObject(overrideTile.m_InstanceTile);
         overrideTile.m_InstanceTile.hideFlags = HideFlags.None;
         RuleTileEditor.DrawCustomFields(overrideTile.m_InstanceTile, instanceTileSerializedObject);
         overrideTile.m_InstanceTile.hideFlags = HideFlags.NotEditable;
         instanceTileSerializedObject.ApplyModifiedProperties();
     }
 }
        public void SaveTile()
        {
            EditorUtility.SetDirty(target);
            SceneView.RepaintAll();

            SaveInstanceTileAsset();
            if (overrideTile.m_InstanceTile)
            {
                overrideTile.Override();
                RuleTileEditor.UpdateAffectedOverrideTiles(overrideTile.m_InstanceTile);
            }
        }
示例#5
0
        public void DrawTileField()
        {
            EditorGUI.BeginChangeCheck();
            RuleTile tile =
                EditorGUILayout.ObjectField("Tile", overrideTile.m_Tile, typeof(RuleTile), false) as RuleTile;

            if (EditorGUI.EndChangeCheck())
            {
                if (!LoopCheck(tile))
                {
                    overrideTile.m_Tile = tile;
                    SaveTile();
                }
                else
                {
                    Debug.LogWarning("Circular tile reference");
                }
            }

            bool LoopCheck(RuleTile checkTile)
            {
                if (!overrideTile.m_InstanceTile)
                {
                    return(false);
                }

                HashSet <RuleTile> renferenceTils = new HashSet <RuleTile>();

                Add(overrideTile.m_InstanceTile);

                return(renferenceTils.Contains(checkTile));

                void Add(RuleTile ruleTile)
                {
                    if (renferenceTils.Contains(ruleTile))
                    {
                        return;
                    }

                    renferenceTils.Add(ruleTile);

                    var overrideTiles = RuleTileEditor.FindAffectedOverrideTiles(ruleTile);

                    foreach (var overrideTile in overrideTiles)
                    {
                        Add(overrideTile.m_InstanceTile);
                    }
                }
            }
        }
示例#6
0
        private void DrawOverrideDefaultElement(Rect rect, RuleTile.TilingRule originalRule)
        {
            float yPos        = rect.yMin + 2f;
            float height      = rect.height - k_PaddingBetweenRules;
            float matrixWidth = k_DefaultElementHeight;

            Rect inspectorRect = new Rect(rect.xMin, yPos, rect.width - matrixWidth - 10f, height);
            Rect spriteRect    = new Rect(rect.xMax - matrixWidth - 5f, yPos, matrixWidth, k_DefaultElementHeight);

            RuleOverrideDefaultInspectorOnGUI(inspectorRect, originalRule);
            if (overrideTile.m_OverrideDefault.m_Enabled)
            {
                RuleTileEditor.SpriteOnGUI(spriteRect, overrideTile.m_OverrideDefault.m_TilingRule);
            }
        }
示例#7
0
        public void SaveTile()
        {
            EditorUtility.SetDirty(target);
            SceneView.RepaintAll();

            SaveInstanceTileAsset();

            if (overrideTile.m_InstanceTile)
            {
                overrideTile.Override();
                RuleTileEditor.UpdateAffectedOverrideTiles(overrideTile.m_InstanceTile);
            }

            if (ruleTileEditor && ruleTileEditor.m_PreviewTilemaps != null)
            {
                foreach (var tilemap in ruleTileEditor.m_PreviewTilemaps)
                {
                    tilemap.RefreshAllTiles();
                }
            }
        }
        private static void RuleInspectorOnGUI(Rect rect, RuleTile.TilingRule tilingRule, int index, RuleTileEditor editor)
        {
            float y = rect.yMin;

            EditorGUI.BeginChangeCheck();
            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Rule-" + index);
            tilingRule.m_RuleTransform = (RuleTile.TilingRule.Transform)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_RuleTransform);
            y += k_SingleLineHeight;
            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Collider");
            tilingRule.m_ColliderType = (Tile.ColliderType)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_ColliderType);
            y += k_SingleLineHeight;
            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Output");
            tilingRule.m_Output = (RuleTile.TilingRule.OutputSprite)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_Output);
            y += k_SingleLineHeight;

            if (tilingRule.m_Output == RuleTile.TilingRule.OutputSprite.Animation)
            {
                GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Speed");
                tilingRule.m_AnimationSpeed = EditorGUI.FloatField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_AnimationSpeed);
                y += k_SingleLineHeight;
            }
            if (tilingRule.m_Output == RuleTile.TilingRule.OutputSprite.Random)
            {
                GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Noise");
                tilingRule.m_PerlinScale = EditorGUI.Slider(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_PerlinScale, 0.001f, 0.999f);
                y += k_SingleLineHeight;

                GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Shuffle");
                tilingRule.m_RandomTransform = (RuleTile.TilingRule.Transform)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_RandomTransform);
                y += k_SingleLineHeight;
            }

            if (tilingRule.m_Output != RuleTile.TilingRule.OutputSprite.Single)
            {
                GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Size");
                EditorGUI.BeginChangeCheck();
                int newLength = EditorGUI.DelayedIntField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), tilingRule.m_Sprites.Length);
                if (EditorGUI.EndChangeCheck())
                {
                    Array.Resize(ref tilingRule.m_Sprites, Math.Max(newLength, 1));
                }
                y += k_SingleLineHeight;

                // Rows is equal to
                float singleWidth = k_DefaultElementHeight + 5.0f;
                float maxWidth    = EditorGUIUtility.currentViewWidth - k_LabelWidth - 34 - 22;
                editor.m_previewsPerRow = (int)(maxWidth / singleWidth);
                for (int i = 0; i < tilingRule.m_Sprites.Length; i++)
                {
                    int col = i % editor.m_previewsPerRow;
                    if (i != 0 && col == 0)
                    {
                        y += k_DefaultElementHeight + 2.0f;
                    }


                    tilingRule.m_Sprites[i] = EditorGUI.ObjectField(new Rect(rect.xMin + k_LabelWidth + col * singleWidth, y, k_DefaultElementHeight, k_DefaultElementHeight), tilingRule.m_Sprites[i], typeof(Sprite), false) as Sprite;
                }
            }
        }