Ejemplo n.º 1
0
 void InternalLoadResource(VisualEffectResource resource)
 {
     m_DisplayedResource  = resource;
     graphView.controller = VFXViewController.GetController(resource, true);
     graphView.UpdateGlobalSelection();
     graphView.FrameNewController();
 }
Ejemplo n.º 2
0
            public void ConvertToSubgraphContext(VFXView sourceView, IEnumerable <Controller> controllers, Rect rect, string path)
            {
                this.m_Rect = rect;
                Init(sourceView, controllers);
                if (path == null)
                {
                    if (!CreateUniqueSubgraph("Subgraph", VisualEffectResource.Extension, VisualEffectAssetEditorUtility.CreateNewAsset))
                    {
                        return;
                    }
                }
                else
                {
                    m_TargetSubgraph = VisualEffectAssetEditorUtility.CreateNewAsset(path);

                    m_TargetController = VFXViewController.GetController(m_TargetSubgraph.GetResource());
                    m_TargetController.useCount++;
                    m_TargetControllers = new List <VFXNodeController>();
                }
                CopyPasteNodes();
                m_SourceNode = ScriptableObject.CreateInstance <VFXSubgraphContext>();
                PostSetupNode();
                m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceControllers.OfType <VFXContextController>().SelectMany(t => t.blockControllers));
                TransferEdges();
                //TransferContextsFlowEdges();
                UninitSmart();
            }
Ejemplo n.º 3
0
            public void ConvertToSubgraphOperator(VFXView sourceView, IEnumerable <Controller> controllers, Rect rect, string path)
            {
                this.m_Rect = rect;
                Init(sourceView, controllers);
                if (path == null)
                {
                    if (!CreateUniqueSubgraph("SubgraphOperator", VisualEffectSubgraphOperator.Extension, VisualEffectAssetEditorUtility.CreateNew <VisualEffectSubgraphOperator>))
                    {
                        return;
                    }
                }
                else
                {
                    m_TargetSubgraph   = VisualEffectAssetEditorUtility.CreateNew <VisualEffectSubgraphOperator>(path);
                    m_TargetController = VFXViewController.GetController(m_TargetSubgraph.GetResource());
                    m_TargetController.useCount++;
                    m_TargetControllers = new List <VFXNodeController>();
                }
                CopyPasteNodes();
                m_SourceNode = ScriptableObject.CreateInstance <VFXSubgraphOperator>();
                PostSetupNode();
                m_SourceControllersWithBlocks = m_SourceControllers.Concat(m_SourceControllers.OfType <VFXContextController>().SelectMany(t => t.blockControllers));
                TransferEdges();
                TransfertOperatorOutputEdges();
                Uninit();

                //The PrepareSubgraphs was initially in compilation
                //This change has been canceled to prevent creation of model in the wrong place
                //Be sure the newly created operator has expected slot
                var subGraphOperator = m_SourceNode as VFXSubgraphOperator;

                subGraphOperator.RecreateCopy();
                subGraphOperator.ResyncSlots(true);
            }
Ejemplo n.º 4
0
            bool CreateUniqueSubgraph(string typeName, string extension, Func <string, VisualEffectObject> createFunc)
            {
                string graphPath = AssetDatabase.GetAssetPath(m_SourceView.controller.model);
                string graphName;
                string graphDirPath;

                if (string.IsNullOrEmpty(graphPath))
                {
                    graphName = m_SourceView.controller.model.name;
                    if (string.IsNullOrEmpty(graphName))
                    {
                        graphName = "New VFX";
                    }

                    graphDirPath = "Assets";
                }
                else
                {
                    graphName    = Path.GetFileNameWithoutExtension(graphPath);
                    graphDirPath = Path.GetDirectoryName(graphPath).Replace('\\', '/');
                }


                string fileName           = $"{graphName}_{typeName}";
                string targetSubgraphPath = string.Format("{0}/{1}{2}", graphDirPath, fileName, extension);
                int    cpt = 1;

                while (File.Exists(targetSubgraphPath))
                {
                    fileName           = $"{graphName}_{typeName}_{cpt++}";
                    targetSubgraphPath = string.Format("{0}/{1}{2}", graphDirPath, fileName, extension);
                }
                targetSubgraphPath = EditorUtility.SaveFilePanelInProject("Create Subgraph", fileName, extension.Substring(1), "Select where you want to save your subgraph.");

                if (string.IsNullOrEmpty(targetSubgraphPath))
                {
                    return(false);
                }

                if (Path.GetExtension(targetSubgraphPath) != extension)
                {
                    targetSubgraphPath += extension;
                }

                if (File.Exists(targetSubgraphPath))
                {
                    Debug.LogError("Can't overwrite a subgraph");
                    return(false);
                }

                m_TargetSubgraph = createFunc(targetSubgraphPath);

                m_TargetController = VFXViewController.GetController(m_TargetSubgraph.GetResource());
                m_TargetController.useCount++;
                m_TargetControllers = new List <VFXNodeController>();

                return(true);
            }
Ejemplo n.º 5
0
        public void LoadResource(VisualEffectResource resource, VisualEffect effectToAttach = null)
        {
            if (graphView.controller == null || graphView.controller.model != resource)
            {
                bool differentAsset = resource != m_DisplayedResource;

                m_DisplayedResource  = resource;
                graphView.controller = VFXViewController.GetController(resource, true);
                graphView.UpdateGlobalSelection();
                if (differentAsset)
                {
                    graphView.FrameNewController();
                }
            }
            if (effectToAttach != null && graphView.controller != null && graphView.controller.model != null && effectToAttach.visualEffectAsset == graphView.controller.model.asset)
            {
                graphView.attachedComponent = effectToAttach;
            }
        }
Ejemplo n.º 6
0
            void CreateUniqueSubgraph(string typeName, string extension, Func <string, VisualEffectObject> createFunc)
            {
                string graphPath = AssetDatabase.GetAssetPath(m_SourceView.controller.model);
                string graphName;
                string graphDirPath;

                if (string.IsNullOrEmpty(graphPath))
                {
                    graphName = m_SourceView.controller.model.name;
                    if (string.IsNullOrEmpty(graphName))
                    {
                        graphName = "New VFX";
                    }

                    graphDirPath = "Assets";
                }
                else
                {
                    graphName    = Path.GetFileNameWithoutExtension(graphPath);
                    graphDirPath = Path.GetDirectoryName(graphPath).Replace('\\', '/');
                }


                string targetSubgraphPath = string.Format("{0}/{1}{2}{3}", graphDirPath, graphName, typeName, extension);
                int    cpt = 1;

                while (File.Exists(targetSubgraphPath))
                {
                    targetSubgraphPath = string.Format("{0}/{1}_{3}_{2}{4}", graphDirPath, graphName, cpt++, typeName, extension);
                }
                m_TargetSubgraph = createFunc(targetSubgraphPath);

                m_TargetController = VFXViewController.GetController(m_TargetSubgraph.GetResource());
                m_TargetController.useCount++;
                m_TargetControllers = new List <VFXNodeController>();
            }