Beispiel #1
0
 public bool TrySave()
 {
     if (mClipPrefab == null)
     {//当前没有保存目标Prefab
         string prefabPath = EditorUtility.SaveFilePanel("保存动画片段", Application.dataPath, "NewSpeAnimClip", "prefab");
         if (prefabPath != "")
         {
             _UpdateAnimationClipItemTransform(mClipGo.GetComponent <SpecialEffectAnimationClip>());
             GameObject saveGo = _GetSaveAnimationClipGameObject(mClipGo);
             //保存Prefab
             mClipPrefab = PrefabUtility.CreatePrefab(prefabPath.Substring(prefabPath.LastIndexOf("Assets/")), saveGo, ReplacePrefabOptions.ReplaceNameBased);
             GameObject.DestroyImmediate(saveGo);
         }
         else
         {
             return(false);
         }
     }
     else
     {//当前存在保存目标
         _UpdateAnimationClipItemTransform(mClipGo.GetComponent <SpecialEffectAnimationClip>());
         GameObject saveGo = _GetSaveAnimationClipGameObject(mClipGo);
         SpecialEffectEditorUtility.ReplacePrefab(saveGo, mClipPrefab);
         GameObject.DestroyImmediate(saveGo);
     }
     AssetDatabase.Refresh();
     mIsDirty = false;
     return(true);
 }
    public void Destroy()
    {
        if (!editTarget)
        {//若为非编辑特效直接删除
            //直接销毁prefab生成的编辑用实例特效
            if (realSpe != null)
            {
                GameObject.DestroyImmediate(realSpe.gameObject);
            }
            return;
        }

        if (targetSpeOldParent == null)
        {
            ForceBindTarget(null);
        }
        else
        {
            ForceBindTarget(targetSpeOldParent.gameObject);
        }

        realSpe.Stop();
        realSpe.CanShow = true;
        SpecialEffectEditorUtility.EnableSpecialEffect(realSpe);
        SpecialEffectEditorUtility.MarkSpecialEffectDirty(realSpe);

        //若此特效来自Prefab
        if (realSpePrefab != null)
        {
            if (IsDirty)
            {
                if (EditorUtility.DisplayDialog("警告!", "此特效为Prefab,编辑过程中有变动,是否保存至Prefab?", "是", "否"))
                {
                    //保存编辑结果至Prefab文件
                    SpecialEffectEditorUtility.ReplacePrefab(realSpe.gameObject, realSpePrefab);
                }
            }

            //直接销毁prefab生成的编辑用实例特效
            GameObject.DestroyImmediate(realSpe.gameObject);
        }

        targetSpeOldParent = null;
        realSpe            = null;
        realSpePrefab      = null;
    }