首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >统一资产错误-在联合5中加载统一4资产时不能从“ViNode[]”转换为“UnityEngine.Object”

统一资产错误-在联合5中加载统一4资产时不能从“ViNode[]”转换为“UnityEngine.Object”
EN

Stack Overflow用户
提问于 2016-12-06 16:14:46
回答 1查看 98关注 0票数 0

我正在尝试使用UnityV5.0中在UnityV5.0中创建的资产。在完成导入之后,我修复了各种“过时”的错误,但我似乎无法回避。

我得到的错误是:

无法从“ViNode[]”转换为“UnityEngine.Object”

这个错误出现在下面一行:

代码语言:javascript
复制
Undo.RecordObject(childNodes, "ReIndexChildren");"

是否需要将childNodes转换为GameObject?或者,我可以在这里使用Undo.RecordObject()的替代方案吗?

以下是资产的代码:

代码语言:javascript
复制
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using ViNoToolkit;
using System.Collections;

/// <summary>
/// Draw NodeI .
/// </summary>
static public class NodeGUI{

    static private int k_PositionEntryNum = 5;      

    /// <summary>
    /// Raises the GUI selection unit event.
    /// </summary>
    /// <param name="unit">Unit.</param>
    static public void OnGUISelectionUnit( SelectionsNode.SelectUnit unit ){
        // ...
    }

    /// <summary>
    /// Raises the GUI ViNode event.
    /// </summary>
    /// <param name="node">Node.</param>
    /// <param name="drawChildList">If set to <c>true</c> draw child list.</param>
    /// <param name="showNextNode">If set to <c>true</c> show next node.</param>
    static public void  OnGUI_ViNode(GameObject[] objs, ViNode node , bool drawChildList , bool showNextNode )
    {       
        GUICommon.DrawLineSpace( 7f , 7f );

        bool hasViNode = false;
        if( drawChildList ){

            Color savedCol = GUI.color;
            GUI.color = Color.green;

            int childCount= node.transform.childCount ;
            for( int i=0;i<childCount;i++){         
                Transform childTra = node.transform.GetChild( i );
                ViNode vinode = childTra.GetComponent<ViNode>();
                if( vinode != null ){                   
                    hasViNode = true;                   
                    Undo.RecordObject( childTra.gameObject , "active" + childTra.name );                

                    EditorGUILayout.BeginHorizontal();                      
//                      bool t = EditorGUILayout.Toggle( childTra.gameObject.activeInHierarchy , GUILayout.Width( 10f) );

                        // Toggle active.
                        if( GUILayout.Button( i.ToString () , GUILayout.Width ( 20f ) ) ){
                            childTra.gameObject.SetActive( ! childTra.gameObject.activeInHierarchy  );
                        }

                        GUI.enabled = childTra.gameObject.activeInHierarchy;

                        if( GUILayout.Button ( childTra.name ) ){
                            EditorGUIUtility.PingObject( childTra.gameObject );
                            if( Application.isPlaying ){
                                VM.Instance.GoToLabel( vinode.GetNodeLabel() );
                            }
                        }                               

                        GUI.enabled = true;

                    EditorGUILayout.EndHorizontal ();
                }
            }       
            GUI.color = savedCol;           
        }

        if( hasViNode ){
            EditorGUILayout.LabelField( "When execution order is not right in Children," );
            EditorGUILayout.LabelField( "Please push RefreshChildren button to fix." );

            EditorGUILayout.BeginHorizontal();

                if( GUILayout.Button( "RefreshChildren" ) ){
                    node.RefreshChildren();
                }   

                if( GUILayout.Button( "ReIndexChildren" ) ){
                    ViNode[] childNodes = node.GetComponentsInChildren<ViNode>();


                Undo.RecordObject(childNodes, "ReIndexChildren");

                node.ReIndexChildren ();

                }   

            EditorGUILayout.EndHorizontal();            
        }       

        GUICommon.DrawLineSpace( 5f , 5f );         
    }

    static public void DrawItemBarBackground(){
        // ...
    }

    static public void DrawDialogItemBar( DialogPartNode node , ref DialogPartData unit , int index , ViNoTextBox textBox , ViNoTextBox nameTextBox ){      
        // ...  
    }

    static public void DrawEnterActorActionsView(  DialogPartNode node , ref DialogPartData unit ){
        // ...                      
    }

    /// <summary>
    /// Draws the action view mode.
    /// </summary>
    /// <param name="action">Action.</param>
    /// <param name="node">Node.</param>
    /// <param name="unit">Unit.</param>
    /// <param name="index">Index.</param>
    /// <param name="textBox">Text box.</param>
    /// <param name="nameTextBox">Name text box.</param>
    static public void DrawActionViewMode( DialogPartNodeActionType action ,  DialogPartNode node , ref DialogPartData unit , int index , ViNoTextBox textBox , ViNoTextBox nameTextBox ){      
        // ...
    }

    static public void DrawEditTextViewMode( DialogPartNodeActionType action , DialogPartNode node , ref DialogPartData unit , int index , ViNoTextBox textBox , ViNoTextBox nameTextBox ){
        // ...
    }

    static public void OnGUI_a( DialogPartNode node , ref DialogPartData unit , int index , ViNoTextBox textBox , ViNoTextBox nameTextBox , int viewMode ){
        // ...
    }

    static public void DrawLayoutEnterActorField( DialogPartData unit ){
        // ...
    }

    static public void DrawLayoutExitActorField( DialogPartData unit ){
        // ...

    }

    static public void DrawLayoutChangeStateActorField( DialogPartData unit ){
        // ...
    }

    static public void DrawLayoutSceneField( DialogPartData unit ){
        // ...
    }

    /// <summary>
    /// Draws the layout name field.
    /// </summary>
    /// <param name="unit">Unit.</param>
    static public void DrawLayoutNameField( DialogPartData unit ){
        // ...
    }

    /// <summary>
    /// Draws the layout dialog text field.
    /// </summary>
    /// <param name="unit">Unit.</param>
    static public void DrawLayoutDialogTextField( DialogPartData unit ){
        // ...
    }   
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-06 16:28:41

您不能将数组直接传递到Undo.RecordObject() (但为了方便起见,您可以编写扩展方法来处理这个问题)。这里最简单的方法就是循环遍历childNodes并将ViNode的每个实例传递到Undo.RecordObject()

代码语言:javascript
复制
if( GUILayout.Button( "ReIndexChildren" ) ){
    ViNode[] childNodes = node.GetComponentsInChildren<ViNode>();

    foreach (ViNode childNode in childNodes){
        Undo.RecordObject(childNode, "ReIndexChildren");
    }

    node.ReIndexChildren ();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40999935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档