Example #1
0
        public void CreateTestAsset()
        {
            lastFileName = string.Format(testAssetName, cpt++);

            var directoryPath = Path.GetDirectoryName(lastFileName);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }


            if (File.Exists(lastFileName))
            {
                AssetDatabase.DeleteAsset(lastFileName);
            }

            var asset = VisualEffectAssetEditorUtility.CreateNewAsset(lastFileName);

            VisualEffectResource resource = asset.GetResource(); // force resource creation

            m_ViewController = VFXViewController.GetController(resource);
            m_ViewController.useCount++;

            m_StartUndoGroupId = Undo.GetCurrentGroup();
        }
Example #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();
            }
Example #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);
            }
Example #4
0
        public void CreateTestAsset()
        {
            var directoryPath = Path.GetDirectoryName(testAssetName);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            if (File.Exists(testAssetName))
            {
                AssetDatabase.DeleteAsset(testAssetName);
            }

            var asset    = VisualEffectAssetEditorUtility.CreateNewAsset(testAssetName);
            var resource = asset.GetResource(); // force resource creation

            m_ViewController = VFXViewController.GetController(resource);
            m_ViewController.useCount++;

            m_StartUndoGroupId = Undo.GetCurrentGroup();


            experimental = EditorPrefs.GetBool(VFXViewPreference.experimentalOperatorKey, false);
            if (!experimental)
            {
                EditorPrefs.SetBool(VFXViewPreference.experimentalOperatorKey, true);
            }
        }
Example #5
0
        VFXGraph MakeTemporaryGraph()
        {
            var tempFilePath = MakeTempFilePath("vfx");
            var asset        = VisualEffectAssetEditorUtility.CreateNewAsset(tempFilePath);
            var resource     = asset.GetResource(); // force resource creation
            var graph        = ScriptableObject.CreateInstance <VFXGraph>();

            graph.visualEffectResource = resource;

            return(graph);
        }
Example #6
0
        private VisualEffectAsset CreateTestAsset(string name)
        {
            var filePath      = string.Format(testAssetName, name);
            var directoryPath = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }


            return(VisualEffectAssetEditorUtility.CreateNewAsset(filePath));
        }
Example #7
0
        VFXGraph MakeTemporaryGraph()
        {
            if (System.IO.File.Exists(tempFilePath))
            {
                AssetDatabase.DeleteAsset(tempFilePath);
            }
            var asset = VisualEffectAssetEditorUtility.CreateNewAsset(tempFilePath);
            VisualEffectResource resource = asset.GetResource(); // force resource creation
            VFXGraph             graph    = ScriptableObject.CreateInstance <VFXGraph>();

            graph.visualEffectResource = resource;
            return(graph);
        }
Example #8
0
        public static VFXGraph MakeTemporaryGraph()
        {
            var    guid         = System.Guid.NewGuid().ToString();
            string tempFilePath = string.Format(tempFileFormat, guid);

            System.IO.Directory.CreateDirectory(tempBasePath);

            var asset = VisualEffectAssetEditorUtility.CreateNewAsset(tempFilePath);
            VisualEffectResource resource = asset.GetOrCreateResource(); // force resource creation
            VFXGraph             graph    = resource.GetOrCreateGraph();

            return(graph);
        }
Example #9
0
        VFXGraph MakeTemporaryGraph()
        {
            m_Asset = VisualEffectAssetEditorUtility.CreateNewAsset(tempFilePath);
            VisualEffectResource resource = m_Asset.GetResource(); // force resource creation
            VFXGraph             graph    = ScriptableObject.CreateInstance <VFXGraph>();

            graph.visualEffectResource = resource;

            var window = EditorWindow.GetWindow <VFXViewWindow>();

            window.Close();
            window            = EditorWindow.GetWindow <VFXViewWindow>();
            m_ViewController  = VFXViewController.GetController(m_Asset.GetResource(), true);
            m_View            = window.graphView;
            m_View.controller = m_ViewController;

            return(graph);
        }
