public void Save()
        {
            if (!dirty)
            {
                return;
            }
            //Create SO
            ItemData newItem = ScriptableObject.CreateInstance <ItemData>();

            //if new name, delete old asset
            if (!oldName.Equals(Name))
            {
                //AssetUtil.ReplaceFolder(Name, oldName);
                AssetUtil.RenameAsset(Name, oldName, FolderPath);
                oldName = Name;
            }
            newItem.Id          = Id;
            newItem.FolderPath  = folderPath;
            newItem.Name        = Name;
            newItem.Icon        = Icon;
            newItem.Effects     = Effects;
            newItem.Description = Description;
            newItem.Category    = Category;
            newItem.Rarity      = Rarity;
            newItem.Active      = Active;
            AssetUtil.SaveAsset(newItem);

            dirty = false;
        }
Example #2
0
        public void Save(string path)
        {
            StringBuilder err = new StringBuilder();

            for (int i = 0; i < _dirs.Count; ++i)
            {
                string d1 = _dirs[i].path + "/";
                for (int j = i; j < _rawDirs.Count; ++j)
                {
                    string d2 = _rawDirs[j].path + "/";
                    if (d1.StartsWith(d2) || d2.StartsWith(d1))
                    {
                        err.AppendFormat("the path '{0}' overlaps with '{1}'", d1, d2).AppendLine();
                    }
                }
            }
            if (err.Length > 0)
            {
                EditorUtility.DisplayDialog("Path overlap", err.ToString(), "OK");
            }
            else
            {
                if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.WebGL)
                {
                    var json = JsonUtility.ToJson(this, true);
                    AssetUtil.WriteAllText(PATH, json, Encoding.UTF8);
                    File.WriteAllText(PATH, json);
                }
                else
                {
                    Debug.LogWarning("Won't save paths");
                }
            }
        }
        public static void SymlinkAssets(Platform oldPlatform, Platform newPlatform)
        {
            // start editing
            AssetDatabase.StartAssetEditing();

            // update symlinks to dot folders
            foreach (Platform platform in PlatformUtilEditor.AndroidPlatforms)
            {
                string srcPath;
                srcPath = GetPluginPathForPlatform(platform);

                string dstPath;
                dstPath = string.Format(
                    "Assets/Plugins/{0}/{1}",
                    platform.ToBuildTargetGroup().ToString(),
                    platform.ToSagoUniqueString()
                    );

                if (platform == newPlatform)
                {
                    AssetUtil.SymlinkAsset(srcPath, dstPath, false);
                }
                else
                {
                    AssetUtil.UnlinkAsset(dstPath);
                }
            }

            // stop editing
            AssetDatabase.StopAssetEditing();
            AssetDatabase.Refresh();
        }
Example #4
0
    public void ShowShip()
    {
        ShipProxy shipProxy = GameFacade.Instance.RetrieveProxy(ProxyName.ShipProxy) as ShipProxy;
        IShip     ship      = shipProxy.GetAppointWarShip();

        if (ship != null)
        {
            CfgEternityProxy cfgEternityProxy = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy;
            Model            model            = cfgEternityProxy.GetItemModelByKey(ship.GetTID());
            GameObject       container        = GameObject.Find(model.ExhibitionPoint);
            if (container)
            {
                m_Show = true;
                TransformUtil.FindUIObject <Transform>(container.transform, "Ship_Light").gameObject.SetActive(true);
                AssetUtil.InstanceAssetAsync(model.AssetName,
                                             (pathOrAddress, returnObject, userData) =>
                {
                    if (returnObject != null)
                    {
                        GameObject gameobj = (GameObject)returnObject;
                        gameobj.transform.SetParent(container.transform, false);
                        m_ShipGameObject = gameobj;
                        if (!m_Show)
                        {
                            HideShip();
                        }
                    }
                    else
                    {
                        Debug.LogError(string.Format("资源加载成功,但返回null,  pathOrAddress = {0}", pathOrAddress));
                    }
                });
            }
        }
    }
