Exemplo n.º 1
0
    public static void CreateUIDynamic(MenuCommand menuCommand)
    {
        GameObject goImg = new GameObject("Image - StP");

        GameObjectUtility.SetParentAndAlign(goImg, menuCommand.context as GameObject);
        Undo.RegisterCreatedObjectUndo(goImg, "Create " + goImg.name);
        Selection.activeObject = goImg;
        goImg.AddComponent <RectTransform>();

        Image  image = goImg.AddComponent <Image>();
        string path  = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("numbloqLogo")[0]);

        image.sprite = (Sprite)AssetDatabase.LoadAssetAtPath(path, typeof(Sprite));
        image.SetNativeSize();

        GameObject goParticles = new GameObject("Particles - StP");

        GameObjectUtility.SetParentAndAlign(goParticles, menuCommand.context as GameObject);
        Undo.RegisterCreatedObjectUndo(goParticles, "Create " + goParticles.name);
        Selection.activeObject = goParticles;

        goParticles.AddComponent <RectTransform>();
        ParticleSystem     ps   = goParticles.AddComponent <ParticleSystem>();
        UIParticleRenderer uipr = goParticles.AddComponent <UIParticleRenderer>();
        SpriteToParticles  stP  = goParticles.AddComponent <SpriteToParticles>();

        #if UNITY_5_5_OR_NEWER
        ParticleSystem.MainModule mainModule = ps.main;
        mainModule.loop            = false;
        mainModule.playOnAwake     = false;
        mainModule.duration        = 1;
        mainModule.startLifetime   = 1;
        mainModule.gravityModifier = 20;
        mainModule.startSize       = 10;
        #endif
        ParticleSystem.EmissionModule em = ps.emission;
        em.enabled = false;
        ParticleSystem.ShapeModule sm = ps.shape;
        sm.enabled = false;

        ParticleSystemRenderer psr = goParticles.GetComponent <ParticleSystemRenderer>();
        psr.enabled = false;

        string path2 = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("UI - Particle Add")[0]);
        uipr.material = (Material)AssetDatabase.LoadAssetAtPath(path2, typeof(Material));

        stP.renderSystemType    = RenderSystemUsing.ImageRenderer;
        stP.imageRenderer       = image;
        stP.UsePixelSourceColor = true;
        stP.ResetAllCache();
    }
