Наследование: ScriptableObject
Пример #1
0
 static void GetConfig()
 {
     config = Resources.Load <UIManConfig> ("UIManConfig");
     if (config == null)
     {
         ConfigFile.Create <UIManConfig> ();
     }
 }
Пример #2
0
        public void GenerateViewModel()
        {
            if (typeName.Contains(" "))
            {
                EditorUtility.DisplayDialog("Error", "View model name cannot constain special character", "OK");
                return;
            }

            bool warn = false;

            if (typeName.Length <= 1 || (!typeName.Substring(0, 2).Equals("UI") && !baseTypePopup.SelectedItem.Equals(CodeGenerator.GetSupportTypeName(0))))
            {
                typeName = "UI" + typeName;
                warn     = true;
            }

            baseType = baseTypePopup.SelectedItem;

            UIManConfig config = Resources.Load <UIManConfig> ("UIManConfig");

            string savePath = "";

            if (baseType.Equals(CodeGenerator.GetSupportTypeName(1)))
            {
                savePath = config.screenScriptFolder;
            }
            else if (baseType.Equals(CodeGenerator.GetSupportTypeName(2)))
            {
                savePath = config.dialogScriptFolder;
            }

            savePath = Application.dataPath + "/" + savePath + "/" + typeName + ".cs";
            if (File.Exists(savePath) || CodeGenerator.IsViewModelExisted(typeName))
            {
                EditorUtility.DisplayDialog("Error", "View model name is already exist, please input other name!", "OK");
                return;
            }

            string[] paths      = Regex.Split(savePath, "/");
            string   scriptName = paths [paths.Length - 1];

            scriptName = scriptName.Replace(".cs", "");

            config.generatingType = typeName;
            string code = CodeGenerationHelper.GenerateScript(typeName, baseType);

            CodeGenerationHelper.SaveScript(savePath, code, true);
            GenerateViewModelHandler(savePath);
            AssetDatabase.Refresh(ImportAssetOptions.Default);

            if (warn)
            {
                Debug.LogWarning("Code generation warning: Invalid name detected, auto generate is activated!");
            }

            Close();
        }
Пример #3
0
        void OnGUI()
        {
            Init();
            GUILayout.Space(10);
            baseTypePopup.Draw();
            LineHelper.Draw(Color.black);
            GUILayout.Space(10);

            if (ColorButton.Draw("Create", CommonColor.LightGreen, GUILayout.Height(30)))
            {
                string      lastPath    = "";
                UIManConfig uiManConfig = Resources.Load <UIManConfig> ("UIManConfig");
                if (uiManConfig != null)
                {
                    if (baseTypePopup.SelectedItem == arrSupportType [0])
                    {
                        lastPath = uiManConfig.modelScriptFolder;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [1])
                    {
                        lastPath = uiManConfig.screenScriptFolder;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [2])
                    {
                        lastPath = uiManConfig.dialogScriptFolder;
                    }
                }

                lastPath = EditorUtility.SaveFilePanel("Save script", Application.dataPath + lastPath, typeName, "cs");

                if (!string.IsNullOrEmpty(lastPath))
                {
                    typeName = Path.GetFileNameWithoutExtension(lastPath);

                    lastPath = Path.GetDirectoryName(lastPath).Replace(Application.dataPath, "");
                    if (baseTypePopup.SelectedItem == arrSupportType [0])
                    {
                        uiManConfig.modelScriptFolder      = lastPath;
                        uiManConfig.generatingTypeIsDialog = false;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [1])
                    {
                        uiManConfig.screenScriptFolder     = lastPath;
                        uiManConfig.generatingTypeIsDialog = false;
                    }
                    else if (baseTypePopup.SelectedItem == arrSupportType [2])
                    {
                        uiManConfig.dialogScriptFolder     = lastPath;
                        uiManConfig.generatingTypeIsDialog = true;
                    }
                    EditorUtility.SetDirty(uiManConfig);

                    GenerateViewModel();
                }
            }
        }
Пример #4
0
        public static string GetNamespace(UIManConfig config)
        {
            var result = DEFAULT_NAMESPACE;

            if (config && !string.IsNullOrEmpty(config.classNamespace))
            {
                result = config.classNamespace;
            }

            return(result);
        }
Пример #5
0
        // Initialize
        public override void Init()
        {
            _uiLoading  = GetComponentInChildren <UIActivity> ();
            config      = Resources.Load <UIManConfig> ("UIManConfig");
            bgRectTrans = background.GetComponent <RectTransform> ();

            UIManScreen[] screens = GetComponentsInChildren <UIManScreen> ();
            if (screens.Length > 0)
            {
                for (int i = 0; i < screens.Length; i++)
                {
                    screenDict.Add(screens [i].UIType, screens [i]);
                }
                CurrentScreen = screenDict [screens [screens.Length - 1].UIType];
            }
        }
Пример #6
0
        public EditablePropertyDrawer(UIManConfig config, Type viewModelType, CustomPropertyInfo property, Action <CustomPropertyInfo> onPropertyChanged, Action <CustomPropertyInfo> onPropertyDelete)
        {
            this._viewModelType     = viewModelType;
            this._property          = property;
            this._onPropertyChanged = onPropertyChanged;
            this._onPropertyDelete  = onPropertyDelete;

            this.observableTypes = UIManEditorReflection.GetAllObservableTypes(this._viewModelType, config.classNamespace);

            for (var i = 0; i < this.observableTypes.Length; i++)
            {
                if (this._property.LastPropertyType == this.observableTypes[i])
                {
                    this.selectedType = i;
                    break;
                }
            }
        }
