예제 #1
0
    MegaBookPageParams NewPage(int prev)
    {
        MegaBookBuilder book = (MegaBookBuilder)target;

        MegaBookPageParams page = new MegaBookPageParams();

        if (prev >= 0 && prev < book.pageparams.Count)
        {
            MegaBookPageParams pp = book.pageparams[prev];

            page.back        = pp.back;
            page.front       = pp.front;
            page.background  = pp.background;
            page.background1 = pp.background1;
            page.backmat     = pp.backmat;
            page.frontmat    = pp.frontmat;
            page.edgemat     = pp.edgemat;

            page.copyarea  = pp.copyarea;
            page.copyarea1 = pp.copyarea1;

            page.usebackground  = pp.usebackground;
            page.usebackground1 = pp.usebackground1;

            page.pagemesh = pp.pagemesh;
            page.pageobj  = pp.pageobj;

            page.rotate = pp.rotate;
        }

        return(page);
    }
예제 #2
0
 void SwapPages(MegaBookBuilder mod, int t1, int t2)
 {
     if (t1 >= 0 && t1 < mod.pages.Count && t2 >= 0 && t2 < mod.pages.Count && t1 != t2)
     {
         MegaBookPageParams mt1 = mod.pageparams[t1];
         mod.pageparams.RemoveAt(t1);
         mod.pageparams.Insert(t2, mt1);
         EditorUtility.SetDirty(target);
     }
 }
예제 #3
0
    static void CreateBook()
    {
        Vector3 pos = Vector3.zero;

        if (UnityEditor.SceneView.lastActiveSceneView)
        {
            pos = UnityEditor.SceneView.lastActiveSceneView.pivot;
        }

        GameObject go = new GameObject("Book");

        MegaBookBuilder book = go.AddComponent <MegaBookBuilder>();

        book.pagesectioncrv = AnimationCurve.Linear(0.0f, 0.0f, 1.0f, 1.0f);
        book.basematerial   = (Material)Resources.Load("Materials/MegaBook Front", typeof(Material));
        book.basematerial1  = (Material)Resources.Load("Materials/MegaBook Back", typeof(Material));
        book.basematerial2  = (Material)Resources.Load("Materials/MegaBook Edge", typeof(Material));

        for (int i = 0; i < book.NumPages; i++)
        {
            MegaBookPageParams page = new MegaBookPageParams();

            if (i == 0)
            {
                page.front = (Texture2D)Resources.Load("Textures/MegaBook Cover", typeof(Texture2D));
                page.back  = (Texture2D)Resources.Load("Textures/MegaBook InsideFrontCover", typeof(Texture2D));
            }
            else
            {
                if (i == book.NumPages - 1)
                {
                    page.front = (Texture2D)Resources.Load("Textures/MegaBook InsideBackCover", typeof(Texture2D));
                    page.back  = (Texture2D)Resources.Load("Textures/MegaBook BackCover", typeof(Texture2D));
                }
                else
                {
                    page.front = (Texture2D)Resources.Load("Textures/MegaBook Front", typeof(Texture2D));
                    page.back  = (Texture2D)Resources.Load("Textures/MegaBook Back", typeof(Texture2D));
                }
            }

            book.pageparams.Add(page);
        }

        go.transform.position  = pos;
        Selection.activeObject = go;
        book.rebuild           = true;
    }
예제 #4
0
    void OnSceneGUI()
    {
        MegaBookBuilder mod = (MegaBookBuilder)target;
        MegaBookPage    pg  = mod.pages[mod.editpage];

        switch (Tools.current)
        {
        case Tool.Move:
            for (int i = 0; i < pg.objects.Count; i++)
            {
#if UNITY_3_5
                if (pg.objects[i].obj && pg.objects[i].obj.active)
#else
                if (pg.objects[i].obj && pg.objects[i].obj.activeInHierarchy)
#endif
                {
                    Transform trans = pg.objects[i].obj.transform;
                    Vector3   pos   = Handles.PositionHandle(trans.position, trans.rotation);                           //Quaternion.identity);
                    if (pos != trans.position)
                    {
                        Vector3 delta = trans.position - pos;

                        //float off = delta.y;
                        delta.y = 0.0f;
                        MegaBookPageParams parms = mod.pageparams[mod.editpage];                                        //.objects[i]];

                        MegaBookPageObject pobj = parms.objects[i];

                        pobj.pos -= delta;

                        pobj.pos.x = Mathf.Clamp(pobj.pos.x, 0.0f, 99.99f);
                        pobj.pos.z = Mathf.Clamp(pobj.pos.z, 0.0f, 99.99f);

                        //if ( Mathf.Abs(delta.x) < 0.01f && Mathf.Abs(delta.z) < 0.01f )
                        //pobj.offset += off;

                        mod.UpdateAttached();
                        EditorUtility.SetDirty(target);
                    }
                }
            }
            break;
        }
    }
