Пример #1
0
    private void AddBindCell(object target)
    {
        BindCell cell = new BindCell();

        bool enabel = false;

        if (target is GameObject)
        {
            enabel = AddComponent((GameObject)target);
            cell.SetRoot((GameObject)target);
            cell.m_Type = BindCell.type.gameobject;
        }
        if (target is Transform)
        {
            enabel = AddComponent((Transform)target);
            cell.SetRoot(((Transform)target).gameObject);
            cell.m_Type = BindCell.type.transform;
        }
        if (target is MonoBehaviour)
        {
            enabel = AddComponent((MonoBehaviour)target);
            cell.SetRoot(((MonoBehaviour)target).gameObject);
            cell.m_Type = BindCell.type.behaviour;
            cell.SetBehaviour((MonoBehaviour)target);
            cell.m_Event.SetEventType(cell.m_Behaviour);

            if (s_EventDefault.Contains(cell.m_BehaviourType))
            {
                cell.m_Event.AddIndex(0);
            }
        }

        if (!enabel)
        {
            return;
        }

        cell.m_Path = GetTargetPath(cell.m_Target.transform, cell.m_Path);

        AddBindCell(target, cell);

        NewCurInfo(m_CurInfo.m_Target != null ? m_CurInfo.m_Target : null);
    }
Пример #2
0
    private void GetCode(string filePath)
    {
        string menberRegex = "(?<name>[\\w\\W]+) = m_Transform.Find\\(\"(?<path>[\\w\\W]+)\"\\)";
        Dictionary <string, BindCell> cells = new Dictionary <string, BindCell>();

        using (StreamReader reader = File.OpenText(filePath))
        {
            string line;
            int    state = 0;
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Contains("Menber End") || line.Contains("Init End") || line.Contains("EventListener End"))
                {
                    state = 0;
                }

                if (state == 1)
                {
                    string[] content = line.Split(' ');
                    if (content.Length < 7)
                    {
                        continue;
                    }
                    BindCell cell = new BindCell();
                    cell.m_BehaviourType = content[5];
                    cell.m_Name          = content[6];
                    cells.Add(cell.m_Name, cell);
                }

                if (state == 2)
                {
                    Match match = Regex.Match(line, menberRegex);
                    if (match.Groups.Count > 1)
                    {
                        string name = match.Groups["name"].Value.Replace(" ", string.Empty);
                        if (!cells.ContainsKey(name))
                        {
                            continue;
                        }

                        BindCell cell = cells[name];
                        cell.m_Path = match.Groups["path"].Value;
                        cell.m_Name = cell.m_Name.Replace("m_", string.Empty).Replace(cell.m_BehaviourType, string.Empty);

                        Transform target = m_Root.transform.Find(cell.m_Path);
                        if (PrefabUtility.GetPrefabParent(target) == null)
                        {
                            target = null;
                        }

                        object component = null;

                        cell.m_Event.SetEventType(cell.m_BehaviourType);

                        if (cell.m_BehaviourType == "GameObject")
                        {
                            cell.m_Type          = BindCell.type.gameobject;
                            cell.m_BehaviourType = string.Empty;
                        }
                        else if (cell.m_BehaviourType == "Transform")
                        {
                            cell.m_Type          = BindCell.type.transform;
                            cell.m_BehaviourType = string.Empty;
                        }
                        else
                        {
                            cell.m_Type = BindCell.type.behaviour;
                        }

                        if (target != null)
                        {
                            cell.SetRoot(target.gameObject);

                            if (cell.m_Type == BindCell.type.gameobject)
                            {
                                component = cell.m_Target;
                                AddComponent(cell.m_Target);
                                cell.SetBehaviour(null);
                            }
                            else if (cell.m_Type == BindCell.type.transform)
                            {
                                component = cell.m_Target.transform;
                                AddComponent(cell.m_Target.transform);
                                cell.SetBehaviour(null);
                            }
                            else
                            {
                                component = cell.m_Target.GetComponent(cell.m_BehaviourType);
                                if (component != null)
                                {
                                    cell.SetBehaviour((MonoBehaviour)component);
                                    AddComponent(cell.m_Behaviour);
                                }
                            }
                        }

                        AddBindCell(component, cell);
                    }
                }

                if (state == 3)
                {
                    BindCell curCell;
                    for (var index = 0; index < m_BindCells.Count; index++)
                    {
                        curCell = m_BindCells[index];
                        if (curCell.m_Event.GetEventType() == EventCell.type.Other)
                        {
                            continue;
                        }

                        if (!line.Contains(curCell.GetName()))
                        {
                            continue;
                        }

                        int id = curCell.m_Event.GetComponentId(line);
                        if (id != -1)
                        {
                            curCell.m_Event.AddIndex(id);
                        }
                    }
                }

                if (line.Contains("Menber Start"))
                {
                    state = 1;
                }

                if (line.Contains("Init Start"))
                {
                    state = 2;
                }

                if (line.Contains("EventListener Start"))
                {
                    state = 3;
                }
            }
        }

        RefreshUnableBindCell();
    }