/// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            ComponentNames?.Add(Text);
            Parent?.Add(this);
        }
        private ComponentNames CreateComponentNamesFromAsset(string projectPath, string asset)
        {
            ComponentNames newComponent = new ComponentNames(NameFromPath(asset), "", asset);

            try
            {
                System.IO.FileStream   FS = new System.IO.FileStream(projectPath + asset, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                System.IO.StreamReader SR = new System.IO.StreamReader(FS);
                string line;
                while (!SR.EndOfStream)
                {
                    line = SR.ReadLine();
                    int index1 = line.IndexOf("namespace");
                    int index2 = line.IndexOf("{");
                    if (index1 != -1 && index2 != -1)
                    {
                        line   = line.Substring(index1 + 9);
                        index2 = line.IndexOf("{");
                        line   = line.Substring(0, index2);
                        line   = line.Replace(" ", "");
                        newComponent.namespaceName = line;
                    }
                }
            }
            catch
            {
            }
            return(newComponent);
        }
Пример #3
0
        public override void HandleAbilities(Entity entity)
        {
            Abilities = GetComponents <IActorAbility>().ToList();

            foreach (var a in GetComponents <IActorAbility>().ToList())
            {
                if (a is IPerkAbility p)
                {
                    PerksToApply.Add(p);
                }
                else
                {
                    Abilities.Add(a);
                }
            }

            foreach (var ability in Abilities)
            {
                ability.AddComponentData(ref entity, this);
                if (ability is IComponentName componentName && !componentName.ComponentName.Equals(string.Empty))
                {
                    ComponentNames.Add(componentName.ComponentName);
                }
            }
        }
        private void AddComponentType <T>(int index) where T : IComponent, new()
        {
            ComponentHelper <TEntity, T> .Initialize(index);

            ComponentNames.Add(typeof(T).PrettyPrintGenericTypeName());
            ComponentTypes.Add(typeof(T));
            ComponentCount++;
        }
Пример #5
0
 internal static string ToSerializedValue(this ComponentNames value)
 {
     switch (value)
     {
     case ComponentNames.MicrosoftWindowsShellSetup:
         return("Microsoft-Windows-Shell-Setup");
     }
     return(null);
 }
Пример #6
0
 string GetPathFromNames(string space, string name)
 {
     ComponentNames test = new ComponentNames(name, space, "");
     int index = existingComponents.IndexOf(test);
     if (index != -1)
     {
         return existingComponents[index].assetPath;
     }
     return "";
 }
        private void Initialize()
        {
            _contextInfo = new ContextInfo(DisplayName,
                                           ComponentNames.ToArray(),
                                           ComponentTypes.ToArray());

            ContextHelper <TContext> .Initialize(_contextInfo);

            IsInitialized = true;
        }
 private void SearchForUsageOfAllScripts()
 {
     _existingComponents = new List <ComponentNames>();
     string[] allAssets = AssetDatabase.GetAllAssetPaths();
     foreach (string asset in allAssets)
     {
         int indexCS = asset.IndexOf(".cs");
         int indexJS = asset.IndexOf(".js");
         if (indexCS != -1 || indexJS != -1)
         {
             ComponentNames newComponent = CreateComponentNamesFromAsset(_projectPath, asset);
             _existingComponents.Add(newComponent);
         }
     }
     SearchForDependencies(_existingComponents);
 }
Пример #9
0
 private void ComponentTypeClicked(object sender, EventArgs e)
 {
     if (((ComboBox)sender).SelectedItem != null)
     {
         mPreviousComponentType = (ComponentNames)((ComboBox)sender).SelectedItem;
     }
 }
Пример #10
0
        private void ComponentClicked(object sender, EventArgs e)
        {
            Button box = (Button)sender;
            mActiveComponentButton = box;

            if (mComponents.ContainsKey(((Button)sender).Text))
            {
                mComponentProperties.SelectedObject = mComponents[((Button)sender).Text];
                mComponentTypeSelection.Text = ((Button)sender).Text;
            }
            else
            {
                mComponentTypeSelection.Text = "";
                mComponentProperties.SelectedObject = null;
            }

            mPreviousComponentType = (ComponentNames)Enum.Parse(typeof(ComponentNames), box.Text);

            mComponentTypeSelection.Items.Clear();
            foreach (ComponentNames name in Enum.GetValues(typeof(ComponentNames)))
            {
                mComponentTypeSelection.Items.Add(name);
            }

            if (mComponents.ContainsKey(((Button)sender).Text))
            {
                string selectedTypeName = mComponents[((Button)sender).Text].GetType().Name;
                mComponentTypeSelection.SelectedIndex = mComponentTypeSelection.FindStringExact(selectedTypeName);
            }
            else
            {
                mComponentTypeSelection.SelectedIndex = (int)ComponentNames.UNSPECIFIED_COMPONENT;
            }

            mComponentPropertiesPanel.Show();
        }
Пример #11
0
        private void AddComponentClicked(object sender, EventArgs e)
        {
            Button newComponent = new Button();
            newComponent.Location = new System.Drawing.Point(0, 0);
            newComponent.Size = new System.Drawing.Size(200, 20);
            newComponent.Text = "UNSPECIFIED_COMPONENT";
            newComponent.UseVisualStyleBackColor = true;
            newComponent.Click += new EventHandler(ComponentClicked);

            mActiveComponentButton = newComponent;

            mPreviousComponentType = ComponentNames.UNSPECIFIED_COMPONENT;

            mComponentButtons.Add(newComponent);
            mComponentsPanel.Controls.Add(newComponent);

            OrderComponents();
        }
Пример #12
0
        /// <summary>
        /// OnInitialized 方法
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();

            ComponentNames?.Add(HeaderText);
        }
 string GetPathFromNames(string space, string name)
 {
     ComponentNames test = new ComponentNames(name, space, "");
         int index = existingComponents.IndexOf(test);
         if (index != -1)
         {
             return existingComponents[index].assetPath;
         }
         return "";
 }
