Exemple #1
0
        public void DrawGeneralFunction()
        {
            AmplifyShaderFunction function = ParentWindow.CurrentGraph.CurrentShaderFunction;

            if (function == null)
            {
                return;
            }

            float cacheWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 115;

            SerializedObject serializedObject = new UnityEditor.SerializedObject(function);

            if (serializedObject != null)
            {
                SerializedProperty temo = serializedObject.FindProperty("m_description");
                EditorGUILayout.PropertyField(temo, new GUIContent("    Description"));

                SerializedProperty cat  = serializedObject.FindProperty("m_nodeCategory");
                SerializedProperty ppos = serializedObject.FindProperty("m_previewPosition");

                EditorGUILayout.PropertyField(ppos, new GUIContent("Preview Position"));
                cat.intValue = ParentWindow.CurrentGraph.CurrentOutputNode.EditorGUILayoutPopup("Category", cat.intValue, UIUtils.CategoryPresets);

                if (cat.enumValueIndex == 0)
                {
                    SerializedProperty custCat = serializedObject.FindProperty("m_customNodeCategory");
                    EditorGUILayout.PropertyField(custCat, new GUIContent("Custom"));
                }
                serializedObject.ApplyModifiedProperties();
            }
            EditorGUIUtility.labelWidth = cacheWidth;
        }
Exemple #2
0
        public override void ReadFromString(ref string[] nodeParams)
        {
            base.ReadFromString(ref nodeParams);
            m_filename    = GetCurrentParam(ref nodeParams);
            m_orderIndex  = Convert.ToInt32(GetCurrentParam(ref nodeParams));
            m_headerTitle = GetCurrentParam(ref nodeParams);

            if (UIUtils.CurrentShaderVersion() > 7203)
            {
                m_functionGraphId = Convert.ToInt32(GetCurrentParam(ref nodeParams));
            }
            string[] guids = AssetDatabase.FindAssets("t:AmplifyShaderFunction " + m_filename);
            if (guids.Length > 0)
            {
                AmplifyShaderFunction loaded = AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(AssetDatabase.GUIDToAssetPath(guids[0]));
                if (loaded != null)
                {
                    CommonInit(loaded);
                }
                else
                {
                    SetTitleText("ERROR");
                }
            }
            else
            {
                SetTitleText("Missing Function");
            }
        }
        public void DrawGeneralFunction()
        {
            AmplifyShaderFunction function = ParentWindow.CurrentGraph.CurrentShaderFunction;

            if (function == null)
            {
                return;
            }

            string oldName = function.FunctionName;

            //oldName = EditorGUILayout.TextField( "Name", oldName );
            //if ( oldName != function.FunctionName )
            //{
            //	function.FunctionName = oldName;
            //	EditorUtility.SetDirty( function );
            //}

            SerializedObject serializedObject = new UnityEditor.SerializedObject(function);

            if (serializedObject != null)
            {
                SerializedProperty temo = serializedObject.FindProperty("m_description");
                oldName = temo.stringValue;
                EditorGUILayout.PropertyField(temo, new GUIContent("    Description"));
                if (!oldName.Equals(temo.stringValue))
                {
                    function.Description = temo.stringValue;
                    oldName = temo.stringValue;
                }
            }
        }
        public override void ReadFromString(ref string[] nodeParams)
        {
            base.ReadFromString(ref nodeParams);
            m_outputName = GetCurrentParam(ref nodeParams);
            m_orderIndex = Convert.ToInt32(GetCurrentParam(ref nodeParams));

            if (UIUtils.CurrentShaderVersion() > 13706)
            {
                m_previewNode = Convert.ToBoolean(GetCurrentParam(ref nodeParams));
            }

            if (IsNodeBeingCopied)
            {
                PreviewNode = false;
            }

            if (m_function == null)
            {
                m_function = UIUtils.CurrentWindow.OpenedShaderFunction;
            }

            if (m_isMainOutputNode && m_function != null)
            {
                m_function.UpdateDirectivesList();
            }

            SetTitleText(m_outputName);
            UIUtils.UpdateFunctionOutputData(UniqueId, m_outputName);
        }
Exemple #5
0
        public override void SetupFromCastObject(UnityEngine.Object obj)
        {
            base.SetupFromCastObject(obj);
            AmplifyShaderFunction function = obj as AmplifyShaderFunction;

            CommonInit(function);
        }
Exemple #6
0
		public override void SetupFromCastObject( UnityEngine.Object obj )
		{
			base.SetupFromCastObject( obj );
			AmplifyShaderFunction function = obj as AmplifyShaderFunction;
			CommonInit( function, UniqueId );
			RefreshExternalReferences();
		}
Exemple #7
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;

            base.Destroy();

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                for (int i = 0; i < m_includes.Count; i++)
                {
                    if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains(m_includes[i]))
                    {
                        ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove(m_includes[i]);
                    }
                }
            }

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.Destroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;
        }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        if (UIUtils.CurrentWindow == null)
        {
            return;
        }

        bool markForRefresh            = false;
        AmplifyShaderFunction function = null;

        for (int i = 0; i < importedAssets.Length; i++)
        {
            function = AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(importedAssets[i]);
            if (function != null)
            {
                markForRefresh = true;
                break;
            }
        }

        if (deletedAssets.Length > 0)
        {
            markForRefresh = true;
        }

        for (int i = 0; i < movedAssets.Length; i++)
        {
            function = AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(movedAssets[i]);
            if (function != null)
            {
                markForRefresh = true;
                break;
            }
        }

        for (int i = 0; i < movedFromAssetPaths.Length; i++)
        {
            function = AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(movedFromAssetPaths[i]);
            if (function != null)
            {
                markForRefresh = true;
                break;
            }
        }

        if (markForRefresh)
        {
            markForRefresh = false;
            if (function != null)
            {
                IOUtils.UpdateSFandRefreshWindows(function);
            }
            UIUtils.CurrentWindow.LateRefreshAvailableNodes();
        }
    }
Exemple #9
0
 public ContextMenuItem(NodeAttributes nodeAttributes, Type type, string name, string category, string description, AmplifyShaderFunction function, KeyCode shortcut)
 {
     m_nodeAttributes   = nodeAttributes;
     m_name             = name;
     m_nameWithShortcut = shortcut != KeyCode.None ? (name + " [ " + UIUtils.KeyCodeToString(shortcut) + " ]") : name;
     m_paletteName      = PALETTE_NAME_MOD_STR + m_name;
     m_type             = type;
     m_category         = category;
     m_description      = description;
     m_function         = function;
     m_guiContent       = new GUIContent(m_nameWithShortcut, m_description);
 }
Exemple #10
0
 public static void LateShaderFunctionOpener()
 {
     Update();
     if (IsProcessing)
     {
         EditorApplication.delayCall += LateShaderFunctionOpener;
     }
     else
     {
         AmplifyShaderEditorWindow.LoadShaderFunctionToASE(m_lateShaderFunction, false);
         m_lateShaderFunction = null;
     }
 }
Exemple #11
0
        public override void ReadFromString(ref string[] nodeParams)
        {
            base.ReadFromString(ref nodeParams);
            m_outputName = GetCurrentParam(ref nodeParams);
            m_orderIndex = Convert.ToInt32(GetCurrentParam(ref nodeParams));

            if (m_function == null)
            {
                m_function = UIUtils.CurrentWindow.OpenedShaderFunction;
            }
            SetTitleText(m_outputName);
            UIUtils.UpdateFunctionOutputData(UniqueId, m_outputName);
        }
Exemple #12
0
 public static void UpdateSFandRefreshWindows(AmplifyShaderFunction function)
 {
     for (int i = 0; i < AllOpenedWindows.Count; i++)
     {
         AllOpenedWindows[i].LateRefreshAvailableNodes();
         if (AllOpenedWindows[i].IsShaderFunctionWindow)
         {
             if (AllOpenedWindows[i].OpenedShaderFunction == function)
             {
                 AllOpenedWindows[i].UpdateTabTitle();
             }
         }
     }
 }
Exemple #13
0
        public static void SetupLateShaderFunction(AmplifyShaderFunction shaderFunction)
        {
            if (shaderFunction == null)
            {
                return;
            }

            //If a previous delayed object is pending discard it and register the new one
            // So the last selection will be the choice of opening
            //This can happen when trying to open an ASE canvas while importing templates or in play mode
            if (m_lateShaderFunction != null)
            {
                EditorApplication.delayCall -= LateShaderFunctionOpener;
            }

            RequestInfo();
            m_lateShaderFunction         = shaderFunction;
            EditorApplication.delayCall += LateShaderFunctionOpener;
        }
Exemple #14
0
        public override void Destroy()
        {
            base.Destroy();

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.Destroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;
        }
Exemple #15
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_refreshIdsRequired = UIUtils.IsLoading && (UIUtils.CurrentShaderVersion() < 14004);

            m_function = function;

            if (Function.FunctionName.Length > 1)
            {
                bool lastIsUpper = Char.IsUpper(Function.FunctionName, 0);
                System.Text.StringBuilder title = new System.Text.StringBuilder();
                title.Append(Function.FunctionName[0]);
                for (int i = 1; i < Function.FunctionName.Length; i++)
                {
                    bool currIsUpper = Char.IsUpper(Function.FunctionName, i);
                    if (currIsUpper && !lastIsUpper && Char.IsLetter(Function.FunctionName[i - 1]))
                    {
                        title.Append(" ");
                    }
                    lastIsUpper = currIsUpper;
                    title.Append(Function.FunctionName[i]);
                    SetTitleText(title.ToString());
                }
            }
            else
            {
                SetTitleText(Function.FunctionName);
            }
            m_tooltipText    = Function.Description;
            m_hasTooltipLink = false;
            if (m_functionGraph == null)
            {
                //m_functionGraph = new ParentGraph();
                m_functionGraph = CreateInstance <ParentGraph>();
                m_functionGraph.Init();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs   = UIUtils.FunctionInputList();
            m_allFunctionOutputs  = UIUtils.FunctionOutputList();
            m_allFunctionSwitches = UIUtils.FunctionSwitchList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionSwitches.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                if (m_refreshIdsRequired)
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                }
                else
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName, -1, MasterNodePortCategory.Fragment, m_allFunctionInputs[i].UniqueId);
                }
                InputPortSwitchRestriction(m_inputPorts[i]);

                if (!m_allFunctionInputs[i].InputPorts[0].IsConnected)
                {
                    m_inputPorts[i].AutoDrawInternalData = true;
                    m_inputPorts[i].InternalData         = m_allFunctionInputs[i].InputPorts[0].InternalData;
                }
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                if (m_refreshIdsRequired)
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                }
                else
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName, m_allFunctionOutputs[i].UniqueId);
                }
                OutputPortSwitchRestriction(m_outputPorts[i]);
            }

            // make sure to hide the ports properly
            CheckPortVisibility();

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 120;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID   = "aca70c900c50c004e8ef0b47c4fac4d4";
            m_useInternalPortData = false;
            m_selectedLocation    = function.PreviewPosition;
        }
Exemple #16
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;
            base.Destroy();

            if (m_functionGraph != null && ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount -= m_functionGraph.InstancePropertyCount;
            }

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                //for( int i = 0; i < m_includes.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains( m_includes[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove( m_includes[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Include, m_includes[ i ] );
                //}

                //for( int i = 0; i < m_pragmas.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Contains( m_pragmas[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Remove( m_pragmas[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Pragma, m_pragmas[ i ] );
                //}
                ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
            }
            else
            {
                if (ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0)
                {
                    List <TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList;
                    int count = nodes.Count;
                    for (int i = 0; i < count; i++)
                    {
                        nodes[i].PassModule.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
                    }
                }
            }

            // Cannot GameObject.Destroy(m_directives[i]) since we would be removing them from
            // the shader function asset itself

            m_directives.Clear();
            m_directives = null;

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.SoftDestroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;

            m_allFunctionOutputsDict.Clear();
            m_allFunctionOutputsDict = null;

            m_allFunctionSwitchesDict.Clear();
            m_allFunctionSwitchesDict = null;

            m_allFunctionInputsDict.Clear();
            m_allFunctionInputsDict = null;
        }
