Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using System;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- /// <summary>
- /// I have no idea how to get the data from the constructor to CreateConnectedAssets
- /// </summary>
- [System.Serializable]
- public class ConnectedAsset {
- public UnityEngine.Object ConnectedAssetObject;
- public string AssetPath;
- public ConnectedAsset(string BasePath, string ObjName) {
- //We have to save the data In a struct Because We can't pass it into the delegate
- //now that the input data is saved we can Save the reference to the new ConnectedAsset so we can access it later
- }
- //This should work but I need to pass data into this
- [UnityEditor.Callbacks.DidReloadScripts]
- private static void CreateAssetWhenReady() {
- //need to get the insides to only call after loading when constructor is called...
- if (EditorApplication.isCompiling || EditorApplication.isUpdating) {
- EditorApplication.delayCall += CreateAssetWhenReady;
- return;
- }
- EditorApplication.delayCall += CreateAssetNow;
- }
- public static void CreateAssetNow() {
- }
- public void CreateConnectedAsset(string BasePath, string ObjName, out string finalPath,out UnityEngine.Object Obj) {
- //Steps for creating a new "Connected Asset"
- //We need the base path of the "donor" object -base for all copies
- var BaseConnectedAssetPath = BasePath;
- //we grab the parent folder - this returns the folder the base is in
- var BaseConnectedAssetParentFolder = Directory.GetParent(BaseConnectedAssetPath).FullName;
- //we grab the grandParent folder this does the same with the parent folder as the input
- var BaseConnectedAssetGrandParentFolder = Directory.GetParent(BaseConnectedAssetParentFolder).FullName;
- //We set the new file path with the file name specified
- var BaseConnectedAssetGrandParentFolderWithFileName = (BaseConnectedAssetGrandParentFolder + "/" + ObjName + ".asset");
- //we use URI to remove unnecesary file info
- //Using Uri to convert From Absolute to relative
- var BaseConnectedAssetGrandParentFolderWithFileNameRelative = AbsoluteToRelativePath(BaseConnectedAssetGrandParentFolderWithFileName);
- //We copy the asset from the "base" path and move it to the grandparentWithFileName path
- //get unique name
- BaseConnectedAssetGrandParentFolderWithFileNameRelative = AssetDatabase.GenerateUniqueAssetPath(BaseConnectedAssetGrandParentFolderWithFileNameRelative);
- finalPath = BaseConnectedAssetGrandParentFolderWithFileNameRelative;
- AssetDatabase.CopyAsset(BaseConnectedAssetPath, BaseConnectedAssetGrandParentFolderWithFileNameRelative);
- Obj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(finalPath);
- return;
- }
- private string AbsoluteToRelativePath(string absolutePath) {
- Uri address1 = new Uri("file://" + Application.dataPath, UriKind.Absolute);
- Uri address2 = new Uri("file://" + absolutePath, UriKind.Absolute);
- absolutePath = address1.MakeRelativeUri(address2).ToString();
- return absolutePath;
- }
- //private void RenameFloatCollection(EffectSharedData tempEffectData) {
- // if (tempEffectData.Floats.name == tempEffectData.name + "FloatCollection") {
- // return;
- // }
- // FloatCollection floatCollection = (FloatCollection)AssetDatabase.LoadAssetAtPath(FloatsPath, typeof(FloatCollection));
- // floatCollection.name = tempEffectData.name + "FloatCollection";
- // AssetDatabase.RenameAsset(FloatsPath, tempEffectData.name + "FloatCollection.asset");
- // FloatsPath = AssetDatabase.GetAssetPath(Floats);
- // return;
- //}
- ////probably need to change function name OnDestroy Might be called unintentionally...
- //public void OnDestroy() {
- // var IntPath = AssetDatabase.GetAssetPath(Ints);
- // var FloatPath = AssetDatabase.GetAssetPath(Floats);
- // AssetDatabase.DeleteAsset(FeedbackPrefabPath);
- // AssetDatabase.DeleteAsset(IntPath);
- // AssetDatabase.DeleteAsset(FloatPath);
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement