コード例 #1
0
    private void SwitchParents()
    {
        VertexInfluenceManager oldManager = vertexInfluenceManager;

        AddLinkManager();
        oldManager.DetectVertexInfluenceSpheres();
    }
コード例 #2
0
    void OnGUI()
    {
        //All the buttons and the functions they correspond to...
        string tooltip = ("Vertex Influence Spheres allow for environment blending.");

        GUILayout.Label(new GUIContent("Vertex Influence Spheres", tooltip), EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        tooltip =
            "This creates a vertex influence sphere. If you parent this to another object, it will only work on that object's children. This can be used to help performance. Otherwise it will apply to every paintable object in the scene";
        if (GUILayout.Button(new GUIContent("Create Sphere", tooltip)))
        {
            VertexInfluenceSphere.CreateVTXSphere();
            VertexInfluenceManager.SetAutoRefresh(autoRefresh);
        }
        tooltip = "This will paint the vertex colors on all the spheres in the scene. This will force a refresh no matter what, including if there are no spheres";
        if (GUILayout.Button(new GUIContent("Paint Spheres", tooltip)))
        {
            VertexInfluenceManager.RefreshAll();
            VertexInfluenceManager.SetAutoRefresh(autoRefresh);
        }
        GUILayout.EndHorizontal();
        tooltip =
            "Automatically paints whenever one of the spheres is modified. Note that this doesn't update in all cases, unlike the 'Paint Spheres' button. Also note this can get slow. To optimize, consider parenting influence spheres under groups so they don't have to check every mesh in the scene.";
        autoRefresh = EditorGUILayout.Toggle(new GUIContent("Auto-Paint", tooltip), autoRefresh);
        if (autoRefresh != autoRefreshStored)
        {
            VertexInfluenceManager.SetAutoRefresh(autoRefresh);
        }
        autoRefreshStored = autoRefresh;
        GUILayout.Label("Material Swap", EditorStyles.boldLabel);
        string[] matTintTypeStrings = new string[] { "Standard", "Sandstone" };
        materialTintType = GUILayout.SelectionGrid(materialTintType, matTintTypeStrings, 2);
        string[] matBlendTypeStrings = new string[] { "Snow", "Overgrowth", "Sand" };
        materialBlendType = GUILayout.SelectionGrid(materialBlendType, matBlendTypeStrings, 3);
        tooltip           = "Changes all relevant materials in the scene to use the materials specified above.";
        if (GUILayout.Button(new GUIContent("Swap Materials", tooltip)))
        {
            MaterialSwapManager.UpdateMaterials(materialTintType, materialBlendType);
        }
        tooltip = "Reverts all the materials to the default (standard + snow)";
        if (GUILayout.Button(new GUIContent("Revert Materials", tooltip)))
        {
            MaterialSwapManager.RevertMaterials();
        }
        tooltip  = "Checking this will automatically update new objects to be the material type you specified. Note this could get slow on larger scenes, and if so it is reccoemended you leave this off and manually swap materials from time to time";
        autoSwap = EditorGUILayout.Toggle(new GUIContent("Auto-Swap", tooltip), autoSwap);
        if (autoSwap != autoSwapStored)
        {
            MaterialSwapManager.SetAutoRefresh(autoSwap);
        }
        autoSwapStored = autoSwap;
        EditorGUILayout.HelpBox("Note: Every button and attribute has a rollover tooltip", MessageType.Info);
    }
コード例 #3
0
    void AddLinkManager()
    {
        GameObject manager;
        Transform  managerTransform;
        bool       actuallyWorldSpace = false;

        //First, we need to get a manager.

        //If manager is parented to our paraent.
        if (parentedTo == ParentedTo.Parent && transform.parent != null)
        {
            managerTransform = transform.parent.Find("CDT_VertexManager_Local");
            if (managerTransform == null)
            {
                manager                  = new GameObject();
                manager.name             = "CDT_VertexManager_Local";
                manager.transform.parent = transform.parent;
                manager.AddComponent <VertexInfluenceManager> ();
            }
            else
            {
                manager = managerTransform.gameObject;
            }
            vertexInfluenceManager = manager.GetComponent <VertexInfluenceManager> ();
            vertexInfluenceManager.SetParent("Parent");
        }
        else
        {
            actuallyWorldSpace = true;
        }

        //If manager is parented to world.
        if (parentedTo == ParentedTo.World || actuallyWorldSpace)
        {
            manager = GameObject.Find("CDT_VertexManager_World");
            if (manager == null)
            {
                manager      = new GameObject();
                manager.name = "CDT_VertexManager_World";
                manager.AddComponent <VertexInfluenceManager>();
            }
            vertexInfluenceManager = manager.GetComponent <VertexInfluenceManager>();
            vertexInfluenceManager.SetParent("World");
        }

        //If we're auto-refreshing, lets set this new one to auto refresh as well.
        autoRefresh = vertexInfluenceManager.areSpheresAutoRefreshing;

        //Next, let's update the manager so that it adds us.
        vertexInfluenceManager.DetectVertexInfluenceSpheres();
    }
コード例 #4
0
    public override void OnInspectorGUI()
    {
        //Overwrite the vanilla inspector
        VertexInfluenceSphere inspector = (VertexInfluenceSphere)target;

        //Fixes color enum from reseting
        if (inspector.color == 0)
        {
            colorType = ColorType.Environmental;
        }
        else
        {
            colorType = ColorType.Wetness;
        }

        //Fixes ParentedTp enum from reseting
        if (inspector.parentedToSet == VertexInfluenceSphere.ParentedTo.World)
        {
            parentedTo = ParentedTo.World;
        }
        else
        {
            parentedTo = ParentedTo.Parent;
        }

        //Starts a listener for if anything is changed in the GUI
        EditorGUI.BeginChangeCheck();

        //Any changes that happen to any of these fields is undoable
        Undo.RecordObject(inspector, "Vertex Influence Sphere modified");

        //The new fields that overwrote the old ones
        colorType          = (ColorType)EditorGUILayout.EnumPopup("Type", colorType);
        inspector.radius   = EditorGUILayout.FloatField("Radius", inspector.radius);
        inspector.maxValue = EditorGUILayout.Slider("Max Value", inspector.maxValue, 0, 1);
        inspector.curve    = EditorGUILayout.CurveField("Falloff Curve", inspector.curve);
        parentedTo         = (ParentedTo)EditorGUILayout.EnumPopup("Parented To", parentedTo);

        //Help box stuff
        string sphereCount = inspector.vertexInfluenceManager.vertexInfluenceSpheres.Count.ToString();
        string parentString;

        if (inspector.parentedTo == VertexInfluenceSphere.ParentedTo.World)
        {
            parentString = "the world";
        }
        else
        {
            parentString = inspector.transform.parent.name;
        }
        string meshCount = inspector.vertexInfluenceManager.staticMeshFilters.Count.ToString();

        EditorGUILayout.HelpBox("There are currently " + sphereCount + " influence spheres parented to " + parentString + ", which contains " + meshCount + " meshes", MessageType.Info);

        //If the GUI was changed, do this
        if (EditorGUI.EndChangeCheck())
        {
            inspector.externalRefresh = true;
            EditorUtility.SetDirty(inspector);
        }

        //Changes elements of the inspector and VIS based on the color type.
        if (colorType != storedColorType)
        {
            int colorIndex = (int)(colorType);
            inspector.SetNewColor(colorIndex);
            storedColorType = colorType;
        }

        //Changes VTX spheres based on a change in parented to
        if (parentedTo != parentedToStored)
        {
            if (parentedTo == ParentedTo.World)
            {
                inspector.parentedToSet = VertexInfluenceSphere.ParentedTo.World;
            }
            else
            {
                inspector.parentedToSet = VertexInfluenceSphere.ParentedTo.Parent;
            }
            parentedToStored = parentedTo;
            VertexInfluenceManager.ForceUpdate();
        }
    }