예제 #1
0
 void ActiveEffect(XffectComponent xft)
 {
     QuadExplode.DeActive();
     SphericalExplode.DeActive();
     QuadFogs.DeActive();
     SphericalFogs.DeActive();
     xft.Active();
 }
예제 #2
0
    protected void AddNodes(int num)
    {
        int added = 0;

        for (int i = 0; i < MaxENodes; i++)
        {
            if (added == num)
            {
                break;
            }
            EffectNode node = AvailableENodes[i];
            if (node != null)
            {
                AddActiveNode(node);
                added++;

                //activate on birth subemitter.
                if (UseSubEmitters && !string.IsNullOrEmpty(BirthSubEmitter))
                {
                    XffectComponent sub = SpawnCache.GetEffect(BirthSubEmitter);
                    if (sub == null)
                    {
                        return;
                    }

                    node.SubEmitter = sub;
                    sub.Active();
                }


                emitter.SetEmitPosition(node);
                float nodeLife = 0;
                if (IsNodeLifeLoop)
                {
                    nodeLife = -1;
                }
                else
                {
                    nodeLife = Random.Range(NodeLifeMin, NodeLifeMax);
                }
                Vector3 oriDir = emitter.GetEmitRotation(node);
                float   speed  = OriSpeed;
                if (IsRandomSpeed)
                {
                    speed = Random.Range(SpeedMin, SpeedMax);
                }
                node.Init(oriDir.normalized, speed, nodeLife, Random.Range(OriRotationMin, OriRotationMax),
                          Random.Range(OriScaleXMin, OriScaleXMax), Random.Range(OriScaleYMin, OriScaleYMax), Color1, UVTopLeft, UVDimension);
            }
            else
            {
                continue;
            }
        }
    }
예제 #3
0
    void OnEnable()
    {
        Script = target as XffectComponent;
        InitSerializedProperty();
        LoadStyle();

        if (Application.isEditor && !EditorApplication.isPlaying)
        {
            EditorApplication.update = Script.Update;
        }
    }
예제 #4
0
 public void Active()
 {
     if (!XffectComponent.IsActive(gameObject))
     {
         XffectComponent.SetActive(gameObject, true);
     }
     foreach (XffectComponent xft in XffectList)
     {
         xft.Active();
     }
 }
예제 #5
0
    public XffectComponent ReleaseEffect(string name)
    {
        XffectComponent xft = GetEffect(name);

        if (xft == null)
        {
            //Debug.LogWarning("can't find available effect in cache!:" + name);
            return(null);
        }
        xft.Active();
        return(xft);
    }
예제 #6
0
 void LateUpdate()
 {
     for (int i = 0; i < XffectList.Count; i++)
     {
         XffectComponent xft = (XffectComponent)XffectList[i];
         if (XffectComponent.IsActive(xft.gameObject))
         {
             return;
         }
     }
     //if all children is done, then set to non-active.
     XffectComponent.SetActive(gameObject, false);
 }
 void LateUpdate()
 {
     for (int i = 0; i < XffectList.Count; i++)
     {
         XffectComponent xft = (XffectComponent)XffectList[i];
         if (xft.gameObject.active == true)
         {
             return;
         }
     }
     //if all children is done, then set to non-active.
     gameObject.active = false;
 }
 void Start()
 {
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft == null)
         {
             continue;
         }
         xft.Initialize();
         XffectList.Add(xft);
     }
 }
예제 #9
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            GameObject      go         = Instantiate(YourEffect.gameObject, Vector3.zero, Quaternion.identity) as GameObject;
            XffectComponent fireEffect = go.GetComponent <XffectComponent>();
            //after you instantiate a Xffect Object, you need to call Active() to activate it
            //and when there are no active nodes in the scene, this Xffect Object will automatically become non-active
            fireEffect.Active();

            //if you fired a loop Xffect Object
            //  fireEffect.Deactive();
        }
    }
