Esempio n. 1
0
    // ===========================================================
    // 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);
            }
        }
    }
Esempio n. 2
0
 void UnregisterSprite(MadPanel panel)
 {
     if (panel != null)
     {
         panel.sprites.Remove(this);
     }
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        static void CreateBullets()
        {
            var panel   = MadPanel.UniqueOrNull();
            var bullets = MadLevelGridBulletsTool.Create(panel);

            Selection.activeObject = bullets.gameObject;
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
    // ===========================================================
    // 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
    }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
    void RegisterSprite()
    {
        parentPanel = FindParent <MadPanel>();

        if (parentPanel != null)
        {
            parentPanel.sprites.Add(this);
        }
    }
Esempio n. 10
0
    private void UpdateDraggable()
    {
        var panel = MadPanel.UniqueOrNull();

        if (panel != null)
        {
            panel.ignoreInput = draggable.animating;
        }
    }
Esempio n. 11
0
    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);
    }
Esempio n. 13
0
    // ===========================================================
    // 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>();
        }
    }
Esempio n. 14
0
    // ===========================================================
    // 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();
        }
    }
Esempio n. 15
0
        static void CreateFreeLayout()
        {
            var panel = MadPanel.UniqueOrNull();

            if (panel != null)
            {
                MadLevelFreeTool.CreateUnderPanel(panel);
            }
            else
            {
                ScriptableWizard.DisplayWizard <MadLevelFreeTool>("Create Free Layout", "Create");
            }
        }
Esempio n. 16
0
        static bool ValidateHasGridLayout()
        {
            var panel = MadPanel.UniqueOrNull();

            if (panel == null)
            {
                return(false);
            }

            var gridLayout = MadTransform.FindChild <MadLevelGridLayout>(panel.transform);

            return(gridLayout != null);
        }
Esempio n. 17
0
    // ===========================================================
    // 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);
            }
        }
    }
Esempio n. 18
0
    // ===========================================================
    // 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;
    }
Esempio n. 20
0
 void RegisterSpriteIfNeeded()
 {
     if (panel != cachedPanel)
     {
         if (cachedPanel != null)
         {
             UnregisterSprite(cachedPanel);
         }
         cachedPanel = panel;
         if (panel != null)
         {
             RegisterSprite();
         }
     }
 }
Esempio n. 21
0
    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;
    }
Esempio n. 22
0
    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;
    }
Esempio n. 23
0
    // ===========================================================
    // 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;
    }
Esempio n. 24
0
    // ===========================================================
    // 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);
        }
    }
Esempio n. 25
0
    protected virtual void OnEnable()
    {
        if (panel == null)
        {
            panel       = MadPanel.FirstOrNull(transform);
            cachedPanel = panel;
        }
        else
        {
            cachedPanel = null;
        }

        if (!MadTransform.instantiating)
        {
            RegisterSprite();
        }
        UpdateTexture();
    }
Esempio n. 26
0
    // ===========================================================
    // 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);
            }
        }
    }
Esempio n. 27
0
    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();
    }
Esempio n. 28
0
    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();
    }
Esempio n. 29
0
    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();
    }
Esempio n. 30
0
 static bool ValidateHasPanel()
 {
     return(MadPanel.UniqueOrNull() != null);
 }
Esempio n. 31
0
        static void CreateIcon()
        {
            var wizard = ScriptableWizard.DisplayWizard <MadLevelIconTool>("Create Icon", "Create");

            wizard.panel = MadPanel.UniqueOrNull();
        }
Esempio n. 32
0
    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();
    }
Esempio n. 33
0
    protected virtual void OnEnable() {
        if (panel == null) {
            panel = MadPanel.FirstOrNull(transform);
            cachedPanel = panel;
        } else {
            cachedPanel = null;
        }

        if (!MadTransform.instantiating) {
            RegisterSprite();
        }
        UpdateTexture();
    }
Esempio n. 34
0
 void RegisterSpriteIfNeeded() {
     if (panel != cachedPanel) {
         if (cachedPanel != null) {
             UnregisterSprite(cachedPanel);
         }
         cachedPanel = panel;
         if (panel != null) {
             RegisterSprite();
         }
     }
 }
Esempio n. 35
0
 void UnregisterSprite(MadPanel panel) {
     if (panel != null) {
         panel.sprites.Remove(this);
     }
 }