Ejemplo n.º 1
0
 private static TypeCastBool TryCastBool(UInt64 id)
 {
     try {
         return(new TypeCastBool(true, (bool)InstancePool.GetInstance(id)));
     } catch (InvalidCastException _) {
         return(new TypeCastBool(false, default(bool)));
     }
 }
Ejemplo n.º 2
0
 private static TypeCastFloat TryCastFloat(UInt64 id)
 {
     try {
         return(new TypeCastFloat(true, (float)InstancePool.GetInstance(id)));
     } catch (InvalidCastException _) {
         return(new TypeCastFloat(false, default(float)));
     }
 }
Ejemplo n.º 3
0
        public static UniBridgeGlue CreateDefault()
        {
            return(new UniBridgeGlue {
                // エラーおよびログ機能
                _handlePanic = HandlePanic,
                _errorLog = ErrorLog,
                _warnLog = WarnLog,
                _infoLog = InfoLog,
                // メソッド呼び出しおよびインスタンス生成・破棄
                _newInstance = InstancePool.NewInstance,
                _disposeInstance = InstancePool.DisposeInstance,
                _invokeMethod = InstancePool.InvokeMethod,
                _invokeAs = InstancePool.InvokeAs,
                _clone = InstancePool.CloneInstance,
                _getProperty = (UInt64 id, Slice <char> className, Slice <char> propertyName) => {
                    var v = InstancePool.GetInstance(id);
                    var ty = v?.GetType() ?? Type.GetType(className.ToString());
                    var prop = propertyName.ToString();
                    var res = ty.GetProperty(prop);

                    return InstancePool.AppendInstance(
                        res?.GetValue(v)
                        );
                },
                _getField = (UInt64 id, Slice <char> className, Slice <char> fieldName) => {
                    var v = InstancePool.GetInstance(id);
                    var ty = v?.GetType() ?? Type.GetType(className.ToString());
                    var prop = fieldName.ToString();
                    var res = ty.GetField(prop);

                    return InstancePool.AppendInstance(
                        res?.GetValue(v)
                        );
                },
                _setProperty = (UInt64 id, Slice <char> className, Slice <char> propertyName, UInt64 value) => {
                    var v = InstancePool.GetInstance(id);
                    var ty = v?.GetType() ?? Type.GetType(className.ToString());
                    var prop = propertyName.ToString();
                    var res = ty.GetProperty(prop);

                    res?.SetValue(v, InstancePool.GetInstance(value));

                    return true;
                },
                _setField = (UInt64 id, Slice <char> className, Slice <char> fieldName, UInt64 value) => {
                    var v = InstancePool.GetInstance(id);
                    var ty = v?.GetType() ?? Type.GetType(className.ToString());
                    var prop = fieldName.ToString();
                    var res = ty.GetField(prop);

                    res?.SetValue(v, InstancePool.GetInstance(value));

                    return true;
                },
                // 特殊キャスト
                _sizedBytes = b => InstancePool.AppendInstance(b.ToArray()),
                // プリミティブ型 <-> オブジェクト型変換
                _toString = s => InstancePool.AppendInstance(s.ToString()),
                _toF32 = x => InstancePool.AppendInstance(x),
                _tryF32 = TryCastFloat,
                _tryBool = TryCastBool,
            });
        }