Example #5
0
        public void ParseAssetNames()
        {
            if (IsIcon)
            {
                return;
            }

            for (int i = 0; i < Node.Attributes.Count; i++)
            {
                var attribute = Node.Attributes.Item(i);

                if (attribute == null)
                {
                    continue;
                }

                if (attribute.Name == "name")
                {
                    FlashAssetName     = attribute.InnerText;
                    ShockwaveAssetName = AssetUtil.ConvertName(Elias, this, attribute.InnerText);// IsShadow ? AssetUtil.ConvertFlashShadow(Elias, attribute.InnerText) : AssetUtil.ConvertFlashName(Elias, attribute.InnerText, Elias.X, Elias.Y);
                }

                if (attribute.Name == "source")
                {
                    IsMemberAlias            = true;
                    FlashSourceAliasName     = attribute.InnerText;
                    ShockwaveSourceAliasName = AssetUtil.ConvertName(Elias, this, attribute.InnerText);// IsShadow ? AssetUtil.ConvertFlashShadow(Elias, attribute.InnerText) : AssetUtil.ConvertFlashName(Elias, attribute.InnerText, Elias.X, Elias.Y);
                }
            }
        }
Example #6
0
    private static Setting LoadSetting(string path)
    {
        if (!AssetUtil.FileExist(path))
        {
#if UNITY_EDITOR
            byte[] _data    = AssetUtil.ReadFile("editor_config/setting.json");
            string savePath = Application.streamingAssetsPath + "/setting.json";
            _data = EnCode(_data);
            File.WriteAllBytes(savePath, _data);
            path = savePath;
#else
            throw new Exception("请执行Setting->Build");
#endif
        }

        string str = GetSettingStr(path);

        Setting setting;
        if (!string.IsNullOrEmpty(str))
        {
            setting = JsonUtility.FromJson <Setting>(str);
        }
        else
        {
            setting = new Setting();
        }
        return(setting);
    }
Example #7
0
    /// <summary>
    /// 加载部件资源
    /// </summary>
    /// <param name="path">部件资源地址</param>
    /// <param name="callback">加载回调</param>
    protected void LoadPrefabFromPool(string assetAddress, UnityAction <GameObject> callback)
    {
        UnityAction <GameObject> callbackFun = callback;

        AssetUtil.LoadAssetAsync(assetAddress,
                                 (pathOrAddress, returnObject, userData) =>
        {
            //忽略关闭之后的加载回调
            if (!Opened)
            {
                return;
            }

            if (returnObject != null)
            {
                GameObject prefab = (GameObject)returnObject;

                prefab.CreatePool(pathOrAddress);

                callbackFun?.Invoke(prefab);

                InstallScrollController();
            }
            else
            {
                Debug.LogError(string.Format("资源加载成功,但返回null,  pathOrAddress = {0}", pathOrAddress));
            }
        });
    }
Example #8
0
        public void AssetUtilCreateERC721AssetData()
        {
            ERC721Asset asset = AssetUtil.Create <ERC721Asset>(_testERC721AssetData);

            Assert.AreEqual(_testAddress, asset.TokenAddress);
            Assert.AreEqual(1, asset.TokenId);
        }
Example #9
0
 public static bool IsVehicle(this CommandArg arg, out VehicleAsset value)
 {
     if (arg.IsUInt16(out ushort id))
     {
         Asset asset = Assets.find(EAssetType.VEHICLE, id);
         if (asset == null)
         {
             value = null;
             return(false);
         }
         value = (VehicleAsset)asset;
         return(value != null);
     }
     else if (arg.IsGuid(out Guid guid))
     {
         value = AssetUtil.GetVehicleAssets().FirstOrDefault(d => d.GUID == guid);
         return(value != null);
     }
     else
     {
         string search = arg.RawValue.StartsWith("@") ? arg.RawValue.Substring(1) : arg.RawValue;
         value = AssetUtil.GetVehicleAsset(search);
         return(value != null);
     }
 }
Example #10
0
 private static void GenerateAutogeneratedFiles()
 {
     foreach (string path in AssetUtil.FindAssetPaths <CharacterEditorData>())
     {
         AssetDatabase.LoadAssetAtPath <CharacterEditorData>(path).Generate();
     }
 }
