示例#1
0
    //-------------------------------------------------------------------------
    public T createUi <T>(string package_name, string component_name,
                          FitScreen fit_screen = FitScreen.FitSize) where T : UiBase, new()
    {
        var go = new GameObject();

        go.name  = component_name;
        go.layer = 5;// "UI"

        var ui_panel = go.AddComponent <UIPanel>();

        ui_panel.packageName   = package_name;
        ui_panel.componentName = component_name;
        ui_panel.sortingOrder  = 1;
        ui_panel.fitScreen     = fit_screen;
        ui_panel.ApplyModifiedProperties(true, true);

        var ui_contentscale = go.AddComponent <UIContentScaler>();

        ui_contentscale.designResolutionX = 1280;
        ui_contentscale.designResolutionY = 800;
        ui_contentscale.screenMatchMode   = UIContentScaler.ScreenMatchMode.MatchWidthOrHeight;
        ui_contentscale.scaleMode         = UIContentScaler.ScaleMode.ScaleWithScreenSize;
        ui_contentscale.ApplyChange();

        var com = ui_panel.ui;

        T ui = new T();

        ui.UiMgr = this;
        ui.GoUi  = go;
        ui.ComUi = com;

        ui.create();

        string        ui_name = typeof(T).Name;
        List <UiBase> list_ui = null;

        MapAllUi.TryGetValue(ui_name, out list_ui);
        if (list_ui == null)
        {
            list_ui           = new List <UiBase>();
            MapAllUi[ui_name] = list_ui;
        }
        list_ui.Add(ui);

        return(ui);
    }
示例#2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            UIPanel panel = target as UIPanel;

#if UNITY_5
            DrawPropertiesExcluding(serializedObject, propertyToExclude);
#endif
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Package Name");
            if (GUILayout.Button(packageName.stringValue, "ObjectField"))
            {
                EditorWindow.GetWindow <PackagesWindow>(true, "Select a UI Component").SetSelection(packageName.stringValue, componentName.stringValue);
            }

            if (GUILayout.Button("Clear", GUILayout.Width(50)))
            {
                bool isPrefab = PrefabUtility.GetPrefabType(panel) == PrefabType.Prefab;
                panel.SendMessage("OnUpdateSource", new object[] { null, null, null, !isPrefab });

#if (UNITY_5_3 || UNITY_5_4)
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
#elif UNITY_5
                EditorApplication.MarkSceneDirty();
#else
                EditorUtility.SetDirty(panel);
#endif
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Component Name");
            if (GUILayout.Button(componentName.stringValue, "ObjectField"))
            {
                EditorWindow.GetWindow <PackagesWindow>(true, "Select a UI Component").SetSelection(packageName.stringValue, componentName.stringValue);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.PropertyField(renderMode);
            if ((RenderMode)renderMode.enumValueIndex != RenderMode.ScreenSpaceOverlay)
            {
                EditorGUILayout.PropertyField(renderCamera);
            }
            int oldSortingOrder = panel.sortingOrder;
            EditorGUILayout.PropertyField(sortingOrder);
            EditorGUILayout.PropertyField(fairyBatching);
            EditorGUILayout.PropertyField(hitTestMode);
            EditorGUILayout.PropertyField(touchDisabled);
            EditorGUILayout.LabelField("UI Transform", (GUIStyle)"OL Title");
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(position);
            EditorGUILayout.PropertyField(rotation);
            EditorGUILayout.PropertyField(scale);
            EditorGUILayout.Space();

            FitScreen oldFitScreen = (FitScreen)fitScreen.enumValueIndex;
            EditorGUILayout.PropertyField(fitScreen);

            if (serializedObject.ApplyModifiedProperties())
            {
                if (PrefabUtility.GetPrefabType(panel) != PrefabType.Prefab)
                {
                    panel.ApplyModifiedProperties(sortingOrder.intValue != oldSortingOrder, (FitScreen)fitScreen.enumValueIndex != oldFitScreen);
                }
            }
        }