public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        Rect outRect = r;

        float len = Mathf.Min(r.height, r.width);

        outRect.width = outRect.height = len;

        outRect.x = r.width / 2f - len / 2f;

        outRect.y = r.y + r.height / 2f - len / 2f;

        Rect bkgRect = outRect;

        outRect.x      += 3;
        outRect.y      += 3;
        outRect.width  -= 6;
        outRect.height -= 6;

        EditorGUI.DrawPreviewTexture(bkgRect, BkgIcon);

        string prefabPath = "none";
        string imgPath    = XEditorTool.GetEditorAssetPath() + "/no_preview.png";

        if (EditorUtility.IsPersistent(target))
        {
            //is prefab
            prefabPath = AssetDatabase.GetAssetPath(target);
            imgPath    = prefabPath.Substring(0, prefabPath.LastIndexOf(".prefab")) + "_preview.png";
        }
        else
        {
            //is scene obj, check if has prefab instance
            Object prefab = PrefabUtility.GetPrefabParent(target);
            if (prefab != null)
            {
                prefabPath = AssetDatabase.GetAssetPath(prefab);
                imgPath    = prefabPath.Substring(0, prefabPath.LastIndexOf(".prefab")) + "_preview.png";
            }
            else
            {
                imgPath = XEditorTool.GetEditorAssetPath() + "/no_prefab.png";
            }
        }


        Texture2D particleImage = AssetDatabase.LoadAssetAtPath(imgPath, typeof(Texture2D)) as Texture2D;

        if (particleImage == null)
        {
            EditorGUI.DrawPreviewTexture(outRect, NoPreviewIcon);
        }
        else
        {
            EditorGUI.DrawPreviewTexture(outRect, particleImage);
        }


        //GUI.Label(r, target.name + " is being previewed");
    }
Esempio n. 2
0
    static void DoCreateXffectObject()
    {
        Transform parent = Selection.activeTransform;

        GameObject go = new GameObject("XffectObj");

        go.transform.localScale = Vector3.one;
        go.transform.rotation   = Quaternion.identity;
        go.AddComponent <XffectComponent> ();

        Selection.activeGameObject = go;

        GameObject  layer = new GameObject("EffectLayer");
        EffectLayer efl   = (EffectLayer)layer.AddComponent("EffectLayer");

        layer.transform.parent = go.transform;

        efl.transform.localPosition = Vector3.zero;
        //fixed 2012.6.25. default to effect layer object.
        efl.ClientTransform  = efl.transform;
        efl.GravityObject    = efl.transform;
        efl.BombObject       = efl.transform;
        efl.TurbulenceObject = efl.transform;
        efl.AirObject        = efl.transform;
        efl.VortexObj        = efl.transform;
        efl.DirCenter        = efl.transform;
        efl.DragObj          = efl.transform;

        efl.Material = AssetDatabase.LoadAssetAtPath(XEditorTool.GetXffectPath() + DefaultMatPath, typeof(Material)) as Material;

        if (parent != null)
        {
            go.transform.parent = parent;
        }
    }
Esempio n. 3
0
    void DoPatch440(EffectLayer layer)
    {
        if (layer.IsRandomStartColor)
        {
            XEditorTool.PatchColorGradient(layer.RandomColorParam, layer.RandomColorGradient);
        }

        if (layer.ColorChangeType == COLOR_CHANGE_TYPE.Gradient)
        {
            XEditorTool.PatchColorGradient(layer.ColorParam, layer.ColorGradient);
        }
    }
Esempio n. 4
0
    public void Init()
    {
        mSearchString      = "";
        mCurSelectCategory = "All";
        RefreshDic();



        mBkgGrey   = Resources.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/grey.png", typeof(Texture2D)) as Texture2D;
        mBkgWhite  = Resources.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/white.png", typeof(Texture2D)) as Texture2D;
        mNoPreview = Resources.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/no_preview.png", typeof(Texture2D)) as Texture2D;

        RefreshShowingPresetItems(mCurSelectCategory, mSearchString);
    }