Пример #7
0
        public override void Initialize()
        {
            this.uiLoading = GetComponentInChildren <UIActivityIndicator>();

            this.config      = Resources.Load <UIManConfig>("UIManConfig");
            this.bgRectTrans = this.background.GetComponent <RectTransform>();

            var screens = GetComponentsInChildren <UIManScreen>();

            if (screens.Length > 0)
            {
                for (var i = 0; i < screens.Length; i++)
                {
                    this.screenDict.Add(screens[i].UIType, screens[i]);
                }
                this.CurrentScreen = this.screenDict[screens[screens.Length - 1].UIType];
            }
        }
Пример #8
0
        public static string GenerateHandler(string modelName, string baseType, UIManConfig config, string customNamespace = null)
        {
            var code = "";
            var text = AssetDatabase.LoadAssetAtPath <TextAsset>(Getpath(HANDLER_TEMPLATE_PATH));

            if (text != null)
            {
                code = text.text;
                code = Regex.Replace(code, NAME_SPACE_TAG, string.IsNullOrEmpty(customNamespace) ? GetNamespace(config) : customNamespace);
                code = Regex.Replace(code, NAME_TAG, modelName);
                code = Regex.Replace(code, TYPE_TAG, baseType);
            }
            else
            {
                UnuLogger.LogError("There are something wrong, could not find code template!");
            }

            return(code);
        }
Пример #9
0
 private static void GetConfig()
 {
     _config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>();
 }
Пример #10
0
        static public Animator GenerateAnimator(GameObject target, params string[] clipsName)
        {
            UIManConfig config = Resources.Load <UIManConfig> ("UIManConfig");

            Animator anim = target.GetComponent <Animator> ();

            if (anim == null)
            {
                anim = target.AddComponent <Animator> ();
            }

            // Create folder
            string assetPath      = Application.dataPath.Substring(Application.dataPath.IndexOf("/Assets") + 1) + "/" + config.animRootFolder;
            string rootFolderPath = string.Format("{0}{1}", assetPath, target.name);

            EditorUtils.CreatePath(rootFolderPath);

            // Create controller
            string             controllerFilePath = string.Format("{0}/{1}.controller", rootFolderPath, target.name);
            AnimatorController controller         = AnimatorController.CreateAnimatorControllerAtPath(controllerFilePath);

            // Change the name of the first layer.
            AnimatorControllerLayer[] layers = controller.layers;
            layers [0].name   = "Base Layer";
            controller.layers = layers;

            // Get the root state machine .
            AnimatorStateMachine rootStateMachine = controller.layers [0].stateMachine;

            // Set the default state.
            AnimatorState defaultState = rootStateMachine.AddState("Default");

            defaultState.motion           = null;
            rootStateMachine.defaultState = defaultState;

            // Add states and transitions
            for (int i = 0; i < clipsName.Length; i++)
            {
                // Add parameters to the controller.
                //string triggerName = string.Format("Do{0}", clipsName[i]);
                //controller.AddParameter (triggerName, AnimatorControllerParameterType.Trigger);

                // Create empty clip and add motion
                AnimationClip clip     = new AnimationClip();
                string        clipName = clipsName [i];
                string        clipPath = string.Format("{0}/{1}.anim", rootFolderPath, clipName);
                clip.name = clipName;
                AssetDatabase.CreateAsset(clip, clipPath);

                // Add motion to controller
                Motion        motion   = AssetDatabase.LoadAssetAtPath(clipPath, typeof(AnimationClip)) as Motion;
                AnimatorState newState = rootStateMachine.AddState(clipName);
                newState.motion = motion;
                UIAnimationState smb = (UIAnimationState)newState.AddStateMachineBehaviour(typeof(UIAnimationState));
                if (clipName == UIManDefine.ANIM_SHOW)
                {
                    smb.Init(UIAnimationType.SHOW, true, false);
                }
                else if (clipName == UIManDefine.ANIM_HIDE)
                {
                    smb.Init(UIAnimationType.HIDE, true, true);
                }
                else if (clipName == UIManDefine.ANIM_IDLE)
                {
                    smb.Init(UIAnimationType.IDLE, true, false);
                }

                // Add trasition to controller

                /*
                 * AnimatorStateTransition transition = rootStateMachine.AddAnyStateTransition(newState);
                 * transition.hasExitTime = false;
                 * transition.exitTime = 0.0f;
                 * transition.hasFixedDuration = true;
                 * transition.duration = 0.0f;
                 * transition.offset = 0.0f;
                 */
                // Add condition for transition
                //transition.AddCondition(AnimatorConditionMode.If, 0, triggerName);
            }

            anim.runtimeAnimatorController = controller;
            return(anim);
        }
Пример #11
0
        public static string GenerateType(string modelName, string baseType, bool isSealed, UIManConfig config, string customNamespace, params CustomPropertyInfo[] properties)
        {
            var code = "";
            var text = AssetDatabase.LoadAssetAtPath <TextAsset>(Getpath(TYPE_TEMPLATE_PATH));

            if (text != null)
            {
                code = text.text;
                code = Regex.Replace(code, NAME_SPACE_TAG, string.IsNullOrEmpty(customNamespace) ? GetNamespace(config) : customNamespace);
                code = Regex.Replace(code, NAME_TAG, modelName);
                code = Regex.Replace(code, TYPE_TAG, baseType);
                code = Regex.Replace(code, SEALED_TAG, isSealed ? "sealed " : string.Empty);
                code = Regex.Replace(code, PROPERTIES_TAG, GeneratePropertiesBlock(properties));
                code = Regex.Replace(code, NAME_SPACES_TAG, GenerateNamespaceBlock(properties));
            }
            else
            {
                UnuLogger.LogError("There are something wrong, could not find code template!");
            }

            return(code);
        }