예제 #10
0
    //release effect by world position. in this case, the client transform's position should be zero.
    //notice: if the xffect is not auto-deactive, you should remember to manually deactive it.
    //** automaticaly set client to EffectCache, so you should make sure EffectCache's position is always zero.
    public XffectComponent ReleaseEffect(string name, Vector3 pos)
    {
        XffectComponent xft = GetEffect(name);

        if (xft == null)
        {
            Debug.LogWarning("can't find available effect in cache!:" + name);
            return(null);
        }
        xft.Active();
        xft.SetClient(transform);
        xft.SetEmitPosition(pos);
        return(xft);
    }
예제 #11
0
        private static IEnumerator EnableXft(XffectComponent xft)
        {
            yield return(null);

            var eft = xft.GetComponentsInChildren <EffectLayer>();

            foreach (var e in eft)
            {
                e.InitCollision();
            }
            xft.gameObject.SetActive(true);
            xft.enabled = true;
            //重置CollisionPlane
            //xft.Reset();
        }
예제 #12
0
    protected void Init()
    {
        //added 2012.6.24
        InitCollision();

        Owner = transform.parent.gameObject.GetComponent <XffectComponent>();
        if (Owner == null)
        {
            Debug.LogError("you must set EffectLayer to be XffectComponent's child.");
        }

        //fixed 2012.6.2. ignoring the red errors.
        if (ClientTransform == null)
        {
            Debug.LogWarning("effect layer: " + gameObject.name + " haven't assign a client transform, automaticly set to itself.");
            ClientTransform = transform;
        }
        AvailableENodes = new EffectNode[MaxENodes];
        ActiveENodes    = new EffectNode[MaxENodes];
        for (int i = 0; i < MaxENodes; i++)
        {
            EffectNode n    = new EffectNode(i, ClientTransform, SyncClient, this);
            ArrayList  afts = InitAffectors(n);
            n.SetAffectorList(afts);
            if (RenderType == 0)
            {
                n.SetType(SpriteWidth, SpriteHeight, (STYPE)SpriteType, (ORIPOINT)OriPoint, SpriteUVStretch, MaxFps);
            }
            else if (RenderType == 1)
            {
                float rwidth = RibbonWidth;
                float rlen   = RibbonLen;
                if (UseRandomRibbon)
                {
                    rwidth = Random.Range(RibbonWidthMin, RibbonWidthMax);
                    rlen   = Random.Range(RibbonLenMin, RibbonLenMax);
                }
                n.SetType(FaceToObject, FaceObject, rwidth, MaxRibbonElements, rlen, ClientTransform.position + EmitPoint, StretchType, MaxFps);
            }
            else if (RenderType == 2)
            {
                n.SetType(ConeSize, ConeSegment, ConeAngle, transform.rotation * OriVelocityAxis, 0, MaxFps, UseConeAngleChange, ConeDeltaAngle);
            }
            AvailableENodes[i] = n;
        }
        AvailableNodeCount = MaxENodes;
        emitter            = new Emitter(this);
    }
예제 #13
0
    //not support auto extend.
    public CompositeXffect GetCompositeXffect(string name)
    {
        List <CompositeXffect> cache = CompEffectDic[name];

        if (cache == null)
        {
            return(null);
        }
        foreach (CompositeXffect xftc in cache)
        {
            if (!XffectComponent.IsActive(xftc.gameObject))
            {
                return(xftc);
            }
        }
        return(null);
    }
예제 #14
0
    //for only-one effect
    public bool IsEffectActive(string eftName)
    {
        List <XffectComponent> cache = EffectDic[eftName];

        if (cache == null)
        {
            Debug.LogError(name + ": cache doesnt exist!");
            return(true);
        }
        if (cache.Count > 1)
        {
            Debug.LogWarning("DeActive() only support one Xffect cache!");
        }
        XffectComponent xft = cache[0];

        return(XffectComponent.IsActive(xft.gameObject));
    }
예제 #15
0
 public void Initialize()
 {
     //already initialized
     if (XffectList.Count > 0)
     {
         return;
     }
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft == null)
         {
             continue;
         }
         xft.Initialize();
         XffectList.Add(xft);
     }
 }
