Ejemplo n.º 1
0
        internal EventProxyFileDetails(string className, string nameSpace, string methodName, PlayMakerEventProxyCreator.ParameterType methodParamType, string fileName, string filePath, System.DateTime updateTime)
        {
            _className       = className;
            _nameSpace       = nameSpace;
            _methodName      = methodName;
            _methodParamType = methodParamType;
            _fileName        = fileName;
            _filePath        = filePath;
            _updateTime      = updateTime;

            _projectPath = filePath.Substring(Application.dataPath.Length + 1);
        }
Ejemplo n.º 2
0
        void OnGUI_DoDefinitionForm()
        {
            Color _orig = Color.clear;

            ReBuildPreview = false;

            /*
             * if (currentFileDetails!=null)
             * {
             *      GUILayout.Label("You are editing an existing enum");
             *      FsmEditorGUILayout.Divider();
             * }
             */
            // FOLDER
            _orig = GUI.color;
            if (!currentDefinition.FolderPathValidation.success)
            {
                GUI.color = new Color(255, 165, 0);
            }
            GUILayout.Label("Project Folder: <color=#ffa500><b>" + currentDefinition.FolderPathValidation.message + "</b></color>");
            currentDefinition.FolderPath = GUILayout.TextField(currentDefinition.FolderPath);
            GUI.color = _orig;

            // NAMESPACE
            _orig = GUI.color;
            if (!currentDefinition.NameSpaceValidation.success)
            {
                GUI.color = Color.red;
            }
            GUILayout.Label("NameSpace: <color=#B20000><b>" + currentDefinition.NameSpaceValidation.message + "</b></color>");
            string _nameSpace = GUILayout.TextField(currentDefinition.NameSpace);

            GUI.color = _orig;
            if (!string.Equals(_nameSpace, currentDefinition.NameSpace))
            {
                currentDefinition.NameSpace = _nameSpace;
                ReBuildPreview = true;
            }

            // Method Name
            _orig = GUI.color;
            if (!currentDefinition.PublicMethodValidation.success)
            {
                GUI.color = Color.red;
            }
            GUILayout.Label("Public Method/Message Name: <color=#B20000><b>" + currentDefinition.PublicMethodValidation.message + "</b></color>");
            string _methodName = GUILayout.TextField(currentDefinition.PublicMethodName);

            GUI.color = _orig;
            if (!string.Equals(_methodName, currentDefinition.PublicMethodName))
            {
                currentDefinition.Name             = _methodName + "Proxy";
                currentDefinition.PublicMethodName = _methodName;
                ReBuildPreview = true;
            }

            // Parameter

            GUILayout.Label("Public Method/Message Parameter:");

            PlayMakerEventProxyCreator.ParameterType _param = (PlayMakerEventProxyCreator.ParameterType)EditorGUILayout.EnumPopup("", currentDefinition.Parameter);

            if (_param != currentDefinition.Parameter)
            {
                currentDefinition.Parameter = _param;
                ReBuildPreview = true;
            }


            GUILayout.Label("FileName being generated: " + currentDefinition.Name + ".cs");

            FsmEditorGUILayout.Divider();

            if (!currentDefinition.DefinitionValidation.success)
            {
                GUILayout.Label("<color=#B20000><b>" + currentDefinition.DefinitionValidation.message + "</b></color>");
            }

            if (currentDefinition.DefinitionValidation.success)
            {
                //if (_currentFileDetails!=null) GUILayout.Label(_currentFileDetails.projectPath);
                // check if this is the item we are currently editing
                string _label      = "Create";
                bool   _isUpdating = _currentFileDetails != null && (currentDefinition.FolderPath + currentDefinition.Name + ".cs").Equals(_currentFileDetails.projectPath);
                if (_isUpdating)
                {
                    _label    = "Save Modification";
                    GUI.color = Color.yellow;
                }

                if (GUILayout.Button(_label))                 // Label "Save Changes" when we detected that we are editing an existing enum
                {
                    eventProxyCreator.CreateProxy(currentDefinition);
                    _list = EventProxyFileFinder.FindFiles();
                }
                GUI.color = Color.white;

                if (_isUpdating)
                {
                    GUILayout.Label("If this component is already in use, this may break your logic.");
                }
            }
            else
            {
                Color _color = GUI.color;

                _color.a  = 0.5f;
                GUI.color = _color;
                GUILayout.Label("Fix form before saving", "Button");
                _color.a  = 1f;
                GUI.color = _color;
            }


            if (ReBuildPreview)
            {
                currentDefinition.ValidateDefinition();

                //enumCreator.BuildScriptLiteral(currentEnum);
                Repaint();
            }
        }
