예제 #1
0
파일: POFXLayer.cs 프로젝트: qcook2000/tile
            public void Awake()
            {
                Init();

                POFXBase pofx = GetComponent <POFXBase>();

                if (pofx == null)
                {
                    if (Application.isPlaying)
                    {
                        Destroy(this);
                    }
                    else
                    {
                        DestroyImmediate(this);
                    }
                }
            }
예제 #2
0
            void AddLayer(POFXLayer layer)
            {
                POFXBase pofx = target as POFXBase;

                pofx.AddLayer(layer);
            }
예제 #3
0
            public override void OnInspectorGUI()
            {
                POFXBase pofx = target as POFXBase;


                if (m_logo == null)
                {
                    m_logo = Resources.Load("POFX_banner") as Texture2D;
                }
                GUILayout.BeginHorizontal(EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                GUILayout.Label(m_logo);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                GUILayout.Space(-26);
                GUILayout.BeginHorizontal(EditorStyles.centeredGreyMiniLabel);
                GUILayout.FlexibleSpace();
                GUILayout.Label("" + POFXBase.version);
                GUILayout.EndHorizontal();

                GUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.Label("Settings", EditorStyles.boldLabel);
                pofx.m_hideRenderer        = EditorGUILayout.Toggle("Hide renderer", pofx.m_hideRenderer);
                pofx.m_hideEditorSelection = EditorGUILayout.Toggle("Hide editor selection", pofx.m_hideEditorSelection);
                if (pofx.m_hideEditorSelection)
                {
                    EditorUtility.SetSelectedRenderState(pofx.GetComponent <Renderer>(), EditorSelectedRenderState.Hidden);
                }
                else
                {
                    EditorUtility.SetSelectedRenderState(pofx.GetComponent <Renderer>(), EditorSelectedRenderState.Highlight);
                }
                GUILayout.EndVertical();


                int deleteId = -1;

                for (int i = 0; i < pofx.m_layers.Count; ++i)
                {
                    pofx.m_layers[i].hideFlags = HideFlags.HideInInspector;
                    POFXLayerEditor e = CreateEditor(pofx.m_layers[i]) as POFXLayerEditor;
                    if (e != null)
                    {
                        POFXLayer tmp;

                        switch (e.OnInspector())
                        {
                        case POFXLayerEditor.eAction.REMOVE:
                            if (EditorUtility.DisplayDialog("Delete layer", "Delete layer " + pofx.m_layers[i].GetName() + " ?", "OK", "CANCEL"))
                            {
                                deleteId = i;
                            }
                            break;

                        case POFXLayerEditor.eAction.UP:
                            tmp = pofx.m_layers[i - 1];
                            pofx.m_layers[i - 1] = pofx.m_layers[i];
                            pofx.m_layers[i]     = tmp;
                            break;

                        case POFXLayerEditor.eAction.DOWN:
                            tmp = pofx.m_layers[i + 1];
                            pofx.m_layers[i + 1] = pofx.m_layers[i];
                            pofx.m_layers[i]     = tmp;
                            break;
                        }
                    }
                }

                if (deleteId != -1)
                {
                    pofx.RemoveLayer(pofx.m_layers[deleteId]);
                }


                //if (GUI.changed)
                {
                    pofx.Refresh();
                    SceneView.RepaintAll();
                }

                bool enableSprite = pofx.m_spriteRenderer != null;


                if (m_types == null)
                {
                    m_types = Resources
                              .FindObjectsOfTypeAll(typeof(MonoScript))
                              .Cast <MonoScript>()
                              .Where(x => x.GetClass() != null)
                              .Where(x => x.GetClass().BaseType != null)
                              .Where(x => (x.GetClass().BaseType.BaseType == typeof(Kalagaan.POFX.POFXLayer)))
                              .Where(x => x.GetClass().BaseType.GetField("path", BindingFlags.Public | BindingFlags.Static) != null)
                              .Where(x => (x.GetClass().BaseType.GetField("spriteCompatible", BindingFlags.Public | BindingFlags.Static) != null) || !enableSprite)
                              .OrderBy(x => "" + x.GetClass().BaseType.GetField("path", BindingFlags.Public | BindingFlags.Static).GetValue(null) + "" + x.GetClass())
                              .ToList();
                }

                GUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.Label("Add FX", EditorStyles.boldLabel);

                string category = "";

                GUILayout.BeginHorizontal();
                for (int i = 0; i < m_types.Count; ++i)
                {
                    string name = "" + m_types[i].GetClass();
                    name = name.Replace("Kalagaan.POFX.POFX_", "");
                    //name = name.Replace("Base", "");
                    //name = types[i].GetClass().GetProperties().Where(p => p.Name == "path").ToList()[0].GetValue(null);

                    FieldInfo field      = m_types[i].GetClass().BaseType.GetField("path", BindingFlags.Public | BindingFlags.Static);
                    string    FXCategory = "";
                    if (field != null)
                    {
                        FXCategory = (string)field.GetValue(null);
                    }

                    if (FXCategory != category)
                    {
                        GUILayout.EndHorizontal();
                        category = FXCategory;
                        if (GUILayout.Button(category, EditorStyles.toolbarDropDown))
                        {
                            selectedCategory = selectedCategory != category ? category : "";
                        }
                        GUILayout.BeginHorizontal();
                    }


                    if (selectedCategory == category)
                    {
                        if (GUILayout.Button(name))
                        {
                            //Debug.Log("Add " + types[i].GetClass());
                            //AddLayer("" + types[i].GetClass().Name);
                            //AddLayer( (types[i].GetClass().BaseType.BaseType) as POFXLayer);
                            AddLayer(pofx.gameObject.AddComponent(m_types[i].GetClass()) as POFXLayer);
                        }
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();



                GUILayout.Space(20);
                //DrawDefaultInspector();
            }
예제 #4
0
            public eAction OnInspector()
            {
                eAction   a = eAction.NONE;
                POFXLayer l = target as POFXLayer;

                GUI.color = Color.grey;
                GUILayout.BeginVertical(EditorStyles.helpBox);
                GUI.color = Color.white;

                if (l.m_material == null)
                {
                    l.Init();
                }

                if (l.m_material == null)
                {
                    //GUILayout.Label("BUG");
                    return(a);
                }

                POFXBase pofx = l.GetComponent <POFXBase>();
                int      id   = pofx.m_layers.IndexOf(l);


                GUILayout.BeginHorizontal();
                l.m_enable = GUILayout.Toggle(l.m_enable, "");
                GUILayout.Label("" + l.GetName(), EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();

                if (id != 0)
                {
                    if (GUILayout.Button("^", EditorStyles.helpBox))
                    {
                        a = eAction.UP;
                    }
                }

                if (id < pofx.m_layers.Count - 1)
                {
                    if (GUILayout.Button("v", EditorStyles.helpBox))
                    {
                        a = eAction.DOWN;
                    }
                }
                if (GUILayout.Button("X", EditorStyles.helpBox))
                {
                    a = eAction.REMOVE;
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical(EditorStyles.helpBox);
                DrawUI();
                if (GUI.changed)
                {
                    Undo.RecordObject(l, "POFX layer update");
                }

                GUILayout.EndVertical();
                GUILayout.Space(20);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (l.GetComponent <SpriteRenderer>() != null)
                {
                    l.m_sortingOrderOffset = EditorGUILayout.IntField("Order in layer offset", l.m_sortingOrderOffset);
                }
                else
                {
                    GUILayoutRenderQueue();
                }

                GUILayout.Space(20);
                GUILayout.EndHorizontal();

                if (l.m_enableMaterials.Count > 0)
                {
                    GUILayout.Label("Apply to materials :");
                    GUILayout.BeginHorizontal();
                    for (int m = 0; m < l.m_enableMaterials.Count; ++m)
                    //for (int m = 0; m < 20; ++m)
                    {
                        l.m_enableMaterials[m] = GUILayout.Toggle(l.m_enableMaterials[m], "" + (m + 1), GUILayout.MaxWidth(30));
                        //GUILayout.Toggle(false, "" + m, GUILayout.MaxWidth(35));
                        if (m % 5 == 4)
                        {
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();
                GUILayout.Space(5);

                return(a);
            }