예제 #16
0
    public static bool DoPatch(Transform xffect)
    {
        XffectComponent xft = xffect.GetComponent <XffectComponent>();

        System.Version myVer = new System.Version(xft.MyVersion);

        if (xft != null && myVer >= new System.Version("4.4.0"))
        {
            return(false);
        }

        bool needToReimport = false;

        Object[] deps = EditorUtility.CollectDeepHierarchy(new Object[] { xffect.gameObject as Object });

        foreach (Object obj in deps)
        {
            if (obj == null || obj.GetType() != typeof(GameObject))
            {
                continue;
            }
            GameObject  go  = obj as GameObject;
            EffectLayer efl = go.GetComponent <EffectLayer>();
            if (efl != null)
            {
                DoPatch(efl);
                needToReimport = true;
            }

            XftEventComponent xevent = go.GetComponent <XftEventComponent>();
            if (xevent != null)
            {
                DoPatch(xevent);
                needToReimport = true;
            }
        }

        if (xft != null)
        {
            xft.MyVersion = XffectComponent.CurVersion;
        }

        return(needToReimport);
    }
예제 #17
0
    void DoPatch440(XffectComponent xffect)
    {
        xffect.MyVersion = XffectComponent.CurVersion;

        Object[] deps = EditorUtility.CollectDeepHierarchy(new Object[] { xffect.gameObject as Object });
        foreach (Object obj in deps)
        {
            if (obj == null || obj.GetType() != typeof(GameObject))
            {
                continue;
            }
            GameObject  go  = obj as GameObject;
            EffectLayer efl = go.GetComponent <EffectLayer>();
            if (efl != null)
            {
                DoPatch440(efl);
            }
        }
    }
예제 #18
0
 void Awake()
 {
     m_instance = this;
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft == null)
         {
             continue;
         }
         //make sure all children is inited.
         xft.Initialize();
         if (!EffectDic.ContainsKey(child.name))
         {
             EffectDic[child.name] = new ArrayList();
         }
         EffectDic[child.name].Add(xft);
     }
 }
예제 #19
0
    //manually emit effect node by expected position.
    public EffectNode EmitNode(string eftName, Vector3 pos)
    {
        ArrayList cache = EffectDic[eftName];

        if (cache == null)
        {
            Debug.LogError(name + ": cache doesnt exist!");
            return(null);
        }
        if (cache.Count > 1)
        {
            Debug.LogWarning("EmitNode() only support only-one xffect cache!");
        }
        XffectComponent xft = (XffectComponent)cache[0];

        if (xft.gameObject.active == false)
        {
            xft.Active();
        }
        return(xft.EmitByPos(pos));
    }
예제 #20
0
    public int GetAvailableEffectCount(string eftName)
    {
        ArrayList cache = EffectDic[eftName];

        if (cache == null)
        {
            return(0);
        }
        int ret = 0;

        for (int i = 0; i < cache.Count; i++)
        {
            XffectComponent xftcomp = (XffectComponent)cache[i];
            if (!XffectComponent.IsActive(xftcomp.gameObject))
            {
                ret++;
            }
        }

        return(ret);
    }
예제 #21
0
    //deactive the effect smoothly.
    public void StopEffect(string eftName)
    {
        List <XffectComponent> cache = EffectDic[eftName];

        if (cache == null)
        {
            Debug.LogError(name + ": cache doesnt exist!");
            return;
        }
        if (cache.Count > 1)
        {
            Debug.LogWarning("DeActive() only support one Xffect cache!");
        }
        XffectComponent xft = cache[0];

        if (!XffectComponent.IsActive(xft.gameObject))
        {
            return;
        }
        xft.StopEmit();
    }
