private SpriteFont LoadSpriteFont(string asset)
        {
            UnityEngine.TextAsset spriteFontText = (UnityEngine.TextAsset)UnityEngine.Resources.Load(asset, typeof(UnityEngine.TextAsset));

            Dictionary <string, string> fontSettings = new Dictionary <string, string>();

            StringReader stringReader = new StringReader(spriteFontText.text);

#if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
            stringReader.Read();             // Skip the byte order mark on Unity 3.x - note that this seems to work as of Unity 4
#endif

            XmlTextReader xmlReader = new XmlTextReader(stringReader);

            XmlDocument document = new XmlDocument();
            document.Load(xmlReader);

            foreach (XmlNode childNode in document.DocumentElement.ChildNodes[0].ChildNodes)           //[0].ChildNodes)
            {
                // Ignore comments
                if (!childNode.Name.StartsWith("#"))
                {
                    fontSettings.Add(childNode.Name, childNode.InnerText);
                }
            }

            xmlReader.Close();
            stringReader.Close();

            if (fontSettings.ContainsKey("FontName") &&
                fontSettings.ContainsKey("Size") &&
                fontSettings.ContainsKey("Spacing") &&
                fontSettings.ContainsKey("UseKerning") &&
                fontSettings.ContainsKey("Style"))
            {
                SpriteFont spriteFont = new SpriteFont(fontSettings["FontName"], float.Parse(fontSettings["Size"]), float.Parse(fontSettings["Spacing"]), bool.Parse(fontSettings["UseKerning"]), fontSettings["Style"]);

                return(spriteFont);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        internal static int LoadFromResource(RealStatePtr L)
        {
            try
            {
                string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + ".lua";

                // Load with Unity3D resources
                UnityEngine.TextAsset file = (UnityEngine.TextAsset)UnityEngine.Resources.Load(filename);
                if (file == null)
                {
                    LuaAPI.lua_pushstring(L, string.Format(
                                              "\n\tno such resource '{0}'", filename));
                }
                else
                {
#if LUA_DEBUG && UNITY_EDITOR
                    //get asset's absolute path
                    string assetPath = UnityEditor.AssetDatabase.GetAssetPath(file);
                    if (assetPath != "")
                    {
                        //find out asset path, remove assetPath's first "Asset/"
                        int idx = assetPath.IndexOf("/");
                        if (idx > 0)
                        {
                            filename = UnityEngine.Application.dataPath + assetPath.Substring(idx);
                        }
                    }
#endif
                    if (LuaAPI.xluaL_loadbuffer(L, file.bytes, file.bytes.Length, "@" + filename) != 0)
                    {
                        return(LuaAPI.luaL_error(L, String.Format("error loading module {0} from resource, {1}",
                                                                  LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1))));
                    }
                }

                return(1);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in LoadFromResource:" + e));
            }
        }
Exemple #3
0
        public void InitFromFile(string path, bool isReload = false)
        {
            try
            {
                UnityEngine.TextAsset textAsset = Utility.FileUtil.LoadResource <UnityEngine.TextAsset>(path);

                XmlDeserializer serializer = new XmlDeserializer(typeof(T));
                using (StringReader reader = new StringReader(textAsset.text))
                {
                    _data = (T)serializer.Deserialize(reader);
                }
            }
            catch (System.NullReferenceException)
            {
            }
            if (_data == null)
            {
                Common.Log.Logger.Error($"SpecificInfo {typeof(T).Name} Init failed, path : {path}");
            }
        }
        public MidiFile(UnityEngine.TextAsset p_file)
        {
            if (Midi.debugLevel > 2)
            {
                UnityEngine.Debug.Log("Create midi track");
            }
            readFile   = p_file.bytes;
            midiTracks = new List <MidiTrack>();
            int readPos = headerSize; // start from pos 14 in midi array- after header

            setMidiType(readFile[9]);
            setNumTracks(readFile[11]);

            trackPosOffset = headerSize;
            for (int i = 0; i < getNumTracks(); i++)
            {
                readPos += 4; // 4 bytes for first half of track header
                readPos  = readTrack(readPos);
            }
        }
        /// <summary>Sets up the bidirectional data.</summary>
        public static void Setup()
        {
            if (Blocks != null)
            {
                return;
            }

            // Get the bidi data now:

                        #if UNITY
            // Get the entity file:
            UnityEngine.TextAsset bidiData = (UnityEngine.Resources.Load("BidirectionalData") as UnityEngine.TextAsset);

            if (bidiData == null)
            {
                return;
            }

            byte[] file = bidiData.bytes;

            // Create a reader:
            BinaryIO.Reader reader = new BinaryIO.Reader(file);

            int count = (int)reader.ReadCompressed();
            Blocks = new BidiBlock[count];
            int index = 0;

            // Setup all blocks:
            while (reader.More())
            {
                // Read the block:
                Blocks[index++] = new BidiBlock(
                    (int)reader.ReadCompressed(),
                    (int)reader.ReadCompressed(),
                    reader.ReadByte()
                    );
            }
                        #else
                                #warning Bidirectional data not available
                        #endif
        }
        static StackObject *SetJson_8(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.TextAsset @data = (UnityEngine.TextAsset) typeof(UnityEngine.TextAsset).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = LCL.MonoTool.SetJson(@data);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
        void LoadResourcesUnityNative(string assetsPath)
        {
            try
            {
                UnityEngine.Object[] array = UnityEngine.Resources.LoadAll(assetsPath, typeof(UnityEngine.TextAsset));

                for (int i = 0; i < array.Length; i++)
                {
                    UnityEngine.TextAsset o = (UnityEngine.TextAsset)array[i];

                    string name = o.name;
                    string text = o.text;

                    m_Resources.Add(name, text);
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogErrorFormat("Error initializing UnityScriptLoader : {0}", ex);
            }
        }
        static int _m_ToString(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            UnityEngine.TextAsset __cl_gen_to_be_invoked = (UnityEngine.TextAsset)translator.FastGetCSObj(L, 1);


            try {
                {
                    string __cl_gen_ret = __cl_gen_to_be_invoked.ToString(  );
                    LuaAPI.lua_pushstring(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
Exemple #9
0
        internal static int LoadFromResource(RealStatePtr L)
        {
            string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + ".lua";

            // Load with Unity3D resources
            UnityEngine.TextAsset file = (UnityEngine.TextAsset)UnityEngine.Resources.Load(filename);
            if (file == null)
            {
                LuaAPI.lua_pushstring(L, string.Format(
                                          "\n\tno such resource '{0}'", filename));
            }
            else
            {
                if (LuaAPI.luaL_loadbuffer(L, file.text, "@" + filename) != 0)
                {
                    return(LuaAPI.luaL_error(L, String.Format("error loading module {0} from resource, {1}",
                                                              LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1))));
                }
            }

            return(1);
        }
Exemple #10
0
        public void InitList(string listFilePath)
        {
            List <string> infoPathList = null;

            try
            {
                UnityEngine.TextAsset textAsset  = Utility.FileUtil.LoadResource <UnityEngine.TextAsset>(listFilePath);
                XmlDeserializer       serializer = new XmlDeserializer(typeof(List <string>));
                using (StringReader reader = new StringReader(textAsset.text))
                {
                    infoPathList = (List <string>)serializer.Deserialize(reader);

                    foreach (string path in infoPathList)
                    {
                        SimpleInit(path, false);
                    }
                }
            }
            catch (System.NullReferenceException)
            {
            }
        }
Exemple #11
0
        static StackObject *SetResult_5(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.TextAsset @ret = (UnityEngine.TextAsset) typeof(UnityEngine.TextAsset).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            ET.ETAsyncTaskMethodBuilder <UnityEngine.TextAsset> instance_of_this_method = (ET.ETAsyncTaskMethodBuilder <UnityEngine.TextAsset>) typeof(ET.ETAsyncTaskMethodBuilder <UnityEngine.TextAsset>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 16);

            instance_of_this_method.SetResult(@ret);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            return(__ret);
        }
        static int _m_LoadTextAsset_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                {
                    string _path = LuaAPI.lua_tostring(L, 1);

                    UnityEngine.TextAsset gen_ret = ETCold.LoadHelper.LoadTextAsset(
                        _path);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
        internal static int LoadFromResource(RealStatePtr L)
        {
            try
            {
                string filename = LuaAPI.lua_tostring(L, 1).Replace('.', '/') + ".lua";
                UnityEngine.TextAsset file;
                // Load with Unity3D resources
                if (File.Exists(filename))
                {
                    Byte[] fileByte = File.ReadAllBytes(filename);
                    String fileText = System.Text.Encoding.Default.GetString(fileByte);
                    file = new UnityEngine.TextAsset(fileText);
                }
                else
                {
                    file = (UnityEngine.TextAsset)UnityEngine.Resources.Load(filename);
                }
                if (file == null)
                {
                    LuaAPI.lua_pushstring(L, string.Format(
                                              "\n\tno such resource '{0}'", filename));
                }
                else
                {
                    if (LuaAPI.xluaL_loadbuffer(L, file.bytes, file.bytes.Length, "@" + filename) != 0)
                    {
                        return(LuaAPI.luaL_error(L, String.Format("error loading module {0} from resource, {1}",
                                                                  LuaAPI.lua_tostring(L, 1), LuaAPI.lua_tostring(L, -1))));
                    }
                }

                return(1);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in LoadFromResource:" + e));
            }
        }
Exemple #14
0
        private static byte[] LoadFileFromDisk(byte *fileName)
        {
            string fileNameStr = System.Runtime.InteropServices.Marshal.PtrToStringAnsi((System.IntPtr)fileName);

            if (fileNameStr.StartsWith("${RESOURCES}"))
            {
                #if UNITY_5 || UNITY_2017 || UNITY_2018
                fileNameStr = fileNameStr.Substring(13);
                UnityEngine.TextAsset bindata = UnityEngine.Resources.Load <UnityEngine.TextAsset>(fileNameStr);
                return(bindata != null ? bindata.bytes : null);
                #else
                return(null);
                #endif
            }
            else
            {
                if (!System.IO.File.Exists(fileNameStr))
                {
                    return(null);
                }
                return(System.IO.File.ReadAllBytes(fileNameStr));
            }
        }
        /// <summary>
        /// Loads all blocktypes from the file "Definitions/blocks.xml"
        /// </summary>
        public static void LoadBlockTypes()
        {
            XmlDocument document = new XmlDocument();

            UnityEngine.TextAsset file = UnityEngine.Resources.Load("Definitions/blocks") as UnityEngine.TextAsset;
            document.LoadXml(file.text);

            XmlNodeList blocks = document.GetElementsByTagName("block");

            for (int i = 0; i < blocks.Count; i++)
            {
                try {
                    var    block       = blocks.Item(i);
                    var    attribs     = block.ChildNodes;
                    string name        = attribs.Item(0).InnerText;
                    string texturename = attribs.Item(1).InnerText;
                    bool   solid       = attribs.Item(2).InnerText == "True" ? true : false;
                    AddBlockType(name, solid, texturename);
                } catch (System.Exception e)
                {
                }
            }
        }
Exemple #16
0
        static int _m_LoadTextAsset(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            Maria.Util.ABLoader __cl_gen_to_be_invoked = (Maria.Util.ABLoader)translator.FastGetCSObj(L, 1);


            try {
                {
                    string path = LuaAPI.lua_tostring(L, 2);
                    string name = LuaAPI.lua_tostring(L, 3);

                    UnityEngine.TextAsset __cl_gen_ret = __cl_gen_to_be_invoked.LoadTextAsset(path, name);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }
        }
        int __CreateInstanceUnityEngineTextAsset(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;

            if (gen_param_count == 1)
            {
                UnityEngine.TextAsset gen_ret = new UnityEngine.TextAsset();
                translator.Push(L, gen_ret);

                return(1);
            }
            if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
            {
                string _text = LuaAPI.lua_tostring(L, 2);

                UnityEngine.TextAsset gen_ret = new UnityEngine.TextAsset(_text);
                translator.Push(L, gen_ret);

                return(1);
            }


            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.TextAsset constructor!"));
        }
        static int _m_GetTextAsset_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                {
                    UnityEngine.GameObject _gameObject = (UnityEngine.GameObject)translator.GetObject(L, 1, typeof(UnityEngine.GameObject));
                    string _key = LuaAPI.lua_tostring(L, 2);

                    UnityEngine.TextAsset gen_ret = DCETRuntime.GameObjectHelper.GetTextAsset(
                        _gameObject,
                        _key);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemple #19
0
 public System.Collections.IEnumerator CreateNewRoleJsonDic(RoleAnaimationData animationData, UnityEngine.TextAsset equipmentJson, List <string> slotAttachmentNameList, Spine.Unity.SkeletonAnimation skeletonAnim, Action <bool> setRoleStatus, bool isCreateNewJson = false)
 {
     if (isCreateNewJson)
     {
         #region 注释掉了
         // //重新绑定引用(更换attachment之后顶点动画引用丢失的情况)
         // //1.把当前装备所替换的attachment保存起来,再分别找到各个attachment在当前装备json中的顶点动画数据。
         // //2.把各个attachment的顶点动画数据复制到roleJson中。
         // //3.利用新的roleJson生成新的动画并和新的attachment进行绑定。(可以用litjson插件替换json里面的数据)
         // Dictionary<string, JsonData> dic = new Dictionary<string, JsonData> ();
         // JsonData allDataFromEquipment = JsonMapper.ToObject (equipmentJson.text);
         // JsonData animDataFromEquipment = allDataFromEquipment.TryGetData ("animations");
         // string[] animNamesFromEquipment = new string[animDataFromEquipment.Count];
         // animDataFromEquipment.Keys.CopyTo (animNamesFromEquipment, 0);
         // //1.先从当前装备的json中拿出来
         // for (int i = 0; i < slotAttachmentNameList.Count; i++) {
         //     for (int j = 0; j < animDataFromEquipment.Count; j++) {
         //         JsonData deformData = animDataFromEquipment[j].TryGetData ("deform");
         //         if (null != deformData) {
         //             JsonData slotData = deformData.TryGetData (SpineConstValue.defaultSkinName).TryGetData (slotAttachmentNameList[i].Split ('$') [0]);
         //             if (null != slotData) {
         //                 JsonData attachmentData = slotData.TryGetData (slotAttachmentNameList[i].Split ('$') [1]);
         //                 dic.Add (animNamesFromEquipment[j] + "$deform$" + SpineConstValue.defaultSkinName + "$" + slotAttachmentNameList[i].Split ('$') [0] + "$" + slotAttachmentNameList[i].Split ('$') [1], attachmentData);
         //             }
         //         }
         //         yield return null;
         //     }
         // }
         // //2.重新组装到roleJson中
         // JsonData allDataFromRoleJson = JsonMapper.ToObject (animationData.roleJsonStr);
         // foreach (KeyValuePair<string, JsonData> keyValue in dic) {
         //     JsonData animsData = allDataFromRoleJson.TryGetData ("animations");
         //     string[] keys = keyValue.Key.Split ('$');
         //     int length = keys.Length;
         //     if (null != animsData) {
         //         for (int i = 0; i < length; i++) {
         //             animsData = animsData.TryGetData (keys[i]);
         //             if (null != animsData) {
         //                 if (i >= length - 1) {
         //                     string newJsonStr = keyValue.Value.ToJson ().Substring (1, keyValue.Value.ToJson ().Length - 2);
         //                     animsData.Add (JsonMapper.ToObject (newJsonStr));
         //                     yield return null;
         //                 }
         //                 continue;
         //             } else {
         //                 break;
         //             }
         //         }
         //     }
         // }
         // //3.刷新json
         // animationData.roleJsonStr = allDataFromRoleJson.ToJson ().ToString ();
         #endregion
         skeletonAnim.skeleton.data.animations.Clear(true);
         this.animationData          = animationData;
         this.equipmentJson          = equipmentJson.text;
         this.slotAttachmentNameList = slotAttachmentNameList;
         this.skeletonAnim           = skeletonAnim;
         this.setRoleStatus          = setRoleStatus;
         thread = new System.Threading.Thread(new System.Threading.ThreadStart(CopyJsonData));
         thread.IsBackground = false;
         thread.Start();
         while (!isFinshedThread)
         {
             yield return(null);
         }
         var input = new StringReader(this.animationData.roleJsonStr);
         Dictionary <String, System.Object> tempDic = GetDictionaryTypeObject((Json.Deserialize(input) as Dictionary <String, Object>) ["animations"]);
         if (null != tempDic)
         {
             foreach (KeyValuePair <string, System.Object> entry in tempDic)
             {
                 try {
                     SpineCreateAttachment.Instance.ReadAnimation((Dictionary <string, System.Object>)entry.Value, entry.Key, skeletonAnim.Skeleton.Data);
                 } catch (Exception e) {
                     throw new Exception("Error reading animation: " + entry.Key, e);
                 }
             }
             skeletonAnim.AnimationState.SetAnimation(SpineConstValue.TrackIndex, skeletonAnim.AnimationState.GetCurrent(SpineConstValue.TrackIndex).animation.name, true);
         }
     }
 }
Exemple #20
0
        /** CoroutineMain
         */
        public System.Collections.IEnumerator CoroutineMain(Fee.File.OnFileCoroutine_CallBackInterface a_callback_interface, Fee.File.Path a_path)
        {
            //result
            this.result = null;

            //ロード。
            UnityEngine.Object t_result_object = null;
            {
                UnityEngine.ResourceRequest t_request = null;

                try{
                    t_request = UnityEngine.Resources.LoadAsync(a_path.GetPath());
                    if (t_request == null)
                    {
                        //エラー。
                        this.result = new ResultType(null, "Unknown Error : LoadResourcesTextFile : " + a_path.GetPath());
                        yield break;
                    }
                }catch (System.Exception t_exception) {
                    //エラー。
                    this.result = new ResultType(null, "Unknown Error : LoadResourcesPrefabFile : " + a_path.GetPath() + " : " + t_exception.Message);
                    yield break;
                }

                do
                {
                    //キャンセルチェック。
                    {
                        if (a_callback_interface != null)
                        {
                            if (a_callback_interface.OnFileCoroutine(t_request.progress) == false)
                            {
                                //t_request.Cancel();
                            }
                        }
                    }

                    yield return(null);
                }while(t_request.isDone == false);

                if (t_request.asset == null)
                {
                    //エラー。
                    this.result = new ResultType(null, "Load Error : LoadResourcesTextFile : " + a_path.GetPath());
                    yield break;
                }

                t_result_object = t_request.asset;
            }

            //コンバート。
            string t_result_text = null;

            {
                UnityEngine.TextAsset t_textasset = t_result_object as UnityEngine.TextAsset;
                if (t_textasset == null)
                {
                    //エラー。
                    this.result = new ResultType(null, "Convert Error : LoadResourcesTextFile : " + a_path.GetPath());
                    yield break;
                }

                string t_result = null;

                try{
                    t_result = t_textasset.text;
                }catch (System.Exception t_exception) {
                    //エラー。
                    this.result = new ResultType(null, "Convert Error : LoadResourcesTextFile : " + a_path.GetPath() + " : " + t_exception.Message);
                    yield break;
                }

                if (t_result == null)
                {
                    //エラー。
                    this.result = new ResultType(null, "Convert Error : LoadResourcesTextFile : " + a_path.GetPath());
                    yield break;
                }

                t_result_text = t_result;
            }

            //成功。
            this.result = new ResultType(t_result_text, null);
            yield break;
        }
Exemple #21
0
 /// <summary>
 /// TextAssetから文字列を読み込む関数
 /// </summary>
 /// <param name="textAsset"></param>
 /// <returns>ASCII形式でエンコードされた文字列を返す</returns>
 private static string LoadTextAsset(UnityEngine.TextAsset textAsset)
 {
     // バイト列でまず読み込み
     byte[] bytes = textAsset.bytes;
     return(System.Text.Encoding.ASCII.GetString(bytes));
 }
        /// <summary>
        /// Validates an ARENA2 folder.
        ///  This currently just checks the right major files exist in the right quantities.
        ///  Does not verify contents so test is quite speedy and can be performed at startup.
        ///  Will also look for main .BSA files in Unity Resources folder.
        /// </summary>
        /// <param name="path">Full path of ARENA2 folder to validate.</param>
        /// <param name="results">Output results.</param>
        /// <param name="requireVideos">Videos must be present to pass final validation.</param>
        public static void ValidateArena2Folder(string path, out ValidationResults results, bool requireVideos = false)
        {
            results            = new ValidationResults();
            results.PathTested = path;

            // Check folder exists
            if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
            {
                return;
            }
            else
            {
                results.FolderValid = true;
            }

            // Get files
            string[] textures = Directory.GetFiles(path, textureSearchPattern);
            string[] models   = Directory.GetFiles(path, Arch3dFile.Filename);
            string[] blocks   = Directory.GetFiles(path, BlocksFile.Filename);
            string[] maps     = Directory.GetFiles(path, MapsFile.Filename);
            string[] sounds   = Directory.GetFiles(path, SndFile.Filename);
            string[] woods    = Directory.GetFiles(path, WoodsFile.Filename);
            string[] videos   = Directory.GetFiles(path, vidSearchPattern);

            // Validate texture count
            if (textures.Length >= minTextureCount)
            {
                results.TexturesValid = true;
            }

            // Validate models count
            if (models.Length >= 1)
            {
                results.ModelsValid = true;
            }

            // Validate blocks count
            if (blocks.Length >= 1)
            {
                results.BlocksValid = true;
            }

            // Validate maps count
            if (maps.Length >= 1)
            {
                results.MapsValid = true;
            }

            // Validate sounds count
            if (sounds.Length >= 1)
            {
                results.SoundsValid = true;
            }

            // Validate woods count
            if (woods.Length >= 1)
            {
                results.WoodsValid = true;
            }

            // Validate videos count
            if (videos.Length >= minVidCount)
            {
                results.VideosValid = true;
            }

            // Support alternate ARCH3D.BSA from Resources if available
            if (!results.ModelsValid)
            {
                UnityEngine.TextAsset arch3dAsset = UnityEngine.Resources.Load(Arch3dFile.Filename) as UnityEngine.TextAsset;
                if (arch3dAsset != null)
                {
                    results.ModelsValid = true;
                }
            }

            // Supports alternate BLOCKS.BSA from Resources if available
            if (!results.BlocksValid)
            {
                UnityEngine.TextAsset blocksAsset = UnityEngine.Resources.Load(BlocksFile.Filename) as UnityEngine.TextAsset;
                if (blocksAsset != null)
                {
                    results.BlocksValid = true;
                }
            }

            // Supports alternate MAPS.BSA from Resources if available
            if (!results.MapsValid)
            {
                UnityEngine.TextAsset mapsAsset = UnityEngine.Resources.Load(MapsFile.Filename) as UnityEngine.TextAsset;
                if (mapsAsset != null)
                {
                    results.MapsValid = true;
                }
            }

            // Supports alternate DAGGER.SND from Resources if available
            if (!results.SoundsValid)
            {
                UnityEngine.TextAsset soundAsset = UnityEngine.Resources.Load(SndFile.Filename) as UnityEngine.TextAsset;
                if (soundAsset != null)
                {
                    results.SoundsValid = true;
                }
            }

            // Supports alternate WOODS.WLD from Resources if available
            if (!results.WoodsValid)
            {
                UnityEngine.TextAsset woodsAsset = UnityEngine.Resources.Load(WoodsFile.Filename) as UnityEngine.TextAsset;
                if (woodsAsset != null)
                {
                    results.WoodsValid = true;
                }
            }

            // Supports alternate *.VID from Resources if available
            // Just tests for smallest video for performance reasons
            // Assumes build creator has added all other videos
            if (!results.VideosValid)
            {
                UnityEngine.TextAsset videoAsset = UnityEngine.Resources.Load(vidAlternateTestFile) as UnityEngine.TextAsset;
                if (videoAsset != null)
                {
                    results.VideosValid = true;
                }
            }

            // If everything else is valid then set AppearsValid flag
            if (results.FolderValid &&
                results.TexturesValid &&
                results.ModelsValid &&
                results.BlocksValid &&
                results.MapsValid &&
                results.SoundsValid &&
                results.WoodsValid)
            {
                results.AppearsValid = true;
            }

            // Check videos
            if (requireVideos && !results.VideosValid)
            {
                results.AppearsValid = false;
            }
        }
Exemple #23
0
 public SpriteFont(UnityEngine.TextAsset asset)
 {
 }
Exemple #24
0
 private void LoadHuType()
 {
     UnityEngine.TextAsset ts = ABLoader.current.LoadTextAsset("Excels", "hutype");
 }
Exemple #25
0
 private void LoadData()
 {
     UnityEngine.TextAsset ts = ABLoader.current.LoadTextAsset("Excels", "data");
 }
Exemple #26
0
        /// <summary>
        /// Validates an ARENA2 folder.
        ///  This currently just checks the right major files exist in the right quantities.
        ///  Does not verify contents so test is quite speedy and can be performed at startup.
        ///  Will also look for main .BSA files in Unity Resources folder.
        ///  Does not verify texture/image files.
        /// </summary>
        /// <param name="path">Full path of ARENA2 folder to validate.</param>
        /// <param name="results">Output results.</param>
        public static void ValidateArena2Folder(string path, out ValidationResults results)
        {
            results            = new ValidationResults();
            results.PathTested = path;

            // Check folder exists
            if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
            {
                return;
            }
            else
            {
                results.FolderValid = true;
            }

            // Get files
            //string[] textures = Directory.GetFiles(path, "TEXTURE.???");
            string[] models = Directory.GetFiles(path, Arch3dFile.Filename);
            string[] blocks = Directory.GetFiles(path, BlocksFile.Filename);
            string[] maps   = Directory.GetFiles(path, MapsFile.Filename);
            string[] sounds = Directory.GetFiles(path, SndFile.Filename);
            string[] woods  = Directory.GetFiles(path, WoodsFile.Filename);

            //// Validate texture count
            //if (textures.Length >= 472)
            //    results.TexturesValid = true;

            // Validate models count
            if (models.Length >= 1)
            {
                results.ModelsValid = true;
            }

            // Validate blocks count
            if (blocks.Length >= 1)
            {
                results.BlocksValid = true;
            }

            // Validate maps count
            if (maps.Length >= 1)
            {
                results.MapsValid = true;
            }

            // Validate sounds count
            if (sounds.Length >= 1)
            {
                results.SoundsValid = true;
            }

            // Validate woods count
            if (woods.Length >= 1)
            {
                results.WoodsValid = true;
            }

            // Support alternate ARCH3D.BSA from Resources if available
            if (!results.ModelsValid)
            {
                UnityEngine.TextAsset arch3dAsset = UnityEngine.Resources.Load(Arch3dFile.Filename) as UnityEngine.TextAsset;
                if (arch3dAsset != null)
                {
                    results.ModelsValid = true;
                }
            }

            // Supports alternate BLOCKS.BSA from Resources if available
            if (!results.BlocksValid)
            {
                UnityEngine.TextAsset blocksAsset = UnityEngine.Resources.Load(BlocksFile.Filename) as UnityEngine.TextAsset;
                if (blocksAsset != null)
                {
                    results.BlocksValid = true;
                }
            }

            // Supports alternate MAPS.BSA from Resources if available
            if (!results.MapsValid)
            {
                UnityEngine.TextAsset mapsAsset = UnityEngine.Resources.Load(MapsFile.Filename) as UnityEngine.TextAsset;
                if (mapsAsset != null)
                {
                    results.MapsValid = true;
                }
            }

            // Supports alternate DAGGER.SND from Resources if available
            if (!results.SoundsValid)
            {
                UnityEngine.TextAsset soundAsset = UnityEngine.Resources.Load(SndFile.Filename) as UnityEngine.TextAsset;
                if (soundAsset != null)
                {
                    results.SoundsValid = true;
                }
            }

            // Supports alternate WOODS.WLD from Resources if available
            if (!results.WoodsValid)
            {
                UnityEngine.TextAsset woodsAsset = UnityEngine.Resources.Load(WoodsFile.Filename) as UnityEngine.TextAsset;
                if (woodsAsset != null)
                {
                    results.WoodsValid = true;
                }
            }

            // If everything else is valid then set AppearsValid flag
            if (results.FolderValid &&
                //results.TexturesValid &&
                results.ModelsValid &&
                results.BlocksValid &&
                results.MapsValid &&
                results.SoundsValid &&
                results.WoodsValid)
            {
                results.AppearsValid = true;
            }
        }
Exemple #27
0
        protected override void OnInitializePhysics()
        {
            ManifoldPoint.ContactAdded += MyContactCallback;

            SetupEmptyDynamicsWorld();

            //CompoundCollisionAlgorithm.CompoundChildShapePairCallback = MyCompoundChildShapeCallback;
            convexDecompositionObjectOffset = new Vector3(10, 0, 0);


            // Load wavefront file
            var wo = new WavefrontObj();

            //string filename = UnityEngine.Application.dataPath + "/BulletUnity/Examples/Scripts/BulletSharpDemos/ConvexDecompositionDemo/data/file.obj";
            UnityEngine.TextAsset bytes      = (UnityEngine.TextAsset)UnityEngine.Resources.Load("file.obj");
            System.IO.Stream      byteStream = new System.IO.MemoryStream(bytes.bytes);

            int tcount = wo.LoadObj(byteStream);

            if (tcount == 0)
            {
                return;
            }

            // Convert file data to TriangleMesh
            var trimesh = new TriangleMesh();

            trimeshes.Add(trimesh);

            Vector3        localScaling = new Vector3(6, 6, 6);
            List <int>     indices      = wo.Indices;
            List <Vector3> vertices     = wo.Vertices;

            int i;

            for (i = 0; i < tcount; i++)
            {
                int index0 = indices[i * 3];
                int index1 = indices[i * 3 + 1];
                int index2 = indices[i * 3 + 2];

                Vector3 vertex0 = vertices[index0] * localScaling;
                Vector3 vertex1 = vertices[index1] * localScaling;
                Vector3 vertex2 = vertices[index2] * localScaling;

                trimesh.AddTriangleRef(ref vertex0, ref vertex1, ref vertex2);
            }

            // Create a hull approximation
            ConvexHullShape convexShape;

            using (var tmpConvexShape = new ConvexTriangleMeshShape(trimesh))
            {
                using (var hull = new ShapeHull(tmpConvexShape))
                {
                    hull.BuildHull(tmpConvexShape.Margin);
                    convexShape = new ConvexHullShape(hull.Vertices);
                }
            }
            if (sEnableSAT)
            {
                convexShape.InitializePolyhedralFeatures();
            }
            CollisionShapes.Add(convexShape);


            // Add non-moving body to world
            float mass = 1.0f;

            LocalCreateRigidBody(mass, Matrix.Translation(0, 2, 14), convexShape);

            const bool useQuantization = true;
            var        concaveShape    = new BvhTriangleMeshShape(trimesh, useQuantization);

            LocalCreateRigidBody(0, Matrix.Translation(convexDecompositionObjectOffset), concaveShape);

            CollisionShapes.Add(concaveShape);


            // HACD
            var hacd = new Hacd();

            hacd.SetPoints(wo.Vertices);
            hacd.SetTriangles(wo.Indices);
            hacd.CompacityWeight = 0.1;
            hacd.VolumeWeight    = 0.0;

            // Recommended HACD parameters: 2 100 false false false
            hacd.NClusters               = 2;        // minimum number of clusters
            hacd.Concavity               = 100;      // maximum concavity
            hacd.AddExtraDistPoints      = false;
            hacd.AddNeighboursDistPoints = false;
            hacd.AddFacesPoints          = false;
            hacd.NVerticesPerCH          = 100; // max of 100 vertices per convex-hull

            hacd.Compute();
            hacd.Save("output.wrl", false);


            // Generate convex result
            var outputFile = new FileStream("file_convex.obj", FileMode.Create, FileAccess.Write);
            var writer     = new StreamWriter(outputFile);

            var convexDecomposition = new ConvexDecomposition(writer, this);

            convexDecomposition.LocalScaling = localScaling;

            for (int c = 0; c < hacd.NClusters; c++)
            {
                int      nVertices    = hacd.GetNPointsCH(c);
                int      trianglesLen = hacd.GetNTrianglesCH(c) * 3;
                double[] points       = new double[nVertices * 3];
                long[]   triangles    = new long[trianglesLen];
                hacd.GetCH(c, points, triangles);

                if (trianglesLen == 0)
                {
                    continue;
                }

                Vector3[] verticesArray = new Vector3[nVertices];
                int       vi3           = 0;
                for (int vi = 0; vi < nVertices; vi++)
                {
                    verticesArray[vi] = new Vector3(
                        (float)points[vi3], (float)points[vi3 + 1], (float)points[vi3 + 2]);
                    vi3 += 3;
                }

                int[] trianglesInt = new int[trianglesLen];
                for (int ti = 0; ti < trianglesLen; ti++)
                {
                    trianglesInt[ti] = (int)triangles[ti];
                }

                convexDecomposition.ConvexDecompResult(verticesArray, trianglesInt);
            }


            // Combine convex shapes into a compound shape
            var compound = new CompoundShape();

            for (i = 0; i < convexDecomposition.convexShapes.Count; i++)
            {
                Vector3 centroid     = convexDecomposition.convexCentroids[i];
                var     convexShape2 = convexDecomposition.convexShapes[i];
                Matrix  trans        = Matrix.Translation(centroid);
                if (sEnableSAT)
                {
                    convexShape2.InitializePolyhedralFeatures();
                }
                CollisionShapes.Add(convexShape2);
                compound.AddChildShape(trans, convexShape2);

                LocalCreateRigidBody(1.0f, trans, convexShape2);
            }
            CollisionShapes.Add(compound);

            writer.Dispose();
            outputFile.Dispose();

#if true
            mass = 10.0f;
            var body2 = LocalCreateRigidBody(mass, Matrix.Translation(-convexDecompositionObjectOffset), compound);
            body2.CollisionFlags |= CollisionFlags.CustomMaterialCallback;

            convexDecompositionObjectOffset.Z = 6;
            body2 = LocalCreateRigidBody(mass, Matrix.Translation(-convexDecompositionObjectOffset), compound);
            body2.CollisionFlags |= CollisionFlags.CustomMaterialCallback;

            convexDecompositionObjectOffset.Z = -6;
            body2 = LocalCreateRigidBody(mass, Matrix.Translation(-convexDecompositionObjectOffset), compound);
            body2.CollisionFlags |= CollisionFlags.CustomMaterialCallback;
#endif
        }
Exemple #28
0
 public static string CustomKeySelector_Id(TestRoot v, UnityEngine.TextAsset textAsset)
 {
     return(v.Id);
 }
Exemple #29
0
 public static string CustomKeySelector_AssetName(UnityEngine.TextAsset textAsset, TestRoot v)
 {
     return(textAsset.name);
 }
        /** CoroutineMain
         */
        public System.Collections.IEnumerator CoroutineMain(Fee.AssetBundleList.OnAssetBundleListCoroutine_CallBackInterface a_callback_interface, string a_assetbundle_name, string a_asset_name)
        {
            //result
            this.result = new ResultType();

            AssetBundleItem t_assetbundle_item = Fee.AssetBundleList.AssetBundleList.GetInstance().GetAssetBundleItem(a_assetbundle_name);

            if (t_assetbundle_item == null)
            {
                //失敗。
                this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : " + a_assetbundle_name;
                yield break;
            }

            if (t_assetbundle_item.assetbundle_dummy != null)
            {
                //ダミーアセットバンドルが設定されている。

                string t_path;
                if (t_assetbundle_item.assetbundle_dummy.asset_list.TryGetValue(a_asset_name, out t_path) == true)
                {
                    Fee.File.Item t_item = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadResourcesTextFile, new File.Path(t_path));

                    do
                    {
                        if (a_callback_interface != null)
                        {
                            a_callback_interface.OnAssetBundleListCoroutine(t_item.GetResultProgress());
                        }
                        yield return(null);
                    }while(t_item.IsBusy() == true);

                    string t_string = null;

                    if (t_item.GetResultAssetType() == Asset.AssetType.Text)
                    {
                        if (t_item.GetResultAssetText() != null)
                        {
                            t_string = t_item.GetResultAssetText();
                        }
                    }

                    if (t_string == null)
                    {
                        //失敗。
                        this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : string = null : " + a_assetbundle_name + " : " + a_asset_name;
                        yield break;
                    }

                    this.result.asset_file = new Asset.Asset(Asset.AssetType.Text, t_string);
                }
                else
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : " + a_assetbundle_name;
                    yield break;
                }
            }
            else if (t_assetbundle_item.assetbundle_raw != null)
            {
                //アセットバンドル。

                UnityEngine.AssetBundleRequest t_request = t_assetbundle_item.assetbundle_raw.LoadAssetAsync(a_asset_name);

                if (t_request == null)
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : " + a_assetbundle_name;
                    yield break;
                }

                do
                {
                    if (a_callback_interface != null)
                    {
                        a_callback_interface.OnAssetBundleListCoroutine(t_request.progress);
                    }
                    yield return(null);
                }while(t_request.isDone == false);

                UnityEngine.TextAsset t_text = t_request.asset as UnityEngine.TextAsset;

                if (t_text == null)
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : " + a_assetbundle_name;
                    yield break;
                }

                string t_string = t_text.text;

                if (t_string == null)
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : " + a_assetbundle_name;
                    yield break;
                }

                this.result.asset_file = new Asset.Asset(Asset.AssetType.Text, t_string);
            }
            else
            {
                Tool.Assert(false);
            }

            //失敗。
            this.result.errorstring = "Coroutine_LoadAssetBundleItemTextFile : " + a_assetbundle_name;
            yield break;
        }