扩展Text组件时设置默认文本颜色

时间:2017-01-19 20:05:11

标签: c# unity3d unity5

Unity的Text组件默认将import java.util.ArrayList; import java.util.Arrays; import org.apache.commons.math3.fitting.PolynomialCurveFitter; import org.apache.commons.math3.fitting.WeightedObservedPoints; public class MyFuncFitter { public static void main(String[] args) { ArrayList<Integer> keyPoints = new ArrayList<Integer>(); keyPoints.add(1); keyPoints.add(150); keyPoints.add(10000); keyPoints.add(100000); keyPoints.add(1000000); WeightedObservedPoints obs = new WeightedObservedPoints(); if(keyPoints != null && keyPoints.size() != 1) { int size = keyPoints.size(); int sectionSize = (int) (1000 / (size - 1)); for(int i = 0; i < size; i++) { if(i != 0) obs.add(keyPoints.get(i), i * sectionSize); else obs.add(keyPoints.get(0), 1); } } else if(keyPoints.size() == 1 && keyPoints.get(0) >= 1) { obs.add(1, 1); obs.add(keyPoints.get(0), 1000); } PolynomialCurveFitter fitter = PolynomialCurveFitter.create(3); fitter.withStartPoint(new double[] {keyPoints.get(0), 1}); double[] coeff = fitter.fit(obs.toList()); System.out.println(Arrays.toString(coeff)); } } 设置为颜色。当我扩展Text组件时,不再设置该颜色(它是白色的)。

enter image description here

¿如何在扩展组件时设置默认文本颜色?

323232FF

Unity的Text组件源代码:

https://bitbucket.org/Unity-Technologies/ui/src/0155c39e05ca5d7dcc97d9974256ef83bc122586/UnityEngine.UI/UI/Core/Text.cs?at=5.2&fileviewer=file-view-default

我没有覆盖看似设置颜色的“GetGenerationSettings”:S

2 个答案:

答案 0 :(得分:0)

这里要考虑两件事:

  1. 当您从一个Text中删除并重新添加GameObject组件时,其初始颜色将变为白色。该白色是Graphic Text继承的默认值。

  2. 这是因为调用层次结构UI /文本上下文菜单不仅仅是添加Text组件,它还会应用默认主题。

  3. 除非您能够确切地发现源中该层次结构菜单所完成的内容,否则您可以执行以下操作来设置默认属性:

    using UnityEngine;
    using UnityEngine.UI;
    
    [AddComponentMenu("UI/MyText", 10)]
    public class MyText : Text
    {
        protected override void Awake()
        {
            color = GUI.skin.textField.normal.textColor; // or whatever
        }
    }
    

答案 1 :(得分:0)

在我看来,没有深入研究Text的代码,你的类没有调用Text的构造函数。即使您没有定义构造函数,默认情况下您的类也是如此。

select table_name, sum(has_last_mod_time) as asdf
from (
    select
      table_name,
      case when lower(column_name) = 'last_modified_time' then 1 else 0 end  has_last_mod_time
    from all_tab_columns
    --<< no ")" here
) sdfsdf --<< no AS here
group by  table_name --<< and the group by needs to go here

您可能需要做的是让构造函数调用Text的构造函数。

public class CodeText : Text
{
    public CodeText() { 
    }

    void Awake() {
        Game.Instance.trackMe();
    }
}