Exemplo n.º 2
0
    public static void CreateSpriteDynamic(MenuCommand menuCommand)
    {
        GameObject go = new GameObject("Sprite - StP");

        GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
        Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
        Selection.activeObject = go;

        SpriteRenderer    sp  = go.AddComponent <SpriteRenderer>();
        ParticleSystem    ps  = go.AddComponent <ParticleSystem>();
        SpriteToParticles stP = go.AddComponent <SpriteToParticles>();

        string path = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("numbloqLogo")[0]);

        sp.sprite = (Sprite)AssetDatabase.LoadAssetAtPath(path, typeof(Sprite));

         #if UNITY_5_5_OR_NEWER
        ParticleSystem.MainModule mainModule = ps.main;
        mainModule.loop            = false;
        mainModule.playOnAwake     = false;
        mainModule.duration        = 1;
        mainModule.startLifetime   = 1;
        mainModule.gravityModifier = 0.2f;
        #endif
        ParticleSystem.EmissionModule em = ps.emission;
        em.enabled = false;
        ParticleSystem.ShapeModule sm = ps.shape;
        sm.enabled = false;

        ParticleSystemRenderer psr = go.GetComponent <ParticleSystemRenderer>();
        string path2 = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("Pixel Material")[0]);
        psr.sharedMaterial = (Material)AssetDatabase.LoadAssetAtPath(path2, typeof(Material));
        psr.sortingOrder   = 100;

        stP.UsePixelSourceColor = true;
        stP.ResetAllCache();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Display precise variables for StP different modes
    /// </summary>
    public override void OnInspectorGUI()
    {
        SpriteToParticles StP = (SpriteToParticles)target;

        showHelp = EditorPrefs.GetBool("SpriteToParticles.ShowTools");
        //showWarnings = EditorPrefs.GetBool("SpriteToParticles.ShowWarnings");

        GUIStyle Title = new GUIStyle(EditorStyles.textArea);

        Title.normal.textColor = Color.white;
        Title.fontStyle        = FontStyle.Bold;

        serializedObject.Update();

        RenderSystemUsing renderType    = (RenderSystemUsing)renderSystemType.intValue;
        SpriteMode        _emissionMode = (SpriteMode)spriteMode.intValue;

        GUILayout.Space(5f);
        EditorGUILayout.LabelField("Main Config", Title);
        EditorGUI.indentLevel++;
        EditorGUILayout.PropertyField(spriteMode);

        EditorGUILayout.PropertyField(renderSystemType);
        EditorGUI.indentLevel--;
        GUILayout.Space(5f);

        EditorGUILayout.LabelField("References", Title);
        EditorGUI.indentLevel++;

        if (renderType == RenderSystemUsing.SpriteRenderer)
        {
            EditorGUILayout.PropertyField(spriteRenderer);
        }
        if (renderType == RenderSystemUsing.ImageRenderer)
        {
            EditorGUILayout.PropertyField(imageRenderer);
        }
        EditorGUILayout.PropertyField(particlesSystem);
        if (showHelp)
        {
            CheckValidations();
        }
        EditorGUI.indentLevel--;
        GUILayout.Space(5f);

        EditorGUILayout.LabelField("Emission Options", Title);
        EditorGUI.indentLevel++;
        EditorGUILayout.PropertyField(PlayOnAwake);
        EditorGUILayout.PropertyField(EmissionRate);

        if (_emissionMode != SpriteMode.Static)
        {
            EditorGUILayout.PropertyField(borderEmission);
        }

        EditorGUILayout.PropertyField(UsePixelSourceColor);
        GUILayout.Space(5f);
        EditorGUILayout.PropertyField(UseEmissionFromColor);
        if (UseEmissionFromColor.boolValue)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(EmitFromColor);
            EditorGUILayout.PropertyField(RedTolerance);
            EditorGUILayout.PropertyField(GreenTolerance);
            EditorGUILayout.PropertyField(BlueTolerance);
            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel--;
        GUILayout.Space(5f);

        if (IsRendererInAnotherGameObject(StP))
        {
            EditorGUILayout.LabelField("Renderer in different GameObject specifics", Title);
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(matchTargetGOPostionData);
            EditorGUILayout.PropertyField(matchTargetGOScale);
            EditorGUI.indentLevel--;
            GUILayout.Space(5f);
        }

        EditorGUILayout.LabelField("Advanced Options", Title);
        EditorGUI.indentLevel++;
        //advancedOptions = EditorGUILayout.Foldout(advancedOptions, "Show");
        //if (advancedOptions)
        {
            //EditorGUI.indentLevel++;
            if (_emissionMode == SpriteMode.Dynamic)
            {
                EditorGUILayout.PropertyField(CacheSprites);
            }
            else
            {
                EditorGUILayout.PropertyField(CacheOnAwake);
            }

            EditorGUILayout.PropertyField(useSpritesSharingCache);
            EditorGUILayout.PropertyField(useBetweenFramesPrecision);
            if (showHelp && useBetweenFramesPrecision.boolValue)
            {
                #if UNITY_5_5_OR_NEWER
                if (StP.particlesSystem && StP.particlesSystem.main.simulationSpace != ParticleSystemSimulationSpace.World)
                {
                    EditorGUILayout.HelpBox("Between frames precision is only to be use with ParticleSystem's simulation space set to world.", MessageType.Warning);
                }
                #endif
            }

            GUILayout.Space(5f);

            EditorGUILayout.PropertyField(verboseDebug);

            showHelp = EditorGUILayout.Toggle("Show Inspector Help", showHelp);
            EditorPrefs.SetBool("SpriteToParticles.ShowTools", showHelp);

            //showWarnings = EditorGUILayout.Toggle("Show Inspector Warnings", showWarnings);
            //EditorPrefs.SetBool("SpriteToParticles.ShowWarnings", showWarnings);
            //EditorGUI.indentLevel--;
        }
        if (GUILayout.Button("Emit All"))
        {
            StP.particlesSystem.Play();
            StP.EmitAll(false);
        }

        if (GUILayout.Button("Reset Cache"))
        {
            StP.ResetAllCache();
        }

        EditorGUI.indentLevel--;
        serializedObject.ApplyModifiedProperties();
    }