/// <summary> /// Should return base type object? /// </summary> /// <param name="typeName">Name of the type.</param> /// <returns></returns> // public bool shouldReturnBaseTypeObject(string typeName) // { // // } /// <summary> /// Sets the object. /// if e == UpdateRefARGV, currIndex must be set before this function /// /// operation of this function: /// 1) if JavaScript already exists, return that JavaScript object. /// 2) else, create a new JavaScript object and return it. /// </summary> /// <param name="e">The e.</param> /// <param name="csObj">The cs object.</param> /// <returns></returns> public int setObject(/* JSApi.SetType */ int e, object csObj) { // http://answers.unity3d.com/questions/1087158/unityengineobject-is-null-but-systemobject-is-not.html if (csObj != null && (csObj is UnityEngine.Object)) { if (csObj.Equals(null)) { csObj = null; } } int jsObjID = 0; if (csObj != null) { Type csType = csObj.GetType(); JSCache.TypeInfo typeInfo = JSCache.GetTypeInfo(csType); if (typeInfo.IsClass) { jsObjID = JSMgr.getJSObj(csObj, typeInfo); } if (jsObjID == 0) { if (csObj is CSRepresentedObject) { jsObjID = ((CSRepresentedObject)csObj).jsObjID; } else { if (typeInfo.IsDelegate) { jsObjID = JSMgr.getFunIDByDelegate((Delegate)csObj); } if (jsObjID == 0) { string typeName = string.Empty; // create a JSRepresentedObject object in JS to represent a C# delegate object if (typeInfo.IsDelegate) { typeName = "JSRepresentedObject"; jsObjID = JSApi.createJSClassObject(typeName); } else { typeName = typeInfo.JSTypeFullName; jsObjID = JSApi.createJSClassObject(typeName); if (jsObjID == 0) { Type baseType = csType.BaseType; JSCache.TypeInfo baseTypeInfo = JSCache.GetTypeInfo(baseType); if (baseType != null) { var baseTypeName = baseTypeInfo.JSTypeFullName; jsObjID = JSApi.createJSClassObject(baseTypeName); if (jsObjID != 0) { Debug.LogWarning("WARNING: Return a \"" + typeName + "\" to JS failed. Return base type\"" + baseTypeName + "\" instead."); } } } } if (jsObjID != 0) { JSMgr.addJSCSRel(jsObjID, csObj); } else { Debug.LogError("Return a \"" + typeName + "\" to JS failed. Did you forget to export that class?"); } } } } } JSApi.setObject(e, jsObjID); return(jsObjID); }