Пример #14
0
        public static string ToString(ComponentNames value)
        {
            switch (value)
            {
            case ComponentNames.Core: return(Core);

            case ComponentNames.CADGeometry: return(CADGeometry);

            case ComponentNames.CubeMapTexturing: return(CubeMapTexturing);

            case ComponentNames.DIS: return(DIS);

            case ComponentNames.EnvironmentalEffects: return(EnvironmentalEffects);

            case ComponentNames.EnvironmentalSensor: return(EnvironmentalSensor);

            case ComponentNames.EventUtilities: return(EventUtilities);

            case ComponentNames.Followers: return(Followers);

            case ComponentNames.Geometry2D: return(Geometry2D);

            case ComponentNames.Geometry3D: return(Geometry3D);

            case ComponentNames.Geospatial: return(Geospatial);

            case ComponentNames.Grouping: return(Grouping);

            case ComponentNames.H_Anim: return(H_Anim);

            case ComponentNames.Interpolation: return(Interpolation);

            case ComponentNames.KeyDeviceSensor: return(KeyDeviceSensor);

            case ComponentNames.Layering: return(Layering);

            case ComponentNames.Layout: return(Layout);

            case ComponentNames.Lighting: return(Lighting);

            case ComponentNames.Navigation: return(Navigation);

            case ComponentNames.Networking: return(Networking);

            case ComponentNames.NURBS: return(NURBS);

            case ComponentNames.ParticleSystems: return(ParticleSystems);

            case ComponentNames.PickingSensor: return(PickingSensor);

            case ComponentNames.PointingDeviceSensor: return(PointingDeviceSensor);

            case ComponentNames.Rendering: return(Rendering);

            case ComponentNames.RigidBodyPhysics: return(RigidBodyPhysics);

            case ComponentNames.Scripting: return(Scripting);

            case ComponentNames.Shaders: return(Shaders);

            case ComponentNames.Shape: return(Shape);

            case ComponentNames.Sound: return(Sound);

            case ComponentNames.Text: return(Text);

            case ComponentNames.Texturing: return(Texturing);

            case ComponentNames.Texturing3D: return(Texturing3D);

            case ComponentNames.Time: return(Time);

            default: throw new FormatException();
            }
        }