Ejemplo n.º 3
0
        public static Dictionary <string, EventProxyFileDetails> FindFiles()
        {
            //Lookup enums in file names
            Dictionary <string, EventProxyFileDetails> detailsList = new Dictionary <string, EventProxyFileDetails>();

            classFiles = new List <string>();
            FindAllCSharpScriptFiles(Application.dataPath);

            //Lookup class name in the class file text
            for (int i = 0; i < classFiles.Count; i++)
            {
                string filePath = classFiles[i];
                string codeFile = File.ReadAllText(filePath);

                if (codeFile.Contains("__" + "PLAYMAKER_EVENT_PROXY__"))               // compose the tag to avoid this file to be found...
                {
                    FileInfo _info = new FileInfo(filePath);

                    string fileName = _info.Name;

                    string className       = "";
                    Match  _classNameMatch = Regex.Match(codeFile, @"(?:public(?:\s+)class(?:\s+))(\w+)(?:\s+)(?::)");
                    if (_classNameMatch.Success)
                    {
                        className = _classNameMatch.Groups[1].Value;
                    }

                    string nameSpace       = "";
                    Match  _nameSpaceMatch = Regex.Match(codeFile, @"namespace (\w.+)");
                    if (_nameSpaceMatch.Success)
                    {
                        nameSpace = _nameSpaceMatch.Groups[1].Value;
                    }

                    string methodName      = "";
                    Match  methodNameMatch = Regex.Match(codeFile, @"public(?:\s+)void(?:\s+)(\w+)");
                    if (methodNameMatch.Success)
                    {
                        methodName = methodNameMatch.Groups[1].Value;
                    }

                    PlayMakerEventProxyCreator.ParameterType methodParamType = PlayMakerEventProxyCreator.ParameterType.none;
                    Match methodParamTypeMatch = Regex.Match(codeFile, @"\((\w*) parameter\)");
                    if (methodParamTypeMatch.Success)
                    {
                        string _type = methodParamTypeMatch.Groups[1].Value;

                        switch (_type)
                        {
                        case "float":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Float;
                            break;

                        case "int":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Int;
                            break;

                        case "bool":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Bool;
                            break;

                        case "GameObject":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.GameObject;
                            break;

                        case "String":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.String;
                            break;

                        case "Vector2":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Vector2;
                            break;

                        case "Vector3":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Vector3;
                            break;

                        case "Color":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Color;
                            break;

                        case "Rect":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Rect;
                            break;

                        case "Material":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Material;
                            break;

                        case "Texture":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Texture;
                            break;

                        case "Quaternion":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Quaternion;
                            break;

                        case "Object":
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.Object;
                            break;

                        default:
                            methodParamType = PlayMakerEventProxyCreator.ParameterType.none;
                            break;
                        }
                    }


                    EventProxyFileDetails _details = new EventProxyFileDetails(
                        className,
                        nameSpace,
                        methodName,
                        methodParamType,
                        fileName,
                        filePath,
                        _info.LastWriteTimeUtc
                        );

                    detailsList.Add(filePath, _details);
                }
            }

            return(detailsList);
        }