private static void SetupSegmentButtons(ReferenceChain refChain, NetInfo.Segment segmentInfo)
        {
            try
            {
                Debug.Log("SetupSegmentButtons() called");
                if (segmentInfo.m_mesh != null && segmentInfo.m_mesh.isReadable && GUILayout.Button("Dump"))
                {
                    var outPath = refChain.ToString().Replace(' ', '_');
                    DumpUtil.DumpMeshAndTextures(
                        outPath,
                        segmentInfo.m_mesh,
                        segmentInfo.m_material);
                    DumpUtil.DumpMeshAndTextures(
                        outPath + "_lod",
                        segmentInfo.m_lodMesh,
                        segmentInfo.m_lodMaterial);
                }

                SetupMeshPreviewButtons(name: null, segmentInfo.m_mesh, segmentInfo.m_material, segmentInfo.m_lodMesh, segmentInfo.m_lodMaterial);
                Debug.Log("SetupSegmentButtons() successful");
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Exemple #2
0
 public static void SetupButtons(Type type, object value, ReferenceChain refChain)
 {
     if (TypeUtil.IsTextureType(type) && value != null)
     {
         var texture = (Texture)value;
         if (GUILayout.Button("Preview"))
         {
             TextureViewer.CreateTextureViewer(refChain, texture);
         }
         if (GUILayout.Button("Dump .png"))
         {
             TextureUtil.DumpTextureToPNG(texture);
         }
     }
     else if (TypeUtil.IsMeshType(type) && value != null)
     {
         if (GUILayout.Button("Preview"))
         {
             MeshViewer.CreateMeshViewer(null, (Mesh)value, null);
         }
         if (((Mesh)value).isReadable)
         {
             if (GUILayout.Button("Dump .obj"))
             {
                 var outPath = refChain.ToString().Replace(' ', '_');
                 DumpUtil.DumpMeshAndTextures(outPath, value as Mesh);
             }
         }
     }
     if (GUILayout.Button("Copy"))
     {
         _buffer = value;
     }
 }
        private static void SetupMeshButtons(ReferenceChain refChain, Mesh mesh)
        {
            if (GUILayout.Button("Preview"))
            {
                MeshViewer.CreateMeshViewer(null, mesh, null);
            }

            if (mesh.isReadable && GUILayout.Button("Dump mesh"))
            {
                var outPath = refChain.ToString().Replace(' ', '_');
                DumpUtil.DumpMeshAndTextures(outPath, mesh);
            }
        }
        private static void SetupNodeButtons(ReferenceChain refChain, NetInfo.Node nodeInfo)
        {
            if (nodeInfo.m_mesh != null && nodeInfo.m_mesh.isReadable && GUILayout.Button("Dump"))
            {
                var outPath = refChain.ToString().Replace(' ', '_');
                DumpUtil.DumpMeshAndTextures(
                    outPath,
                    nodeInfo.m_mesh,
                    nodeInfo.m_material);
                DumpUtil.DumpMeshAndTextures(
                    outPath + "_lod",
                    nodeInfo.m_lodMesh,
                    nodeInfo.m_lodMaterial);
            }

            SetupMeshPreviewButtons(name: null, nodeInfo.m_mesh, nodeInfo.m_material, nodeInfo.m_lodMesh, nodeInfo.m_lodMaterial);
        }
Exemple #5
0
        private static void OnSceneTreeReflectUnityEngineVector3 <T>(ReferenceChain refChain, T obj, string name, ref UnityEngine.Vector3 vec)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            GUIControls.Vector3Field(refChain.ToString(), name, ref vec, ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident, () =>
            {
                try
                {
                    ModTools.Instance.watches.AddWatch(refChain);
                }
                catch (Exception ex)
                {
                    Log.Error("Exception in ModTools:OnSceneTreeReflectUnityEngineVector3 - " + ex.Message);
                }
            });
        }
        public static void OnSceneReflectUnityEngineMaterial(SceneExplorerState state, ReferenceChain refChain, Material material)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (material == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            ReferenceChain oldRefChain = refChain;

            foreach (var prop in textureProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value = material.GetTexture(prop);
                if (value == null)
                {
                    continue;
                }

                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * (refChain.Ident + 1));

                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label(type.ToString() + " ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;
                GUILayout.Label(value.ToString());
                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }

                if (doPaste)
                {
                    material.SetTexture(prop, (Texture)paste);
                }
            }

            foreach (string prop in colorProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                Color value = material.GetColor(prop);
                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * (refChain.Ident + 1));

                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label(type.ToString() + " ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");
                var f = value;

                GUI.contentColor = ModTools.Instance.config.valueColor;

                var propertyCopy = prop;
                GUIControls.ColorField(refChain.ToString(), "", ref f, 0.0f, null, true, true, color => { material.SetColor(propertyCopy, color); });
                if (f != value)
                {
                    material.SetColor(prop, f);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }
                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }

            GUIReflect.OnSceneTreeReflect(state, refChain, material, true);
        }
