Esempio n. 1
0
 // This method is called when the script is destroy
 protected void OnDestroy()
 {
     // If this is the currently active singleton, delete the static instance too
     if (singleton == this)
     {
         singleton = null;
     }
 }
Esempio n. 2
0
 private void Awake()
 {
     if (materialManager == null)
     {
         materialManager = this;
     }
     else if (materialManager != this)
     {
         Destroy(materialManager.gameObject);
         materialManager = this;
     }
 }
Esempio n. 3
0
 protected void Awake()
 {
     // Check if there is already a singleton instance
     if (singleton == null)
     {
         singleton = this;
         DontDestroyOnLoad(singleton.gameObject);
         init();
     }
     else
     {
         Destroy(this);
     }
 }
    public override void OnInspectorGUI()
    {
        manager = (Material_Manager)target;

        //Set GUI Styles
        GUIStyle centeredStyle      = new GUIStyle();
        GUIStyle centeredRightStyle = new GUIStyle();

        centeredStyle.alignment      = TextAnchor.MiddleLeft;
        centeredRightStyle.alignment = TextAnchor.MiddleRight;

        GUILayout.Space(10);
        EditorGUI.BeginChangeCheck();
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        //Create Object and Toggle field labels
        GUILayout.Label(new GUIContent("Add Material"), centeredStyle, GUILayout.ExpandWidth(true));
        GUILayout.Label(new GUIContent("Include Inactive?"), centeredRightStyle, GUILayout.ExpandWidth(true));
        GUILayout.EndHorizontal();
        GUILayout.Space(10);
        GUILayout.BeginHorizontal();

        //Create rect for Object field
        Rect objectFieldRect = GUILayoutUtility.GetRect(new GUIContent("Add Material"), GUIStyle.none);

        objectFieldRect.width = EditorGUIUtility.currentViewWidth - 125;
        //Create Object field GUI
        manager.material = (Material)EditorGUI.ObjectField(objectFieldRect, manager.material, typeof(Material), false);

        //Create Rect for Toggle field
        Rect toggleFieldRect = new Rect(objectFieldRect.x + objectFieldRect.width + 50, objectFieldRect.y, 50, EditorGUIUtility.singleLineHeight);

        //Create Toggle field GUI
        manager.includeInactiveGameobjects = EditorGUI.Toggle(toggleFieldRect, manager.includeInactiveGameobjects);

        GUILayout.EndHorizontal();
        GUILayout.Space(10);
        GUILayout.EndVertical();
        EditorGUI.EndChangeCheck();

        //Apply Changes to the custom inspector
        if (manager.material != null)
        {
            manager.ApplyMaterialToChildrenRenderers(manager.material);
            serializedObject.ApplyModifiedProperties();
            serializedObject.Update();
            manager.material = null;
        }
    }