Example #11
0
        public Sprite(Entity owner, Texture2D texture, Rectangle?sourceRectangle = null, Vector2 drawOffset = default, float rotation = 0f, Vector2 origin = default, bool flipHorizontal = false, bool flipVertical = false)
        {
            if (flipHorizontal || flipVertical)
            {
                Texture = AssetUtil.FlipTexture(texture, flipVertical, flipHorizontal);
            }
            else
            {
                Texture = texture;
            }

            if (sourceRectangle.HasValue)
            {
                SourceRectangle = sourceRectangle.Value;
            }
            else
            {
                SourceRectangle = new Rectangle(0, 0, Config.GRID, Config.GRID);
            }

            UniquePerEntity = true;
            DrawOffset      = drawOffset;
            Owner           = owner;
            Rotation        = rotation;
            Origin          = origin;
        }
        public static DictionarySet Create(string path, params string[] pages)
        {
            AssetUtil.CreateAssetDirectory(Path.GetDirectoryName(path));
            AssetUtil.DeleteAsset(path);

            var instance = ScriptableObject.CreateInstance <DictionarySet>();

            AssetDatabase.CreateAsset(instance, path);

            instance._pageNumbers = new string[pages.Length];

            var items = new List <LocalizedDictionary>();

            for (var i = 0; i < pages.Length; ++i)
            {
                var item = ScriptableObject.CreateInstance <LocalizedDictionary>();
                item.name = pages[i];
                items.Add(item);

                instance._pageNumbers[i] = pages[i];

                AssetDatabase.AddObjectToAsset(item, path);
            }
            instance._dictionaries = items.ToArray();

            AssetDatabase.ImportAsset(path);

            return(instance);
        }
Example #13
0
        public static void SymlinkLibrary(Platform oldPlatform, Platform newPlatform)
        {
            try {
                string submodulePath;
                submodulePath = SubmoduleMap.GetSubmodulePath(typeof(SagoPhoto.SubmoduleInfo));

                string srcPath;
                srcPath = Path.Combine(submodulePath, "Plugins/Android/.Native/");

                string dstRoot;
                dstRoot = "Assets/Plugins/Android/";

                string dstPath;
                dstPath = dstRoot;

                Debug.Log("Copying SaveScreenshot.jar from " + srcPath + " to " + dstPath);

                if (Directory.Exists(srcPath) && Directory.Exists(dstPath))
                {
                    if (newPlatform.ToBuildTargetGroup() == BuildTargetGroup.Android)
                    {
                        AssetUtil.SymlinkAsset(srcPath + "SaveScreenshot.jar", dstPath + "SaveScreenshot.jar", false);
                    }
                    else
                    {
                        AssetUtil.UnlinkAsset(dstPath + "SaveScreenshot.jar");
                    }
                }
            } catch (System.Exception e) {
                Debug.LogException(e);
            }
        }
Example #14
0
        public void StashScripts()
        {
            foreach (var source in Sources)
            {
                var sourcePath = AssetUtil.CombinePath(ProjectInfo.RootPath, source.AssetPath);
                var destPath   = AssetUtil.CombinePath(_destRoot, source.AssetPath);
                AssetUtil.CopyFile(sourcePath, destPath, true);
            }

            foreach (var source in Sources)
            {
                AssetDatabase.DeleteAsset(source.AssetPath);
            }

            var directories = Sources.Select(x => Path.GetDirectoryName(x.AssetPath)).Distinct();

            foreach (var directory in directories)
            {
                var files = AssetDatabase.FindAssets(string.Empty, new[] { directory });
                if (!files.Any())
                {
                    AssetDatabase.DeleteAsset(directory);
                }
            }
        }
Example #15
0
    /// <summary>
    /// 加载环境
    /// </summary>
    private void LoadEnvirontment()
    {
        uint   reloadID = m_ReloadID;
        string path     = m_EnvironmentPath;

        AssetUtil.LoadAssetAsync(path,
                                 (pathOrAddress, returnObject, userData) =>
        {
            if (returnObject != null)
            {
                GameObject prefab = (GameObject)returnObject;
                if (reloadID == m_ReloadID && path.Equals(m_EnvironmentPath) && m_ModelInfoArray != null && m_ModelInfoArray.Length > 0)
                {
                    prefab.CreatePool(1, path);
                    m_LightEnvirontment = prefab.Spawn();
                    m_LightEnvirontment.SetActive(false);

                    ModelBox = m_LightEnvirontment.transform.Find("UI3DBox");
                    ModelBox.localEulerAngles = Vector3.zero;
                    ModelBox.localScale       = Vector3.one;

                    LoadModel(0);
                }
            }
            else
            {
                Debug.LogError(string.Format("资源加载成功,但返回null,  pathOrAddress = {0}", pathOrAddress));
            }
        });
    }
