예제 #1
0
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }

            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            // Load default Actions
            DirectoryInfo dir = new DirectoryInfo("Assets/" + actionsManager.folderPath);

            FileInfo[] info = dir.GetFiles("*.cs");

            actionsManager.AllActions.Clear();
            foreach (FileInfo f in info)
            {
                try
                {
                    int    extentionPosition = f.Name.IndexOf(".cs");
                    string className         = f.Name.Substring(0, extentionPosition);

                    StreamReader streamReader = new StreamReader(f.FullName);
                    string       fileContents = streamReader.ReadToEnd();
                    streamReader.Close();

                    fileContents = fileContents.Replace(" ", "");

                    if (fileContents.Contains("class" + className + ":Action") ||
                        fileContents.Contains("class" + className + ":AC.Action"))
                    {
                        Action tempAction = (Action)CreateInstance(className);
                        if (tempAction is Action)
                        {
                            ActionType newActionType = new ActionType(className, tempAction);

                            // Transfer back data
                            foreach (ActionType oldActionType in oldActionTypes)
                            {
                                if (newActionType.IsMatch(oldActionType))
                                {
                                    newActionType.color = oldActionType.color;
                                    if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                    {
                                        newActionType.color = Color.white;
                                    }
                                    if (newActionType.color.a < 1f)
                                    {
                                        newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                    }
                                }
                            }

                            actionsManager.AllActions.Add(newActionType);
                        }
                    }
                    else
                    {
                        ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                    }
                }
                catch {}
            }

            // Load custom Actions
            if (!string.IsNullOrEmpty(actionsManager.customFolderPath) && actionsManager.customFolderPath != actionsManager.folderPath)
            {
                dir  = new DirectoryInfo("Assets/" + actionsManager.customFolderPath);
                info = dir.GetFiles("*.cs");

                foreach (FileInfo f in info)
                {
                    try
                    {
                        int    extentionPosition = f.Name.IndexOf(".cs");
                        string className         = f.Name.Substring(0, extentionPosition);

                        StreamReader streamReader = new StreamReader(f.FullName);
                        string       fileContents = streamReader.ReadToEnd();
                        streamReader.Close();

                        fileContents = fileContents.Replace(" ", "");

                        if (fileContents.Contains("class" + className + ":Action") ||
                            fileContents.Contains("class" + className + ":AC.Action"))
                        {
                            Action tempAction = (Action)CreateInstance(className);
                            if (tempAction is Action)
                            {
                                actionsManager.AllActions.Add(new ActionType(className, tempAction));
                            }
                        }
                        else
                        {
                            ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                        }
                    }
                    catch {}
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
            actionsManager.SetEnabled();
        }
예제 #2
0
        private static void AddActionsFromFolder(ActionsManager actionsManager, string folderPath, List <ActionType> oldActionTypes)
        {
            DirectoryInfo dir = new DirectoryInfo(folderPath);

            FileInfo[] info = dir.GetFiles("*.cs");
            foreach (FileInfo f in info)
            {
                if (f.Name.StartsWith("._"))
                {
                    continue;
                }

                try
                {
                    int    extentionPosition = f.Name.IndexOf(".cs");
                    string className         = f.Name.Substring(0, extentionPosition);

                    StreamReader streamReader = new StreamReader(f.FullName);
                    string       fileContents = streamReader.ReadToEnd();
                    streamReader.Close();

                    fileContents = fileContents.Replace(" ", "");

                    if (fileContents.Contains("class" + className + ":Action") ||
                        fileContents.Contains("class" + className + ":AC.Action"))
                    {
                        MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript> (folderPath + "/" + f.Name);
                        if (script == null)
                        {
                            continue;
                        }

                        Action tempAction = (Action)CreateInstance(script.GetClass());
                        if (tempAction != null && tempAction is Action)
                        {
                            ActionType newActionType = new ActionType(className, tempAction);

                            // Transfer back data
                            foreach (ActionType oldActionType in oldActionTypes)
                            {
                                if (newActionType.IsMatch(oldActionType))
                                {
                                    newActionType.color     = oldActionType.color;
                                    newActionType.isEnabled = oldActionType.isEnabled;
                                    if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                    {
                                        newActionType.color = Color.white;
                                    }
                                    if (newActionType.color.a < 1f)
                                    {
                                        newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                    }
                                }
                            }

                            actionsManager.AllActions.Add(newActionType);
                        }
                    }
                    else
                    {
                        ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                    }
                }
                catch {}
            }
        }
예제 #3
0
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }

            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            // Load default Actions
            DirectoryInfo dir = new DirectoryInfo("Assets/" + actionsManager.folderPath);

            FileInfo[] info = dir.GetFiles("*.cs");

            actionsManager.AllActions.Clear();
            foreach (FileInfo f in info)
            {
                int    extentionPosition = f.Name.IndexOf(".cs");
                string className         = f.Name.Substring(0, extentionPosition);
                Action tempAction        = (Action)CreateInstance(className);

                ActionType newActionType = new ActionType(className, tempAction);

                // Transfer back data
                foreach (ActionType oldActionType in oldActionTypes)
                {
                    if (newActionType.IsMatch(oldActionType))
                    {
                        newActionType.color = oldActionType.color;
                        if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                        {
                            newActionType.color = Color.white;
                        }
                        if (newActionType.color.a < 1f)
                        {
                            newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                        }
                    }
                }

                actionsManager.AllActions.Add(newActionType);
            }

            // Load custom Actions
            if (actionsManager.customFolderPath != actionsManager.folderPath)
            {
                dir  = new DirectoryInfo("Assets/" + actionsManager.customFolderPath);
                info = dir.GetFiles("*.cs");

                foreach (FileInfo f in info)
                {
                    try
                    {
                        int    extentionPosition = f.Name.IndexOf(".cs");
                        string className         = f.Name.Substring(0, extentionPosition);
                        Action tempAction        = (Action)CreateInstance(className);
                        if (tempAction is Action)
                        {
                            actionsManager.AllActions.Add(new ActionType(className, tempAction));
                        }
                    }
                    catch {}
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
            actionsManager.SetEnabled();
        }
        public static void RefreshActions()
        {
            if (AdvGame.GetReferences() == null || AdvGame.GetReferences().actionsManager == null)
            {
                return;
            }

            ActionsManager actionsManager = AdvGame.GetReferences().actionsManager;

            // Collect data to transfer
            List <ActionType> oldActionTypes = new List <ActionType>();

            foreach (ActionType actionType in actionsManager.AllActions)
            {
                oldActionTypes.Add(actionType);
            }

            actionsManager.AllActions.Clear();

            // Load default Actions
            string        targetDir = "Assets/" + actionsManager.FolderPath;
            DirectoryInfo dir       = new DirectoryInfo(targetDir);

            FileInfo[] info = dir.GetFiles("*.cs");
            foreach (FileInfo f in info)
            {
                try
                {
                    int    extentionPosition = f.Name.IndexOf(".cs");
                    string className         = f.Name.Substring(0, extentionPosition);

                    StreamReader streamReader = new StreamReader(f.FullName);
                    string       fileContents = streamReader.ReadToEnd();
                    streamReader.Close();

                    fileContents = fileContents.Replace(" ", "");

                    if (fileContents.Contains("class" + className + ":Action") ||
                        fileContents.Contains("class" + className + ":AC.Action"))
                    {
                        MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript> (targetDir + "/" + f.Name);
                        if (script == null)
                        {
                            continue;
                        }

                        Action tempAction = (Action)CreateInstance(script.GetClass());
                        if (tempAction != null && tempAction is Action)
                        {
                            ActionType newActionType = new ActionType(className, tempAction);

                            // Transfer back data
                            foreach (ActionType oldActionType in oldActionTypes)
                            {
                                if (newActionType.IsMatch(oldActionType))
                                {
                                    newActionType.color     = oldActionType.color;
                                    newActionType.isEnabled = oldActionType.isEnabled;
                                    if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                    {
                                        newActionType.color = Color.white;
                                    }
                                    if (newActionType.color.a < 1f)
                                    {
                                        newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                    }
                                }
                            }

                            actionsManager.AllActions.Add(newActionType);
                        }
                    }
                    else
                    {
                        ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                    }
                }
                catch {}
            }

            // Load custom Actions
            if (!string.IsNullOrEmpty(actionsManager.customFolderPath) && actionsManager.UsingCustomActionsFolder)
            {
                targetDir = "Assets/" + actionsManager.customFolderPath;
                dir       = new DirectoryInfo(targetDir);

                try
                {
                    info = dir.GetFiles("*.cs");

                    foreach (FileInfo f in info)
                    {
                        try
                        {
                            int    extentionPosition = f.Name.IndexOf(".cs");
                            string className         = f.Name.Substring(0, extentionPosition);

                            StreamReader streamReader = new StreamReader(f.FullName);
                            string       fileContents = streamReader.ReadToEnd();
                            streamReader.Close();

                            fileContents = fileContents.Replace(" ", "");

                            if (fileContents.Contains("class" + className + ":Action") ||
                                fileContents.Contains("class" + className + ":AC.Action"))
                            {
                                MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript> (targetDir + "/" + f.Name);
                                if (script == null)
                                {
                                    continue;
                                }

                                Action tempAction = (Action)CreateInstance(script.GetClass());
                                if (tempAction != null && tempAction is Action)
                                {
                                    ActionType newActionType = new ActionType(className, tempAction);

                                    // Transfer back data
                                    foreach (ActionType oldActionType in oldActionTypes)
                                    {
                                        if (newActionType.IsMatch(oldActionType))
                                        {
                                            newActionType.color     = oldActionType.color;
                                            newActionType.isEnabled = oldActionType.isEnabled;
                                            if (newActionType.color == new Color(0f, 0f, 0f, 0f))
                                            {
                                                newActionType.color = Color.white;
                                            }
                                            if (newActionType.color.a < 1f)
                                            {
                                                newActionType.color = new Color(newActionType.color.r, newActionType.color.g, newActionType.color.b, 1f);
                                            }
                                        }
                                    }

                                    actionsManager.AllActions.Add(newActionType);
                                }
                            }
                            else
                            {
                                ACDebug.LogError("The script '" + f.FullName + "' must derive from AC's Action class in order to be available as an Action.");
                            }
                        }
                        catch
                        {}
                    }
                }
                catch (System.Exception e)
                {
                    ACDebug.LogWarning("Can't access directory " + "Assets/" + actionsManager.customFolderPath + " - does it exist?\n\nException: " + e);
                }
            }

            actionsManager.AllActions.Sort(delegate(ActionType i1, ActionType i2) { return(i1.GetFullTitle(true).CompareTo(i2.GetFullTitle(true))); });
        }