// Copyright | Raumgleiter AG | 2019 | All Rights Reserved //*********************************************************************************************************************** //Headers using System.Collections; using System.Collections.Generic; using UnityEngine; using Raumgleiter.BaseRGDK.Painter; //*********************************************************************************************************************** namespace Raumgleiter.RGDKDevLab { public class TestPainter: MonoBehaviour { //------------------------------------------------------------------------------------------------------------------ //Connections [Header("Connections")] public GameObject PaintedObject; //Resources [Header("Resources")] public Material PaintMaterial; //Attributes //[Header("Attributes")] private string LastMaterial = "solar_00"; public List allMaterials; //Stats //[Header("Stats")] //protected bool IsSetUp = false; //protected bool IsAwoken = false; //Getter //Delegates //------------------------------------------------------------------------------------------------------------------ //awake //protected void Awake() //{ // //Already Awoken? // if (!IsAwoken) // { // IsAwoken = true; // } //} //------------------------------------------------------------------------------------------------------------------ //start public void Start() { //UpdateMaterial(PaintMaterial); } //------------------------------------------------------------------------------------------------------------------ public void UpdateMaterial(Material thisPaintMaterial) { // current material var CurrentMaterial = PaintedObject.transform.GetChild(0).GetComponent().material; var CurrentMaterialName = CurrentMaterial.name.Replace(" (Instance)", ""); Debug.Log("old material " + CurrentMaterialName); Debug.Log("new material " + thisPaintMaterial.name); MaterialLibrary Library = ScriptableObject.CreateInstance(); Library.LoadFromMaterials(new Material[] { thisPaintMaterial }); MaterialPainter.PaintSelective( PaintedObject, Library, new Dictionary() { { CurrentMaterialName, thisPaintMaterial.name } }); Debug.Log("name " + thisPaintMaterial.name); } //------------------------------------------------------------------------------------------------------------------ public void UpdateMaterial2(Material NewPaintMaterial, GameObject thisGameObject) { MaterialLibrary Library = ScriptableObject.CreateInstance(); Library.LoadFromMaterials(new Material[] { NewPaintMaterial }); MaterialPainter.PaintSelective( thisGameObject, Library, LastMaterial, NewPaintMaterial.name); LastMaterial = NewPaintMaterial.name; } //------------------------------------------------------------------------------------------------------------------ public List GetAllMaterials(GameObject thisGameObject) { var allChildren = thisGameObject.GetComponentsInChildren(); for (int i =0; i < allChildren.Length; i++) { Debug.Log(allChildren[i].name); if (allChildren[i].GetComponent()) { var MatName = allChildren[i].GetComponent().material.name; allMaterials.Add(MatName); //Debug.Log("printing material key :" + MatName); } else { //Debug.Log("TestPainter::GetAllMaterials: well, there was no material"); } } foreach (var item in allMaterials) { Debug.Log("TestPainter::GetAllMaterials: All materials:"); Debug.Log("TestPainter::GetAllMaterials: " + item); } return allMaterials; Debug.Log("TestPainter::GetAllMaterials: should have printed all materials"); } //------------------------------------------------------------------------------------------------------------------ //setup //public void SetUp() //{ // Awake(); // IsSetUp = true; //} //------------------------------------------------------------------------------------------------------------------ //destroy //*********************************************************************************************************************** //update //*********************************************************************************************************************** //refresh //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //events //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //private //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //protected //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //internal //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //public //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //public static //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ //*********************************************************************************************************************** //getter, setter //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ } }