Ejemplo n.º 1
0
 static void EraseSessionStateKeys(int min, int max)
 {
     for (int i = min; i < max; i++)
     {
         SessionState.EraseString(GetSessionStateKey(i));
     }
 }
Ejemplo n.º 2
0
        static void StoreCachedMDStoreInformation()
        {
            SessionState.EraseString(k_CachedMDStoreKey);
            string data = JsonUtility.ToJson(s_CachedMDStoreInformation, true);

            SessionState.SetString(k_CachedMDStoreKey, data);
        }
Ejemplo n.º 3
0
        private static T GetNextWorkItem()
        {
            T ret = default(T);

            if (!Instance.HasWorkItems)
            {
                return(ret);
            }

            string fromJson = SessionState.GetString(Instance.QueueName, "{}");

            SessionState.EraseString(Instance.QueueName);

            Queue queue = JsonUtility.FromJson <Queue>(fromJson);

            if (queue.workItems.Count <= 0)
            {
                return(ret);
            }

            ret = queue.workItems[0];
            queue.workItems.Remove(ret);

            if (queue.workItems.Count > 0)
            {
                string json = JsonUtility.ToJson(queue);
                SessionState.SetString(Instance.QueueName, json);
            }

            return(ret);
        }
Ejemplo n.º 4
0
 internal static void Clear()
 {
     for (int i = 0; i < NumItems; i++)
     {
         SessionState.EraseString(SCPE.ASSET_ABRV + "_LOG_ITEM_" + i);
     }
     NumItems = 0;
 }
        protected static void ClearPathsFromSession(string varName, string prefix)
        {
            var n = SessionState.GetInt(string.Format(prefix, varName), 0);

            SessionState.EraseInt(string.Format(prefix, varName));
            for (int i = 0; i < n; i++)
            {
                SessionState.EraseString(string.Format(prefix + "_{1}", varName, i));
            }
        }
Ejemplo n.º 6
0
 private static void OnPlayModeChanged(PlayModeStateChange obj)
 {
     if (obj == PlayModeStateChange.EnteredEditMode)
     {
         string lastScene = SessionState.GetString("lastScene", "");
         if (lastScene != "")
         {
             SessionState.EraseString("lastScene");
             EditorSceneManager.OpenScene($"Assets/Scenes/{lastScene}.unity");
         }
     }
 }
Ejemplo n.º 7
0
        private static void PrepareForEnteringPlayMode()
        {
            SessionState.EraseString(EditorBootstrapHandler.LOADED_SCENES_KEY);
            SessionState.EraseString(EditorBootstrapHandler.SERIALIZED_BOOTSTRAPPER_JSON_KEY);
            EditorSceneManager.playModeStartScene = null;

            var bootstrapper = Object.FindObjectOfType <Bootstrapper>();

            if (bootstrapper == null || !bootstrapper.isActiveAndEnabled)
            {
                return;
            }

            FabricLog.Logger.Log(LogTags.FABRIC_CORE, "Running bootstrap helper...");

            var bootstrapScene = EditorBuildSettings.scenes.FirstOrDefault(
                s => AssetDatabase.LoadAssetAtPath <SceneAsset>(s.path) != null);

            if (bootstrapScene == null)
            {
                FabricLog.Logger.LogWarning(LogTags.FABRIC_CORE, "No valid first scene in EditorBuildSettings");
            }
            else
            {
                var sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(bootstrapScene.path);
                EditorSceneManager.playModeStartScene = sceneAsset;

                var scenePaths = new List <string>();
                for (var i = 0; i < SceneManager.sceneCount; i++)
                {
                    var scene = SceneManager.GetSceneAt(i);
                    if (scene.buildIndex != 0)
                    {
                        scenePaths.Add(scene.path);
                    }
                }

                var scenesString = string.Join(
                    EditorBootstrapHandler.LOADED_SCENES_SEPARATOR.ToString(),
                    scenePaths);
                SessionState.SetString(EditorBootstrapHandler.LOADED_SCENES_KEY, scenesString);

                var serializedBootstrapperJson = EditorJsonUtility.ToJson(bootstrapper);
                if (!string.IsNullOrWhiteSpace(serializedBootstrapperJson))
                {
                    SessionState.SetString(
                        EditorBootstrapHandler.SERIALIZED_BOOTSTRAPPER_JSON_KEY,
                        serializedBootstrapperJson);
                }
            }
        }