Exemple #17
0
        public override void ReadFromString(ref string[] nodeParams)
        {
            base.ReadFromString(ref nodeParams);
            m_filename    = GetCurrentParam(ref nodeParams);
            m_orderIndex  = Convert.ToInt32(GetCurrentParam(ref nodeParams));
            m_headerTitle = GetCurrentParam(ref nodeParams);

            if (UIUtils.CurrentShaderVersion() > 7203)
            {
                m_functionGraphId = Convert.ToInt32(GetCurrentParam(ref nodeParams));
            }

            if (UIUtils.CurrentShaderVersion() > 13704)
            {
                m_functionGUID = GetCurrentParam(ref nodeParams);
            }

            AmplifyShaderFunction loaded = AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(AssetDatabase.GUIDToAssetPath(m_functionGUID));

            if (loaded != null)
            {
                CommonInit(loaded, UniqueId);
            }
            else
            {
                string[] guids = AssetDatabase.FindAssets("t:AmplifyShaderFunction " + m_filename);
                if (guids.Length > 0)
                {
                    string sfGuid = null;

                    foreach (string guid in guids)
                    {
                        string assetPath = AssetDatabase.GUIDToAssetPath(guid);
                        string name      = System.IO.Path.GetFileNameWithoutExtension(assetPath);
                        if (name.Equals(m_filename, StringComparison.OrdinalIgnoreCase))
                        {
                            sfGuid = guid;
                            break;
                        }
                    }
                    loaded = AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(AssetDatabase.GUIDToAssetPath(sfGuid));

                    if (loaded != null)
                    {
                        CommonInit(loaded, UniqueId);
                    }
                    else
                    {
                        SetTitleText("ERROR");
                        UIUtils.ShowMessage(string.Format("Error loading {0} shader function from project folder", m_filename), MessageSeverity.Error);
                    }
                }
                else
                {
                    SetTitleText("Missing Function");
                    UIUtils.ShowMessage(string.Format("Missing {0} shader function on project folder", m_filename), MessageSeverity.Error);
                }
            }
            if (UIUtils.CurrentShaderVersion() > 14203)
            {
                ReadOptionsHelper = GetCurrentParam(ref nodeParams).Split(',');
            }
        }
 public static void SetupLateShaderFunction(AmplifyShaderFunction shaderFunction)
 {
     RequestInfo();
     m_lateShaderFunction         = shaderFunction;
     EditorApplication.delayCall += LateShaderFunctionOpener;
 }
Exemple #19
0
 public void FireNodeCreateEvent(System.Type type, string name, AmplifyShaderFunction function)
 {
     OnPaletteNodeCreateEvt(type, name, function);
 }
Exemple #20
0
        public void CommonInit(AmplifyShaderFunction function)
        {
            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);

            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            m_functionCheckSum = LastLine(m_function.FunctionInfo);
            List <ParentNode> propertyList = UIUtils.PropertyNodesList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs  = new List <FunctionInput>();
            m_allFunctionOutputs = new List <FunctionOutput>();

            for (int i = 0; i < m_functionGraph.AllNodes.Count; i++)
            {
                //Debug.Log( m_functionGraph.AllNodes[ i ].GetType()+" "+ m_functionGraph.AllNodes[ i ].IsConnected );
                if (m_functionGraph.AllNodes[i].GetType() == typeof(FunctionInput))
                {
                    m_allFunctionInputs.Add(m_functionGraph.AllNodes[i] as FunctionInput);
                }
                else if (m_functionGraph.AllNodes[i].GetType() == typeof(FunctionOutput))
                {
                    m_allFunctionOutputs.Add(m_functionGraph.AllNodes[i] as FunctionOutput);
                }
            }

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int outputCount = m_allFunctionOutputs.Count;

            for (int i = 0; i < outputCount; i++)
            {
                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;
        }
Exemple #21
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;
            base.Destroy();

            if (m_functionGraph != null && ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount -= m_functionGraph.InstancePropertyCount;
            }

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                //for( int i = 0; i < m_includes.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains( m_includes[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove( m_includes[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Include, m_includes[ i ] );
                //}

                //for( int i = 0; i < m_pragmas.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Contains( m_pragmas[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Remove( m_pragmas[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Pragma, m_pragmas[ i ] );
                //}
                ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
                m_directives.Clear();
                m_directives = null;
            }

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            if (m_allFunctionInputs != null)
            {
                m_allFunctionInputs.Clear();
            }
            m_allFunctionInputs = null;

            if (m_allFunctionOutputs != null)
            {
                m_allFunctionOutputs.Clear();
            }
            m_allFunctionOutputs = null;

            if (m_functionGraph != null)
            {
                m_functionGraph.SoftDestroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;

            m_allFunctionOutputsDict.Clear();
            m_allFunctionOutputsDict = null;

            m_allFunctionSwitchesDict.Clear();
            m_allFunctionSwitchesDict = null;

            m_allFunctionInputsDict.Clear();
            m_allFunctionInputsDict = null;
        }
 void OnEnable()
 {
     m_target = (target as AmplifyShaderFunction);
 }
