private void CreateInstanceTile() { var t = m_Tile.GetType(); RuleTile instanceTile = CreateInstance(t) as RuleTile; instanceTile.hideFlags = HideFlags.NotEditable; instanceTile.name = m_Tile.name + " (Override)"; m_InstanceTile = instanceTile; #if UNITY_EDITOR if (AssetDatabase.Contains(this)) { AssetDatabase.AddObjectToAsset(instanceTile, this); } EditorUtility.SetDirty(this); #endif }
public void Override() { m_RuntimeTile = m_Tile ? Instantiate(m_Tile) : new RuleTile(); m_RuntimeTile.m_Self = m_OverrideSelf ? this : m_Tile as TileBase; if (!m_Advanced) { if (m_RuntimeTile.m_DefaultSprite) { m_RuntimeTile.m_DefaultSprite = this[m_RuntimeTile.m_DefaultSprite]; } if (m_RuntimeTile.m_TilingRules != null) { foreach (RuleTile.TilingRule rule in m_RuntimeTile.m_TilingRules) { for (int i = 0; i < rule.m_Sprites.Length; i++) { if (rule.m_Sprites[i]) { rule.m_Sprites[i] = this[rule.m_Sprites[i]]; } } } } } else { if (m_OverrideDefault.m_Enabled) { m_RuntimeTile.m_DefaultSprite = m_OverrideDefault.m_TilingRule.m_Sprites.Length > 0 ? m_OverrideDefault.m_TilingRule.m_Sprites[0] : null; m_RuntimeTile.m_DefaultColliderType = m_OverrideDefault.m_TilingRule.m_ColliderType; } if (m_RuntimeTile.m_TilingRules != null) { for (int i = 0; i < m_RuntimeTile.m_TilingRules.Count; i++) { RuleTile.TilingRule originalRule = m_RuntimeTile.m_TilingRules[i]; RuleTile.TilingRule overrideRule = this[m_Tile.m_TilingRules[i]]; if (overrideRule == null) { continue; } CopyTilingRule(overrideRule, originalRule, false); } } } }
public void OnEnable() { if (m_Tile == null) { return; } if (m_InstanceTile == null) { var t = m_Tile.GetType(); RuleTile instanceTile = ScriptableObject.CreateInstance(t) as RuleTile; instanceTile.hideFlags = HideFlags.NotEditable; instanceTile.name = m_Tile.name + " (Override)"; m_InstanceTile = instanceTile; Override(); #if UNITY_EDITOR AssetDatabase.AddObjectToAsset(instanceTile, this); EditorUtility.SetDirty(this); #endif } }