コード例 #1
0
 internal void DebugColorCustomizer(ColorCustomizer colorCustomizer)
 {
     foreach (ColorCustomizer.ColorData colorData in colorCustomizer.colorDatas)
     {
         print($"Renderer: {colorData.renderer.name}, material index: {colorData.materialIndex}");
     }
 }
コード例 #2
0
        public static void AddRendererToColorCustomizer(GameObject containCustomizer, GameObject containRenderer, bool clearCustomizer, params int[] materialIndexes)
        {
            ColorCustomizer colorCustomizer = containCustomizer.GetComponent <ColorCustomizer>();

            if (colorCustomizer == null)
            {
                throw new ArgumentException("GameObject does not have ColorCustomizer component!");
            }

            Renderer renderer = containRenderer.GetComponent <Renderer>();

            if (renderer == null)
            {
                throw new ArgumentException($"GameObject [{containRenderer.name}] does not have Renderer component!");
            }

            List <ColorCustomizer.ColorData> colorDatas = colorCustomizer.colorDatas.ToList();

            if (clearCustomizer)
            {
                colorDatas.Clear();
            }
            else
            {
                foreach (ColorCustomizer.ColorData colorData in colorDatas)
                {
                    if (colorData.renderer.Equals(renderer))
                    {
                        BZLogger.Log($"ColorData.renderers [{renderer.name}] has contain the desired renderer!");
                        return;
                    }
                }
            }

            foreach (int index in materialIndexes)
            {
                colorDatas.Add(new ColorCustomizer.ColorData {
                    renderer = renderer, materialIndex = index
                });
            }

            colorCustomizer.colorDatas = colorDatas.ToArray();
        }