Ejemplo n.º 8
0
        static LoaderAssignmentRequests GetAllRequestsInQueue(string queueName)
        {
            var reqs = new LoaderAssignmentRequests();

            reqs.activeRequests = new List <LoaderAssignmentRequest>();

            if (XRPackageMetadataStore.SessionStateHasStoredData(queueName))
            {
                string fromJson = SessionState.GetString(queueName, k_DefaultSessionStateString);
                reqs = JsonUtility.FromJson <LoaderAssignmentRequests>(fromJson);
                SessionState.EraseString(queueName);
            }

            return(reqs);
        }
        public static void ResetAllSessionSettings(string prefix, string settingsDefaults = null)
        {
            SessionState.EraseString(string.Format(prefix, k_SessionSettingsName));
            // Set the defaults of the settings.
            // If there exists a Default Preset for the Convert/Export settings, then if the project settings are modified,
            // the Default Preset will be reloaded instead of the project settings. Therefore, set them explicitely if projects settings desired.
            if (!string.IsNullOrEmpty(settingsDefaults))
            {
                SessionState.SetString(string.Format(prefix, k_SessionSettingsName), settingsDefaults);
            }

            ClearPathsFromSession(k_SessionFbxPathsName, prefix);
            SessionState.EraseInt(string.Format(prefix, k_SessionSelectedFbxPathName));

            ClearPathsFromSession(k_SessionPrefabPathsName, prefix);
            SessionState.EraseInt(string.Format(prefix, k_SessionSelectedPrefabPathName));
        }
