Roman 5b28c9a977 Squashed commit of the following:
commit bb3be793ca5db3df43679f2d6c34c75f768047a1
Author: SAIPO <grasste0403@hotmail.com>
Date:   Wed Dec 22 07:46:07 2021 +0800

    修改佛教Boss关卡和伊斯兰Boss关卡的粒子特效

commit 1987a63954402be8894f9cc9805545432afefa18
Author: SAIPO <grasste0403@hotmail.com>
Date:   Tue Dec 21 20:55:05 2021 +0800

    任务:编写shader,完善数据库类
    1.完善了PlayerInfo类,用以数据库功能
     1) 编写GetSqlData()函数,使用多线程获取用户信息,使用前请先设置公关变量name。
     2) 编写CreateUser(string username)函数,在用户表内创建一个用户。
     3) 编写hasName(string _searchName)函数,判断是否存在这个用户。
     4) 编写GetBoardInfo(int WorldId)函数,获取指定世界的留言板链表。
     5) 编写GetDeadInfo(int WorldId)函数,获取指定世界的死亡信息链表。
     6) 编写CreateDead(int WorldId, Vector2 postion)函数,创建一条死亡信息。
     7) 编写CreateBoard(int WorldId, Vector2 postion,string text)函数,创建一条留言信息。
     8) 编写UpdatePlayerInfo()函数,将类里储存的信息上传到数据库。

    2.实装相关Shader
     1)完善以撒关卡的屏幕后特效,使其可以在发怒场景发出红色辉光。
     2)完善以撒鬼魂的粒子,并且颜色和发怒与否关联。
     3)实装以撒关卡的窗户辉光效果。
     4)实装伊斯兰Boss关卡炸弹弹反的粒子特效。
     5)实装伊斯兰Boss关卡的尘土特效(需要重做)
     6)实装佛教Boss关卡的敲钟声波特效。
     7)实装佛教Boss关卡的钟声受击灰尘(需要重做)

    3.目前发现的bug
     1)当人物恰好调到角落里会卡动画。
     2)伊斯兰Boss关卡,特洛伊木马吐出的炸弹落到特效小怪上会闪退。

