示例#1
0
    public void AddToContent(IModelBase item)
    {
        var prefabObject = Instantiate(prefab, content.transform, false);

        prefabObject.GetModelComponentBase();
        IModelComponentBase componentBase = prefab.GetModelComponentBase();

        componentBase.SetModel(item);
        contentPrefabObjectList.Add(componentBase);
    }
示例#2
0
    //<summary>
    //Return the first component that implements IModelComponentBase in provided GameObject
    //</summary>
    public static IModelComponentBase GetModelComponentBase(this GameObject gameObject)
    {
        Component[]         components    = gameObject.GetComponents <Component>();
        IModelComponentBase componentBase = null;

        for (int i = 0; i < components.Length; i++)
        {
            var c = components[i];
            if (c is IModelComponentBase)
            {
                componentBase = c as IModelComponentBase;
                break;
            }
        }

        if (componentBase == null)
        {
            throw new Exception("Não há um IModelComponentBase nesse gameObject!");
        }
        else
        {
            return(componentBase);
        }
    }