Esempio n. 5
0
    void InitCapture()
    {
        mCaptureLen = 256f;

        mHandleRCLen = 32f;

        HandleImgTL = AssetDatabase.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/handle_tl.png", typeof(Texture2D)) as Texture2D;
        HandleImgTR = AssetDatabase.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/handle_tr.png", typeof(Texture2D)) as Texture2D;
        HandleImgBL = AssetDatabase.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/handle_bl.png", typeof(Texture2D)) as Texture2D;
        HandleImgBR = AssetDatabase.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/handle_br.png", typeof(Texture2D)) as Texture2D;

        HandleImgCT = AssetDatabase.LoadAssetAtPath(XEditorTool.GetEditorAssetPath() + "/handle_center.png", typeof(Texture2D)) as Texture2D;

        mCTOft = Vector2.zero;
    }
    public static void DoPatch(EffectLayer layer)
    {
        Debug.Log("patching for effect layer:" + GetPath(layer.transform));


        if (layer.IsRandomStartColor)
        {
            XEditorTool.PatchColorGradient(layer.RandomColorParam, layer.RandomColorGradient);
        }

        if (layer.ColorChangeType == COLOR_CHANGE_TYPE.Gradient)
        {
            XEditorTool.PatchColorGradient(layer.ColorParam, layer.ColorGradient);
        }
    }
Esempio n. 7
0
    public static void DoPatch(EffectLayer layer)
    {
        Debug.Log("patching for effect layer:" + GetPath(layer.transform));

        if (layer.ColorAffectType == 0)
        {
            layer.ColorChangeType     = COLOR_CHANGE_TYPE.Constant;
            layer.ColorAffectorEnable = false;
        }
        else if (layer.ColorAffectType == 1)
        {
            layer.ColorParam.Colors.Clear();

            layer.ColorParam.AddColorKey(0f, layer.Color1);
            layer.ColorParam.AddColorKey(1f, layer.Color2);

            layer.ColorChangeType = COLOR_CHANGE_TYPE.Gradient;

            layer.ColorAffectorEnable = true;
        }
        else if (layer.ColorAffectType == 2)
        {
            layer.ColorParam.Colors.Clear();
            layer.ColorParam.AddColorKey(0f, layer.Color1);
            layer.ColorParam.AddColorKey(0.25f, layer.Color2);
            layer.ColorParam.AddColorKey(0.5f, layer.Color3);
            layer.ColorParam.AddColorKey(0.75f, layer.Color4);
            layer.ColorParam.AddColorKey(1f, layer.Color5);

            layer.ColorChangeType     = COLOR_CHANGE_TYPE.Gradient;
            layer.ColorAffectorEnable = true;
        }

        if (layer.Material == null)
        {
            layer.Material = AssetDatabase.LoadAssetAtPath(XEditorTool.GetXffectPath() + XffectComponentCustom.DefaultMatPath,
                                                           typeof(Material)) as Material;
        }
    }