Exemple #23
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);
            m_tooltipText = Function.Description;
            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs  = UIUtils.FunctionInputList();
            m_allFunctionOutputs = UIUtils.FunctionOutputList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID = "aca70c900c50c004e8ef0b47c4fac4d4";
        }
        public bool Draw(Rect parentPosition, ParentNode selectedNode, Vector2 mousePosition, int mouseButtonId, bool hasKeyboardFocus)
        {
            bool changeCheck = false;

            base.Draw(parentPosition, mousePosition, mouseButtonId, hasKeyboardFocus);
            if (m_nodePropertiesStyle == null)
            {
                m_nodePropertiesStyle = UIUtils.GetCustomStyle(CustomStyle.NodePropertiesTitle);
                m_nodePropertiesStyle.normal.textColor = m_nodePropertiesStyle.active.textColor = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f) : new Color(0f, 0f, 0f);
            }

            if (m_isMaximized)
            {
                KeyCode key = Event.current.keyCode;
                if (m_isMouseInside || hasKeyboardFocus)
                {
                    if (key == ShortcutsManager.ScrollUpKey)
                    {
                        m_currentScrollPos.y -= 10;
                        if (m_currentScrollPos.y < 0)
                        {
                            m_currentScrollPos.y = 0;
                        }
                        Event.current.Use();
                    }

                    if (key == ShortcutsManager.ScrollDownKey)
                    {
                        m_currentScrollPos.y += 10;
                        Event.current.Use();
                    }
                }

                if (m_forceUpdate)
                {
                    if (m_propertyReordableList != null)
                    {
                        m_propertyReordableList.ReleaseKeyboardFocus();
                    }
                    m_propertyReordableList = null;

                    if (m_functionInputsReordableList != null)
                    {
                        m_functionInputsReordableList.ReleaseKeyboardFocus();
                    }
                    m_functionInputsReordableList = null;

                    if (m_functionSwitchesReordableList != null)
                    {
                        m_functionSwitchesReordableList.ReleaseKeyboardFocus();
                    }
                    m_functionSwitchesReordableList = null;

                    if (m_functionOutputsReordableList != null)
                    {
                        m_functionOutputsReordableList.ReleaseKeyboardFocus();
                    }
                    m_functionOutputsReordableList = null;
                    m_forceUpdate = false;
                }

                GUILayout.BeginArea(m_transformedArea, m_content, m_style);
                {
                    //Draw selected node parameters
                    if (selectedNode != null)
                    {
                        // this hack is need because without it the several FloatFields/Textfields/... would show wrong values ( different from the ones they were assigned to show )
                        if (m_lastSelectedNode != selectedNode.UniqueId)
                        {
                            m_lastSelectedNode = selectedNode.UniqueId;
                            GUI.FocusControl("");
                        }

                        EditorGUILayout.BeginVertical();
                        {
                            EditorGUILayout.Separator();
                            if (selectedNode.UniqueId == ParentWindow.CurrentGraph.CurrentMasterNodeId)
                            {
                                m_dummyContent.text = "Output Node";
                            }
                            else
                            {
                                if (selectedNode.Attributes != null)
                                {
                                    m_dummyContent.text = selectedNode.Attributes.Name;
                                }
                                else if (selectedNode is CommentaryNode)
                                {
                                    m_dummyContent.text = "Commentary";
                                }
                                else
                                {
                                    m_dummyContent.text = TitleStr;
                                }
                            }

                            EditorGUILayout.LabelField(m_dummyContent, m_nodePropertiesStyle);

                            EditorGUILayout.Separator();
                            //UIUtils.RecordObject( selectedNode , "Changing properties on node " + selectedNode.UniqueId);
                            m_currentScrollPos = EditorGUILayout.BeginScrollView(m_currentScrollPos, GUILayout.Width(0), GUILayout.Height(0));
                            float labelWidth = EditorGUIUtility.labelWidth;
                            //if( selectedNode.TextLabelWidth > 0 )
                            //	EditorGUIUtility.labelWidth = selectedNode.TextLabelWidth;
                            //else
                            EditorGUIUtility.labelWidth = TransformedArea.width * 0.42f;

                            changeCheck = selectedNode.SafeDrawProperties();
                            EditorGUIUtility.labelWidth = labelWidth;
                            EditorGUILayout.EndScrollView();
                        }
                        EditorGUILayout.EndVertical();

                        if (changeCheck)
                        {
                            if (selectedNode.ConnStatus == NodeConnectionStatus.Connected)
                            {
                                ParentWindow.SetSaveIsDirty();
                            }
                        }
                    }
                    else
                    {
                        //Draw Graph Params
                        EditorGUILayout.BeginVertical();
                        {
                            EditorGUILayout.Separator();
                            EditorGUILayout.LabelField("Graph Properties", m_nodePropertiesStyle);
                            EditorGUILayout.Separator();

                            m_currentScrollPos = EditorGUILayout.BeginScrollView(m_currentScrollPos, GUILayout.Width(0), GUILayout.Height(0));
                            float labelWidth = EditorGUIUtility.labelWidth;
                            EditorGUIUtility.labelWidth = 90;

                            bool generalIsVisible = m_parentWindow.InnerWindowVariables.ExpandedGeneralShaderOptions;
                            NodeUtils.DrawPropertyGroup(ref generalIsVisible, " General", DrawGeneralFunction);
                            m_parentWindow.InnerWindowVariables.ExpandedGeneralShaderOptions = generalIsVisible;
                            AmplifyShaderFunction function = ParentWindow.CurrentGraph.CurrentShaderFunction;
                            if (function != null)
                            {
                                //function.AdditionalIncludes.Draw( ParentWindow.CurrentGraph.CurrentOutputNode );
                                //function.AdditionalPragmas.Draw( ParentWindow.CurrentGraph.CurrentOutputNode );
                                function.AdditionalDirectives.Draw(ParentWindow.CurrentGraph.CurrentOutputNode);
                            }

                            bool inputIsVisible = m_parentWindow.InnerWindowVariables.ExpandedFunctionInputs;
                            NodeUtils.DrawPropertyGroup(ref inputIsVisible, " Function Inputs", DrawFunctionInputs);
                            m_parentWindow.InnerWindowVariables.ExpandedFunctionInputs = inputIsVisible;

                            bool swicthIsVisible = m_parentWindow.InnerWindowVariables.ExpandedFunctionSwitches;
                            NodeUtils.DrawPropertyGroup(ref swicthIsVisible, " Function Switches", DrawFunctionSwitches);
                            m_parentWindow.InnerWindowVariables.ExpandedFunctionSwitches = swicthIsVisible;

                            bool outputIsVisible = m_parentWindow.InnerWindowVariables.ExpandedFunctionOutputs;
                            NodeUtils.DrawPropertyGroup(ref outputIsVisible, " Function Outputs", DrawFunctionOutputs);
                            m_parentWindow.InnerWindowVariables.ExpandedFunctionOutputs = outputIsVisible;

                            bool properties = ParentWindow.InnerWindowVariables.ExpandedProperties;
                            NodeUtils.DrawPropertyGroup(ref properties, " Material Properties", DrawFunctionProperties);
                            ParentWindow.InnerWindowVariables.ExpandedProperties = properties;

                            EditorGUIUtility.labelWidth = labelWidth;
                            EditorGUILayout.EndScrollView();
                        }
                        EditorGUILayout.EndVertical();
                    }
                }
                // Close window area
                GUILayout.EndArea();
            }

            PostDraw();
            return(changeCheck);
        }
Exemple #25
0
        // This override is removing focus from our window ... need to figure out a workaround before re-using it
        //public override bool CheckButton( GUIContent content, GUIStyle style, int buttonId )
        //{
        //	if ( buttonId != m_validButtonId )
        //		return false;

        //	return GUILayout.Button( content, style );
        //}

        void OnOptionSelected(System.Type type, string name, AmplifyShaderFunction function)
        {
            Disable();
        }