Пример #15
0
 public Component(ComponentNames name, SFInt32 level)
 {
     this.Name  = name;
     this.Level = level;
 }
 int SortAlphabetically(ComponentNames a, ComponentNames b)
 {
     return a.assetPath.CompareTo(b.assetPath);
 }
    void OnGUI()
    {
        GUILayout.Label(position + "");
            GUILayout.Space(3);
            int oldValue = GUI.skin.window.padding.bottom;
            GUI.skin.window.padding.bottom = -20;
            Rect windowRect = GUILayoutUtility.GetRect(1, 17);
            windowRect.x += 4;
            windowRect.width -= 7;
            editorMode = GUI.SelectionGrid(windowRect, editorMode, modes, 2, "Window");
            GUI.skin.window.padding.bottom = oldValue;

            switch (editorMode)
            {
                case 0:
                    selectedCheckType = GUILayout.SelectionGrid(selectedCheckType, checkType, 2, "Toggle");
                    GUI.enabled = selectedCheckType == 0;
                    targetComponent = (MonoScript)EditorGUILayout.ObjectField(targetComponent, typeof(MonoScript), false);
                    GUI.enabled = true;

                    if (GUILayout.Button("Check component usage"))
                    {
                        AssetDatabase.SaveAssets();
                        switch (selectedCheckType)
                        {
                            case 0:
                                componentName = targetComponent.name;
                                string targetPath = AssetDatabase.GetAssetPath(targetComponent);
                                string[] allPrefabs = GetAllPrefabs();
                                listResult = new List<string>();
                                foreach (string prefab in allPrefabs)
                                {
                                    string[] single = new string[] { prefab };
                                    string[] dependencies = AssetDatabase.GetDependencies(single);
                                    foreach (string dependedAsset in dependencies)
                                    {
                                        if (dependedAsset == targetPath)
                                        {
                                            listResult.Add(prefab);
                                        }
                                    }
                                }
                                break;
                            case 1:
                                List<string> scenesToLoad = new List<string>();
                                existingComponents = new List<ComponentNames>();
                                prefabComponents = new List<ComponentNames>();
                                notUsedComponents = new List<ComponentNames>();
                                addedComponents = new List<ComponentNames>();
                                sceneComponents = new List<ComponentNames>();

                                if (EditorApplication.SaveCurrentSceneIfUserWantsTo())
                                {
                                    string projectPath = Application.dataPath;
                                    projectPath = projectPath.Substring(0, projectPath.IndexOf("Assets"));

                                    string[] allAssets = AssetDatabase.GetAllAssetPaths();

                                    foreach (string asset in allAssets)
                                    {
                                        int indexCS = asset.IndexOf(".cs");
                                        int indexJS = asset.IndexOf(".js");
                                        if (indexCS != -1 || indexJS != -1)
                                        {
                                            ComponentNames newComponent = new ComponentNames(NameFromPath(asset), "", asset);
                                            try
                                            {
                                                System.IO.FileStream FS = new System.IO.FileStream(projectPath + asset, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                                                System.IO.StreamReader SR = new System.IO.StreamReader(FS);
                                                string line;
                                                while (!SR.EndOfStream)
                                                {
                                                    line = SR.ReadLine();
                                                    int index1 = line.IndexOf("namespace");
                                                    int index2 = line.IndexOf("{");
                                                    if (index1 != -1 && index2 != -1)
                                                    {
                                                        line = line.Substring(index1 + 9);
                                                        index2 = line.IndexOf("{");
                                                        line = line.Substring(0, index2);
                                                        line = line.Replace(" ", "");
                                                        newComponent.namespaceName = line;
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                            }

                                            existingComponents.Add(newComponent);

                                            try
                                            {
                                                System.IO.FileStream FS = new System.IO.FileStream(projectPath + asset, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                                                System.IO.StreamReader SR = new System.IO.StreamReader(FS);

                                                string line;
                                                int lineNum = 0;
                                                while (!SR.EndOfStream)
                                                {
                                                    lineNum++;
                                                    line = SR.ReadLine();
                                                    int index = line.IndexOf("AddComponent");
                                                    if (index != -1)
                                                    {
                                                        line = line.Substring(index + 12);
                                                        if (line[0] == '(')
                                                        {
                                                            line = line.Substring(1, line.IndexOf(')') - 1);
                                                        }
                                                        else if (line[0] == '<')
                                                        {
                                                            line = line.Substring(1, line.IndexOf('>') - 1);
                                                        }
                                                        else
                                                        {
                                                            continue;
                                                        }
                                                        line = line.Replace(" ", "");
                                                        line = line.Replace("\"", "");
                                                        index = line.LastIndexOf('.');
                                                        ComponentNames newComp;
                                                        if (index == -1)
                                                        {
                                                            newComp = new ComponentNames(line, "", "");
                                                        }
                                                        else
                                                        {
                                                            newComp = new ComponentNames(line.Substring(index + 1, line.Length - (index + 1)), line.Substring(0, index), "");
                                                        }
                                                        string pName = asset + ", Line " + lineNum;
                                                        newComp.usageSource.Add(pName);
                                                        index = addedComponents.IndexOf(newComp);
                                                        if (index == -1)
                                                        {
                                                            addedComponents.Add(newComp);
                                                        }
                                                        else
                                                        {
                                                            if (!addedComponents[index].usageSource.Contains(pName)) addedComponents[index].usageSource.Add(pName);
                                                        }
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                            }
                                        }
                                        int indexPrefab = asset.IndexOf(".prefab");

                                        if (indexPrefab != -1)
                                        {
                                            string[] single = new string[] { asset };
                                            string[] dependencies = AssetDatabase.GetDependencies(single);
                                            foreach (string dependedAsset in dependencies)
                                            {
                                                if (dependedAsset.IndexOf(".cs") != -1 || dependedAsset.IndexOf(".js") != -1)
                                                {
                                                    ComponentNames newComponent = new ComponentNames(NameFromPath(dependedAsset), GetNamespaceFromPath(dependedAsset), dependedAsset);
                                                    int index = prefabComponents.IndexOf(newComponent);
                                                    if (index == -1)
                                                    {
                                                        newComponent.usageSource.Add(asset);
                                                        prefabComponents.Add(newComponent);
                                                    }
                                                    else
                                                    {
                                                        if (!prefabComponents[index].usageSource.Contains(asset)) prefabComponents[index].usageSource.Add(asset);
                                                    }
                                                }
                                            }
                                        }
                                        int indexUnity = asset.IndexOf(".unity");
                                        if (indexUnity != -1)
                                        {
                                            scenesToLoad.Add(asset);
                                        }
                                    }

                                    for (int i = addedComponents.Count - 1; i > -1; i--)
                                    {
                                        addedComponents[i].assetPath = GetPathFromNames(addedComponents[i].namespaceName, addedComponents[i].componentName);
                                        if (addedComponents[i].assetPath == "") addedComponents.RemoveAt(i);

                                    }

                                    foreach (string scene in scenesToLoad)
                                    {
                                        EditorApplication.OpenScene(scene);
                                        GameObject[] sceneGOs = GetAllObjectsInScene();
                                        foreach (GameObject g in sceneGOs)
                                        {
                                            Component[] comps = g.GetComponentsInChildren<Component>(true);
                                            foreach (Component c in comps)
                                            {

                                                if (c != null && c.GetType() != null && c.GetType().BaseType != null && c.GetType().BaseType == typeof(MonoBehaviour))
                                                {
                                                    SerializedObject so = new SerializedObject(c);
                                                    SerializedProperty p = so.FindProperty("m_Script");
                                                    string path = AssetDatabase.GetAssetPath(p.objectReferenceValue);
                                                    ComponentNames newComp = new ComponentNames(NameFromPath(path), GetNamespaceFromPath(path), path);
                                                    newComp.usageSource.Add(scene);
                                                    int index = sceneComponents.IndexOf(newComp);
                                                    if (index == -1)
                                                    {
                                                        sceneComponents.Add(newComp);
                                                    }
                                                    else
                                                    {
                                                        if (!sceneComponents[index].usageSource.Contains(scene)) sceneComponents[index].usageSource.Add(scene);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    foreach (ComponentNames c in existingComponents)
                                    {
                                        if (addedComponents.Contains(c)) continue;
                                        if (prefabComponents.Contains(c)) continue;
                                        if (sceneComponents.Contains(c)) continue;
                                        notUsedComponents.Add(c);
                                    }

                                    addedComponents.Sort(SortAlphabetically);
                                    prefabComponents.Sort(SortAlphabetically);
                                    sceneComponents.Sort(SortAlphabetically);
                                    notUsedComponents.Sort(SortAlphabetically);
                                }
                                break;
                        }
                    }
                    break;
                case 1:
                    if (GUILayout.Button("Search!"))
                    {
                        string[] allPrefabs = GetAllPrefabs();
                        listResult = new List<string>();
                        foreach (string prefab in allPrefabs)
                        {
                            UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath(prefab);
                            GameObject go;
                            try
                            {
                                go = (GameObject)o;
                                Component[] components = go.GetComponentsInChildren<Component>(true);
                                foreach (Component c in components)
                                {
                                    if (c == null)
                                    {
                                        listResult.Add(prefab);
                                    }
                                }
                            }
                            catch
                            {
                                Debug.Log("For some reason, prefab " + prefab + " won't cast to GameObject");
                            }
                        }
                    }
                    break;
            }
            if (editorMode == 1 || selectedCheckType == 0)
            {
                if (listResult != null)
                {
                    if (listResult.Count == 0)
                    {
                        GUILayout.Label(editorMode == 0 ? (componentName == "" ? "Choose a component" : "No prefabs use component " + componentName) : ("No prefabs have missing components!\nClick Search to check again"));
                    }
                    else
                    {
                        GUILayout.Label(editorMode == 0 ? ("The following prefabs use component " + componentName + ":") : ("The following prefabs have missing components:"));
                        scroll = GUILayout.BeginScrollView(scroll);
                        foreach (string s in listResult)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Label(s, GUILayout.Width(position.width / 2));
                            if (GUILayout.Button("Select", GUILayout.Width(position.width / 2 - 10)))
                            {
                                Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(s);
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.EndScrollView();
                    }
                }
            }
            else
            {
                showPrefabs = GUILayout.Toggle(showPrefabs, "Show prefab components");
                if (showPrefabs)
                {
                    GUILayout.Label("The following components are attatched to prefabs:");
                    DisplayResults(ref scroll1, ref prefabComponents);
                }
                showAdded = GUILayout.Toggle(showAdded, "Show AddComponent arguments");
                if (showAdded)
                {
                    GUILayout.Label("The following components are AddComponent arguments:");
                    DisplayResults(ref scroll2, ref addedComponents);
                }
                showScene = GUILayout.Toggle(showScene, "Show Scene-used components");
                if (showScene)
                {
                    GUILayout.Label("The following components are used by scene objects:");
                    DisplayResults(ref scroll3, ref sceneComponents);
                }
                showUnused = GUILayout.Toggle(showUnused, "Show Unused Components");
                if (showUnused)
                {
                    GUILayout.Label("The following components are not used by prefabs, by AddComponent, OR in any scene:");
                    DisplayResults(ref scroll4, ref notUsedComponents);
                }
            }
    }
Пример #18
0
 int SortAlphabetically(ComponentNames a, ComponentNames b)
 {
     return a.assetPath.CompareTo(b.assetPath);
 }
Пример #19
0
        public static string PacketToDescriber(Blaze.Packet p)
        {
            string t  = p.Command.ToString("X");
            string t2 = p.Component.ToString("X");

            string[] lines = ComponentNames.Split(',');
            string   cname = "Unknown";

            foreach (string line in lines)
            {
                string[] parts = line.Split('=');
                if (parts.Length == 2 && parts[1] == t2)
                {
                    cname = parts[0];
                    break;
                }
            }
            switch (p.Component)
            {
            case 0x1:
                for (int i = 0; i < DescComponent1.Length / 2; i++)
                {
                    if (DescComponent1[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent1[i * 2 + 1]);
                    }
                }
                break;

            case 0x4:
                for (int i = 0; i < DescComponent4.Length / 2; i++)
                {
                    if (DescComponent4[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent4[i * 2 + 1]);
                    }
                }
                break;

            case 0x7:
                for (int i = 0; i < DescComponent7.Length / 2; i++)
                {
                    if (DescComponent7[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent7[i * 2 + 1]);
                    }
                }
                break;

            case 0x9:
                for (int i = 0; i < DescComponent9.Length / 2; i++)
                {
                    if (DescComponent9[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent9[i * 2 + 1]);
                    }
                }
                break;

            case 0xF:
                for (int i = 0; i < DescComponentF.Length / 2; i++)
                {
                    if (DescComponentF[i * 2] == t)
                    {
                        return(cname + ":" + DescComponentF[i * 2 + 1]);
                    }
                }
                break;

            case 0x19:
                for (int i = 0; i < DescComponent19.Length / 2; i++)
                {
                    if (DescComponent19[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent19[i * 2 + 1]);
                    }
                }
                break;

            case 0x1C:
                for (int i = 0; i < DescComponent1C.Length / 2; i++)
                {
                    if (DescComponent1C[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent1C[i * 2 + 1]);
                    }
                }
                break;

            case 0x7802:
                for (int i = 0; i < DescComponent7802.Length / 2; i++)
                {
                    if (DescComponent7802[i * 2] == t)
                    {
                        return(cname + ":" + DescComponent7802[i * 2 + 1]);
                    }
                }
                break;
            }
            return(cname + ":Unknown");
        }
Пример #20
0
    void OnGUI()
    {
        GUILayout.Label(position + "");
        GUILayout.Space(3);
        int oldValue = GUI.skin.window.padding.bottom;
        GUI.skin.window.padding.bottom = -20;
        Rect windowRect = GUILayoutUtility.GetRect(1, 17);
        windowRect.x += 4;
        windowRect.width -= 7;
        editorMode = GUI.SelectionGrid(windowRect, editorMode, modes, 2, "Window");
        GUI.skin.window.padding.bottom = oldValue;

        switch (editorMode)
        {
            case 0:
                selectedCheckType = GUILayout.SelectionGrid(selectedCheckType, checkType, 2, "Toggle");
                recursionVal = GUILayout.Toggle(recursionVal, "Search all dependencies");
                GUI.enabled = selectedCheckType == 0;
                targetComponent = (MonoScript)EditorGUILayout.ObjectField(targetComponent, typeof(MonoScript), false);
                GUI.enabled = true;

                if (GUILayout.Button("Check component usage"))
                {
                    AssetDatabase.SaveAssets();
                    switch (selectedCheckType)
                    {
                        case 0:
                            componentName = targetComponent.name;
                            string targetPath = AssetDatabase.GetAssetPath(targetComponent);
                            string[] allPrefabs = GetAllPrefabs();
                            listResult = new List<string>();
                            foreach (string prefab in allPrefabs)
                            {
                                string[] single = new string[] { prefab };
                                string[] dependencies = AssetDatabase.GetDependencies(single, recursionVal);
                                foreach (string dependedAsset in dependencies)
                                {
                                    if (dependedAsset == targetPath)
                                    {
                                        listResult.Add(prefab);
                                    }
                                }
                            }
                            break;
                        case 1:
                            List<string> scenesToLoad = new List<string>();
                            existingComponents = new List<ComponentNames>();
                            prefabComponents = new List<ComponentNames>();
                            notUsedComponents = new List<ComponentNames>();
                            addedComponents = new List<ComponentNames>();
                            sceneComponents = new List<ComponentNames>();

                            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                            {
                                string projectPath = Application.dataPath;
                                projectPath = projectPath.Substring(0, projectPath.IndexOf("Assets"));

                                string[] allAssets = AssetDatabase.GetAllAssetPaths();

                                foreach (string asset in allAssets)
                                {
                                    int indexCS = asset.IndexOf(".cs");
                                    int indexJS = asset.IndexOf(".js");
                                    if (indexCS != -1 || indexJS != -1)
                                    {
                                        ComponentNames newComponent = new ComponentNames(NameFromPath(asset), "", asset);
                                        try
                                        {
                                            System.IO.FileStream FS = new System.IO.FileStream(projectPath + asset, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                                            System.IO.StreamReader SR = new System.IO.StreamReader(FS);
                                            string line;
                                            while (!SR.EndOfStream)
                                            {
                                                line = SR.ReadLine();
                                                int index1 = line.IndexOf("namespace");
                                                int index2 = line.IndexOf("{");
                                                if (index1 != -1 && index2 != -1)
                                                {
                                                    line = line.Substring(index1 + 9);
                                                    index2 = line.IndexOf("{");
                                                    line = line.Substring(0, index2);
                                                    line = line.Replace(" ", "");
                                                    newComponent.namespaceName = line;
                                                }
                                            }
                                        }
                                        catch
                                        {
                                        }

                                        existingComponents.Add(newComponent);

                                        try
                                        {
                                            System.IO.FileStream FS = new System.IO.FileStream(projectPath + asset, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                                            System.IO.StreamReader SR = new System.IO.StreamReader(FS);

                                            string line;
                                            int lineNum = 0;
                                            while (!SR.EndOfStream)
                                            {
                                                lineNum++;
                                                line = SR.ReadLine();
                                                int index = line.IndexOf("AddComponent");
                                                if (index != -1)
                                                {
                                                    line = line.Substring(index + 12);
                                                    if (line[0] == '(')
                                                    {
                                                        line = line.Substring(1, line.IndexOf(')') - 1);
                                                    }
                                                    else if (line[0] == '<')
                                                    {
                                                        line = line.Substring(1, line.IndexOf('>') - 1);
                                                    }
                                                    else
                                                    {
                                                        continue;
                                                    }
                                                    line = line.Replace(" ", "");
                                                    line = line.Replace("\"", "");
                                                    index = line.LastIndexOf('.');
                                                    ComponentNames newComp;
                                                    if (index == -1)
                                                    {
                                                        newComp = new ComponentNames(line, "", "");
                                                    }
                                                    else
                                                    {
                                                        newComp = new ComponentNames(line.Substring(index + 1, line.Length - (index + 1)), line.Substring(0, index), "");
                                                    }
                                                    string pName = asset + ", Line " + lineNum;
                                                    newComp.usageSource.Add(pName);
                                                    index = addedComponents.IndexOf(newComp);
                                                    if (index == -1)
                                                    {
                                                        addedComponents.Add(newComp);
                                                    }
                                                    else
                                                    {
                                                        if (!addedComponents[index].usageSource.Contains(pName)) addedComponents[index].usageSource.Add(pName);
                                                    }
                                                }
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                    int indexPrefab = asset.IndexOf(".prefab");

                                    if (indexPrefab != -1)
                                    {
                                        string[] single = new string[] { asset };
                                        string[] dependencies = AssetDatabase.GetDependencies(single, recursionVal);
                                        foreach (string dependedAsset in dependencies)
                                        {
                                            if (dependedAsset.IndexOf(".cs") != -1 || dependedAsset.IndexOf(".js") != -1)
                                            {
                                                ComponentNames newComponent = new ComponentNames(NameFromPath(dependedAsset), GetNamespaceFromPath(dependedAsset), dependedAsset);
                                                int index = prefabComponents.IndexOf(newComponent);
                                                if (index == -1)
                                                {
                                                    newComponent.usageSource.Add(asset);
                                                    prefabComponents.Add(newComponent);
                                                }
                                                else
                                                {
                                                    if (!prefabComponents[index].usageSource.Contains(asset)) prefabComponents[index].usageSource.Add(asset);
                                                }
                                            }
                                        }
                                    }
                                    int indexUnity = asset.IndexOf(".unity");
                                    if (indexUnity != -1)
                                    {
                                        scenesToLoad.Add(asset);
                                    }
                                }

                                for (int i = addedComponents.Count - 1; i > -1; i--)
                                {
                                    addedComponents[i].assetPath = GetPathFromNames(addedComponents[i].namespaceName, addedComponents[i].componentName);
                                    if (addedComponents[i].assetPath == "") addedComponents.RemoveAt(i);

                                }

                                foreach (string scene in scenesToLoad)
                                {
                                    EditorSceneManager.OpenScene(scene);
                                    GameObject[] sceneGOs = GetAllObjectsInScene();
                                    foreach (GameObject g in sceneGOs)
                                    {
                                        Component[] comps = g.GetComponentsInChildren<Component>(true);
                                        foreach (Component c in comps)
                                        {

                                            if (c != null && c.GetType() != null && c.GetType().BaseType != null && c.GetType().BaseType == typeof(MonoBehaviour))
                                            {
                                                SerializedObject so = new SerializedObject(c);
                                                SerializedProperty p = so.FindProperty("m_Script");
                                                string path = AssetDatabase.GetAssetPath(p.objectReferenceValue);
                                                ComponentNames newComp = new ComponentNames(NameFromPath(path), GetNamespaceFromPath(path), path);
                                                newComp.usageSource.Add(scene);
                                                int index = sceneComponents.IndexOf(newComp);
                                                if (index == -1)
                                                {
                                                    sceneComponents.Add(newComp);
                                                }
                                                else
                                                {
                                                    if (!sceneComponents[index].usageSource.Contains(scene)) sceneComponents[index].usageSource.Add(scene);
                                                }
                                            }
                                        }
                                    }
                                }

                                foreach (ComponentNames c in existingComponents)
                                {
                                    if (addedComponents.Contains(c)) continue;
                                    if (prefabComponents.Contains(c)) continue;
                                    if (sceneComponents.Contains(c)) continue;
                                    notUsedComponents.Add(c);
                                }

                                addedComponents.Sort(SortAlphabetically);
                                prefabComponents.Sort(SortAlphabetically);
                                sceneComponents.Sort(SortAlphabetically);
                                notUsedComponents.Sort(SortAlphabetically);
                            }
                            break;
                    }
                }
                break;
            case 1:
                if (GUILayout.Button("Search!"))
                {
                    string[] allPrefabs = GetAllPrefabs();
                    listResult = new List<string>();
                    foreach (string prefab in allPrefabs)
                    {
                        UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath(prefab);
                        GameObject go;
                        try
                        {
                            go = (GameObject)o;
                            Component[] components = go.GetComponentsInChildren<Component>(true);
                            foreach (Component c in components)
                            {
                                if (c == null)
                                {
                                    listResult.Add(prefab);
                                }
                            }
                        }
                        catch
                        {
                            Debug.Log("For some reason, prefab " + prefab + " won't cast to GameObject");
                        }
                    }
                }
                break;
        }
        if (editorMode == 1 || selectedCheckType == 0)
        {
            if (listResult != null)
            {
                if (listResult.Count == 0)
                {
                    GUILayout.Label(editorMode == 0 ? (componentName == "" ? "Choose a component" : "No prefabs use component " + componentName) : ("No prefabs have missing components!\nClick Search to check again"));
                }
                else
                {
                    GUILayout.Label(editorMode == 0 ? ("The following " + listResult.Count + " prefabs use component " + componentName + ":") : ("The following prefabs have missing components:"));
                    scroll = GUILayout.BeginScrollView(scroll);
                    foreach (string s in listResult)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(s, GUILayout.Width(position.width / 2));
                        if (GUILayout.Button("Select", GUILayout.Width(position.width / 2 - 10)))
                        {
                            Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(s);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndScrollView();
                }
            }
        }
        else
        {
            showPrefabs = GUILayout.Toggle(showPrefabs, "Show prefab components");
            if (showPrefabs)
            {
                GUILayout.Label("The following components are attatched to prefabs:");
                DisplayResults(ref scroll1, ref prefabComponents);
            }
            showAdded = GUILayout.Toggle(showAdded, "Show AddComponent arguments");
            if (showAdded)
            {
                GUILayout.Label("The following components are AddComponent arguments:");
                DisplayResults(ref scroll2, ref addedComponents);
            }
            showScene = GUILayout.Toggle(showScene, "Show Scene-used components");
            if (showScene)
            {
                GUILayout.Label("The following components are used by scene objects:");
                DisplayResults(ref scroll3, ref sceneComponents);
            }
            showUnused = GUILayout.Toggle(showUnused, "Show Unused Components");
            if (showUnused)
            {
                GUILayout.Label("The following components are not used by prefabs, by AddComponent, OR in any scene:");
                DisplayResults(ref scroll4, ref notUsedComponents);
            }
        }
    }
Пример #21
0
        void saveObjKey()
        {
            objk.Components.Clear();
            objk.ComponentData.Clear();
            foreach (string name in ComponentNames)
            {
                if (!hasComponent(name))
                {
                    continue;
                }
                objk.Components.Add(new ObjKeyResource.ObjKeyResource.ComponentElement(0, null, (ObjKeyResource.ObjKeyResource.Component)Enum.Parse(typeof(ObjKeyResource.ObjKeyResource.Component), name)));
                if (ComponentDataTypeMap.ContainsKey(name))
                {
                    int row = ComponentNames.IndexOf(name);
                    row++;
                    if (name.Equals("Sim") && !((CheckBox)tableLayoutPanel1.GetControlFromPosition(1, row)).Checked)
                    {
                        continue;
                    }

                    TypeKey tk   = ComponentDataTypeMap[name];
                    string  type = tk.type.Name.Substring(3);
                    if (type == "String")
                    {
                        TextBox tb    = (TextBox)tableLayoutPanel1.GetControlFromPosition(2, row);
                        string  value = tb.Text;
                        objk.ComponentData.Add(new ObjKeyResource.ObjKeyResource.CDTString(0, null, tk.key, 0x00, value));
                    }
                    else if (type == "ResourceKey")
                    {
                        TGIBlockCombo cb    = (TGIBlockCombo)tableLayoutPanel1.GetControlFromPosition(2, row);
                        Int32         value = cb.SelectedIndex;
                        objk.ComponentData.Add(new ObjKeyResource.ObjKeyResource.CDTResourceKey(0, null, tk.key, 0x01, value));
                    }
                    else if (type == "AssetResourceName")
                    {
                        TGIBlockCombo cb    = (TGIBlockCombo)tableLayoutPanel1.GetControlFromPosition(2, row);
                        Int32         value = cb.SelectedIndex;
                        objk.ComponentData.Add(new ObjKeyResource.ObjKeyResource.CDTAssetResourceName(0, null, tk.key, 0x02, value));
                    }
                    else if (type == "SteeringInstance")
                    {
                        TextBox tb    = (TextBox)tableLayoutPanel1.GetControlFromPosition(2, row);
                        string  value = tb.Text;
                        objk.ComponentData.Add(new ObjKeyResource.ObjKeyResource.CDTSteeringInstance(0, null, tk.key, 0x03, value));
                    }
                    else if (type == "UInt32")
                    {
                        TextBox tb = (TextBox)tableLayoutPanel1.GetControlFromPosition(2, row);
                        string  s  = tb.Text.ToLower().Trim();
                        UInt32  value;
                        if (s.StartsWith("0x"))
                        {
                            value = uint.Parse(s.Substring(2), System.Globalization.NumberStyles.HexNumber);
                        }
                        else
                        {
                            value = uint.Parse(s);
                        }
                        objk.ComponentData.Add(new ObjKeyResource.ObjKeyResource.CDTUInt32(0, null, tk.key, 0x04, value));
                    }
                }
            }
            if (ckbAllowObjectHiding.Checked)
            {
                objk.ComponentData.Add(new ObjKeyResource.ObjKeyResource.CDTUInt32(0, null, "allowObjectHiding", 0x04, 0));
            }

            result = (byte[])objk.AsBytes.Clone();
        }