예제 #22
0
    public static bool DoPatch(Transform xffect)
    {
        bool needToReimport = false;

        Object[] deps = EditorUtility.CollectDeepHierarchy(new Object[] { xffect.gameObject as Object });


        XffectComponent xcomp = xffect.GetComponent <XffectComponent>();

        if (xcomp != null)
        {
            xcomp.MyVersion = "4.1.5";
            needToReimport  = true;
        }


        foreach (Object obj in deps)
        {
            if (obj == null || obj.GetType() != typeof(GameObject))
            {
                continue;
            }
            GameObject  go  = obj as GameObject;
            EffectLayer efl = go.GetComponent <EffectLayer>();
            if (efl != null)
            {
                DoPatch(efl);
                needToReimport = true;
            }

            XftEventComponent xevent = go.GetComponent <XftEventComponent>();
            if (xevent != null)
            {
                DoPatch(xevent);
                needToReimport = true;
            }
        }

        return(needToReimport);
    }
예제 #23
0
    protected XffectComponent AddXffect(string name)
    {
        Transform baseobj = transform.Find(name);

        if (baseobj == null)
        {
            Debug.Log("object:" + name + "doesn't exist!");
            return(null);
        }
        Transform newobj = Instantiate(baseobj, Vector3.zero, Quaternion.identity) as Transform;

        newobj.parent            = transform;
        newobj.gameObject.active = false;
        XffectComponent xft = newobj.GetComponent <XffectComponent>();

        EffectDic[name].Add(xft);
        if (xft != null)
        {
            xft.Initialize();
        }
        return(xft);
    }
예제 #24
0
    void LateUpdate()
    {
        // if no collision needed, hide the colliders.
        if (!XffectComponent.IsActive(XCollisionTest1.gameObject) && !XffectComponent.IsActive(XCollisionTest2.gameObject))
        {
            if (Colliders.gameObject == true)
            {
                foreach (Transform child in Colliders)
                {
                    XffectComponent.SetActive(child.gameObject, false);
                }
            }
            XffectComponent.SetActive(Colliders.gameObject, false);
        }

        //auto deactive background
        m_checkTime += Time.deltaTime;
        if (m_checkTime > 5f)
        {
            XffectComponent.SetActive(BackgroundWallBottom.gameObject, false);
        }
    }
예제 #25
0
    public XffectComponent GetEffect(string name)
    {
        if (!EffectDic.ContainsKey(name))
        {
            Debug.LogError("there is no effect:" + name + " in effect cache!");
            return(null);
        }
        ArrayList cache = EffectDic[name];

        if (cache == null)
        {
            return(null);
        }
        foreach (XffectComponent xft in cache)
        {
            if (!XffectComponent.IsActive(xft.gameObject))
            {
                return(xft);
            }
        }
        return(AddXffect(name));
    }
예제 #26
0
    //useful for only-one effect cache and the effect is looping.
    public void DeActiveEffect(string eftName)
    {
        ArrayList cache = EffectDic[eftName];

        if (cache == null)
        {
            Debug.LogError(name + ": cache doesnt exist!");
            return;
        }
        if (cache.Count > 1)
        {
            Debug.LogWarning("DeActive() only support one Xffect cache!");
        }
        XffectComponent xft = (XffectComponent)cache[0];

        if (xft.gameObject.active == false)
        {
            return;
        }
        xft.DeActive();
        xft.Reset();
        xft.gameObject.active = false;
    }
예제 #27
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();
    }