Ejemplo n.º 10
0
        static bool RestoreSessionState()
        {
            var json = SessionState.GetString(k_InMemorySceneStateSessionKey, null);

            if (string.IsNullOrEmpty(json))
            {
                return(false);
            }
            s_CurrentInMemorySceneState = InMemorySceneState.Import(json);

            s_TempFolderBase     = SessionState.GetString(k_TempFolderBaseSessionKey, Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            registeredTempFolder = SessionState.GetBool(k_RegisteredTempFolderSessionKey, false);

            // To make sure that we don't affect future session in case something happens, we delete everything
            SessionState.EraseString(k_InMemorySceneStateSessionKey);
            SessionState.EraseString(k_TempFolderBaseSessionKey);
            SessionState.EraseBool(k_RegisteredTempFolderSessionKey);

            return(true);
        }
        public void LoadSessionStateKeys_ExcludesMissingKeys()
        {
            string ipAddressKey = m_Manager.GetPrivateIpAddressKey(1);

            m_Manager.Initialize(m_Settings);
            m_Manager.GlobalProfileVariables.Clear();
            m_Manager.GlobalProfileVariables.Add(m_Manager.GetPrivateIpAddressKey(0), "111.1.1.1");
            m_Manager.GlobalProfileVariables.Add(ipAddressKey, "222.2.2.2");
            m_Manager.GlobalProfileVariables.Add(m_Manager.GetPrivateIpAddressKey(2), "333.3.3.3");

            m_Manager.SaveSessionStateKeys();
            m_Manager.GlobalProfileVariables.Clear();

            SessionState.EraseString(HostingServicesManager.GetSessionStateKey(1));
            m_Manager.LoadSessionStateKeys();
            Assert.AreEqual(2, m_Manager.GlobalProfileVariables.Count);
            Assert.IsFalse(m_Manager.GlobalProfileVariables.ContainsKey(ipAddressKey));

            HostingServicesManager.EraseSessionStateKeys();
        }
 /// <summary>
 /// Erases the configuration from SessionState and from memory. Will force the configuration to be fetched
 /// from the server the next time it is requested.
 /// </summary>
 public void ClearCache()
 {
     SessionState.EraseString(m_SessionStateKey);
     m_IsConfigurationLoaded = false;
     m_CachedConfiguration   = default;
 }
Ejemplo n.º 13
0
        public void ToSubGraph()
        {
            var graphView = graphEditorView.graphView;

            string path;
            string sessionStateResult = SessionState.GetString(k_PrevSubGraphPathKey, k_PrevSubGraphPathDefaultValue);
            string pathToOriginSG     = Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(selectedGuid));

            if (!sessionStateResult.Equals(k_PrevSubGraphPathDefaultValue))
            {
                path = sessionStateResult;
            }
            else
            {
                path = pathToOriginSG;
            }

            path = EditorUtility.SaveFilePanelInProject("Save Sub Graph", "New Shader Sub Graph", ShaderSubGraphImporter.Extension, "", path);
            path = path.Replace(Application.dataPath, "Assets");
            if (path.Length == 0)
            {
                return;
            }

            graphObject.RegisterCompleteObjectUndo("Convert To Subgraph");

            var nodes  = graphView.selection.OfType <IShaderNodeView>().Where(x => !(x.node is PropertyNode || x.node is SubGraphOutputNode)).Select(x => x.node).Where(x => x.allowedInSubGraph).ToArray();
            var bounds = Rect.MinMaxRect(float.PositiveInfinity, float.PositiveInfinity, float.NegativeInfinity, float.NegativeInfinity);

            foreach (var node in nodes)
            {
                var center = node.drawState.position.center;
                bounds = Rect.MinMaxRect(
                    Mathf.Min(bounds.xMin, center.x),
                    Mathf.Min(bounds.yMin, center.y),
                    Mathf.Max(bounds.xMax, center.x),
                    Mathf.Max(bounds.yMax, center.y));
            }
            var middle = bounds.center;

            bounds.center = Vector2.zero;

            // Collect graph inputs
            var graphInputs = graphView.selection.OfType <BlackboardField>().Select(x => x.userData as ShaderInput);

            // Collect the property nodes and get the corresponding properties
            var propertyNodes  = graphView.selection.OfType <IShaderNodeView>().Where(x => (x.node is PropertyNode)).Select(x => ((PropertyNode)x.node).property);
            var metaProperties = graphView.graph.properties.Where(x => propertyNodes.Contains(x));

            // Collect the keyword nodes and get the corresponding keywords
            var keywordNodes = graphView.selection.OfType <IShaderNodeView>().Where(x => (x.node is KeywordNode)).Select(x => ((KeywordNode)x.node).keyword);
            var metaKeywords = graphView.graph.keywords.Where(x => keywordNodes.Contains(x));

            var copyPasteGraph = new CopyPasteGraph(graphView.selection.OfType <ShaderGroup>().Select(x => x.userData),
                                                    graphView.selection.OfType <IShaderNodeView>().Where(x => !(x.node is PropertyNode || x.node is SubGraphOutputNode)).Select(x => x.node).Where(x => x.allowedInSubGraph).ToArray(),
                                                    graphView.selection.OfType <Edge>().Select(x => x.userData as Graphing.Edge),
                                                    graphInputs,
                                                    metaProperties,
                                                    metaKeywords,
                                                    graphView.selection.OfType <StickyNote>().Select(x => x.userData),
                                                    true);

            // why do we serialize and deserialize only to make copies of everything in the steps below?
            // is this just to clear out all non-serialized data?
            var deserialized = CopyPasteGraph.FromJson(MultiJson.Serialize(copyPasteGraph), graphView.graph);

            if (deserialized == null)
            {
                return;
            }

            var subGraph = new GraphData {
                isSubGraph = true, path = "Sub Graphs"
            };
            var subGraphOutputNode = new SubGraphOutputNode();

            {
                var drawState = subGraphOutputNode.drawState;
                drawState.position           = new Rect(new Vector2(bounds.xMax + 200f, 0f), drawState.position.size);
                subGraphOutputNode.drawState = drawState;
            }
            subGraph.AddNode(subGraphOutputNode);
            subGraph.outputNode = subGraphOutputNode;

            // Always copy deserialized keyword inputs
            foreach (ShaderKeyword keyword in deserialized.metaKeywords)
            {
                var copiedInput = (ShaderKeyword)keyword.Copy();
                subGraph.SanitizeGraphInputName(copiedInput);
                subGraph.SanitizeGraphInputReferenceName(copiedInput, keyword.overrideReferenceName);
                subGraph.AddGraphInput(copiedInput);

                // Update the keyword nodes that depends on the copied keyword
                var dependentKeywordNodes = deserialized.GetNodes <KeywordNode>().Where(x => x.keyword == keyword);
                foreach (var node in dependentKeywordNodes)
                {
                    node.owner   = graphView.graph;
                    node.keyword = copiedInput;
                }
            }

            foreach (GroupData groupData in deserialized.groups)
            {
                subGraph.CreateGroup(groupData);
            }

            foreach (var node in deserialized.GetNodes <AbstractMaterialNode>())
            {
                var drawState = node.drawState;
                drawState.position = new Rect(drawState.position.position - middle, drawState.position.size);
                node.drawState     = drawState;

                // Checking if the group guid is also being copied.
                // If not then nullify that guid
                if (node.group != null && !subGraph.groups.Contains(node.group))
                {
                    node.group = null;
                }

                subGraph.AddNode(node);
            }

            foreach (var note in deserialized.stickyNotes)
            {
                if (note.group != null && !subGraph.groups.Contains(note.group))
                {
                    note.group = null;
                }

                subGraph.AddStickyNote(note);
            }

            // figure out what needs remapping
            var externalOutputSlots = new List <Graphing.Edge>();
            var externalInputSlots  = new List <Graphing.Edge>();

            foreach (var edge in deserialized.edges)
            {
                var outputSlot = edge.outputSlot;
                var inputSlot  = edge.inputSlot;

                var outputSlotExistsInSubgraph = subGraph.ContainsNode(outputSlot.node);
                var inputSlotExistsInSubgraph  = subGraph.ContainsNode(inputSlot.node);

                // pasting nice internal links!
                if (outputSlotExistsInSubgraph && inputSlotExistsInSubgraph)
                {
                    subGraph.Connect(outputSlot, inputSlot);
                }
                // one edge needs to go to outside world
                else if (outputSlotExistsInSubgraph)
                {
                    externalInputSlots.Add(edge);
                }
                else if (inputSlotExistsInSubgraph)
                {
                    externalOutputSlots.Add(edge);
                }
            }

            // Find the unique edges coming INTO the graph
            var uniqueIncomingEdges = externalOutputSlots.GroupBy(
                edge => edge.outputSlot,
                edge => edge,
                (key, edges) => new { slotRef = key, edges = edges.ToList() });

            var externalInputNeedingConnection = new List <KeyValuePair <IEdge, AbstractShaderProperty> >();

            var       amountOfProps  = uniqueIncomingEdges.Count();
            const int height         = 40;
            const int subtractHeight = 20;
            var       propPos        = new Vector2(0, -((amountOfProps / 2) + height) - subtractHeight);

            foreach (var group in uniqueIncomingEdges)
            {
                var sr       = group.slotRef;
                var fromNode = sr.node;
                var fromSlot = sr.slot;

                var materialGraph = graphObject.graph;
                var fromProperty  = fromNode is PropertyNode fromPropertyNode
                    ? materialGraph.properties.FirstOrDefault(p => p == fromPropertyNode.property)
                    : null;

                AbstractShaderProperty prop;
                switch (fromSlot.concreteValueType)
                {
                case ConcreteSlotValueType.Texture2D:
                    prop = new Texture2DShaderProperty();
                    break;

                case ConcreteSlotValueType.Texture2DArray:
                    prop = new Texture2DArrayShaderProperty();
                    break;

                case ConcreteSlotValueType.Texture3D:
                    prop = new Texture3DShaderProperty();
                    break;

                case ConcreteSlotValueType.Cubemap:
                    prop = new CubemapShaderProperty();
                    break;

                case ConcreteSlotValueType.Vector4:
                    prop = new Vector4ShaderProperty();
                    break;

                case ConcreteSlotValueType.Vector3:
                    prop = new Vector3ShaderProperty();
                    break;

                case ConcreteSlotValueType.Vector2:
                    prop = new Vector2ShaderProperty();
                    break;

                case ConcreteSlotValueType.Vector1:
                    prop = new Vector1ShaderProperty();
                    break;

                case ConcreteSlotValueType.Boolean:
                    prop = new BooleanShaderProperty();
                    break;

                case ConcreteSlotValueType.Matrix2:
                    prop = new Matrix2ShaderProperty();
                    break;

                case ConcreteSlotValueType.Matrix3:
                    prop = new Matrix3ShaderProperty();
                    break;

                case ConcreteSlotValueType.Matrix4:
                    prop = new Matrix4ShaderProperty();
                    break;

                case ConcreteSlotValueType.SamplerState:
                    prop = new SamplerStateShaderProperty();
                    break;

                case ConcreteSlotValueType.Gradient:
                    prop = new GradientShaderProperty();
                    break;

                case ConcreteSlotValueType.VirtualTexture:
                    prop = new VirtualTextureShaderProperty()
                    {
                        // also copy the VT settings over from the original property (if there is one)
                        value = (fromProperty as VirtualTextureShaderProperty)?.value ?? new SerializableVirtualTexture()
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                prop.displayName = fromProperty != null
                    ? fromProperty.displayName
                    : fromSlot.concreteValueType.ToString();
                prop.displayName = GraphUtil.SanitizeName(subGraph.addedInputs.Select(p => p.displayName), "{0} ({1})",
                                                          prop.displayName);

                subGraph.AddGraphInput(prop);
                var propNode = new PropertyNode();
                {
                    var drawState = propNode.drawState;
                    drawState.position = new Rect(new Vector2(bounds.xMin - 300f, 0f) + propPos,
                                                  drawState.position.size);
                    propPos           += new Vector2(0, height);
                    propNode.drawState = drawState;
                }
                subGraph.AddNode(propNode);
                propNode.property = prop;

                foreach (var edge in group.edges)
                {
                    subGraph.Connect(
                        new SlotReference(propNode, PropertyNode.OutputSlotId),
                        edge.inputSlot);
                    externalInputNeedingConnection.Add(new KeyValuePair <IEdge, AbstractShaderProperty>(edge, prop));
                }
            }

            var uniqueOutgoingEdges = externalInputSlots.GroupBy(
                edge => edge.outputSlot,
                edge => edge,
                (key, edges) => new { slot = key, edges = edges.ToList() });

            var externalOutputsNeedingConnection = new List <KeyValuePair <IEdge, IEdge> >();

            foreach (var group in uniqueOutgoingEdges)
            {
                var outputNode = subGraph.outputNode as SubGraphOutputNode;

                AbstractMaterialNode node = group.edges[0].outputSlot.node;
                MaterialSlot         slot = node.FindSlot <MaterialSlot>(group.edges[0].outputSlot.slotId);
                var slotId = outputNode.AddSlot(slot.concreteValueType);

                var inputSlotRef = new SlotReference(outputNode, slotId);

                foreach (var edge in group.edges)
                {
                    var newEdge = subGraph.Connect(edge.outputSlot, inputSlotRef);
                    externalOutputsNeedingConnection.Add(new KeyValuePair <IEdge, IEdge>(edge, newEdge));
                }
            }

            if (FileUtilities.WriteShaderGraphToDisk(path, subGraph))
            {
                AssetDatabase.ImportAsset(path);
            }

            // Store path for next time
            if (!pathToOriginSG.Equals(Path.GetDirectoryName(path)))
            {
                SessionState.SetString(k_PrevSubGraphPathKey, Path.GetDirectoryName(path));
            }
            else
            {
                // Or continue to make it so that next time it will open up in the converted-from SG's directory
                SessionState.EraseString(k_PrevSubGraphPathKey);
            }

            var loadedSubGraph = AssetDatabase.LoadAssetAtPath(path, typeof(SubGraphAsset)) as SubGraphAsset;

            if (loadedSubGraph == null)
            {
                return;
            }

            var subGraphNode = new SubGraphNode();
            var ds           = subGraphNode.drawState;

            ds.position            = new Rect(middle - new Vector2(100f, 150f), Vector2.zero);
            subGraphNode.drawState = ds;

            // Add the subgraph into the group if the nodes was all in the same group group
            var firstNode = copyPasteGraph.GetNodes <AbstractMaterialNode>().FirstOrDefault();

            if (firstNode != null && copyPasteGraph.GetNodes <AbstractMaterialNode>().All(x => x.group == firstNode.group))
            {
                subGraphNode.group = firstNode.group;
            }

            subGraphNode.asset = loadedSubGraph;
            graphObject.graph.AddNode(subGraphNode);

            foreach (var edgeMap in externalInputNeedingConnection)
            {
                graphObject.graph.Connect(edgeMap.Key.outputSlot, new SlotReference(subGraphNode, edgeMap.Value.guid.GetHashCode()));
            }

            foreach (var edgeMap in externalOutputsNeedingConnection)
            {
                graphObject.graph.Connect(new SlotReference(subGraphNode, edgeMap.Value.inputSlot.slotId), edgeMap.Key.inputSlot);
            }

            graphObject.graph.RemoveElements(
                graphView.selection.OfType <IShaderNodeView>().Select(x => x.node).Where(x => x.allowedInSubGraph).ToArray(),
                new IEdge[] {},
                new GroupData[] {},
                graphView.selection.OfType <StickyNote>().Select(x => x.userData).ToArray());
            graphObject.graph.ValidateGraph();
        }
 public void ResetState()
 {
     Debug.Log("Resetting state");
     SessionState.EraseString(PersistentStateKey);
 }
Ejemplo n.º 15
0
        private static void DuplicatePrefab(TemplateSetting[] settings)
        {
            if (settings == null || settings.Length == 0)
            {
                Debug.LogWarning("設定ファイルがありません");
                return;
            }

            var components = new List <Component>(settings.Length);

            foreach (var setting in settings)
            {
                // Load Attach Script
                var scriptKye  = string.Format(TempCreateScriptPathKeyFormat, setting.GetInstanceID());
                var scriptPath = SessionState.GetString(scriptKye, null);
                var mono       = AssetDatabase.LoadAssetAtPath <MonoScript>(scriptPath);
                SessionState.EraseString(scriptKye);

                if (mono == null)
                {
                    Debug.LogErrorFormat("{0} : スクリプトファイルがありませんでした", scriptPath);
                    return;
                }

                var scriptType = mono.GetClass();

                if (scriptType == null)
                {
                    Debug.LogErrorFormat("{0} : クラスを取得できませんでした。ファイル名とクラス名が違う可能性があります", mono.name);
                    return;
                }

                components.Add(setting.AttachTarget.AddComponent(scriptType));
            }

            // コピーパスは同じなはずのため、最初のを使用する
            var prefabPath = AssetDatabase.GetAssetPath(settings[0].DuplicatePrefab);
            var createPath = settings[0].PrefabPath;
            var prefabName = settings[0].PrefabName;

            if (string.IsNullOrEmpty(createPath))
            {
                // 空白の場合はアクティブなパスへ生成
                createPath = TemplateUtility.GetActiveFolder();
            }

            if (string.IsNullOrEmpty(prefabName))
            {
                // 空白の場合はコピー元のプレハブ名
                prefabName = Path.GetFileName(prefabPath);
            }

            prefabName += Path.GetExtension(prefabName) == string.Empty ? ".prefab" : string.Empty;
            var createFullPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(createPath, prefabName));

            AssetDatabase.CopyAsset(prefabPath, createFullPath);

            foreach (var component in components)
            {
                UnityEngine.Object.DestroyImmediate(component, true);
            }
        }