Unity资产错误 - 在Unity 5中加载Unity 4资产时无法从'ViNode []'转换为'UnityEngine.Object'

时间:2016-12-06 16:14:46

标签: c# unity3d

我正在尝试在Unity v5.0中使用Unity v4中创建的资源。在导入之后我修复了各种“过时”的错误,但我似乎无法绕过它。

我得到的错误是:

  

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

此错误出现在以下行:

Undo.RecordObject(childNodes, "ReIndexChildren");"

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

以下是资产的代码:

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 ){
        // ...
    }   
}

1 个答案:

答案 0 :(得分:1)

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

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

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

    node.ReIndexChildren ();
}