commit c06b842382051bc260d9f509491c683a41ca2a4c
Author: SAIPO <grasste0403@hotmail.com>
Date:   Tue Dec 21 14:08:06 2021 +0800

    Squashed commit of the following:

    commit e7dcdec1d9913e283f42d42f72f1030f0c8b6fda
    Author: Roman <1325980292@qq.com>
    Date:   Tue Dec 21 00:45:50 2021 +0800

        任务:搭建前置关卡,编写演出逻辑

        1.流程化游戏
        (1.制作转移器,内含字典,根据玩家的静态属性“阶段”来决定到转移点后将会移动到哪一个场景
        (2.制作转场器,水平方向从左到右

        下班

    commit 74f926815ec8d00fa051192eb3b978ff4b3c01a6
    Author: Roman <1325980292@qq.com>
    Date:   Mon Dec 20 23:33:14 2021 +0800

        任务:搭建前置关卡,编写演出逻辑

        1.编写基督前置关卡
        (1.放置平台、怪物和男童
        (2.修改男童类,外加OnSaveEvent,OnSave时若有事件则触发该Event
        (3.编写开幕演出,与yi前置类似
        (4.编写男童解救演出
        ((1.触发Fungus对话
        ((2.对话结束后,开启通往上层的门

        2.搭建村场景
        (1.放置平台和元素
        (2.为可动元素制作动画

        3.为玩家添加static属性,进度。0:刚开,1进村,2通佛,3通伊,4.通基

        4.制作死亡重开功能
        (1.当玩家生命值降到0及以下,触发死亡事件
        (2.死亡后reload当前场景,并设记录员,关闭某些事件和演出不再执行

        *优化和修复
        (1.尝试制作击中卡肉效果,目前打击感太弱。也可以尝试粒子效果

        *至此,全部前置关卡搭建完毕,村场景搭建完毕。
        *明天可以完成流程化,接下来就是填充剧情、UI、死亡标记和留言板等系统了

        下班

    commit f257b40d10373a13380e9c395fe94d6559a82a0f
    Author: Roman <1325980292@qq.com>
    Date:   Sun Dec 19 23:57:44 2021 +0800

        任务:搭建前置关卡,编写演出逻辑

        1.编写佛教前置关开场演出
        (*.休整地形,使得左边多出一块地面,方便演出正常运作
        (*.项目后期再通过逻辑触发该演出,目前先用调试方式触发演出
        (1.关闭空气墙
        (2.修改玩家inputDir使玩家从屏幕外冲进到屏幕内部
        (3.等待一段时间
        (4.此时玩家应该走到某个合适的位置,停止玩家的inputDir
        (5.等待一小段时间给玩家反应
        (6.修改相机offset,使其对准对话的两个小怪
        (7.等待一小段时间给玩家反应
        (8.触发Fungus对话
        (9.Fungus对话结束后,返回标记命令演出Main继续执行
        *.修改NormalEnemy,添加标识isInFoStage,在Update中判断,若是,使该怪物水平方向上追踪玩家,可以参考爱欲品的Seek
        (10.修改左边小怪的isInFoStage
        (11.开启右边小怪的Path动画,表现其慌忙逃跑
        (12.Invoke一个延时,等右边小怪逃出视野后删除它
        (13.触发善后和结束事件
        (14.重写善后事件,重新开启空气墙

        2.搭建伊斯兰前置关卡

        3.创建伊斯兰前置关卡演出
        (1.关闭空气墙
        (2.修改玩家inputDir使玩家从屏幕外冲进到屏幕内部
        (3.等待一段时间
        (4.此时玩家应该走到某个合适的位置,停止玩家的inputDir
        (5.等待一小段时间给玩家反应
        (6.触发善后与结束事件

        4.创建玩家隔间触发事件
        (1.是进入式触发器对象
        (2.触发时Call隔间演出

        5.编写隔间演出逻辑
        (1.表现关门
        (2.左右晃一下镜头,中心移动到左右门处,表示门被关闭
        (3.镜头回到玩家处,同时压缩相机可移动范围更窄
        (4.打开隔间墙壁的空气墙
        (5.设置EndEvent为伊斯兰事件

        6.编写召唤伊斯兰事件
        (1.摘自木马的召唤攻击,稍作修改
        (2.当召唤的伊斯兰全部挂了,触发隔间结束事件

        7.编写隔间结束事件
        (1.表现开门
        (2.关闭隔间的空气墙
        (3.重设相机移动范围

        8.搭建基督前置关卡

        *.至此,第一关、第二关前置关卡的逻辑基本开发完毕

        *.明天能做完所有前置关,顺便应该能搭完村场景,后天可以开始搭建新系统,目前还差留言、死亡标记等系统等待编写

        下班

    commit cd22966ad7637a84c0f08c3a716d5ec549699749
    Author: Roman <1325980292@qq.com>
    Date:   Sun Dec 19 14:12:05 2021 +0800

        Squashed commit of the following:

        commit 26aff356971bdc2c2a6a3bd444eeb50c4bf7ec14
        Author: SAIPO <grasste0403@hotmail.com>
        Date:   Sun Dec 19 02:20:44 2021 +0800

            导入近期制作的一些Shader
            1.合并分支
            2.完成了人物描边的流动shader制作,并且可以对Bloom屏幕后处理产生反应。
            3.完成了基督教boss关卡,彩色窗户辉光的shader制作,可以对Bloom产生反应。
            4.完成了伊斯兰教弹反的炸弹拖尾粒子shader的制作。
            5.完成了火焰粒子shader的制作(可以用在基督教的以撒鬼魂上)。
            6.完成了灰尘粒子像素化的shader制作。
            7.完成了边缘扭曲的shader制作,可以用在一些树木上,让画面产生动感。

            明天制作敲钟的声波Shader

    # Conflicts:
    #	UserSettings/EditorUserSettings.asset

commit 26aff356971bdc2c2a6a3bd444eeb50c4bf7ec14
Author: SAIPO <grasste0403@hotmail.com>
Date:   Sun Dec 19 02:20:44 2021 +0800

    导入近期制作的一些Shader
    1.合并分支
    2.完成了人物描边的流动shader制作,并且可以对Bloom屏幕后处理产生反应。
    3.完成了基督教boss关卡,彩色窗户辉光的shader制作,可以对Bloom产生反应。
    4.完成了伊斯兰教弹反的炸弹拖尾粒子shader的制作。
    5.完成了火焰粒子shader的制作(可以用在基督教的以撒鬼魂上)。
    6.完成了灰尘粒子像素化的shader制作。
    7.完成了边缘扭曲的shader制作,可以用在一些树木上,让画面产生动感。

    明天制作敲钟的声波Shader

# Conflicts:
#	Assets/Scenes/TeLuoYiStageTest.unity
#	Assets/Shader/火焰粒子shader/particle.shadergraph
#	Assets/Shader/灰尘粒子用shader/Pixel_My.shader
#	Assets/Shader/灰尘粒子用shader/Unlit_Pixel_My 1.mat
#	Assets/Shader/灰尘粒子用shader/Unlit_Pixel_My 2.mat
#	Assets/Shader/灰尘粒子用shader/Unlit_Pixel_My.mat
#	Logs/ApiUpdaterCheck.txt
#	UserSettings/EditorUserSettings.asset
2021-12-22 10:01:30 +08:00

1840 lines
62 KiB
C#

// Amplify Shader Editor - Visual Shader Editing Tool
// Copyright (c) Amplify Creations, Lda <info@amplify.pt>
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Text.RegularExpressions;
namespace AmplifyShaderEditor
{
public enum CustomExpressionMode
{
Create,
Call,
File
}
[Serializable]
public class CustomExpressionInputItem
{
public PrecisionType Precision;
public VariableQualifiers Qualifier;
public WirePortDataType Type;
public bool IsSamplerState;
public bool IsTexture2DArray;
public string CustomType;
public bool IsVariable;
public bool FoldoutFlag;
public string FoldoutLabel;
public CustomExpressionInputItem( PrecisionType precision , VariableQualifiers qualifier , string customType , bool isVariable , bool foldoutFlag , string foldoutLabel )
{
Precision = precision;
Qualifier = qualifier;
CustomType = customType;
FoldoutFlag = foldoutFlag;
FoldoutLabel = foldoutLabel;
IsVariable = isVariable;
}
}
[Serializable]
public class CustomExpressionDependency
{
public int DependencyArrayIdx;
public int DependencyNodeId;
public CustomExpressionDependency() { DependencyArrayIdx = DependencyNodeId = -1; }
public CustomExpressionDependency( string id ) { DependencyNodeId = Convert.ToInt32( id ); DependencyArrayIdx = -1; }
public void Reset()
{
DependencyArrayIdx = -1;
DependencyNodeId = -1;
}
}
[Serializable]
[NodeAttributes( "Custom Expression" , "Miscellaneous" , "Creates a custom expression or function if <b>return</b> is detected in the written code." )]
public sealed class CustomExpressionNode : ParentNode
{
private const string WarningText = "Characters $ and @ are NOT allowed inside code since they are internally used as delimiters over the node meta.\nThey will be automatically removed when saving the shader.";
private const float AddRemoveButtonLayoutWidth = 15;
private const float LineAdjust = 1.15f;
private const float IdentationAdjust = 5f;
private const string CustomExpressionInfo = "Creates a custom expression or function according to how code is written on text area.\n\n" +
"- If a return function is detected on Code text area then a function will be created.\n" +
"Also in function mode a ; is expected on the end of each instruction line.\n\n" +
"- If no return function is detected then an expression will be generated and used directly on the vertex/frag body.\n" +
"On Expression mode a ; is not required on the end of an instruction line.\n\n" +
"- You can also call a function from an external file, just make sure to add the include file via the 'Additional Directives' group " +
"in the main property panel. Also works with shader functions.";
private const string ReturnHelper = "return";
private const double MaxTimestamp = 1;
private const string DefaultExpressionNameStr = "My Custom Expression";
private const string DefaultInputNameStr = "In";
private const string CodeTitleStr = "Code";
private const string OutputTypeStr = "Output Type";
private const string CustomTypeStr = " ";
private const string IsVariableStr = "Is Variable";
private const string InputsStr = "Inputs";
private const string InputNameStr = "Name";
private const string InputTypeStr = "Type";
private const string InputValueStr = "Value";
private const string InputQualifierStr = "Qualifier";
private const string ExpressionNameLabelStr = "Name";
private const string FunctionCallModeStr = "Mode";
private const string GenerateUniqueNameStr = "Set Unique";
private const string AutoRegisterStr = "Auto-Register";
private const string DependenciesStr = "Dependencies";
private const string VarRegexReplacer = @"\b{0}\b";
private readonly string[] PrecisionLabelsExtraLocal = { "Float" , "Half" , "Inherit Local" };
private readonly string[] AvailableWireTypesStr =
{
"int",
"float",
"float2",
"float3",
"float4",
"float3x3",
"float4x4",
"sampler1D",
"sampler2D",
"sampler3D",
"samplerCUBE",
"sampler2Darray",
"samplerState",
"custom"};
private readonly string[] AvailableOutputWireTypesStr =
{
"int",
"float",
"float2",
"float3",
"float4",
"float3x3",
"float4x4",
"void",
};
private readonly string[] QualifiersStr =
{
"In",
"Out",
"InOut"
};
private readonly WirePortDataType[] AvailableWireTypes =
{
WirePortDataType.INT,
WirePortDataType.FLOAT,
WirePortDataType.FLOAT2,
WirePortDataType.FLOAT3,
WirePortDataType.FLOAT4,
WirePortDataType.FLOAT3x3,
WirePortDataType.FLOAT4x4,
WirePortDataType.SAMPLER1D,
WirePortDataType.SAMPLER2D,
WirePortDataType.SAMPLER3D,
WirePortDataType.SAMPLERCUBE,
WirePortDataType.SAMPLER2DARRAY,
WirePortDataType.SAMPLERSTATE,
WirePortDataType.OBJECT
};
private readonly WirePortDataType[] AvailableOutputWireTypes =
{
WirePortDataType.INT,
WirePortDataType.FLOAT,
WirePortDataType.FLOAT2,
WirePortDataType.FLOAT3,
WirePortDataType.FLOAT4,
WirePortDataType.FLOAT3x3,
WirePortDataType.FLOAT4x4,
WirePortDataType.OBJECT,
};
private readonly Dictionary<WirePortDataType , int> WireToIdx = new Dictionary<WirePortDataType , int>
{
{ WirePortDataType.INT, 0},
{ WirePortDataType.FLOAT, 1},
{ WirePortDataType.FLOAT2, 2},
{ WirePortDataType.FLOAT3, 3},
{ WirePortDataType.FLOAT4, 4},
{ WirePortDataType.FLOAT3x3, 5},
{ WirePortDataType.FLOAT4x4, 6},
{ WirePortDataType.SAMPLER1D, 7},
{ WirePortDataType.SAMPLER2D, 8},
{ WirePortDataType.SAMPLER3D, 9},
{ WirePortDataType.SAMPLERCUBE, 10},
{ WirePortDataType.SAMPLER2DARRAY, 11},
{ WirePortDataType.SAMPLERSTATE, 12},
{ WirePortDataType.OBJECT, 13}
};
[SerializeField]
private string m_customExpressionName = DefaultExpressionNameStr;
[SerializeField]
private List<CustomExpressionInputItem> m_items = new List<CustomExpressionInputItem>();
[SerializeField]
private string m_code = " ";
[SerializeField]
private int m_outputTypeIdx = 1;
[SerializeField]
private bool m_visibleInputsFoldout = true;
[SerializeField]
private CustomExpressionMode m_mode = CustomExpressionMode.Create;
[SerializeField]
private string m_fileGUID = string.Empty;
[SerializeField]
private TextAsset m_fileAsset = null;
[SerializeField]
private bool m_precisionSuffix = false;
[SerializeField]
private bool m_voidMode = false;
[SerializeField]
private bool m_autoRegisterMode = false;
[SerializeField]
private bool m_functionMode = false;
[SerializeField]
private int m_firstAvailablePort = 0;
[SerializeField]
private string m_uniqueName;
[SerializeField]
private bool m_generateUniqueName = true;
[SerializeField]
private bool m_dependenciesFoldout = false;
[SerializeField]
private List<CustomExpressionDependency> m_dependencies = new List<CustomExpressionDependency>();
private const float ButtonLayoutWidth = 15;
private bool m_repopulateNameDictionary = true;
private Dictionary<string , int> m_usedNames = new Dictionary<string , int>();
private double m_lastTimeNameModified = 0;
private bool m_nameModified = false;
private double m_lastTimeCodeModified = 0;
private bool m_codeModified = false;
//Title editing
private bool m_isEditing;
private bool m_stopEditing;
private bool m_startEditing;
private double m_clickTime;
private double m_doubleClickTime = 0.3;
private Rect m_titleClickArea;
//Item Reordable List
private ReordableAction m_actionType = ReordableAction.None;
private int m_actionIndex = 0;
private int m_lastIndex = 0;
private ReorderableList m_itemReordableList = null;
private ReorderableList m_dependenciesReordableList = null;
protected override void CommonInit( int uniqueId )
{
base.CommonInit( uniqueId );
AddInputPort( WirePortDataType.FLOAT , false , "In0" );
m_items.Add( new CustomExpressionInputItem( PrecisionType.Inherit , VariableQualifiers.In , string.Empty , false , true , string.Empty/*"[0]"*/ ) );
AddOutputPort( WirePortDataType.FLOAT , "Out" );
m_textLabelWidth = 97;
m_customPrecision = true;
}
protected override void OnUniqueIDAssigned()
{
base.OnUniqueIDAssigned();
if( m_mode == CustomExpressionMode.Create )
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.AddNode( this );
SetTitleText( m_customExpressionName );
if( m_nodeAttribs != null )
m_uniqueName = m_nodeAttribs.Name + OutputId;
else
m_uniqueName = "CustomExpression" + OutputId;
}
public override void OnInputPortConnected( int portId , int otherNodeId , int otherPortId , bool activateNode = true )
{
base.OnInputPortConnected( portId , otherNodeId , otherPortId , activateNode );
CheckPortConnection( portId );
}
public override void OnConnectedOutputNodeChanges( int portId , int otherNodeId , int otherPortId , string name , WirePortDataType type )
{
base.OnConnectedOutputNodeChanges( portId , otherNodeId , otherPortId , name , type );
CheckPortConnection( portId );
}
void CheckPortConnection( int portId )
{
if( portId == 0 && ( m_mode == CustomExpressionMode.Call || m_voidMode ) )
{
m_inputPorts[ 0 ].MatchPortToConnection();
m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType , false );
}
}
public override void OnNodeLogicUpdate( DrawInfo drawInfo )
{
base.OnNodeLogicUpdate( drawInfo );
if( m_nameModified )
{
if( ( EditorApplication.timeSinceStartup - m_lastTimeNameModified ) > MaxTimestamp )
{
m_nameModified = false;
m_sizeIsDirty = true;
m_repopulateNameDictionary = true;
}
}
if( m_repopulateNameDictionary )
{
m_repopulateNameDictionary = false;
m_usedNames.Clear();
for( int i = 0 ; i < m_inputPorts.Count ; i++ )
{
m_usedNames.Add( m_inputPorts[ i ].Name , i );
}
}
if( m_codeModified )
{
if( ( EditorApplication.timeSinceStartup - m_lastTimeCodeModified ) > MaxTimestamp )
{
m_codeModified = false;
bool functionMode = m_code.Contains( ReturnHelper );
if( functionMode != m_functionMode )
{
m_functionMode = functionMode;
CheckCallMode();
}
}
}
}
bool CheckCallMode()
{
if( m_functionMode && m_mode == CustomExpressionMode.Call )
{
Mode = CustomExpressionMode.Create;
m_outputTypeIdx = ( AvailableOutputWireTypesStr.Length - 1 );
//m_outputPorts[ 0 ].ChangeType( AvailableOutputWireTypes[ m_outputTypeIdx ], false );
m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType , false );
m_voidMode = true;
return true;
}
return false;
}
public override void Draw( DrawInfo drawInfo )
{
base.Draw( drawInfo );
if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
{
if( !m_isEditing && ( ( !ContainerGraph.ParentWindow.MouseInteracted && drawInfo.CurrentEventType == EventType.MouseDown && m_titleClickArea.Contains( drawInfo.MousePosition ) ) ) )
{
if( ( EditorApplication.timeSinceStartup - m_clickTime ) < m_doubleClickTime )
m_startEditing = true;
else
GUI.FocusControl( null );
m_clickTime = EditorApplication.timeSinceStartup;
}
else if( m_isEditing && ( ( drawInfo.CurrentEventType == EventType.MouseDown && !m_titleClickArea.Contains( drawInfo.MousePosition ) ) || !EditorGUIUtility.editingTextField ) )
{
m_stopEditing = true;
}
if( m_isEditing || m_startEditing )
{
EditorGUI.BeginChangeCheck();
GUI.SetNextControlName( m_uniqueName );
m_customExpressionName = EditorGUITextField( m_titleClickArea , string.Empty , m_customExpressionName , UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) );
if( EditorGUI.EndChangeCheck() )
{
SetTimedUpdate( 2 );
SetTitleText( m_customExpressionName );
m_sizeIsDirty = true;
m_isDirty = true;
}
if( m_startEditing )
EditorGUI.FocusTextInControl( m_uniqueName );
}
if( drawInfo.CurrentEventType == EventType.Repaint )
{
if( m_startEditing )
{
m_startEditing = false;
m_isEditing = true;
}
if( m_stopEditing )
{
m_stopEditing = false;
m_isEditing = false;
GUI.FocusControl( null );
}
}
}
}
public override void OnNodeLayout( DrawInfo drawInfo )
{
base.OnNodeLayout( drawInfo );
m_titleClickArea = m_titlePos;
m_titleClickArea.height = Constants.NODE_HEADER_HEIGHT;
}
public override void OnNodeRepaint( DrawInfo drawInfo )
{
base.OnNodeRepaint( drawInfo );
if( !m_isVisible )
return;
// Fixed Title ( only renders when not editing )
if( !m_isEditing && !m_startEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
{
GUI.Label( m_titleClickArea , m_content , UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) );
}
}
public string GetFirstAvailableName()
{
string name = string.Empty;
for( int i = 0 ; i < m_inputPorts.Count + 1 ; i++ )
{
name = DefaultInputNameStr + i;
if( !m_usedNames.ContainsKey( name ) )
{
return name;
}
}
Debug.LogWarning( "Could not find valid name" );
return string.Empty;
}
public override void DrawProperties()
{
base.DrawProperties();
NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout , Constants.ParameterLabelStr , DrawBaseProperties );
//NodeUtils.DrawPropertyGroup( ref m_visibleInputsFoldout, InputsStr, DrawInputs, DrawAddRemoveInputs );
NodeUtils.DrawPropertyGroup( ref m_visibleInputsFoldout , InputsStr , DrawReordableInputs , DrawItemsAddRemoveInputs );
EditorGUILayout.HelpBox( CustomExpressionInfo , MessageType.Info );
EditorGUILayout.HelpBox( WarningText , MessageType.Warning );
}
string WrapCodeInFunction( bool isTemplate , string functionName , bool expressionMode )
{
//Hack to be used util indent is properly used
int currIndent = UIUtils.ShaderIndentLevel;
UIUtils.ShaderIndentLevel = isTemplate ? 0 : 1;
if( !isTemplate ) UIUtils.ShaderIndentLevel++;
//string functionName = UIUtils.RemoveInvalidCharacters( m_customExpressionName );
string returnType = ( m_mode == CustomExpressionMode.Call || m_voidMode ) ? "void" : UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType , m_outputPorts[ 0 ].DataType );
if( expressionMode )
returnType = "inline " + returnType;
string functionBody = UIUtils.ShaderIndentTabs + returnType + " " + functionName + "( ";
int count = m_inputPorts.Count - m_firstAvailablePort;
for( int i = 0 ; i < count ; i++ )
{
int portIdx = i + m_firstAvailablePort;
string qualifier = m_items[ i ].Qualifier == VariableQualifiers.In ? string.Empty : UIUtils.QualifierToCg( m_items[ i ].Qualifier ) + " ";
PrecisionType precision = m_items[ i ].Precision;
if( precision == PrecisionType.Inherit )
precision = CurrentPrecisionType;
//string dataType = ( m_inputPorts[ portIdx ].DataType == WirePortDataType.OBJECT ) ? m_items[ i ].CustomType : UIUtils.PrecisionWirePortToCgType( precision, m_inputPorts[ portIdx ].DataType );
string declaration = string.Empty;
if( m_inputPorts[ portIdx ].DataType == WirePortDataType.OBJECT )
declaration = m_items[ i ].CustomType + " " + m_inputPorts[ portIdx ].Name;
else
declaration = UIUtils.PrecisionWirePortToTypeValue( precision , m_inputPorts[ portIdx ].DataType , m_inputPorts[ portIdx ].Name );
functionBody += qualifier + declaration;
//functionBody += qualifier + dataType + " " + m_inputPorts[ portIdx ].Name;
if( i < ( count - 1 ) )
{
functionBody += ", ";
}
}
functionBody += " )\n" + UIUtils.ShaderIndentTabs + "{\n";
UIUtils.ShaderIndentLevel++;
{
if( expressionMode )
functionBody += UIUtils.ShaderIndentTabs + "return ";
string[] codeLines = m_code.Split( IOUtils.LINE_TERMINATOR );
for( int i = 0 ; i < codeLines.Length ; i++ )
{
if( codeLines[ i ].Length > 0 )
{
functionBody += ( ( i == 0 && expressionMode ) ? string.Empty : UIUtils.ShaderIndentTabs ) + codeLines[ i ] + ( ( ( i == codeLines.Length - 1 ) && expressionMode ) ? string.Empty : "\n" );
}
}
if( expressionMode )
functionBody += ";\n";
}
UIUtils.ShaderIndentLevel--;
functionBody += UIUtils.ShaderIndentTabs + "}\n";
UIUtils.ShaderIndentLevel = currIndent;
return functionBody;
}
void DrawBaseProperties()
{
EditorGUI.BeginChangeCheck();
m_customExpressionName = EditorGUILayoutTextField( ExpressionNameLabelStr , m_customExpressionName );
if( EditorGUI.EndChangeCheck() )
{
SetTimedUpdate( 2 );
SetTitleText( m_customExpressionName );
}
EditorGUI.BeginChangeCheck();
Mode = (CustomExpressionMode)EditorGUILayoutEnumPopup( FunctionCallModeStr , m_mode );
if( EditorGUI.EndChangeCheck() )
{
if( CheckCallMode() )
UIUtils.ShowMessage( UniqueId , "Call Mode cannot have return over is code.\nFalling back to Create Mode" );
SetupCallMode();
RecalculateInOutOutputPorts();
}
if( m_mode == CustomExpressionMode.File )
{
m_fileAsset = EditorGUILayoutObjectField( "Source" , m_fileAsset , typeof( TextAsset ) , false ) as TextAsset;
m_precisionSuffix = EditorGUILayoutToggle( "Precision Suffix" , m_precisionSuffix );
}
else
{
EditorGUILayout.LabelField( CodeTitleStr );
EditorGUI.BeginChangeCheck();
{
m_code = EditorGUILayoutTextArea( m_code , UIUtils.MainSkin.textArea );
}
if( EditorGUI.EndChangeCheck() )
{
m_codeModified = true;
m_lastTimeCodeModified = EditorApplication.timeSinceStartup;
}
}
if( m_mode == CustomExpressionMode.Create || m_mode == CustomExpressionMode.File )
{
DrawPrecisionProperty();
bool guiEnabled = GUI.enabled;
GUI.enabled = !AutoRegisterMode && Mode != CustomExpressionMode.File;
m_generateUniqueName = EditorGUILayoutToggle( GenerateUniqueNameStr , m_generateUniqueName ) && !AutoRegisterMode;
GUI.enabled = !m_generateUniqueName;
AutoRegisterMode = EditorGUILayoutToggle( AutoRegisterStr , AutoRegisterMode ) && !m_generateUniqueName;
GUI.enabled = guiEnabled;
EditorGUI.BeginChangeCheck();
m_outputTypeIdx = EditorGUILayoutPopup( OutputTypeStr , m_outputTypeIdx , AvailableOutputWireTypesStr );
if( EditorGUI.EndChangeCheck() )
{
bool oldVoidValue = m_voidMode;
UpdateVoidMode();
if( oldVoidValue != m_voidMode )
{
SetupCallMode();
RecalculateInOutOutputPorts();
}
else
{
m_outputPorts[ 0 ].ChangeType( AvailableOutputWireTypes[ m_outputTypeIdx ] , false );
}
}
}
NodeUtils.DrawNestedPropertyGroup( ref m_dependenciesFoldout , "Dependencies" , DrawDependencies , DrawDependenciesAddRemoveInputs );
}
void UpdateVoidMode()
{
m_voidMode = ( m_outputTypeIdx == ( AvailableOutputWireTypesStr.Length - 1 ) );
}
void SetupCallMode()
{
if( m_mode == CustomExpressionMode.Call || m_voidMode )
{
if( m_firstAvailablePort != 1 )
{
m_firstAvailablePort = 1;
AddInputPortAt( 0 , WirePortDataType.FLOAT , false , DefaultInputNameStr );
m_outputPorts[ 0 ].ChangeType( WirePortDataType.FLOAT , false );
}
}
else
{
if( m_firstAvailablePort != 0 )
{
m_firstAvailablePort = 0;
if( m_inputPorts[ 0 ].IsConnected )
{
m_containerGraph.DeleteConnection( true , UniqueId , m_inputPorts[ 0 ].PortId , false , true );
}
DeleteInputPortByArrayIdx( 0 );
m_outputPorts[ 0 ].ChangeType( AvailableOutputWireTypes[ m_outputTypeIdx ] , false );
}
}
}
void DrawItemsAddRemoveInputs()
{
if( m_inputPorts.Count == m_firstAvailablePort )
m_visibleInputsFoldout = false;
// Add new port
if( GUILayoutButton( string.Empty , UIUtils.PlusStyle , GUILayout.Width( ButtonLayoutWidth ) ) )
{
AddPortAt( m_inputPorts.Count );
m_visibleInputsFoldout = true;
EditorGUI.FocusTextInControl( null );
}
//Remove port
if( GUILayoutButton( string.Empty , UIUtils.MinusStyle , GUILayout.Width( ButtonLayoutWidth ) ) )
{
RemovePortAt( m_inputPorts.Count - 1 );
EditorGUI.FocusTextInControl( null );
}
}
void DrawDependenciesAddRemoveInputs()
{
// Add new port
if( GUILayoutButton( string.Empty , UIUtils.PlusStyle , GUILayout.Width( ButtonLayoutWidth ) ) )
{
m_dependencies.Add( new CustomExpressionDependency() );
EditorGUI.FocusTextInControl( null );
}
//Remove port
if( GUILayoutButton( string.Empty , UIUtils.MinusStyle , GUILayout.Width( ButtonLayoutWidth ) ) )
{
m_dependencies.RemoveAt( m_dependencies.Count - 1 );
}
}
void DrawDependencies()
{
if( m_dependenciesReordableList == null )
{
m_dependenciesReordableList = new ReorderableList( m_dependencies , typeof( CustomExpressionDependency ) , true , false , false , false )
{
headerHeight = 0 ,
footerHeight = 0 ,
showDefaultBackground = false ,
drawElementCallback = ( Rect rect , int index , bool isActive , bool isFocused ) =>
{
if( m_dependencies[ index ] != null )
{
rect.xMin -= 1;
Rect popupPos = new Rect( rect.x , rect.y , rect.width - 2 * Constants.PlusMinusButtonLayoutWidth , EditorGUIUtility.singleLineHeight );
Rect buttonPlusPos = new Rect( rect.x + rect.width - 2 * Constants.PlusMinusButtonLayoutWidth , rect.y - 2 , Constants.PlusMinusButtonLayoutWidth , Constants.PlusMinusButtonLayoutWidth );
Rect buttonMinusPos = new Rect( rect.x + rect.width - Constants.PlusMinusButtonLayoutWidth , rect.y - 2 , Constants.PlusMinusButtonLayoutWidth , Constants.PlusMinusButtonLayoutWidth );
EditorGUI.BeginChangeCheck();
m_dependencies[ index ].DependencyArrayIdx = EditorGUIPopup( popupPos , string.Empty , m_dependencies[ index ].DependencyArrayIdx , UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.NodesArr );
if( EditorGUI.EndChangeCheck() )
{
m_dependencies[ index ].DependencyNodeId = UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.GetNode( m_dependencies[ index ].DependencyArrayIdx ).UniqueId;
if( m_dependencies[ index ].DependencyNodeId == UniqueId )
{
m_dependencies[ index ].Reset();
}
}
if( GUI.Button( buttonPlusPos , string.Empty , UIUtils.PlusStyle ) )
{
m_actionType = ReordableAction.Add;
m_actionIndex = index;
}
if( GUI.Button( buttonMinusPos , string.Empty , UIUtils.MinusStyle ) )
{
m_actionType = ReordableAction.Remove;
m_actionIndex = index;
}
}
}
};
}
if( m_dependenciesReordableList != null )
{
EditorGUILayout.Space();
if( m_dependencies.Count == 0 )
{
EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add one." , MessageType.Info );
}
else
{
m_dependenciesReordableList.DoLayoutList();
}
EditorGUILayout.Space();
}
if( m_actionType != ReordableAction.None )
{
switch( m_actionType )
{
case ReordableAction.Add:
m_dependencies.Insert( m_actionIndex + 1 , new CustomExpressionDependency() );
break;
case ReordableAction.Remove:
m_dependencies.RemoveAt( m_actionIndex );
break;
}
m_isDirty = true;
m_actionType = ReordableAction.None;
EditorGUI.FocusTextInControl( null );
}
}
void DrawReordableInputs()
{
if( m_itemReordableList == null )
{
m_itemReordableList = new ReorderableList( m_items , typeof( CustomExpressionInputItem ) , true , false , false , false )
{
headerHeight = 0 ,
footerHeight = 0 ,
showDefaultBackground = false ,
elementHeightCallback = ( int index ) =>
{
float lineHeight = EditorGUIUtility.singleLineHeight * LineAdjust;
if( m_items[ index ].FoldoutFlag )
{
float size = 7 * lineHeight;
// Take Is Variable toggle into account
if( m_mode == CustomExpressionMode.Call )
size += lineHeight;
if( m_inputPorts[ m_firstAvailablePort + index ].DataType == WirePortDataType.OBJECT )
size += lineHeight;
if( !m_inputPorts[ m_firstAvailablePort + index ].IsConnected )
{
switch( m_inputPorts[ m_firstAvailablePort + index ].DataType )
{
case WirePortDataType.INT:
case WirePortDataType.FLOAT:
size += 0;// lineHeight;
break;
case WirePortDataType.FLOAT2:
case WirePortDataType.FLOAT3:
case WirePortDataType.FLOAT4:
size += lineHeight;//2 * lineHeight;
break;
case WirePortDataType.FLOAT3x3:
size += 5 * lineHeight;//6 * lineHeight;
break;
case WirePortDataType.FLOAT4x4:
size += 6 * lineHeight;//8 * lineHeight;
break;
}
}
return size;
}
else
{
return lineHeight;
}
} ,
onReorderCallback = ( ReorderableList list ) =>
{
int realLastIndex = m_firstAvailablePort + m_lastIndex;
int realCurrIndex = m_firstAvailablePort + list.index;
InputPort portA = m_inputPorts[ realLastIndex ];
int originalOutputPortId = CreateOutputId( portA.PortId );
SwapInputPorts( realLastIndex , realCurrIndex );
if( m_outputPorts.Count > 1 )
{
if( list.index > m_lastIndex )
{
for( int i = m_lastIndex ; i <= list.index ; i++ )
{
if( m_items[ i ].Qualifier != VariableQualifiers.In )
{
int portIdx = i + m_firstAvailablePort;
int oldOutputPortId;
if( i < list.index )
{
int oldinputPortId = m_inputPorts[ portIdx ].PortId + 1;
oldOutputPortId = CreateOutputId( oldinputPortId );
}
else
{
oldOutputPortId = originalOutputPortId;
}
m_outputPortsDict[ oldOutputPortId ].ChangePortId( CreateOutputId( m_inputPorts[ portIdx ].PortId ) );
}
}
}
else
{
for( int i = list.index ; i <= m_lastIndex ; i++ )
{
if( m_items[ i ].Qualifier != VariableQualifiers.In )
{
int portIdx = i + m_firstAvailablePort;
int oldOutputPortId;
if( i > list.index )
{
int oldinputPortId = m_inputPorts[ portIdx ].PortId - 1;
oldOutputPortId = CreateOutputId( oldinputPortId );
}
else
{
oldOutputPortId = originalOutputPortId;
}
m_outputPortsDict[ oldOutputPortId ].ChangePortId( CreateOutputId( m_inputPorts[ portIdx ].PortId ) );
}
}
}
}
m_outputPorts.Sort( ( A , B ) =>
{
return A.PortId.CompareTo( B.PortId );
} );
m_outputPortsDict.Clear();
for( int i = 0 ; i < m_outputPorts.Count ; i++ )
{
m_outputPortsDict.Add( m_outputPorts[ i ].PortId , m_outputPorts[ i ] );
}
} ,
onSelectCallback = ( ReorderableList list ) =>
{
m_lastIndex = list.index;
} ,
drawElementCallback = ( Rect rect , int index , bool isActive , bool isFocused ) =>
{
if( m_items[ index ] != null )
{
float lineHeight = EditorGUIUtility.singleLineHeight;
float lineSpacing = lineHeight * LineAdjust;
rect.x -= IdentationAdjust;
rect.height = lineHeight;
int portIdx = index + m_firstAvailablePort;
Rect foldoutRect = rect;
if( !m_items[ index ].FoldoutFlag )
{
foldoutRect.width -= 2 * AddRemoveButtonLayoutWidth;
}
m_items[ index ].FoldoutFlag = EditorGUIFoldout( foldoutRect , m_items[ index ].FoldoutFlag , /*m_items[ index ].FoldoutLabel + " - " +*/ m_inputPorts[ portIdx ].Name );
if( m_items[ index ].FoldoutFlag )
{
rect.x += IdentationAdjust;
//Qualifier
rect.y += lineSpacing;
VariableQualifiers newQualifier = (VariableQualifiers)EditorGUIPopup( rect , InputQualifierStr , (int)m_items[ index ].Qualifier , QualifiersStr );
if( newQualifier != m_items[ index ].Qualifier )
{
VariableQualifiers oldQualifier = m_items[ index ].Qualifier;
m_items[ index ].Qualifier = newQualifier;
if( newQualifier == VariableQualifiers.In )
{
RemoveOutputPort( CreateOutputId( m_inputPorts[ portIdx ].PortId ) , false );
}
else if( oldQualifier == VariableQualifiers.In )
{
int outputId = CreateOutputId( m_inputPorts[ portIdx ].PortId );
AddOutputPort( m_inputPorts[ portIdx ].DataType , m_inputPorts[ portIdx ].Name , outputId );
}
m_inputPorts[ portIdx ].Visible = newQualifier != VariableQualifiers.Out;
m_sizeIsDirty = true;
RecalculateInOutOutputPorts();
}
// Precision
rect.y += lineSpacing;
m_items[ index ].Precision = (PrecisionType)EditorGUIPopup( rect , PrecisionContent.text , (int)m_items[ index ].Precision , PrecisionLabelsExtraLocal );
// Type
rect.y += lineSpacing;
int typeIdx = WireToIdx[ m_inputPorts[ portIdx ].DataType ];
EditorGUI.BeginChangeCheck();
typeIdx = EditorGUIPopup( rect , InputTypeStr , typeIdx , AvailableWireTypesStr );
if( EditorGUI.EndChangeCheck() )
{
// actual type is need in order for texture array and sampler state to fallback correctly
m_inputPorts[ portIdx ].ChangeType( AvailableWireTypes[ typeIdx ] , false );
if( typeIdx == 5 || typeIdx == 6 )
{
m_inputPorts[ portIdx ].Matrix4x4InternalData = Matrix4x4.identity;
}
if( m_items[ index ].Qualifier != VariableQualifiers.In )
{
OutputPort currOutPort = GetOutputPortByUniqueId( CreateOutputId( m_inputPorts[ portIdx ].PortId ) );
currOutPort.ChangeType( AvailableWireTypes[ typeIdx ] , false );
}
}
if( AvailableWireTypes[ typeIdx ] == WirePortDataType.OBJECT )
{
rect.y += lineSpacing;
m_items[ index ].CustomType = EditorGUITextField( rect , CustomTypeStr , m_items[ index ].CustomType );
}
//Name
rect.y += lineSpacing;
EditorGUI.BeginChangeCheck();
{
m_inputPorts[ portIdx ].Name = EditorGUITextField( rect , InputNameStr , m_inputPorts[ portIdx ].Name );
}
if( EditorGUI.EndChangeCheck() )
{
m_nameModified = true;
m_lastTimeNameModified = EditorApplication.timeSinceStartup;
m_inputPorts[ portIdx ].Name = UIUtils.RemoveInvalidCharacters( m_inputPorts[ portIdx ].Name );
if( string.IsNullOrEmpty( m_inputPorts[ portIdx ].Name ) )
{
m_inputPorts[ portIdx ].Name = DefaultInputNameStr + index;
}
if( m_items[ index ].Qualifier != VariableQualifiers.In )
{
OutputPort currOutPort = GetOutputPortByUniqueId( CreateOutputId( m_inputPorts[ portIdx ].PortId ) );
currOutPort.Name = m_inputPorts[ portIdx ].Name;
}
}
if( m_mode == CustomExpressionMode.Call )
{
//Is Unique
rect.y += lineSpacing;
m_items[ index ].IsVariable = EditorGUIToggle( rect , IsVariableStr , m_items[ index ].IsVariable );
}
// Port Data
if( !m_inputPorts[ portIdx ].IsConnected )
{
rect.y += lineSpacing;
m_inputPorts[ portIdx ].ShowInternalData( rect , this , true , InputValueStr );
}
//Buttons
rect.x += rect.width - 2 * AddRemoveButtonLayoutWidth;
rect.y += lineSpacing;
if( !m_inputPorts[ m_firstAvailablePort + index ].IsConnected )
{
switch( m_inputPorts[ m_firstAvailablePort + index ].DataType )
{
case WirePortDataType.INT:
case WirePortDataType.FLOAT:
rect.y += 0;// lineSpacing;
break;
case WirePortDataType.FLOAT2:
case WirePortDataType.FLOAT3:
case WirePortDataType.FLOAT4:
rect.y += lineSpacing;//2 * lineSpacing;
break;
case WirePortDataType.FLOAT3x3:
rect.y += 5 * lineSpacing;//6 * lineSpacing;
break;
case WirePortDataType.FLOAT4x4:
rect.y += 6 * lineSpacing;//8 * lineSpacing;
break;
}
}
rect.width = AddRemoveButtonLayoutWidth;
if( GUI.Button( rect , string.Empty , UIUtils.PlusStyle ) )
{
m_actionType = ReordableAction.Add;
m_actionIndex = index;
}
rect.x += AddRemoveButtonLayoutWidth;
if( GUI.Button( rect , string.Empty , UIUtils.MinusStyle ) )
{
m_actionType = ReordableAction.Remove;
m_actionIndex = index;
}
}
else
{
//Buttons
rect.x += IdentationAdjust + rect.width - 2 * AddRemoveButtonLayoutWidth;
rect.width = AddRemoveButtonLayoutWidth;
if( GUI.Button( rect , string.Empty , UIUtils.PlusStyle ) )
{
m_actionType = ReordableAction.Add;
m_actionIndex = index;
}
rect.x += AddRemoveButtonLayoutWidth;
if( GUI.Button( rect , string.Empty , UIUtils.MinusStyle ) )
{
m_actionType = ReordableAction.Remove;
m_actionIndex = index;
}
}
}
}
};
}
if( m_itemReordableList != null )
{
EditorGUILayout.Space();
if( m_items.Count == 0 )
{
EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add one." , MessageType.Info );
}
else
{
m_itemReordableList.DoLayoutList();
}
EditorGUILayout.Space();
}
if( m_actionType != ReordableAction.None )
{
switch( m_actionType )
{
case ReordableAction.Add:
AddPortAt( m_firstAvailablePort + m_actionIndex + 1 );
break;
case ReordableAction.Remove:
RemovePortAt( m_firstAvailablePort + m_actionIndex );
break;
}
m_isDirty = true;
m_actionType = ReordableAction.None;
EditorGUI.FocusTextInControl( null );
}
}
void RecalculateInOutOutputPorts()
{
m_outputPorts.Sort( ( x , y ) => x.PortId.CompareTo( y.PortId ) );
m_outputPortsDict.Clear();
int count = m_inputPorts.Count - m_firstAvailablePort;
int outputId = 1;
for( int i = 0 ; i < count ; i++ )
{
int idx = i + m_firstAvailablePort;
if( m_items[ i ].Qualifier != VariableQualifiers.In )
{
m_outputPorts[ outputId ].ChangeProperties( m_inputPorts[ idx ].Name , m_inputPorts[ idx ].DataType , false );
m_outputPorts[ outputId ].ChangePortId( CreateOutputId( m_inputPorts[ idx ].PortId ) );
outputId++;
}
}
int outCount = m_outputPorts.Count;
for( int i = 0 ; i < outCount ; i++ )
{
m_outputPortsDict.Add( m_outputPorts[ i ].PortId , m_outputPorts[ i ] );
}
}
void AddPortAt( int idx )
{
AddInputPortAt( idx , WirePortDataType.FLOAT , false , GetFirstAvailableName() );
m_items.Insert( idx - m_firstAvailablePort , new CustomExpressionInputItem( PrecisionType.Inherit , VariableQualifiers.In , string.Empty , false , true , string.Empty/* "[" + idx + "]"*/ ) );
m_repopulateNameDictionary = true;
RecalculateInOutOutputPorts();
}
void RemovePortAt( int idx )
{
if( m_inputPorts.Count > m_firstAvailablePort )
{
int varIdx = idx - m_firstAvailablePort;
if( m_items[ varIdx ].Qualifier != VariableQualifiers.In )
{
int id = CreateOutputId( m_inputPorts[ idx ].PortId );
RemoveOutputPort( id , false );
}
DeleteInputPortByArrayIdx( idx );
m_items.RemoveAt( varIdx );
m_repopulateNameDictionary = true;
RecalculateInOutOutputPorts();
}
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_repopulateNameDictionary = true;
}
public string DealWithFileMode( int outputId , ref MasterNodeDataCollector dataCollector , bool ignoreLocalvar )
{
OutputPort outputPort = GetOutputPortByUniqueId( outputId );
if( outputPort.IsLocalValue( dataCollector.PortCategory ) )
return outputPort.LocalValue( dataCollector.PortCategory );
if( m_fileAsset == null && !string.IsNullOrEmpty( m_fileGUID ) )
{
m_fileAsset = AssetDatabase.LoadAssetAtPath<TextAsset>( AssetDatabase.GUIDToAssetPath( m_fileGUID ) );
}
if( m_fileAsset != null )
{
string path = AssetDatabase.GetAssetPath( m_fileAsset );
dataCollector.AddToIncludes( UniqueId , path );
int dependenciesCount = m_dependencies.Count;
Dictionary<int , CustomExpressionNode> examinedNodes = new Dictionary<int , CustomExpressionNode>();
for( int i = 0 ; i < dependenciesCount ; i++ )
{
CustomExpressionNode node = m_containerGraph.GetNode( m_dependencies[ i ].DependencyNodeId ) as CustomExpressionNode;
if( node == null )
{
node = UIUtils.CurrentWindow.OutsideGraph.GetNode( m_dependencies[ i ].DependencyNodeId ) as CustomExpressionNode;
}
if( node != null )
{
node.CheckDependencies( ref dataCollector , ref examinedNodes );
}
}
examinedNodes.Clear();
examinedNodes = null;
string expressionName = UIUtils.RemoveInvalidCharacters( m_customExpressionName );
string localVarName = "local" + expressionName;
localVarName += OutputId;
int count = m_inputPorts.Count;
if( m_voidMode )
{
string mainData = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
RegisterLocalVariable( 0 , string.Format( Constants.CodeWrapper , mainData ) , ref dataCollector , localVarName );
}
string precisionSuffix = string.Empty;
if( m_precisionSuffix )
{
switch( CurrentPrecisionType )
{
default:
case PrecisionType.Float: precisionSuffix = "_float"; break;
case PrecisionType.Half: precisionSuffix = "_half"; break;
}
}
string functionCall = expressionName + precisionSuffix + "( ";
for( int i = m_firstAvailablePort ; i < count ; i++ )
{
if( UIUtils.CurrentWindow.OutsideGraph.SamplingMacros && !UIUtils.CurrentWindow.OutsideGraph.IsSRP )
{
// we don't know what kind of sampling the user will do so we add all of them
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.Auto );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.MipLevel );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.MipBias );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.Derivative );
}
string inputPortLocalVar = m_inputPorts[ i ].Name + OutputId;
int idx = i - m_firstAvailablePort;
if( m_inputPorts[ i ].DataType != WirePortDataType.OBJECT )
{
string result = m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector );
dataCollector.AddLocalVariable( UniqueId , CurrentPrecisionType , m_inputPorts[ i ].DataType , inputPortLocalVar , result );
}
else
{
string result = ( m_inputPorts[ i ].IsConnected ) ? m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector ) : m_inputPorts[ i ].InternalData.ToString();
string inputLocalVar = string.Format( Constants.CustomTypeLocalValueDecWithoutIdent , m_items[ idx ].CustomType , inputPortLocalVar , result );
dataCollector.AddLocalVariable( UniqueId , inputLocalVar );
}
if( m_items[ idx ].Qualifier != VariableQualifiers.In )
{
OutputPort currOutputPort = GetOutputPortByUniqueId( CreateOutputId( m_inputPorts[ i ].PortId ) );
currOutputPort.SetLocalValue( inputPortLocalVar , dataCollector.PortCategory );
}
functionCall += inputPortLocalVar;
if( i < ( count - 1 ) )
{
functionCall += " , ";
}
}
functionCall += " )";
if( m_voidMode )
{
dataCollector.AddLocalVariable( 0 , functionCall + ";" , true );
}
else
{
RegisterLocalVariable( 0 , functionCall , ref dataCollector , localVarName );
}
return outputPort.LocalValue( dataCollector.PortCategory );
}
return GenerateErrorValue( outputId );
}
public override string GenerateShaderForOutput( int outputId , ref MasterNodeDataCollector dataCollector , bool ignoreLocalvar )
{
if( Mode == CustomExpressionMode.File )
{
return DealWithFileMode( outputId , ref dataCollector , ignoreLocalvar );
}
if( string.IsNullOrEmpty( m_code ) )
{
UIUtils.ShowMessage( UniqueId , string.Format( "Custom Expression \"{0}\" need to have code associated" , m_customExpressionName ) , MessageSeverity.Warning );
return "0";
}
m_code = UIUtils.ForceLFLineEnding( m_code );
bool codeContainsReturn = m_code.Contains( ReturnHelper );
bool expressionMode = false;
if( !codeContainsReturn )
{
string[] codeLines = m_code.Split( IOUtils.LINE_TERMINATOR );
expressionMode = codeLines.Length == 1 && !m_voidMode;
}
if( !expressionMode &&
!codeContainsReturn &&
m_mode == CustomExpressionMode.Create && !m_voidMode )
{
UIUtils.ShowMessage( UniqueId , string.Format( "Custom Expression \"{0}\" has a non-void return type but no return instruction was detected" , m_customExpressionName ) , MessageSeverity.Error );
if( outputId != 0 )
UIUtils.ShowMessage( UniqueId , string.Format( "Attempting to get value on Custom Expression \"{0}\" from inexisting \"{1}\" inout/out variable" , m_customExpressionName , m_outputPorts[ outputId ].Name ) , MessageSeverity.Error );
return "0";
}
int dependenciesCount = m_dependencies.Count;
Dictionary<int , CustomExpressionNode> examinedNodes = new Dictionary<int , CustomExpressionNode>();
for( int i = 0 ; i < dependenciesCount ; i++ )
{
CustomExpressionNode node = m_containerGraph.GetNode( m_dependencies[ i ].DependencyNodeId ) as CustomExpressionNode;
if( node == null )
{
node = UIUtils.CurrentWindow.OutsideGraph.GetNode( m_dependencies[ i ].DependencyNodeId ) as CustomExpressionNode;
}
if( node != null )
{
node.CheckDependencies( ref dataCollector , ref examinedNodes );
}
}
examinedNodes.Clear();
examinedNodes = null;
OutputPort outputPort = GetOutputPortByUniqueId( outputId );
if( outputPort.IsLocalValue( dataCollector.PortCategory ) )
return outputPort.LocalValue( dataCollector.PortCategory );
string expressionName = UIUtils.RemoveInvalidCharacters( m_customExpressionName );
string localVarName = "local" + expressionName;
if( m_generateUniqueName )
{
expressionName += OutputId;
}
localVarName += OutputId;
int count = m_inputPorts.Count;
if( count > 0 )
{
if( m_mode == CustomExpressionMode.Call || m_voidMode )
{
string mainData = m_inputPorts[ 0 ].GeneratePortInstructions( ref dataCollector );
RegisterLocalVariable( 0 , string.Format( Constants.CodeWrapper , mainData ) , ref dataCollector , localVarName );
}
if( codeContainsReturn )
{
string function = WrapCodeInFunction( dataCollector.IsTemplate , expressionName , false );
string functionCall = expressionName + "( ";
for( int i = m_firstAvailablePort ; i < count ; i++ )
{
if( UIUtils.CurrentWindow.OutsideGraph.SamplingMacros && !UIUtils.CurrentWindow.OutsideGraph.IsSRP )
{
// we don't know what kind of sampling the user will do so we add all of them
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.Auto );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.MipLevel );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.MipBias );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.Derivative );
}
string inputPortLocalVar = m_inputPorts[ i ].Name + OutputId;
int idx = i - m_firstAvailablePort;
if( m_inputPorts[ i ].DataType != WirePortDataType.OBJECT )
{
string result = m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector );
dataCollector.AddLocalVariable( UniqueId , CurrentPrecisionType , m_inputPorts[ i ].DataType , inputPortLocalVar , result );
}
else
{
string result = ( m_inputPorts[ i ].IsConnected ) ? m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector ) : m_inputPorts[ i ].InternalData.ToString();
string inputLocalVar = string.Format( Constants.CustomTypeLocalValueDecWithoutIdent , m_items[ idx ].CustomType , inputPortLocalVar , result );
dataCollector.AddLocalVariable( UniqueId , inputLocalVar );
}
if( m_items[ idx ].Qualifier != VariableQualifiers.In )
{
OutputPort currOutputPort = GetOutputPortByUniqueId( CreateOutputId( m_inputPorts[ i ].PortId ) );
currOutputPort.SetLocalValue( inputPortLocalVar , dataCollector.PortCategory );
}
functionCall += inputPortLocalVar;
if( i < ( count - 1 ) )
{
functionCall += " , ";
}
}
functionCall += " )";
if( m_mode == CustomExpressionMode.Call || m_voidMode )
{
dataCollector.AddLocalVariable( 0 , functionCall + ";" , true );
}
else
{
RegisterLocalVariable( 0 , functionCall , ref dataCollector , localVarName );
}
dataCollector.AddFunction( expressionName , function );
}
else
{
string localCode = m_code;
if( m_mode == CustomExpressionMode.Call || m_voidMode )
{
for( int i = m_firstAvailablePort ; i < count ; i++ )
{
int idx = i - m_firstAvailablePort;
if( !m_items[ idx ].IsVariable ||
m_items[ idx ].Qualifier != VariableQualifiers.In ||
!m_inputPorts[ i ].IsConnected
)
{
string inputPortLocalVar = m_inputPorts[ i ].Name + OutputId;
string nameToReplaceRegex = string.Format( VarRegexReplacer , m_inputPorts[ i ].Name );
localCode = Regex.Replace( localCode , nameToReplaceRegex , inputPortLocalVar , RegexOptions.Multiline );
//localCode = localCode.Replace( m_inputPorts[ i ].Name, inputPortLocalVar );
if( m_inputPorts[ i ].IsConnected )
{
string result = m_inputPorts[ i ].GenerateShaderForOutput( ref dataCollector , m_inputPorts[ i ].DataType , true , true );
if( m_inputPorts[ i ].DataType == WirePortDataType.OBJECT )
{
dataCollector.AddLocalVariable( UniqueId , m_items[ idx ].CustomType + " " + inputPortLocalVar , result + ";" );
}
else
{
dataCollector.AddLocalVariable( UniqueId , CurrentPrecisionType , m_inputPorts[ i ].DataType , inputPortLocalVar , result );
}
}
else
{
if( m_inputPorts[ i ].DataType == WirePortDataType.OBJECT )
{
dataCollector.AddLocalVariable( UniqueId , m_items[ idx ].CustomType + " " + inputPortLocalVar , m_inputPorts[ i ].WrappedInternalData + ";" );
}
else
{
dataCollector.AddLocalVariable( UniqueId , CurrentPrecisionType , m_inputPorts[ i ].DataType , inputPortLocalVar , m_inputPorts[ i ].WrappedInternalData );
}
}
if( m_items[ idx ].Qualifier != VariableQualifiers.In )
{
OutputPort currOutputPort = GetOutputPortByUniqueId( CreateOutputId( m_inputPorts[ i ].PortId ) );
currOutputPort.SetLocalValue( inputPortLocalVar , dataCollector.PortCategory );
}
}
else
{
// Not Unique
string result = m_inputPorts[ i ].GenerateShaderForOutput( ref dataCollector , m_inputPorts[ i ].DataType , true , true );
string nameToReplaceRegex = string.Format( VarRegexReplacer , m_inputPorts[ i ].Name );
localCode = Regex.Replace( localCode , nameToReplaceRegex , result , RegexOptions.Multiline );
//localCode = localCode.Replace( m_inputPorts[ i ].Name, result );
}
}
localCode = string.Format( Constants.InlineCodeWrapper , localCode );
string[] codeLines = localCode.Split( '\n' );
for( int codeIdx = 0 ; codeIdx < codeLines.Length ; codeIdx++ )
{
dataCollector.AddLocalVariable( 0 , codeLines[ codeIdx ] , true );
}
}
else
{
string function = WrapCodeInFunction( dataCollector.IsTemplate , expressionName , true );
string functionCall = expressionName + "( ";
for( int i = m_firstAvailablePort ; i < count ; i++ )
{
if( UIUtils.CurrentWindow.OutsideGraph.SamplingMacros && !UIUtils.CurrentWindow.OutsideGraph.IsSRP )
{
// we don't know what kind of sampling the user will do so we add all of them
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.Auto );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.MipLevel );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.MipBias );
GeneratorUtils.AddCustomStandardSamplingMacros( ref dataCollector , m_inputPorts[ i ].DataType , MipType.Derivative );
}
string inputPortLocalVar = m_inputPorts[ i ].Name + OutputId;
int idx = i - m_firstAvailablePort;
if( m_inputPorts[ i ].DataType != WirePortDataType.OBJECT )
{
string result = m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector );
dataCollector.AddLocalVariable( UniqueId , CurrentPrecisionType , m_inputPorts[ i ].DataType , inputPortLocalVar , result );
}
else
{
string result = ( m_inputPorts[ i ].IsConnected ) ? m_inputPorts[ i ].GeneratePortInstructions( ref dataCollector ) : m_inputPorts[ i ].InternalData.ToString();
string inputLocalVar = string.Format( Constants.CustomTypeLocalValueDecWithoutIdent , m_items[ idx ].CustomType , inputPortLocalVar , result );
dataCollector.AddLocalVariable( UniqueId , inputLocalVar );
}
if( m_items[ idx ].Qualifier != VariableQualifiers.In )
{
OutputPort currOutputPort = GetOutputPortByUniqueId( CreateOutputId( m_inputPorts[ i ].PortId ) );
currOutputPort.SetLocalValue( inputPortLocalVar , dataCollector.PortCategory );
}
functionCall += inputPortLocalVar;
if( i < ( count - 1 ) )
{
functionCall += " , ";
}
}
functionCall += " )";
RegisterLocalVariable( 0 , functionCall , ref dataCollector , localVarName );
dataCollector.AddFunction( expressionName , function );
}
}
return outputPort.LocalValue( dataCollector.PortCategory );
}
else
{
if( m_code.Contains( ReturnHelper ) )
{
string function = WrapCodeInFunction( dataCollector.IsTemplate , expressionName , false );
dataCollector.AddFunction( expressionName , function );
string functionCall = expressionName + "()";
RegisterLocalVariable( 0 , functionCall , ref dataCollector , localVarName );
}
else
{
RegisterLocalVariable( 0 , string.Format( Constants.CodeWrapper , m_code ) , ref dataCollector , localVarName );
}
return m_outputPorts[ 0 ].LocalValue( dataCollector.PortCategory );
}
}
int CreateOutputId( int inputId )
{
return ( inputId + 1 );
}
int CreateInputId( int outputId )
{
return outputId - 1;
}
void UpdateOutputPorts()
{
int count = m_inputPorts.Count - m_firstAvailablePort;
for( int i = 0 ; i < count ; i++ )
{
if( m_items[ i ].Qualifier != VariableQualifiers.In )
{
int portIdx = i + m_firstAvailablePort;
int outputPortId = CreateOutputId( m_inputPorts[ portIdx ].PortId );
AddOutputPort( m_inputPorts[ portIdx ].DataType , m_inputPorts[ portIdx ].Name , outputPortId );
}
}
}
public override void ReadFromString( ref string[] nodeParams )
{
// This node is, by default, created with one input port
base.ReadFromString( ref nodeParams );
m_code = GetCurrentParam( ref nodeParams );
m_code = m_code.Replace( Constants.LineFeedSeparator , '\n' );
m_code = m_code.Replace( Constants.SemiColonSeparator , ';' );
m_outputTypeIdx = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
if( m_outputTypeIdx >= AvailableWireTypes.Length )
{
UIUtils.ShowMessage( UniqueId , "Sampler types were removed as a valid output custom expression type" );
m_outputTypeIdx = 1;
}
UpdateVoidMode();
m_outputPorts[ 0 ].ChangeType( AvailableWireTypes[ m_outputTypeIdx ] , false );
if( UIUtils.CurrentShaderVersion() > 12001 )
{
if( UIUtils.CurrentShaderVersion() > 18901 )
{
m_mode = (CustomExpressionMode)Enum.Parse( typeof( CustomExpressionMode ) , GetCurrentParam( ref nodeParams ) );
}
else
{
bool mode = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
m_mode = mode ? CustomExpressionMode.Call : CustomExpressionMode.Create;
}
if( m_mode == CustomExpressionMode.Call || m_voidMode )
{
m_firstAvailablePort = 1;
AddInputPortAt( 0 , WirePortDataType.FLOAT , false , DefaultInputNameStr );
}
}
if( m_mode == CustomExpressionMode.Call || m_mode == CustomExpressionMode.File )
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.RemoveNode( this );
int count = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
if( count == 0 )
{
DeleteInputPortByArrayIdx( m_firstAvailablePort );
m_items.Clear();
}
else
{
for( int i = 0 ; i < count ; i++ )
{
bool foldoutValue = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
string name = GetCurrentParam( ref nodeParams );
WirePortDataType type = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ) , GetCurrentParam( ref nodeParams ) );
string internalData = GetCurrentParam( ref nodeParams );
VariableQualifiers qualifier = VariableQualifiers.In;
if( UIUtils.CurrentShaderVersion() > 12001 )
{
qualifier = (VariableQualifiers)Enum.Parse( typeof( VariableQualifiers ) , GetCurrentParam( ref nodeParams ) );
}
string customType = string.Empty;
if( UIUtils.CurrentShaderVersion() > 15311 )
{
customType = GetCurrentParam( ref nodeParams );
}
PrecisionType precision = PrecisionType.Float;
if( UIUtils.CurrentShaderVersion() > 15607 )
{
precision = (PrecisionType)Enum.Parse( typeof( PrecisionType ) , GetCurrentParam( ref nodeParams ) );
}
bool isVariable = false;
if( UIUtils.CurrentShaderVersion() > 16600 )
{
isVariable = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
}
int portIdx = i + m_firstAvailablePort;
if( i == 0 )
{
m_inputPorts[ portIdx ].ChangeProperties( name , type , false );
m_inputPorts[ portIdx ].Visible = qualifier != VariableQualifiers.Out;
m_items[ 0 ].Qualifier = qualifier;
m_items[ 0 ].FoldoutFlag = foldoutValue;
m_items[ 0 ].CustomType = customType;
m_items[ 0 ].Precision = precision;
m_items[ 0 ].IsVariable = isVariable;
}
else
{
m_items.Add( new CustomExpressionInputItem( precision , qualifier , customType , isVariable , foldoutValue , string.Empty/*"[" + i + "]"*/ ) );
AddInputPort( type , false , name );
m_inputPorts[ m_inputPorts.Count - 1 ].Visible = qualifier != VariableQualifiers.Out;
}
m_inputPorts[ i ].InternalData = internalData;
}
}
if( UIUtils.CurrentShaderVersion() > 7205 )
{
m_customExpressionName = GetCurrentParam( ref nodeParams );
SetTitleText( m_customExpressionName );
}
if( UIUtils.CurrentShaderVersion() > 14401 )
{
m_generateUniqueName = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
}
if( UIUtils.CurrentShaderVersion() > 15102 )
{
m_autoRegisterMode = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
}
if( UIUtils.CurrentShaderVersion() > 15403 )
{
int dependencyCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
for( int i = 0 ; i < dependencyCount ; i++ )
{
m_dependencies.Add( new CustomExpressionDependency( GetCurrentParam( ref nodeParams ) ) );
}
}
if( UIUtils.CurrentShaderVersion() > 18901 )
{
m_fileGUID = GetCurrentParam( ref nodeParams );
if( !string.IsNullOrEmpty( m_fileGUID ) )
{
m_fileAsset = AssetDatabase.LoadAssetAtPath<TextAsset>( AssetDatabase.GUIDToAssetPath( m_fileGUID ) );
}
m_precisionSuffix = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
}
if( m_mode == CustomExpressionMode.Create )
{
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.AddNode( this );
}
UpdateOutputPorts();
m_repopulateNameDictionary = true;
m_functionMode = m_code.Contains( ReturnHelper );
CheckCallMode();
}
public override void WriteToString( ref string nodeInfo , ref string connectionsInfo )
{
base.WriteToString( ref nodeInfo , ref connectionsInfo );
m_code = m_code.Replace( Constants.LineFeedSeparator.ToString() , string.Empty );
m_code = m_code.Replace( Constants.SemiColonSeparator.ToString() , string.Empty );
m_code = UIUtils.ForceLFLineEnding( m_code );
string parsedCode = m_code.Replace( '\n' , Constants.LineFeedSeparator );
parsedCode = parsedCode.Replace( ';' , Constants.SemiColonSeparator );
IOUtils.AddFieldValueToString( ref nodeInfo , parsedCode );
IOUtils.AddFieldValueToString( ref nodeInfo , m_outputTypeIdx );
//IOUtils.AddFieldValueToString( ref nodeInfo, m_mode == CustomExpressionMode.Call );
IOUtils.AddFieldValueToString( ref nodeInfo , m_mode );
int count = m_inputPorts.Count - m_firstAvailablePort;
IOUtils.AddFieldValueToString( ref nodeInfo , count );
for( int i = 0 ; i < count ; i++ )
{
int portIdx = m_firstAvailablePort + i;
IOUtils.AddFieldValueToString( ref nodeInfo , m_items[ i ].FoldoutFlag );
IOUtils.AddFieldValueToString( ref nodeInfo , m_inputPorts[ portIdx ].Name );
IOUtils.AddFieldValueToString( ref nodeInfo , m_inputPorts[ portIdx ].DataType );
IOUtils.AddFieldValueToString( ref nodeInfo , m_inputPorts[ portIdx ].InternalData );
IOUtils.AddFieldValueToString( ref nodeInfo , m_items[ i ].Qualifier );
IOUtils.AddFieldValueToString( ref nodeInfo , m_items[ i ].CustomType );
IOUtils.AddFieldValueToString( ref nodeInfo , m_items[ i ].Precision );
IOUtils.AddFieldValueToString( ref nodeInfo , m_items[ i ].IsVariable );
}
IOUtils.AddFieldValueToString( ref nodeInfo , m_customExpressionName );
IOUtils.AddFieldValueToString( ref nodeInfo , m_generateUniqueName );
IOUtils.AddFieldValueToString( ref nodeInfo , m_autoRegisterMode );
count = m_dependencies.Count;
IOUtils.AddFieldValueToString( ref nodeInfo , count );
for( int i = 0 ; i < count ; i++ )
{
IOUtils.AddFieldValueToString( ref nodeInfo , m_dependencies[ i ].DependencyNodeId );
}
m_fileGUID = ( m_fileAsset == null ) ? string.Empty :
AssetDatabase.AssetPathToGUID( AssetDatabase.GetAssetPath( m_fileAsset ) );
IOUtils.AddFieldValueToString( ref nodeInfo , m_fileGUID );
IOUtils.AddFieldValueToString( ref nodeInfo , m_precisionSuffix );
}
public override void Destroy()
{
base.Destroy();
if( m_mode == CustomExpressionMode.Create )
{
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.RemoveNode( this );
}
m_items.Clear();
m_items = null;
m_dependencies.Clear();
m_dependencies = null;
m_itemReordableList = null;
}
public void CheckDependencies( ref MasterNodeDataCollector dataCollector , ref Dictionary<int , CustomExpressionNode> examinedNodes )
{
if( !examinedNodes.ContainsKey( UniqueId ) && m_mode == CustomExpressionMode.Create && !m_generateUniqueName )
{
int dependencyCount = m_dependencies.Count;
for( int d = 0 ; d < dependencyCount ; d++ )
{
if( !examinedNodes.ContainsKey( m_dependencies[ d ].DependencyNodeId ) )
{
CustomExpressionNode dNode = m_containerGraph.GetNode( m_dependencies[ d ].DependencyNodeId ) as CustomExpressionNode;
if( dNode == null )
{
dNode = UIUtils.CurrentWindow.OutsideGraph.GetNode( m_dependencies[ d ].DependencyNodeId ) as CustomExpressionNode;
}
if( dNode != null )
{
dNode.CheckDependencies( ref dataCollector , ref examinedNodes );
}
}
}
dataCollector.AddFunction( ExpressionName , EncapsulatedCode( dataCollector.IsTemplate ) );
examinedNodes.Add( UniqueId , this );
}
}
public string EncapsulatedCode( bool isTemplate )
{
string functionName = UIUtils.RemoveInvalidCharacters( m_customExpressionName );
if( m_generateUniqueName )
{
functionName += OutputId;
}
return WrapCodeInFunction( isTemplate , functionName , false );
}
public CustomExpressionMode Mode
{
get { return m_mode; }
set
{
if( m_mode != value )
{
m_mode = value;
if( m_mode == CustomExpressionMode.Call )
{
AutoRegisterMode = false;
m_generateUniqueName = false;
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.RemoveNode( this );
}
else if( m_mode == CustomExpressionMode.File )
{
m_generateUniqueName = false;
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.RemoveNode( this );
}
else if( m_mode == CustomExpressionMode.Create )
{
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.AddNode( this );
}
}
}
}
public string ExpressionName
{
get
{
string expressionName = UIUtils.RemoveInvalidCharacters( m_customExpressionName );
if( m_generateUniqueName )
{
expressionName += OutputId;
}
return expressionName;
}
}
public override string DataToArray { get { return m_customExpressionName; } }
public bool AutoRegisterMode
{
get { return m_autoRegisterMode; }
set
{
if( value != m_autoRegisterMode )
{
m_autoRegisterMode = value;
}
}
}
public override void RefreshExternalReferences()
{
base.RefreshExternalReferences();
int portCount = m_inputPorts.Count;
for( int i = 0 ; i < portCount ; i++ )
{
if( m_inputPorts[ i ].DataType == WirePortDataType.COLOR )
{
m_inputPorts[ i ].ChangeType( WirePortDataType.FLOAT4 , false ); ;
}
}
int dependencyCount = m_dependencies.Count;
for( int i = 0 ; i < dependencyCount ; i++ )
{
m_dependencies[ i ].DependencyArrayIdx = UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.GetNodeRegisterIdx( m_dependencies[ i ].DependencyNodeId );
}
//Fixing bug where user could set main output port as OBJECT
if( m_outputPorts[ 0 ].DataType == WirePortDataType.OBJECT && ( m_voidMode || m_mode == CustomExpressionMode.Call ) )
{
m_outputPorts[ 0 ].ChangeType( m_inputPorts[ 0 ].DataType , false );
}
}
public override void FireTimedUpdate()
{
UIUtils.CurrentWindow.OutsideGraph.CustomExpressionOnFunctionMode.UpdateDataOnNode( UniqueId , m_customExpressionName );
}
public List<CustomExpressionDependency> Dependencies { get { return m_dependencies; } }
}
}