Example #16
0
 public string GetCachedScriptPath()
 {
     return(AssetUtil.CombinePath(
                ProjectInfo.RootPath,
                _settings.SourceCodeCacheRoot,
                _assemblyName,
                AssetPath));
 }
Example #17
0
        public static FileImportSettings Find()
        {
            var settingsPath = AssetUtil.CombinePath(
                Path.GetDirectoryName(AssetUtil.FindScriptPath <FileImportSettings>()),
                "settings.asset");

            return(File.Exists(settingsPath) ? AssetDatabase.LoadAssetAtPath <FileImportSettings>(settingsPath) : null);
        }
Example #18
0
 public Circle(AbstractScene scene, Entity parent, Vector2 center, int radius, Color color) : base(scene.LayerManager.EntityLayer, parent, center)
 {
     SetSprite(AssetUtil.CreateCircle(radius, color));
     this.color  = color;
     this.center = center;
     this.radius = radius;
     this.offset = new Vector2(radius, radius) / 2;
 }
Example #19
0
        public static void ImportExcel()
        {
            var inputFile       = AssetDatabase.GetAssetPath(Selection.activeObject);
            var outputDirectory = AssetUtil.CombinePath(
                Path.GetDirectoryName(inputFile),
                Path.GetFileNameWithoutExtension(inputFile));

            Translator.UpdateDictionaries(inputFile, outputDirectory);
        }
Example #20
0
        public static string GetDecompiledFileName(string fileName, Asset asset)
        {
            var correctHash = fileName.Substring(0, 8);

            if (correctHash == AssetUtil.CrcName(asset.AssetHeader.Name).ToString("X8", CultureInfo.InvariantCulture))
            {
                return(asset.AssetHeader.Name);
            }
            return(asset.AssetHeader.Name + '.' + correctHash);
        }
Example #21
0
        public static void LoadTextureGroup(string name, List <string> paths)
        {
            List <Texture2D> result = new List <Texture2D>();

            foreach (string path in paths)
            {
                result.Add(AssetUtil.LoadTexture(path));
            }
            textureGroups.Add(name, result);
        }
Example #22
0
        public static void AddSound(string name, string path, bool isLooped = false, AudioTag audioTag = AudioTag.SOUND_EFFECT, bool isMuted = false, float maxVolume = 1)
        {
            if (maxVolume < 0 || maxVolume > 1)
            {
                throw new Exception("Max volume should be a value between 0 and 1");
            }
            SoundEffectInstance audio = AssetUtil.LoadSoundEffect(path).CreateInstance();

            audio.IsLooped = isLooped;
            audioCache.Add(name, new AudioEntry(audio, audioTag, isMuted, maxVolume));
        }
Example #23
0
 private void LoadAgents()
 {
     Object[] objs = AssetUtil.Load(@"Prefabs\Agents");
     for (int i = 0; i < objs.Length; i++)
     {
         GameObject  go       = objs[i] as GameObject;
         AgentRemote remote   = go.GetComponent <AgentRemote>();
         int         hashCode = remote.Type.GetHashCode();
         AgentPrefabs[hashCode] = remote;
     }
 }
Example #24
0
 public static void LoadTexture(string name, string path, bool flipVertical = false, bool flipHorizontal = false)
 {
     if (flipVertical || flipHorizontal)
     {
         textures.Add(name, AssetUtil.FlipTexture(AssetUtil.LoadTexture(path), flipVertical, flipHorizontal));
     }
     else
     {
         textures.Add(name, AssetUtil.LoadTexture(path));
     }
 }
Example #25
0
 public Line(AbstractScene scene, Entity parent, Vector2 from, float angleRad, float length, Color color, float thickness = 1f) : base(scene.LayerManager.EntityLayer, parent, from)
 {
     this.From      = fromSaved = from;
     this.thickness = thickness;
     this.color     = color;
     SetSprite(AssetUtil.CreateRectangle(1, Color.White));
     this.length   = length;
     this.angleRad = angleRad;
     To            = toSaved = MathUtil.EndPointOfLine(from, length, this.angleRad);
     Origin        = new Vector2(0f, 0f);
     Scale         = new Vector2(length, thickness);
 }
