Inheritance: MonoBehaviour
Example #1
0
    public override void _Ready()
    {
        _world = (World)GetNode("/root/World");
        _light = (Light2D)GetNode("Light2D");

        var mat = (ParticlesMaterial)ProcessMaterial;

        _sound = (AudioStreamPlayer)FindNode("ExtinguishSound");

        var gradient = new Gradient();

        gradient.AddPoint(2048 * 0.0f, new Color(255, 0, 0));
        gradient.AddPoint(2048 * 0.2f, new Color(255, 90, 0));
        gradient.AddPoint(2048 * 0.4f, new Color(255, 109, 0));
        gradient.AddPoint(2048 * 0.6f, new Color(255, 154, 0));
        gradient.AddPoint(2048 * 0.8f, new Color(255, 206, 0));
        gradient.AddPoint(2048 * 1.0f, new Color(255, 226, 6));

        var gradientTex = new GradientTexture();

        gradientTex.SetGradient(gradient);
        gradientTex.SetWidth(2048);

        var scale = new Curve();

        scale.AddPoint(new Vector2(0.0f, 1.0f));
        scale.AddPoint(new Vector2(1.0f, 0.5f));

        var scaleTex = new CurveTexture();

        scaleTex.SetCurve(scale);

        var matCopy = new ParticlesMaterial()
        {
            EmissionShape        = ParticlesMaterial.EMISSION_SHAPE_SPHERE,
            EmissionSphereRadius = 10,
            FlagDisableZ         = true,
            Spread                = 180,
            Gravity               = new Vector3(0, -98, 0),
            InitialVelocity       = 2,
            InitialVelocityRandom = 1,
            AngularVelocity       = 10,
            RadialAccel           = -15,
            Scale      = 3,
            ColorRamp  = gradientTex,
            ScaleCurve = scaleTex
        };

        this.ProcessMaterial = matCopy;
    }
Example #2
0
        ///-------------------------------------------------------------------------
        /// <summary>起動処理</summary>
        ///-------------------------------------------------------------------------
        public void Awake()
        {
            try
            {
                GameObject.DontDestroyOnLoad(this);

                ReadPluginPreferences();
                CurveTexture.Init();
                Translation.Initialize(configLanguage);
            }
            catch (Exception e)
            {
                Debug.LogError(e.ToString());
            }
        }
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        SerializedProperty R                 = serializedObject.FindProperty("R");
        SerializedProperty G                 = serializedObject.FindProperty("G");
        SerializedProperty B                 = serializedObject.FindProperty("B");
        SerializedProperty A                 = serializedObject.FindProperty("A");
        SerializedProperty wrapMode          = serializedObject.FindProperty("wrapMode");
        SerializedProperty filterMode        = serializedObject.FindProperty("filterMode");
        SerializedProperty resolution        = serializedObject.FindProperty("resolution");
        SerializedProperty useSharedMaterial = serializedObject.FindProperty("useSharedMaterial");
        SerializedProperty anisoLevel        = serializedObject.FindProperty("anisoLevel");

        CurveTexture ct = target as CurveTexture;
        Renderer     r  = ct.GetComponent <Renderer>();

        if (r == null)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("global name");
            ct.globalName = EditorGUILayout.TextField(ct.globalName);
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            Material      mat          = r.sharedMaterial;
            Shader        s            = mat.shader;
            int           count        = ShaderUtil.GetPropertyCount(s);
            List <string> textureNames = new List <string>();
            for (int i = 0; i < count; ++i)
            {
                if (ShaderUtil.GetPropertyType(s, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    textureNames.Add(ShaderUtil.GetPropertyName(s, i));
                }
            }
            int index  = textureNames.IndexOf(ct.propertyName);
            int newIdx = EditorGUILayout.Popup(index, textureNames.ToArray());
            if (newIdx != index)
            {
                ct.propertyName = textureNames[newIdx];
            }
        }
        EditorGUILayout.PropertyField(R);
        EditorGUILayout.PropertyField(G);
        EditorGUILayout.PropertyField(B);
        EditorGUILayout.PropertyField(A);
        EditorGUILayout.PropertyField(wrapMode);
        EditorGUILayout.PropertyField(filterMode);
        EditorGUILayout.PropertyField(resolution);
        if (r != null)
        {
            EditorGUILayout.PropertyField(useSharedMaterial);
        }
        EditorGUILayout.PropertyField(anisoLevel);
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
            ct.Refresh();
        }

        if (GUILayout.Button("Save Texture"))
        {
            string path = EditorUtility.SaveFilePanel("Save Texture", Application.dataPath, "curve", "png");
            if (!string.IsNullOrEmpty(path))
            {
                Texture2D tex   = ct.Generate(false);
                byte[]    bytes = tex.EncodeToPNG();
                File.WriteAllBytes(path, bytes);
                DestroyImmediate(tex);
                AssetImporter ai = AssetImporter.GetAtPath(path);
                if (ai != null)
                {
                    TextureImporter ti = ai as TextureImporter;
                    ti.anisoLevel                = ct.anisoLevel;
                    ti.linearTexture             = true;
                    ti.generateMipsInLinearSpace = true;
                    ti.filterMode                = ct.filterMode;
                    ti.wrapMode      = ct.wrapMode;
                    ti.textureFormat = TextureImporterFormat.ARGB32;
                    ti.SaveAndReimport();
                }
            }
        }
    }