Exemple #7
0
 public static void SetupButtons(Type type, object value, ReferenceChain refChain)
 {
     if (value is VehicleInfo)
     {
         var info = (VehicleInfo)value;
         if (info.m_mesh != null)
         {
             if (GUILayout.Button("Preview"))
             {
                 MeshViewer.CreateMeshViewer(info.name, info.m_mesh, info.m_material);
             }
         }
         if (info.m_lodMesh != null)
         {
             if (GUILayout.Button("Preview LOD"))
             {
                 MeshViewer.CreateMeshViewer(info.name + "_LOD", info.m_lodMesh, info.m_lodMaterial);
             }
         }
     }
     else if (value is NetInfo)
     {
         SetupPlopButton(value);
     }
     else if (value is BuildingInfo)
     {
         var info = (BuildingInfo)value;
         SetupPlopButton(value);
         if (info.m_mesh != null)
         {
             if (GUILayout.Button("Preview"))
             {
                 MeshViewer.CreateMeshViewer(info.name, info.m_mesh, info.m_material);
             }
         }
         if (info.m_lodMesh != null)
         {
             if (GUILayout.Button("Preview LOD"))
             {
                 MeshViewer.CreateMeshViewer(info.name + "_LOD", info.m_lodMesh, info.m_lodMaterial);
             }
         }
     }
     else if (value is PropInfo)
     {
         var info = (PropInfo)value;
         SetupPlopButton(value);
         if (info.m_mesh != null)
         {
             if (GUILayout.Button("Preview"))
             {
                 MeshViewer.CreateMeshViewer(info.name, info.m_mesh, info.m_material);
             }
         }
         if (info.m_lodMesh != null)
         {
             if (GUILayout.Button("Preview LOD"))
             {
                 MeshViewer.CreateMeshViewer(info.name + "_LOD", info.m_lodMesh, info.m_lodMaterial);
             }
         }
     }
     else if (value is TreeInfo)
     {
         var info = (TreeInfo)value;
         SetupPlopButton(value);
         if (info.m_mesh != null)
         {
             if (GUILayout.Button("Preview"))
             {
                 MeshViewer.CreateMeshViewer(info.name, info.m_mesh, info.m_material);
             }
         }
     }
     else if (value is CitizenInfo)
     {
         var info = (CitizenInfo)value;
         if (info.m_lodMesh != null)
         {
             if (GUILayout.Button("Preview LOD"))
             {
                 MeshViewer.CreateMeshViewer(info.name, info.m_lodMesh, info.m_lodMaterial);
             }
         }
     }
     else if (value is MilestoneInfo)
     {
         var info = (MilestoneInfo)value;
         if (GUILayout.Button("Unlock"))
         {
             var wrapper = new MilestonesWrapper(UnlockManager.instance);
             wrapper.UnlockMilestone(info.name);
         }
     }
     else if (value is NetInfo.Segment)
     {
         var info = (NetInfo.Segment)value;
         if (info.m_mesh != null)
         {
             if (GUILayout.Button("Preview"))
             {
                 MeshViewer.CreateMeshViewer(null, info.m_mesh, info.m_material);
             }
             if (GUILayout.Button("Preview LOD"))
             {
                 MeshViewer.CreateMeshViewer(null, info.m_lodMesh, info.m_lodMaterial);
             }
         }
     }
     else if (value is NetInfo.Node)
     {
         var info = (NetInfo.Node)value;
         if (info.m_mesh != null)
         {
             if (GUILayout.Button("Preview"))
             {
                 MeshViewer.CreateMeshViewer(null, info.m_mesh, info.m_material);
             }
             if (GUILayout.Button("Preview LOD"))
             {
                 MeshViewer.CreateMeshViewer(null, info.m_lodMesh, info.m_lodMaterial);
             }
         }
     }
     else if (TypeUtil.IsTextureType(type) && value != null)
     {
         var texture = (Texture)value;
         if (GUILayout.Button("Preview"))
         {
             TextureViewer.CreateTextureViewer(refChain, texture);
         }
         if (GUILayout.Button("Dump .png"))
         {
             TextureUtil.DumpTextureToPNG(texture);
         }
     }
     else if (TypeUtil.IsMeshType(type) && value != null)
     {
         if (GUILayout.Button("Preview"))
         {
             MeshViewer.CreateMeshViewer(null, (Mesh)value, null);
         }
         if (((Mesh)value).isReadable)
         {
             if (GUILayout.Button("Dump .obj"))
             {
                 var outPath = refChain.ToString().Replace(' ', '_');
                 DumpUtil.DumpMeshAndTextures(outPath, value as Mesh);
             }
         }
     }
     if (GUILayout.Button("Copy"))
     {
         _buffer = value;
     }
 }