예제 #5
0
    bool DisplayPage(MegaBookPageParams page, int i)
    {
        MegaBookBuilder mod    = (MegaBookBuilder)target;
        bool            retval = false;

        Mesh mesh = (Mesh)EditorGUILayout.ObjectField("Page Mesh", page.pagemesh, typeof(Mesh), false);

        if (mesh != page.pagemesh)
        {
            page.pagemesh = mesh;
            retval        = true;
        }

        mesh = (Mesh)EditorGUILayout.ObjectField("Hole Mesh", page.holemesh, typeof(Mesh), false);
        if (mesh != page.holemesh)
        {
            page.holemesh = mesh;
            retval        = true;
        }

        GameObject obj = (GameObject)EditorGUILayout.ObjectField("Page Object", page.pageobj, typeof(GameObject), false);

        if (obj != page.pageobj)
        {
            page.pageobj = obj;
            retval       = true;
        }

        obj = (GameObject)EditorGUILayout.ObjectField("Hole Object", page.holeobj, typeof(GameObject), false);
        if (obj != page.holeobj)
        {
            page.holeobj = obj;
            retval       = true;
        }

        int mi = EditorGUILayout.IntField("Front Mat Index", page.frontmatindex);

        if (mi != page.frontmatindex)
        {
            page.frontmatindex = mi;
            retval             = true;
        }

        mi = EditorGUILayout.IntField("Back Mat Index", page.backmatindex);
        if (mi != page.backmatindex)
        {
            page.backmatindex = mi;
            retval            = true;
        }

        Vector3 rotate = EditorGUILayout.Vector3Field("Rotate", page.rotate);

        if (rotate != page.rotate)
        {
            page.rotate = rotate;
            retval      = true;
        }

        Material mat = (Material)EditorGUILayout.ObjectField("Front Material", page.frontmat, typeof(Material), false);

        if (mat != page.frontmat)
        {
            page.frontmat = mat;
            retval        = true;
        }

        mat = (Material)EditorGUILayout.ObjectField("Back Material", page.backmat, typeof(Material), false);
        if (mat != page.backmat)
        {
            page.backmat = mat;
            retval       = true;
        }

        EditorGUILayout.BeginHorizontal("box");
        EditorGUILayout.LabelField("Front " + i, GUILayout.Width(80));
        Texture2D ptex = (Texture2D)EditorGUILayout.ObjectField("", page.front, typeof(Texture2D), false, GUILayout.Width(64));

        if (ptex != page.front)
        {
            page.front = ptex;
            retval     = true;
        }

        ptex = (Texture2D)EditorGUILayout.ObjectField("", page.background, typeof(Texture2D), false, GUILayout.Width(64));

        if (ptex != page.background && CheckTextureReadable(ptex))
        {
            if (ptex == null)
            {
                mod.ClearMadeTextures();
            }
            page.background = ptex;
        }

        EditorGUILayout.EndHorizontal();
        bool alpha = EditorGUILayout.Toggle("Use Alpha as Mask", page.alphatexturefront);

        if (alpha != page.alphatexturefront)
        {
            page.alphatexturefront = alpha;
            retval = true;
        }

        EditorGUILayout.BeginHorizontal("box");
        EditorGUILayout.LabelField("Back", GUILayout.Width(80));

        ptex = (Texture2D)EditorGUILayout.ObjectField("", page.back, typeof(Texture2D), false, GUILayout.Width(64));
        if (ptex != page.back)
        {
            page.back = ptex;
            retval    = true;
        }

        ptex = (Texture2D)EditorGUILayout.ObjectField("", page.background1, typeof(Texture2D), false, GUILayout.Width(64));

        if (ptex != page.background1 && CheckTextureReadable(ptex))
        {
            if (ptex == null)
            {
                mod.ClearMadeTextures();
            }
            page.background1 = ptex;
        }

        EditorGUILayout.EndHorizontal();

        alpha = EditorGUILayout.Toggle("Use Alpha as Mask", page.alphatextureback);
        if (alpha != page.alphatextureback)
        {
            page.alphatextureback = alpha;
            retval = true;
        }

        page.swapsides = EditorGUILayout.Toggle("Swap Sides", page.swapsides);

        // Should just update the page not the whole book
        page.usebackground = EditorGUILayout.Toggle("Front Background", page.usebackground);
        page.copyarea      = EditorGUILayout.RectField("Copy Area", page.copyarea);

        page.usebackground1 = EditorGUILayout.Toggle("Back Background", page.usebackground1);
        page.copyarea1      = EditorGUILayout.RectField("Copy Area Back", page.copyarea1);

        //bool bval = EditorGUILayout.Toggle("Stiff", page.stiff);
        //if ( bval != page.stiff )
        //{
        //page.stiff = bval;
        //retval = true;
        //}

        // Attached objects
        mod.showobjects = EditorGUILayout.Foldout(mod.showobjects, "Page Objects");

        if (mod.showobjects)
        {
            page.visobjlow  = EditorGUILayout.FloatField("Visible Low", page.visobjlow);
            page.visobjhigh = EditorGUILayout.FloatField("Visible High", page.visobjhigh);

            if (GUILayout.Button("Add Object"))
            {
                MegaBookPageObject pobj = new MegaBookPageObject();
                if (page.objects.Count > 0)
                {
                    MegaBookPageObject prevobj = page.objects[page.objects.Count - 1];
                    pobj.pos    = prevobj.pos;
                    pobj.rot    = prevobj.rot;
                    pobj.offset = prevobj.offset;
                }
                page.objects.Add(pobj);
                retval      = true;
                mod.rebuild = true;
                GUI.changed = false;
                EditorUtility.SetDirty(target);
            }

            for (int j = 0; j < page.objects.Count; j++)
            {
                MegaBookPageObject pobj   = page.objects[j];
                GameObject         newobj = (GameObject)EditorGUILayout.ObjectField("Object", pobj.obj, typeof(GameObject), true);

                if (newobj != pobj.obj)
                {
                    if (pobj.obj == null)
                    {
                        pobj.pos = mod.CalcPos(newobj, page, pobj.pos);
                    }

                    pobj.obj    = newobj;
                    retval      = true;
                    GUI.changed = false;
                }
                pobj.pos    = EditorGUILayout.Vector3Field("Pos", pobj.pos);
                pobj.rot    = EditorGUILayout.Vector3Field("Rot", pobj.rot);
                pobj.offset = EditorGUILayout.FloatField("Offset", pobj.offset);

                pobj.attachforward = EditorGUILayout.Vector3Field("Fwd", pobj.attachforward);

                pobj.overridevisi = EditorGUILayout.BeginToggleGroup("Use Obj Visi", pobj.overridevisi);

                pobj.visilow  = EditorGUILayout.FloatField("Visibility Low", pobj.visilow);
                pobj.visihigh = EditorGUILayout.FloatField("Visibility High", pobj.visihigh);

                EditorGUILayout.EndToggleGroup();

                pobj.message = EditorGUILayout.Toggle("Message", pobj.message);

                if (GUILayout.Button("Delete Page Object"))
                {
                    page.objects.RemoveAt(j);
                    retval      = true;
                    mod.rebuild = true;
                    GUI.changed = false;
                    EditorUtility.SetDirty(target);
                }
            }

            if (GUI.changed)
            {
                mod.UpdateAttached();

                EditorUtility.SetDirty(target);
            }
        }

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Insert"))
        {
            mod.pageparams.Insert(i, NewPage(i));
            retval = true;
        }

        if (GUILayout.Button("Delete"))
        {
            mod.pageparams.RemoveAt(i);
            retval = true;
        }

        if (GUILayout.Button("Up"))
        {
            if (i > 0)
            {
                SwapPages(mod, i, i - 1);
            }
            retval = true;
        }

        if (GUILayout.Button("Down"))
        {
            if (i < mod.pagetextures.Count - 1)
            {
                SwapPages(mod, i, i + 1);
            }
            retval = true;
        }

        EditorGUILayout.EndHorizontal();

        return(retval);
    }