// =========================================================== // Methods // =========================================================== void OnGUI() { MadGUI.Info("This tool initialized your scene for GUI drawing. Please choose root object name and layer " + "on which GUI will be painted."); rootObjectName = EditorGUILayout.TextField("Root Name", rootObjectName); layer = EditorGUILayout.LayerField("Layer", layer); OnFormGUI(); if (GUILayout.Button("Create")) { var panel = MadPanel.UniqueOrNull(); bool doInit = true; if (panel != null) { doInit = EditorUtility.DisplayDialog("Scene initialized", "Scene looks like it is already initialized. " + "Are you sure that you want to continue?", "Yes", "No"); } if (doInit) { root = Init(rootObjectName, layer, hideInvisibleSprites, depthBasedRenderMode); AfterCreate(root); } } }
void UnregisterSprite(MadPanel panel) { if (panel != null) { panel.sprites.Remove(this); } }
static Transform ActiveParentOrPanel() { Transform parentTransform = null; var transforms = Selection.transforms; if (transforms.Length > 0) { var firstTransform = transforms[0]; if (MadTransform.FindParent <MadPanel>(firstTransform) != null) { parentTransform = firstTransform; } } if (parentTransform == null) { var panel = MadPanel.UniqueOrNull(); if (panel != null) { parentTransform = panel.transform; } } return(parentTransform); }
static void CreateBullets() { var panel = MadPanel.UniqueOrNull(); var bullets = MadLevelGridBulletsTool.Create(panel); Selection.activeObject = bullets.gameObject; }
static Transform ActiveParentOrPanel() { Transform parentTransform = null; var transforms = Selection.transforms; if (transforms.Length > 0) { var firstTransform = transforms[0]; if (firstTransform.GetComponent <MadPanel>() != null || MadTransform.FindParent <MadPanel>(firstTransform) != null) { parentTransform = firstTransform; } } if (parentTransform == null) { var selected = Selection.activeGameObject; Transform selectedTransform = null; if (selected != null) { selectedTransform = selected.transform; } var panel = MadPanel.FirstOrNull(selectedTransform); if (panel != null) { parentTransform = panel.transform; } } return(parentTransform); }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void Start() { panel = GetComponent <MadPanel>(); var meshFilter = transform.GetComponent <MeshFilter>(); var mesh = meshFilter.sharedMesh; if (mesh == null) { mesh = new Mesh(); mesh.name = "Generated Mesh"; meshFilter.sharedMesh = mesh; } #if !UNITY_3_5 mesh.MarkDynamic(); #endif #if UNITY_4_2 if (Application.unityVersion.StartsWith("4.2.0")) { Debug.LogError("Unity 4.2 comes with terrible bug that breaks down Mad Level Manager rendering process. " + "Please upgrade/downgrade to different version. http://forum.unity3d.com/threads/192467-Unity-4-2-submesh-draw-order"); } #endif }
public static MadLevelFreeLayout CreateUnderPanel(MadPanel panel) { MadUndo.LegacyRegisterSceneUndo("Creating Free Layout"); var child = MadTransform.CreateChild<MadLevelFreeLayout>(panel.transform, "Free Layout"); Selection.activeObject = child; return child; }
public static MadLevelGridLayout CreateUnderPanel(MadPanel panel) { MadUndo.LegacyRegisterSceneUndo("Creating Grid Layout"); var child = MadTransform.CreateChild<MadLevelGridLayout>(panel.transform, "Grid Layout"); child.setupMethod = MadLevelGridLayout.SetupMethod.Generate; Selection.activeObject = child; return child; }
void RegisterSprite() { parentPanel = FindParent <MadPanel>(); if (parentPanel != null) { parentPanel.sprites.Add(this); } }
private void UpdateDraggable() { var panel = MadPanel.UniqueOrNull(); if (panel != null) { panel.ignoreInput = draggable.animating; } }
public static MadLevelFreeLayout CreateUnderPanel(MadPanel panel) { MadUndo.LegacyRegisterSceneUndo("Creating Free Layout"); var child = MadTransform.CreateChild <MadLevelFreeLayout>(panel.transform, "Free Layout"); Selection.activeObject = child; return(child); }
public static MadLevelGridLayout CreateUnderPanel(MadPanel panel) { MadUndo.LegacyRegisterSceneUndo("Creating Grid Layout"); var child = MadTransform.CreateChild <MadLevelGridLayout>(panel.transform, "Grid Layout"); child.setupMethod = MadLevelGridLayout.SetupMethod.Generate; Selection.activeObject = child; return(child); }
// =========================================================== // Static Methods // =========================================================== public static void ShowWindow() { var tool = EditorWindow.GetWindow <MadLevelBackgroundTool>(false, "Create Background", true); tool.panel = MadPanel.UniqueOrNull(); if (tool.panel != null) { tool.draggable = tool.panel.GetComponentInChildren <MadDraggable>(); } }
// =========================================================== // Static Methods // =========================================================== public static void Display() { var wizard = ScriptableWizard.DisplayWizard <MadLevelIconTool>("Create Icon", "Create"); wizard.panel = MadPanel.UniqueOrNull(); if (Selection.activeObject is Texture2D) { wizard.texture = Selection.activeObject as Texture2D; wizard.OnWizardUpdate(); } }
static void CreateFreeLayout() { var panel = MadPanel.UniqueOrNull(); if (panel != null) { MadLevelFreeTool.CreateUnderPanel(panel); } else { ScriptableWizard.DisplayWizard <MadLevelFreeTool>("Create Free Layout", "Create"); } }
static bool ValidateHasGridLayout() { var panel = MadPanel.UniqueOrNull(); if (panel == null) { return(false); } var gridLayout = MadTransform.FindChild <MadLevelGridLayout>(panel.transform); return(gridLayout != null); }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnEnable() { panel = GetComponent<MadPanel>(); // enable existing draw calls for (int i = 0; i < drawCalls.Count; i++) { var drawCall = drawCalls[i]; if (drawCall == null) { drawCalls.RemoveAt(i); i--; } else { MadGameObject.SetActive(drawCall.gameObject, true); } } }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnEnable() { if (drawCall == null) { drawCall = MadDrawCall.Create(); drawCall.gameObject.layer = gameObject.layer; MadTransform.SetLocalScale(drawCall.transform, transform.lossyScale); } panel = GetComponent<MadPanel>(); if (drawCall != null) { MadGameObject.SetActive(drawCall.gameObject, true); } }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnGUI() { MadGUI.Message("Here you can create backgrounds for your level screens. Draggable is optional, " + "but necessary if you want to setup follow animations.", MessageType.None); panel = (MadPanel) EditorGUILayout.ObjectField("Panel", panel, typeof(MadPanel), true); objectName = EditorGUILayout.TextField("Object Name", objectName); draggable = (MadDraggable) EditorGUILayout.ObjectField("Draggable", draggable, typeof(MadDraggable), true); bool valid = panel != null && !string.IsNullOrEmpty(objectName); GUI.enabled = valid; if (GUILayout.Button("Create")) { Create(); } GUI.enabled = true; }
void RegisterSpriteIfNeeded() { if (panel != cachedPanel) { if (cachedPanel != null) { UnregisterSprite(cachedPanel); } cachedPanel = panel; if (panel != null) { RegisterSprite(); } } }
public static MadLevelGridBullets Create(MadPanel panel) { var anchor = MadTransform.CreateChild<MadAnchor>(panel.transform, "Bullets Anchor"); anchor.mode = MadAnchor.Mode.ScreenAnchor; anchor.position = MadAnchor.Position.Bottom; var bullets = MadTransform.CreateChild<MadLevelGridBullets>(anchor.transform, "Bullets"); bullets.transform.localPosition = new Vector3(0, 50, 0); var draggable = MadTransform.FindChild<MadDragStopDraggable>(panel.transform, int.MaxValue); bullets.draggable = draggable; bullets.bulletTextureOff = (Texture2D) AssetDatabase.LoadAssetAtPath(BulletOff, typeof(Texture2D)); bullets.bulletTextureOn = (Texture2D) AssetDatabase.LoadAssetAtPath(BulletOn, typeof(Texture2D)); return bullets; }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnGUI() { MadGUI.Message("Here you can create backgrounds for your level screens. Draggable is optional, " + "but necessary if you want to setup follow animations.", MessageType.None); panel = (MadPanel)EditorGUILayout.ObjectField("Panel", panel, typeof(MadPanel), true); objectName = EditorGUILayout.TextField("Object Name", objectName); draggable = (MadDraggable)EditorGUILayout.ObjectField("Draggable", draggable, typeof(MadDraggable), true); bool valid = panel != null && !string.IsNullOrEmpty(objectName); GUI.enabled = valid; if (GUILayout.Button("Create")) { Create(); } GUI.enabled = true; }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnEnable() { if (drawCall == null) { drawCall = MadDrawCall.Create(); drawCall.gameObject.layer = gameObject.layer; MadTransform.SetLocalScale(drawCall.transform, transform.lossyScale); } panel = GetComponent <MadPanel>(); if (drawCall != null) { MadGameObject.SetActive(drawCall.gameObject, true); } }
protected virtual void OnEnable() { if (panel == null) { panel = MadPanel.FirstOrNull(transform); cachedPanel = panel; } else { cachedPanel = null; } if (!MadTransform.instantiating) { RegisterSprite(); } UpdateTexture(); }
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== // =========================================================== // Methods // =========================================================== void OnEnable() { panel = GetComponent <MadPanel>(); // enable existing draw calls for (int i = 0; i < drawCalls.Count; i++) { var drawCall = drawCalls[i]; if (drawCall == null) { drawCalls.RemoveAt(i); i--; } else { MadGameObject.SetActive(drawCall.gameObject, true); } } }
void LateUpdate() { if (panel == null) { panel = GetComponent <MadPanel>(); } var visibleSprites = VisibleSprites(panel.sprites); switch (panel.renderMode) { case MadPanel.RenderMode.Legacy: { SortByGUIDepth(visibleSprites); var batchedSprites = Batch(visibleSprites); DrawOnSingleDrawCall(batchedSprites); } break; case MadPanel.RenderMode.DepthBased: { SortByZ(visibleSprites); var batchedSprites = Batch(visibleSprites); DrawOnMultipleDrawCalls(batchedSprites); } break; default: throw new ArgumentOutOfRangeException(); } vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }
void LateUpdate() { if (panel == null) { panel = GetComponent<MadPanel>(); } var visibleSprites = VisibleSprites(panel.sprites); switch (panel.renderMode) { case MadPanel.RenderMode.Legacy: { SortByGUIDepth(visibleSprites); var batchedSprites = Batch(visibleSprites); DrawOnSingleDrawCall(batchedSprites); } break; case MadPanel.RenderMode.DepthBased: { SortByZ(visibleSprites); var batchedSprites = Batch(visibleSprites); DrawOnMultipleDrawCalls(batchedSprites); } break; default: throw new ArgumentOutOfRangeException(); } vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }
void LateUpdate() { if (panel == null) { panel = GetComponent<MadPanel>(); } var mesh = drawCall.mesh; mesh.Clear(); var visibleSprites = VisibleSprites(panel.sprites); SortByGUIDepth(visibleSprites); var batchedSprites = Batch(visibleSprites); Material[] materials = new Material[batchedSprites.Count]; mesh.subMeshCount = batchedSprites.Count; for (int i = 0; i < batchedSprites.Count; ++i) { List<MadSprite> sprites = batchedSprites[i]; MadList<int> triangles; if (!trianglesPool.CanTake()) { trianglesPool.Add(new MadList<int>()); } triangles = trianglesPool.Take(); for (int j = 0; j < sprites.Count; ++j) { var sprite = sprites[j]; Material material; sprite.DrawOn(ref vertices, ref colors, ref uv, ref triangles, out material); materials[i] = material; } triangles.Trim(); triangleList.Add(triangles); } vertices.Trim(); colors.Trim(); uv.Trim(); triangleList.Trim(); mesh.vertices = vertices.Array; mesh.colors32 = colors.Array; mesh.uv = uv.Array; // excluding for metro, because of a bug #if !UNITY_METRO mesh.RecalculateNormals(); #endif for (int i = 0; i < triangleList.Count; ++i) { MadList<int> triangles = triangleList[i]; mesh.SetTriangles(triangles.Array, i); triangles.Clear(); trianglesPool.Release(triangles); } //renderer.sharedMaterials = materials; drawCall.SetMaterials(materials); vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }
static bool ValidateHasPanel() { return(MadPanel.UniqueOrNull() != null); }
static void CreateIcon() { var wizard = ScriptableWizard.DisplayWizard <MadLevelIconTool>("Create Icon", "Create"); wizard.panel = MadPanel.UniqueOrNull(); }
void LateUpdate() { if (panel == null) { panel = GetComponent <MadPanel>(); } var mesh = drawCall.mesh; mesh.Clear(); var visibleSprites = VisibleSprites(panel.sprites); SortByGUIDepth(visibleSprites); var batchedSprites = Batch(visibleSprites); Material[] materials = new Material[batchedSprites.Count]; mesh.subMeshCount = batchedSprites.Count; for (int i = 0; i < batchedSprites.Count; ++i) { List <MadSprite> sprites = batchedSprites[i]; MadList <int> triangles; if (!trianglesPool.CanTake()) { trianglesPool.Add(new MadList <int>()); } triangles = trianglesPool.Take(); for (int j = 0; j < sprites.Count; ++j) { var sprite = sprites[j]; Material material; sprite.DrawOn(ref vertices, ref colors, ref uv, ref triangles, out material); materials[i] = material; } triangles.Trim(); triangleList.Add(triangles); } vertices.Trim(); colors.Trim(); uv.Trim(); triangleList.Trim(); mesh.vertices = vertices.Array; mesh.colors32 = colors.Array; mesh.uv = uv.Array; // excluding for metro, because of a bug #if !UNITY_METRO mesh.RecalculateNormals(); #endif for (int i = 0; i < triangleList.Count; ++i) { MadList <int> triangles = triangleList[i]; mesh.SetTriangles(triangles.Array, i); triangles.Clear(); trianglesPool.Release(triangles); } //renderer.sharedMaterials = materials; drawCall.SetMaterials(materials); vertices.Clear(); colors.Clear(); uv.Clear(); triangleList.Clear(); }