Example #1
0
    private void Awake()
    {
        Debug.Log($"{name}.{MethodBase.GetCurrentMethod().Name}");
        Manager = FindObjectOfType <ExplosiveBarrelManager>();
        // Will duplicate the material (create a per instance new material and leak materials into the scene)
        //GetComponent<MeshRenderer>().material.color = Color.red;
        // Will duplicate the mesh
        //GetComponent<MeshFilter>().mesh.name = "";

        // Will modify the *asset*
        //GetComponent<MeshRenderer>().sharedMaterial.color = Color.red;

        // Should use "material-blocks"???

        // With the hide-flag we can instruct the engine to don't save this material en just clear it on a reload.

        /*
         * Shader shader = Shader.Find("Default/Diffuse");
         * Material tempMaterial = new Material(shader)
         * {
         *      hideFlags = HideFlags.HideAndDontSave,
         *      color = Color.cyan
         * };
         * //*/
        //GetComponent<MeshRenderer>().m
    }
    public override void OnInspectorGUI()
    {
        // base.OnInspectorGUI();

        so.Update();
        EditorGUILayout.PropertyField(propRadius);
        EditorGUILayout.PropertyField(propDamage);
        EditorGUILayout.PropertyField(propColor);
        if (so.ApplyModifiedProperties())
        {
            // if something changed
            ExplosiveBarrelManager.UpdateBarrelColors();
        }
    }
Example #3
0
    public override void OnInspectorGUI()
    {
        // This can be replaced
        // base.OnInspectorGUI();
        EditorGUILayout.PropertyField(propRadius);
        EditorGUILayout.PropertyField(propDamage);
        EditorGUILayout.PropertyField(propColor);
        //so.ApplyModifiedProperties();
        if (so.ApplyModifiedProperties())
        {
            ExplosiveBarrelManager.UpdateAllBarrelColors();
        }


        GUILayout.Space(20);

        // Way 1: BeginHorizontal - EndHorizontal
        GUILayout.Label("Way 1: BeginHorizontal - EndHorizontal", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Things: ", GUILayout.Width(60));
        if (GUILayout.Button("Do a thing"))
        {
            Debug.Log("did the thing");
        }
        things = (Things)EditorGUILayout.EnumPopup(things);
        GUILayout.EndHorizontal();

        GUILayout.Space(20);

        // Way 2(safer): HorizontalScope
        GUILayout.Label("Way 2(safer): HorizontalScope", EditorStyles.boldLabel);
        using (new GUILayout.HorizontalScope())
        {
            GUILayout.Label("Things: ", GUILayout.Width(60));
            if (GUILayout.Button("Do a thing"))
            {
                Debug.Log("did the thing");
            }
            things = (Things)EditorGUILayout.EnumPopup(things);
        }

        GUILayout.Space(20);

        // Example layout
        GUILayout.Label("Example layout", EditorStyles.boldLabel);
        using (new GUILayout.VerticalScope(EditorStyles.helpBox))
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Label("SomeValue: ", GUILayout.Width(60));
                someValue = GUILayout.HorizontalSlider(someValue, -1f, 1f);
            }
            GUILayout.Label("Things");
            GUILayout.Label("Things", GUI.skin.button);


            EditorGUILayout.ObjectField("Assign here: ", null, typeof(Transform), true);
        }



        // explicit positioning using rect
        // GUI
        // EditorGUI

        // implicit positioning, auto-layout
        // GUILayout
        // EditorGUILayout
    }