예제 #28
0
    protected void Init()
    {
        //added 2012.6.24
        InitCollision();

        Owner = transform.parent.gameObject.GetComponent<XffectComponent>();
        if (Owner == null)
            Debug.LogError("you must set EffectLayer to be XffectComponent's child.");

        //fixed 2012.6.2. ignoring the red errors.
        if (ClientTransform == null)
        {
            Debug.LogWarning("effect layer: "+ gameObject.name + " haven't assign a client transform, automaticly set to itself.");
            ClientTransform = transform;
        }
        AvailableENodes = new EffectNode[MaxENodes];
        ActiveENodes = new EffectNode[MaxENodes];
        for (int i = 0; i < MaxENodes; i++)
        {
            EffectNode n = new EffectNode(i, ClientTransform, SyncClient, this);
            List<Affector> afts = InitAffectors(n);
            n.SetAffectorList(afts);
            if (RenderType == 0)
                n.SetType(SpriteWidth, SpriteHeight, (STYPE)SpriteType, (ORIPOINT)OriPoint, SpriteUVStretch, 60f);
            else if (RenderType == 1)
            {
                float rwidth = RibbonWidth;
                float rlen = RibbonLen;
                if (UseRandomRibbon)
                {
                    rwidth = Random.Range(RibbonWidthMin, RibbonWidthMax);
                    rlen = Random.Range(RibbonLenMin, RibbonLenMax);
                }
                n.SetType(FaceToObject, FaceObject, rwidth, MaxRibbonElements, rlen, ClientTransform.position + EmitPoint, StretchType, 60f);
            }
            else if (RenderType == 2)
            {
                n.SetType(ConeSize,ConeSegment,ConeAngle, transform.rotation * OriVelocityAxis,0,60f,UseConeAngleChange,ConeDeltaAngle);
            }
            else if (RenderType == 3)
            {
                Vector3 dir = Vector3.zero;
                if (OriVelocityAxis == Vector3.zero)
                {
                    OriVelocityAxis = Vector3.up;
                }

                dir = transform.rotation * OriVelocityAxis;

                n.SetType(CMesh,dir,60f);
            }

            AvailableENodes[i] = n;
        }
        AvailableNodeCount = MaxENodes;
        emitter = new Emitter(this);
    }
예제 #29
0
    void ReleasePooledEffect(string effectName)
    {
        XffectComponent eft = EffectPool.GetEffect(effectName);

        eft.Active();
    }
    void DoPatch440(XffectComponent xffect)
    {

        xffect.MyVersion = XffectComponent.CurVersion;

        Object[] deps = EditorUtility.CollectDeepHierarchy(new Object[] { xffect.gameObject as Object });
        foreach (Object obj in deps)
        {
            if (obj == null || obj.GetType() != typeof(GameObject))
                continue;
            GameObject go = obj as GameObject;
            EffectLayer efl = go.GetComponent<EffectLayer>();
            if (efl != null)
            {
                DoPatch440(efl);
            }
        }
    }
예제 #31
0
    void DrawPresets()
    {
        #region preset box0
        EditorGUILayout.BeginVertical("box");

        if (mShowingPresetList.Count > 0)
        {
            #region rows
            EditorGUILayout.BeginHorizontal();
            int rows       = 1;
            int iconwidths = 0;
            for (int i = 0; i < mShowingPresetList.Count; i++)
            {
                rows        = Mathf.FloorToInt(PresetViewWidth / PRESET_WIDTH);
                iconwidths += PRESET_WIDTH;
                if (iconwidths > PresetViewWidth && i > 0)
                {
                    iconwidths = PRESET_WIDTH;
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                }


                if (PresetViewWidth >= PRESET_WIDTH * 2)
                {
                    EditorGUILayout.BeginVertical("box", GUILayout.MaxWidth(Mathf.CeilToInt(PresetViewWidth / rows) - 44 / rows));
                }
                else
                {
                    EditorGUILayout.BeginVertical("box");
                }


                //begin preset unit
                EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(46));

                //EditorGUI.DrawPreviewTexture(new Rect(0, 0, 40, 40), texTest);



                if (GUILayout.Button(mShowingPresetList[i].PreviewIcon, PreviewButtonStyle, new GUILayoutOption[] { GUILayout.Width(64), GUILayout.Height(64) }))
                {
                    GameObject pobj = AssetDatabase.LoadAssetAtPath(mShowingPresetList[i].Path, typeof(GameObject)) as GameObject;

                    if (pobj == null)
                    {
                        Debug.LogWarning("prefab isn't existed, please refresh." + mShowingPresetList[i].Path);
                    }
                    else
                    {
                        GameObject obj = PrefabUtility.InstantiatePrefab(pobj) as GameObject;
                        if (obj != null)
                        {
                            Selection.activeGameObject = obj;
                            XffectComponent xobj = obj.GetComponent <XffectComponent>();
                            if (xobj != null)
                            {
                                xobj.EditView = true;
                                xobj.EnableEditView();
                            }

                            CompositeXffect cxobj = obj.GetComponent <CompositeXffect>();
                            if (cxobj != null)
                            {
                                cxobj.EnableEditView();
                            }
                        }

                        EditorUtility.UnloadUnusedAssetsImmediate();
                        System.GC.Collect();
                    }
                }

                //GUI.backgroundColor = bcolor;

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField(mShowingPresetList[i].Name, new GUILayoutOption[] { GUILayout.Width(PRESET_WIDTH - 64), GUILayout.Height(40) });
                EditorGUILayout.LabelField(mShowingPresetList[i].CreatedTime);
                EditorGUILayout.EndVertical();

                //end preset unit
                EditorGUILayout.EndHorizontal();

                //end preset frame
                EditorGUILayout.EndVertical();
            }

            //end presets box.
            EditorGUILayout.EndHorizontal();
            #endregion //row
        }
        else
        {
            EditorGUILayout.HelpBox("No prefabs found.", MessageType.Info);
        }

        //end outer frame box.
        EditorGUILayout.EndVertical();
        #endregion //box0
    }