Exemple #8
0
        public static void OnSceneTreeReflectIList(SceneExplorerState state,
                                                   ReferenceChain refChain, System.Object myProperty)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            var list = myProperty as IList;

            if (list == null)
            {
                return;
            }

            var oldRefChain    = refChain;
            var collectionSize = list.Count;

            if (collectionSize == 0)
            {
                GUILayout.BeginHorizontal();
                GUI.contentColor = Color.yellow;
                GUILayout.Label("List is empty!");
                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                return;
            }

            int arrayStart;
            int arrayEnd;

            GUICollectionNavigation.SetUpCollectionNavigation("List", state, refChain, oldRefChain, collectionSize, out arrayStart, out arrayEnd);
            for (int i = arrayStart; i <= arrayEnd; i++)
            {
                refChain = oldRefChain.Add(i);
                if (list[i] == null)
                {
                    continue;
                }

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident);


                GUI.contentColor = Color.white;
                var type = list[i] == null ? null : list[i].GetType();
                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label($"{type} ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label($"{oldRefChain.LastItemName}.[{i}]");

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;

                if (list[i] == null || !TypeUtil.IsSpecialType(list[i].GetType()))
                {
                    GUILayout.Label(list[i] == null ? "null" : list[i].ToString());
                }
                else
                {
                    try
                    {
                        var newValue = GUIControls.EditorValueField(refChain, refChain.ToString(), list[i].GetType(), list[i]);
                        if (newValue != list[i])
                        {
                            list[i] = newValue;
                        }
                    }
                    catch (Exception)
                    {
                        GUILayout.Label(list[i] == null ? "null" : list[i].ToString());
                    }
                }

                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, list[i], refChain);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    if (list[i] is GameObject)
                    {
                        var go = list[i] as GameObject;
                        foreach (var component in go.GetComponents <Component>())
                        {
                            GUIComponent.OnSceneTreeComponent(state, refChain, component);
                        }
                    }
                    else if (list[i] is Transform)
                    {
                        GUITransform.OnSceneTreeReflectUnityEngineTransform(refChain, (Transform)list[i]);
                    }
                    else
                    {
                        GUIReflect.OnSceneTreeReflect(state, refChain, list[i]);
                    }
                }
            }
        }
        public static void OnSceneReflectUnityEngineMaterial(SceneExplorerState state, ReferenceChain refChain, Material material)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (material == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            ReferenceChain oldRefChain = refChain;

            foreach (var prop in textureProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value = material.GetTexture(prop);
                if (value == null)
                {
                    continue;
                }

                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * (refChain.Ident + 1));

                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label(type.ToString() + " ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;
                GUILayout.Label(value.ToString());
                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }

                if (doPaste)
                {
                    material.SetTexture(prop, (Texture)paste);
                }
            }

            foreach (string prop in colorProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                Color value = material.GetColor(prop);
                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * (refChain.Ident + 1));

                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label(type.ToString() + " ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");
                var f = value;

                GUI.contentColor = ModTools.Instance.config.valueColor;

                var propertyCopy = prop;
                GUIControls.ColorField(refChain.ToString(), "", ref f, 0.0f, null, true, true, color => { material.SetColor(propertyCopy, color); });
                if (f != value)
                {
                    material.SetColor(prop, f);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }
                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }
//            GUILayout.BeginHorizontal();
//            GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * (refChain.Ident + 1));
//            GUI.contentColor = ModTools.Instance.config.typeColor;
//
//            GUILayout.Label("Shader:");
//
//            GUI.contentColor = ModTools.Instance.config.nameColor;
//
//            var shaders = Resources.FindObjectsOfTypeAll<Shader>();
//            Array.Sort(shaders, (a, b) => string.Compare(a.name, b.name, StringComparison.Ordinal));
//            var availableShaders = shaders.Select(s => s.name).ToArray();
//            var currentShader = material.shader;
//            var selectedShader = Array.IndexOf(shaders, currentShader);
//
//            var newSelectedShader = GUIComboBox.Box(selectedShader, availableShaders, "SceneExplorerShadersComboBox");
//            if (newSelectedShader != selectedShader)
//            {
//                material.shader = shaders[newSelectedShader];
//            }
//            GUILayout.FlexibleSpace();
//            GUILayout.EndHorizontal();

            GUIReflect.OnSceneTreeReflect(state, refChain, material, true);
        }