Example #10
0
        static VisualEffectObject CreateUniquePath(VFXView sourceView, Type type)
        {
            string graphPath    = AssetDatabase.GetAssetPath(sourceView.controller.model.asset);
            string graphName    = Path.GetFileNameWithoutExtension(graphPath);
            string graphDirPath = Path.GetDirectoryName(graphPath);

            switch (type)
            {
            case Type.Operator:
            {
                string targetSubgraphPath = string.Format("{0}/{1}_SubgraphOperator.vfxoperator", graphDirPath, graphName);
                int    cpt = 1;
                while (File.Exists(targetSubgraphPath))
                {
                    targetSubgraphPath = string.Format("{0}/{1}_SubgraphOperator_{2}.vfxoperator", graphDirPath, graphName, cpt++);
                }
                return(VisualEffectAssetEditorUtility.CreateNew <VisualEffectSubgraphOperator>(targetSubgraphPath));
            }

            case Type.Context:
            {
                string targetSubgraphPath = string.Format("{0}/{1}_Subgraph.vfx", graphDirPath, graphName);
                int    cpt = 1;
                while (File.Exists(targetSubgraphPath))
                {
                    targetSubgraphPath = string.Format("{0}/{1}_Subgraph_{2}.vfx", graphDirPath, graphName, cpt++);
                }
                return(VisualEffectAssetEditorUtility.CreateNewAsset(targetSubgraphPath));
            }

            case Type.Block:
            {
                string targetSubgraphPath = string.Format("{0}/{1}_SubgraphBlock.vfxblock", graphDirPath, graphName);
                int    cpt = 1;
                while (File.Exists(targetSubgraphPath))
                {
                    targetSubgraphPath = string.Format("{0}/{1}_SubgraphBlock_{2}.vfxblock", graphDirPath, graphName, cpt++);
                }
                return(VisualEffectAssetEditorUtility.CreateNew <VisualEffectSubgraphBlock>(targetSubgraphPath));
            }
            }
            return(null);
        }
        public void Initial_Space_Supposed_To_Be_Same_As_Context()
        {
            //Cover also case 1163442, this behavior only exists in controller
            var directoryPath = Path.GetDirectoryName(testAssetName);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            if (File.Exists(testAssetName))
            {
                AssetDatabase.DeleteAsset(testAssetName);
            }

            VisualEffectAsset asset = VisualEffectAssetEditorUtility.CreateNewAsset(testAssetName);
            var resource            = asset.GetResource(); // force resource creation
            var viewController      = VFXViewController.GetController(resource);

            viewController.useCount++;
            var startUndoGroupId = Undo.GetCurrentGroup();

            var updateContext = ScriptableObject.CreateInstance <VFXBasicUpdate>();

            updateContext.space = VFXCoordinateSpace.World;
            viewController.AddVFXModel(Vector2.zero, updateContext);
            viewController.ApplyChanges();
            viewController.ForceReload();

            var collision         = ScriptableObject.CreateInstance <CollisionSphere>();
            var contextController = viewController.allChildren.OfType <VFXContextController>().First();

            contextController.AddBlock(0, collision, true);

            Assert.IsTrue(collision.inputSlots.Where(o => o.spaceable).All(o => o.space == VFXCoordinateSpace.World));

            viewController.useCount--;
            Undo.RevertAllDownToGroup(startUndoGroupId);
            AssetDatabase.DeleteAsset(testAssetName);
        }
Example #12
0
        protected override void AssetField(VisualEffectResource resource)
        {
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PropertyField(m_VisualEffectAsset, Contents.assetPath);

                bool saveEnabled = GUI.enabled;
                if (m_VisualEffectAsset.objectReferenceValue == null && !m_VisualEffectAsset.hasMultipleDifferentValues)
                {
                    GUI.enabled = saveEnabled;
                    if (GUILayout.Button(Contents.createAsset, EditorStyles.miniButton, Styles.MiniButtonWidth))
                    {
                        string filePath = EditorUtility.SaveFilePanelInProject("", "New Graph", "vfx", "Create new VisualEffect Graph");
                        if (!string.IsNullOrEmpty(filePath))
                        {
                            VisualEffectAssetEditorUtility.CreateTemplateAsset(filePath);
                            var asset = AssetDatabase.LoadAssetAtPath <VisualEffectAsset>(filePath);
                            m_VisualEffectAsset.objectReferenceValue = asset;
                            serializedObject.ApplyModifiedProperties();

                            VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
                            window.LoadAsset(asset, targets.Length > 1 ? null : target as VisualEffect);
                        }
                    }
                }
                else
                {
                    GUI.enabled = saveEnabled && !m_VisualEffectAsset.hasMultipleDifferentValues && m_VisualEffectAsset.objectReferenceValue != null && resource != null; // Enabled state will be kept for all content until the end of the inspectorGUI.
                    if (GUILayout.Button(Contents.openEditor, EditorStyles.miniButton, Styles.MiniButtonWidth))
                    {
                        VFXViewWindow window = EditorWindow.GetWindow <VFXViewWindow>();
                        var           asset  = m_VisualEffectAsset.objectReferenceValue as VisualEffectAsset;
                        window.LoadAsset(asset, targets.Length > 1 ? null : target as VisualEffect);
                    }
                }
                GUI.enabled = saveEnabled;
            }
        }
Example #13
0
 private VisualEffectAsset CreateAssetAtPath(string path)
 {
     return(VisualEffectAssetEditorUtility.CreateNewAsset(path));
 }