예제 #32
0
        IEnumerator EnableXft(XffectComponent xft)
        {
            yield return(null);

            xft.enabled = true;
        }
예제 #33
0
 // Use this for initialization
 void Start()
 {
     theEffect = GameObject.Find("EffectCache").GetComponent<XffectCache>().GetEffect(xffectName);
     theEffect.Active();
     theEffect.transform.position = transform.position;
 }
	void OnEnable()
	{
		Script = target as XffectComponent;
		InitSerializedProperty();
		LoadStyle();
		
		if (Application.isEditor && !EditorApplication.isPlaying) {
			EditorApplication.update = Script.Update;
		}
	}
예제 #35
0
    void RefreshPresets()
    {
        Data.Presets.Clear();

        // check all prefabs to see if we can find any objects we are interested in
        List <string>  allPrefabPaths = new List <string>();
        Stack <string> paths          = new Stack <string>();

        paths.Push(Application.dataPath);
        while (paths.Count != 0)
        {
            string   path  = paths.Pop();
            string[] files = Directory.GetFiles(path, "*.prefab");
            foreach (var file in files)
            {
                allPrefabPaths.Add(file.Substring(Application.dataPath.Length - 6));
            }

            foreach (string subdirs in Directory.GetDirectories(path))
            {
                paths.Push(subdirs);
            }
        }

        // Check all prefabs
        int currPrefabCount = 1;

        foreach (string prefabPath in allPrefabPaths)
        {
            EditorUtility.DisplayProgressBar("Xffect Browser", "Searching xffect prefabs in project folder, please wait...", (float)currPrefabCount / (float)(allPrefabPaths.Count));

            GameObject iterGo = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
            if (!iterGo)
            {
                continue;
            }

            XffectComponent xft     = iterGo.GetComponent <XffectComponent>();
            CompositeXffect cxffect = iterGo.GetComponent <CompositeXffect>();
            if (xft == null && cxffect == null)
            {
                continue;
            }

            Data.Presets.Add(new XffectPresetData(ConvertPathToCategoryPath(prefabPath), prefabPath));



            ++currPrefabCount;
            if (currPrefabCount % 50 == 0)
            {
                iterGo = null;
                xft    = null;
                EditorUtility.UnloadUnusedAssetsImmediate();
                System.GC.Collect();
            }
        }


        // unload all unused assets
        EditorUtility.UnloadUnusedAssetsImmediate();
        System.GC.Collect();


        //save
        EditorUtility.SetDirty(Data);
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();


        EditorUtility.ClearProgressBar();


        RefreshDic();
        RefreshShowingPresetItems(mCurSelectCategory, mSearchString);
    }