Esempio n. 8
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        XEditor.BeginCommonArea("xffect main config", Script.gameObject.name, this, true);

        EditorGUILayout.Space();

        XEditor.DrawToggle("update in editor?", "", EditView);

        //EditView.boolValue = EditorGUILayout.Toggle("update in editor:", EditView.boolValue,GUILayout.Height(40f));


        if (EditView.boolValue == true)
        {
            if (!XffectComponent.IsActive(Script.gameObject))
            {
                EditView.boolValue = false;
                Debug.Log("you need to activate the xffect object: " + Script.gameObject.name + " before updating it in editor.");
            }
        }

        if (EditView.boolValue)
        {
            Script.EnableEditView();
        }
        else
        {
            Script.DisableEditView();
        }

        if (EditView.boolValue)
        {
            if (GUILayout.Button("Reset"))
            {
                Script.ResetEditScene();
            }
        }

        XEditor.DrawSeparator();

        XEditor.DrawFloat("life(-1 means infinite):", "", LifeTime);
        XEditor.DrawToggle("ignore time scale?", "", IgnoreTimeScale);


        EditorGUILayout.Space();

        XEditor.DrawFloat("scale:", "change this Xffect's scale", Scale);


        if (GUILayout.Button("Add Layer"))
        {
            GameObject  layer = new GameObject(LayerName);
            EffectLayer efl   = (EffectLayer)layer.AddComponent("EffectLayer");
            layer.transform.parent      = Selection.activeTransform;
            efl.transform.localPosition = Vector3.zero;
            //default to effect layer object.
            efl.ClientTransform  = efl.transform;
            efl.GravityObject    = efl.transform;
            efl.BombObject       = efl.transform;
            efl.TurbulenceObject = efl.transform;
            efl.AirObject        = efl.transform;
            efl.VortexObj        = efl.transform;
            efl.DirCenter        = efl.transform;
            efl.Material         = AssetDatabase.LoadAssetAtPath(XEditorTool.GetXffectPath() + DefaultMatPath, typeof(Material)) as Material;

            efl.gameObject.layer = Script.gameObject.layer;

            Selection.activeGameObject = layer;
        }


        if (GUILayout.Button("Add Event"))
        {
            GameObject        obj    = new GameObject("_Event");
            XftEventComponent xevent = (XftEventComponent)obj.AddComponent("XftEventComponent");
            xevent.transform.parent        = Selection.activeTransform;
            xevent.transform.localPosition = Vector3.zero;
            xevent.RadialBlurShader        = Shader.Find("Xffect/PP/radial_blur_new");
            xevent.GlowCompositeShader     = Shader.Find("Xffect/PP/glow_compose");
            xevent.GlowDownSampleShader    = Shader.Find("Xffect/PP/glow_downsample");
            xevent.GlowBlurShader          = Shader.Find("Xffect/PP/glow_conetap");
            xevent.RadialBlurObj           = xevent.transform;
            xevent.ColorInverseShader      = Shader.Find("Xffect/PP/color_inverse");

            xevent.GlowPerObjBlendShader       = Shader.Find("Xffect/glow_per_obj/blend");
            xevent.GlowPerObjReplacementShader = Shader.Find("Xffect/glow_per_obj/replacement");

            xevent.gameObject.layer = Script.gameObject.layer;

            Selection.activeGameObject = obj;
        }


        EditorGUILayout.Space();

        XEditor.EndXArea();

        DrawInfos();

        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 9
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();


        //check if need to upgrade.
        System.Version myVer = new System.Version(Script.MyVersion);
        if (myVer <= new System.Version("4.4.0"))
        {
            DoPatch440(Script);
            EditorUtility.SetDirty(target);
        }

        XEditor.BeginCommonArea("xffect main config", Script.gameObject.name, this, true);

        EditorGUILayout.Space();


        if (EditorUtility.IsPersistent(target))
        {
            if (GUILayout.Button("Put To Scene"))
            {
                GameObject obj = PrefabUtility.InstantiatePrefab(Selection.activeObject as GameObject) as GameObject;
                Selection.activeGameObject = obj;
                if (obj != null)
                {
                    XffectComponent xobj = obj.GetComponent <XffectComponent>();
                    if (xobj != null)
                    {
                        xobj.EditView = true;
                        xobj.EnableEditView();
                    }
                }
            }
        }


        XEditor.DrawToggle("update in editor?", "", EditView);

        //EditView.boolValue = EditorGUILayout.Toggle("update in editor:", EditView.boolValue,GUILayout.Height(40f));


        //if (EditView.boolValue == true) {
        //if (!XffectComponent.IsActive(Script.gameObject)) {
        //EditView.boolValue = false;
        //Debug.Log ("you need to activate the xffect object: " + Script.gameObject.name + " before updating it in editor.");
        //}
        //}

        if (EditView.boolValue)
        {
            Script.EnableEditView();
        }
        else
        {
            Paused.boolValue = false;
            Script.DisableEditView();
        }

        if (EditView.boolValue)
        {
            PlaybackTime.floatValue = EditorGUILayout.FloatField("Playback time: ", PlaybackTime.floatValue);

            if (PlaybackTime.floatValue < 0f)
            {
                PlaybackTime.floatValue = 0f;
            }

            string disp = "Pause";
            if (Paused.boolValue)
            {
                disp = "Play";
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(disp))
            {
                Paused.boolValue = !Paused.boolValue;
            }

            if (GUILayout.Button("Reset"))
            {
                Paused.boolValue = false;
                Script.ResetEditScene();
            }
            EditorGUILayout.EndHorizontal();
        }

        XEditor.DrawSeparator();

        XEditor.DrawFloat("life(-1 means infinite):", "", LifeTime);
        XEditor.DrawToggle("ignore time scale?", "", IgnoreTimeScale);

        XEditor.DrawToggle("auto destroy?", "check on this option if you want this obj to be destroyed when finished, note this option only works in play mode.", AutoDestroy);

        XEditor.DrawToggle("merge same mesh?", "check on this option to merge the meshes with same material, can reduce drawcalls.", MergeSameMaterialMesh);

        XEditor.DrawToggle("update when offscreen?", "", UpdateWhenOffScreen);

        if (XEditor.DrawToggle("use with 2d sprite?", "", UseWith2DSprite))
        {
            XEditor.DrawText("sorting layer name:", "", SortingLayerName);
            XEditor.DrawInt("sorting order:", "", SortingOrder);
        }

        EditorGUILayout.Space();



        XEditor.DrawInt("Max Fps:", "", MaxFps);

        XEditor.DrawFloat("scale:", "change this Xffect's scale", Scale);



        if (!Mathf.Approximately(1f, Scale.floatValue))
        {
            XEditor.DrawInfo("note it's not recommended to use this function to change xffect's scale. if you encounter strange behavious, please change it back to 1.");
        }

        if (GUILayout.Button("Add Layer"))
        {
            GameObject  layer = new GameObject(LayerName);
            EffectLayer efl   = (EffectLayer)layer.AddComponent <EffectLayer>();
            layer.transform.parent      = Selection.activeTransform;
            efl.transform.localPosition = Vector3.zero;
            //default to effect layer object.
            efl.ClientTransform  = efl.transform;
            efl.GravityObject    = efl.transform;
            efl.BombObject       = efl.transform;
            efl.TurbulenceObject = efl.transform;
            efl.AirObject        = efl.transform;
            efl.VortexObj        = efl.transform;
            //efl.DirCenter = efl.transform;
            efl.Material = AssetDatabase.LoadAssetAtPath(XEditorTool.GetXffectPath() + DefaultMatPath, typeof(Material)) as Material;

            efl.gameObject.layer = Script.gameObject.layer;

            efl.LineStartObj = efl.transform;

            Selection.activeGameObject = layer;
        }


        if (GUILayout.Button("Add Event"))
        {
            GameObject        obj    = new GameObject("_Event");
            XftEventComponent xevent = (XftEventComponent)obj.AddComponent <XftEventComponent>();
            xevent.transform.parent        = Selection.activeTransform;
            xevent.transform.localPosition = Vector3.zero;
            xevent.RadialBlurShader        = Shader.Find("Xffect/PP/radial_blur");
            xevent.GlowCompositeShader     = Shader.Find("Xffect/PP/glow_compose");
            xevent.GlowDownSampleShader    = Shader.Find("Xffect/PP/glow_downsample");
            xevent.GlowBlurShader          = Shader.Find("Xffect/PP/glow_conetap");
            xevent.RadialBlurObj           = xevent.transform;
            xevent.ColorInverseShader      = Shader.Find("Xffect/PP/color_inverse");

            xevent.GlowPerObjBlendShader       = Shader.Find("Hidden/PP/Xffect/glow_per_obj/blend");
            xevent.GlowPerObjReplacementShader = Shader.Find("Hidden/PP/Xffect/glow_per_obj/replacement");
            xevent.gameObject.layer            = Script.gameObject.layer;

            Selection.activeGameObject = obj;
        }
        XEditor.EndXArea();

        DrawInfos();
        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 10