Example #26
0
        public void SaveToFile()
        {
            CleanupCache();
            Directory.CreateDirectory(_destRoot);

            var configPath = AssetUtil.CombinePath(
                _destRoot,
                Path.GetFileNameWithoutExtension(Assembly) + ".json");
            var jsonStr = JsonUtility.ToJson(this);

            File.WriteAllText(configPath, jsonStr);
        }
Example #27
0
 public Line(AbstractScene scene, Entity parent, Vector2 from, Vector2 to, Color color, float thickness = 1f) : base(scene.LayerManager.EntityLayer, parent, from)
 {
     this.From      = fromSaved = from;
     this.To        = toSaved = to;
     this.thickness = thickness;
     this.color     = color;
     SetSprite(AssetUtil.CreateRectangle(1, Color.White));
     length   = Vector2.Distance(from, to);
     angleRad = MathUtil.RadFromVectors(from, to);
     Origin   = new Vector2(0f, 0f);
     Scale    = new Vector2(length, thickness);
 }
        private void OnWizardCreate()
        {
            // Check if the character data already exists
            if (AssetDatabase.IsValidFolder(data.RootFolder))
            {
                bool result = EditorUtility.DisplayDialog("Error",
                                                          "A character with the internal name of \"" + data.InternalName +
                                                          "\" already exists. Either edit the existing Character, or delete and restart.",
                                                          "Delete",
                                                          "Cancel");
                if (result)
                {
                    AssetDatabase.DeleteAsset(data.RootFolder);
                }
                else
                {
                    return;
                }
            }

            data.Generate();

            GameObject prefabSource;

            if (_sourceObject == null)
            {
                prefabSource = new GameObject(data.InternalName);
            }
            else
            {
                prefabSource = _sourceObject.gameObject;
            }

            prefabSource.GetOrAddComponent <Character>().InternalName = data.InternalName;

            Object prefab = prefabSource.GetPrefab();

            if (prefab == null)
            {
                prefab = PrefabUtil.CreatePrefab(data.RootFolder, prefabSource);
            }
            else
            {
                AssetUtil.MoveAsset(data.RootFolder, prefab);
            }

            data.Prefab = prefab as GameObject;

            Selection.activeGameObject = prefabSource;

            CharacterEditorWindow.ShowWindow().Target = data;
        }
Example #29
0
    private void OnRecordingButtonClick()
    {
        recordingTimeText.text = StartTimeText;
        switch (state)
        {
        case State.Idle:
            if (!recorder.IsRecording)
            {
                recordingStartTime = Time.time;
                recorder.StartRecording(true, true, false);
                recordingButtonText.text   = RecordingButtonStopRecText;
                recordingButtonImage.color = Color.red;
                state = State.Recording;
            }
            break;

        case State.Recording:
            if (recorder.IsRecording)
            {
                recorder.StopRecording();
                AnimationClip clip = recorder.SaveRecording(DataFilePath, false);
                AssetUtil.CreateAsset(clip, AnimationClipsFolderPath, AnimationClipName);
                OverrideAnimationClip(RecordedClipKeyName, clip);
                Debug.Log(GetType() + ".OnRecordingButtonClick: animation clip saved to " + Path.Combine(AnimationClipsFolderPath, AnimationClipName));
                cancelReplayButton.gameObject.SetActive(true);
                recordingButtonText.text   = RecordingButtonPlayText;
                recordingButtonImage.color = Color.white;
                state = State.RecordedIdle;
            }
            break;

        case State.RecordedIdle:
            // start replay
            recordingStartTime       = Time.time;
            recordingButtonText.text = RecordingButtonStopText;
            replayText.gameObject.SetActive(true);
            SetTrigger(TriggerName.recorded);
            state = State.Replay;
            break;

        case State.Replay:
            // stop replay;
            recordingButtonText.text = RecordingButtonPlayText;
            replayText.gameObject.SetActive(false);
            SetTrigger(TriggerName.idle);
            state = State.RecordedIdle;
            break;

        default:
            break;
        }
    }
Example #30
0
    private static string GetSettingStr(string path)
    {
        if (path == string.Empty)
        {
            return(string.Empty);
        }

        byte[] data = AssetUtil.ReadFile(path);
        data = DeCode(data);
        var str = System.Text.Encoding.UTF8.GetString(data);

        return(str);
    }