0
    void OnGUI()
    {
        if (mColorKeys == null || mEditor == null)
        {
            return;
        }

        bool leftMouseDown  = Event.current.type == EventType.MouseDown && Event.current.button == 0;
        bool leftMouseUp    = Event.current.type == EventType.MouseUp && Event.current.button == 0;
        bool doubleClick    = leftMouseDown && Event.current.clickCount > 1;
        bool rightMouseDown = Event.current.type == EventType.MouseDown && Event.current.button == 1;
        bool isDrag         = Event.current.type == EventType.MouseDrag;

        GUILayout.Label("Usage: double click to add new color; drag to move color; right click to delete color.", new GUILayoutOption[] { GUILayout.MinHeight(20), GUILayout.ExpandWidth(true) });

        if (Event.current.type == EventType.Repaint)
        {
            InfoBox = GUILayoutUtility.GetLastRect();
        }

        GUILayout.Box("", new GUILayoutOption[] { GUILayout.MinHeight(ColorBoxHeight), GUILayout.Width(InfoBox.width - ColorBoxRightPadding) });
        Rect r = GUILayoutUtility.GetLastRect();

        r = new Rect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);

        if (!mEditorTex && Event.current.type == EventType.Repaint)
        {
            XEditorTool.RefreshGradientTex(ref mEditorTex, mColorParam, mEditor);
        }

        if (mEditorTex)
        {
            EditorGUI.DrawPreviewTexture(r, mEditorTex, EffectLayerCustom.ColorBkgMat);
        }

        Vector2 mp = Event.current.mousePosition;

        bool isOutSideWindow = (mp.x > InfoBox.width);

        for (int k = 0; k < mColorKeys.Count; k++)
        {
            Rect HandleRect = new Rect(r.x + mColorKeys[k].t * r.width, r.y, ColorFieldWidth, r.height);

            // Delete Key?
            if (rightMouseDown && HandleRect.Contains(mp) && mColorKeys.Count > 1)
            {
                mColorKeys.RemoveAt(k);
                XEditorTool.RefreshGradientTex(ref mEditorTex, mColorParam, mEditor);
                Event.current.Use();
                Repaint();
                break;
            }

            // Begin Drag?
            if (isDrag && !mDragging && HandleRect.Contains(mp))
            {
                mDragging   = true;
                mDragKey    = k;
                mDragOffset = mp.x - HandleRect.x;
                Event.current.Use();
            }
            // Drag?
            if (Event.current.type == EventType.Repaint && mDragging && mDragKey == k)
            {
                float pos = mp.x - r.x - mDragOffset;

                pos = Mathf.Clamp(pos, 0, r.width);

                float t = pos / (r.width);
                mColorKeys[mDragKey].t = t;

                HandleRect = new Rect(r.x + t * r.width, r.y, ColorFieldWidth, r.height);
                Repaint();
            }

            if (leftMouseDown && HandleRect.Contains(mp))
            {
                Event.current.Use();
            }

            if (leftMouseUp || mp.x < 0 || isOutSideWindow)
            {
                //Debug.LogWarning(mp.x + ":" + r.width);
                if (mDragging && mDragKey == k)
                {
                    mDragging = false;
                    mDragKey  = -1;
                    XEditorTool.RefreshGradientTex(ref mEditorTex, mColorParam, mEditor);
                    Event.current.Use();
                }
                else if (HandleRect.Contains(mp) && !isOutSideWindow)
                {
                    Event.current.type = EventType.MouseDown;
                }
            }

            Color c = mColorKeys[k].Color;
            mColorKeys[k].Color = EditorGUI.ColorField(HandleRect, mColorKeys[k].Color);
            if (c != mColorKeys[k].Color)
            {
                XEditorTool.RefreshGradientTex(ref mEditorTex, mColorParam, mEditor);
            }
        }

        if (doubleClick && r.Contains(mp))
        {
            mColorParam.AddColorKey((mp.x - r.x) / r.width, Color.white);
            XEditorTool.RefreshGradientTex(ref mEditorTex, mColorParam, mEditor);
            Repaint();
        }

        if (mDragKey >= 0)
        {
            string location = "Location:" + mColorKeys[mDragKey].t * 100f + "%";
            GUILayout.Label(location, new GUILayoutOption[] { GUILayout.MinHeight(20), GUILayout.ExpandWidth(true) });
        }
    }