Esempio n. 1
0
    private void CreateEnable(InventoryDirectories inventoryDirectories, string objName)
    {
        string enableAnimLoc = inventoryDirectories.enableDir + "/" + objName + "_ENABLE.anim";

        if (!File.Exists(enableAnimLoc))
        {
            FileUtil.CopyFileOrDirectory(inventoryDirectories.pathToTemplate, enableAnimLoc);
            AssetDatabase.ImportAsset(enableAnimLoc, ImportAssetOptions.ForceSynchronousImport);
        }

        AnimationClip anim = (AnimationClip)AssetDatabase.LoadAssetAtPath(enableAnimLoc, typeof(AnimationClip));

        if (inventoryDirectories.pathToInv == "")
        {
            anim.SetCurve("Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", enableCurve());
            anim.SetCurve("Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", disableCurve());
        }
        else
        {
            anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", enableCurve());
            anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", disableCurve());
        }

        CreateDisable(inventoryDirectories, objName);
    }
Esempio n. 2
0
    private static void CreateAnimIfNotExists(InventoryDirectories inventoryDirectories, string animPath)
    {
        if (!File.Exists(animPath))
        {
            //Find template anim
            AnimationClip templateAnim = (AnimationClip)AssetDatabase.LoadAssetAtPath(inventoryDirectories.pathToTemplate, typeof(AnimationClip));

            Debug.Assert(templateAnim.humanMotion, "Template animiation is not humanoid. Path: " + inventoryDirectories.pathToTemplate);

            //Create new clip to copy to
            AnimationClip newClip = new AnimationClip();
            //Get all bindings and set every curve from the template to the new clip
            EditorCurveBinding[] templateBindings = AnimationUtility.GetCurveBindings(templateAnim);

            foreach (EditorCurveBinding binding in templateBindings)
            {
                newClip.SetCurve(binding.path, binding.type, binding.propertyName,
                                 AnimationUtility.GetEditorCurve(templateAnim, binding));
            }

            Debug.Assert(newClip.humanMotion && templateAnim.humanMotion, "Created clip is not humanoid after copying from a humanoid template");
            AssetDatabase.CreateAsset(newClip, animPath);
            AssetDatabase.SaveAssets();
        }
    }
Esempio n. 3
0
 private static void CreateAnimIfNotExists(InventoryDirectories inventoryDirectories, string anim)
 {
     if (!File.Exists(anim))
     {
         FileUtil.CopyFileOrDirectory(inventoryDirectories.pathToTemplate, anim);
         AssetDatabase.ImportAsset(anim, ImportAssetOptions.ForceSynchronousImport);
     }
 }
Esempio n. 4
0
    private void remapInv(Transform target, bool enableDefault)
    {
        //Bail if the target is null.
        if (target == null)
        {
            return;
        }

        string pathToInv = GetGameObjectPath(target.transform);

        string[] splitString = pathToInv.Split('/');

        ArrayUtility.RemoveAt(ref splitString, 0);
        ArrayUtility.RemoveAt(ref splitString, splitString.Length - 1);

        pathToInv = string.Join("/", splitString);

        string assetPath        = findAssetPath();
        string pathToEditor     = assetPath + "/Editor";
        string pathToAnimFolder = assetPath + "/Animations";
        string pathToTemplate   = pathToEditor + "/Templates/BehaviorKeyframeTemplate.anim";
        string pathToGenerated  = pathToAnimFolder + "/" + avatar.name;

        //Make sure we have all the directories we need
        if (!Directory.Exists(pathToGenerated))
        {
            Directory.CreateDirectory(pathToGenerated);
        }

        string globalDir = pathToGenerated + "/Global Animations";

        if (!Directory.Exists(globalDir))
        {
            Directory.CreateDirectory(globalDir);
        }

        string enableDir = pathToGenerated + "/Enable Animations";

        if (!Directory.Exists(enableDir))
        {
            Directory.CreateDirectory(enableDir);
        }

        string disableDir = pathToGenerated + "/Disable Animations";

        if (!Directory.Exists(disableDir))
        {
            Directory.CreateDirectory(disableDir);
        }

        InventoryDirectories inventoryDirectories = new InventoryDirectories(pathToTemplate, pathToGenerated, pathToInv, pathToEditor, disableDir, enableDir, globalDir);

        CreateInvAndMoveObject(inventoryDirectories, target, enableDefault);
    }
Esempio n. 5
0
    private void CreateDisable(InventoryDirectories inventoryDirectories, string objName)
    {
        string disableAnimLoc = inventoryDirectories.disableDir + "/" + objName + "_DISABLE_TEMPANIMXD.anim";

        CreateAnimIfNotExists(inventoryDirectories, disableAnimLoc);

        AnimationClip anim = (AnimationClip)AssetDatabase.LoadAssetAtPath(disableAnimLoc, typeof(AnimationClip));

        SetCurveOrCreatePathToInv(inventoryDirectories, objName, anim, disableCurve(), enableCurve());
        CopyAssetReqMemeXD(disableAnimLoc);
    }
 private void SetCurveOrCreatePathToInv(InventoryDirectories inventoryDirectories, string objName, AnimationClip anim, AnimationCurve firstCurve, AnimationCurve secondCurve)
 {
     Debug.Assert(anim != null, "Anim was null");
     if (inventoryDirectories.pathToInv == "")
     {
         anim.SetCurve("Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", firstCurve);
         anim.SetCurve("Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", secondCurve);
     }
     else
     {
         anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", firstCurve);
         anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", secondCurve);
     }
 }
Esempio n. 7
0
    private void SetCurveOrCreatePathToInv(InventoryDirectories inventoryDirectories, string objName, AnimationClip anim, AnimationCurve firstCurve, AnimationCurve secondCurve)
    {
        Debug.Assert(anim != null, "Anim was null");
        string baseSlotName        = slotPrefix + "_" + objName + "/";
        string enableAnimatorPath  = baseSlotName + this.getAnimatorName(objName, true);
        string disableAnimatorPath = enableAnimatorPath + "/" + this.getAnimatorName(objName, false);

        if (inventoryDirectories.pathToInv == "")
        {
            anim.SetCurve(enableAnimatorPath, typeof(UnityEngine.Behaviour), "m_Enabled", firstCurve);
            anim.SetCurve(disableAnimatorPath, typeof(UnityEngine.Behaviour), "m_Enabled", secondCurve);
        }
        else
        {
            anim.SetCurve(inventoryDirectories.pathToInv + "/" + enableAnimatorPath, typeof(UnityEngine.Behaviour), "m_Enabled", firstCurve);
            anim.SetCurve(inventoryDirectories.pathToInv + "/" + disableAnimatorPath, typeof(UnityEngine.Behaviour), "m_Enabled", secondCurve);
        }
    }
Esempio n. 8
0
    private void CreateDisable(InventoryDirectories inventoryDirectories, string objName)
    {
        string disableAnimLoc = inventoryDirectories.disableDir + "/" + objName + "_DISABLE.anim";

        CreateAnimIfNotExists(inventoryDirectories, disableAnimLoc);

        AnimationClip anim = (AnimationClip)AssetDatabase.LoadAssetAtPath(disableAnimLoc, typeof(AnimationClip));

        if (inventoryDirectories.pathToInv == "")
        {
            anim.SetCurve("Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", disableCurve());
            anim.SetCurve("Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", enableCurve());
        }
        else
        {
            anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", disableCurve());
            anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", enableCurve());
        }
    }
Esempio n. 9
0
    private void CreateInvAndMoveObject(InventoryDirectories inventoryDirectories, Transform target, bool enableDefault)
    {
        //Make sure we don't allow you to generate an inventory slot within an inventory slot.
        if (target.transform.parent.name == "Object")
        {
            //If the slot already exists, but you want to change wether the item starts as active or not, we can allow that.
            switch (enableDefault)
            {
            case true:
                target.transform.parent.gameObject.SetActive(true);
                break;

            case false:
                target.transform.parent.gameObject.SetActive(false);
                break;
            }
            return;
        }

        //Load the prefab for the inventory slot.
        Object slotPrefab = (Object)AssetDatabase.LoadAssetAtPath(inventoryDirectories.pathToEditor + "/Prefab/Inv_Single_Slot.prefab", typeof(Object));

        //Instantiate the prefab, set the parent to your items parent, set the name to match your item, and set the scale to 1.
        GameObject invSpawn = Instantiate(slotPrefab, target.position, target.rotation) as GameObject;

        invSpawn.transform.parent     = target.transform.parent;
        invSpawn.name                 = "Inv_" + target.name;
        invSpawn.transform.localScale = new Vector3(1, 1, 1);

        //Get the Object child of the prefab, and set the parent of your target item to the object slot.
        Transform objectSlot = invSpawn.transform.GetChild(0).GetChild(0).GetChild(0);

        target.transform.parent = objectSlot;

        //If you want the object to be enabled by default, set the object slot to active.
        if (enableDefault)
        {
            objectSlot.transform.gameObject.SetActive(true);
        }

        //Call create Globals
        CreateGlobalDisable(inventoryDirectories, target.name);
    }
Esempio n. 10
0
    private void CreateGlobalEnable(InventoryDirectories inventoryDirectories, string objName, string globalDir)
    {
        string globalAnimLoc = globalDir + "/ENABLE_ALL - " + avatar.name + ".anim";

        CreateAnimIfNotExists(inventoryDirectories, globalAnimLoc);

        AnimationClip anim = (AnimationClip)AssetDatabase.LoadAssetAtPath(globalAnimLoc, typeof(AnimationClip));

        if (inventoryDirectories.pathToInv == "")
        {
            anim.SetCurve("Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", enableCurve());
            anim.SetCurve("Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", disableCurve());
        }
        else
        {
            anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE", typeof(UnityEngine.Behaviour), "m_Enabled", enableCurve());
            anim.SetCurve(inventoryDirectories.pathToInv + "/Inv_" + objName + "/ENABLE/DISABLE", typeof(UnityEngine.Behaviour), "m_Enabled", disableCurve());
        }

        CreateEnable(inventoryDirectories, objName);
    }
Esempio n. 11
0
    private void CreateGlobalEnable(InventoryDirectories inventoryDirectories, string objName, string globalDir)
    {
        string globalAnimLoc = globalDir + "/ENABLE_ALL - " + avatar.name + "_TEMPANIMXD.anim";
        bool   exists        = CheckIfReplaced(globalAnimLoc);

        if (exists)
        {
            globalAnimLoc = globalDir + "/ENABLE_ALL - " + avatar.name + ".anim";
        }

        CreateAnimIfNotExists(inventoryDirectories, globalAnimLoc);

        AnimationClip anim = (AnimationClip)AssetDatabase.LoadAssetAtPath(globalAnimLoc, typeof(AnimationClip));

        SetCurveOrCreatePathToInv(inventoryDirectories, objName, anim, enableCurve(), disableCurve());

        CreateEnable(inventoryDirectories, objName);
        if (!exists)
        {
            CopyAssetReqMemeXD(globalAnimLoc);
        }
    }
Esempio n. 12
0
    private void CreateInvAndMoveObject(InventoryDirectories inventoryDirectories, Transform target, bool enableDefault)
    {
        //Make sure we don't allow you to generate an inventory slot within an inventory slot.
        if (this.isAlreadySlot(target))
        {
            //If the slot already exists, but you want to change wether the item starts as active or not, we can allow that.
            this.toggleActivateStateOnExistingSlot(target, enableDefault);
            return;
        }

        //Load the prefab for the inventory slot.
        Object slotPrefab = (Object)AssetDatabase.LoadAssetAtPath(inventoryDirectories.pathToEditor + "/Prefab/Inv_Single_Slot.prefab", typeof(Object));

        //Instantiate the prefab, set the parent to your items parent, set the name to match your item, and set the scale to 1.
        GameObject invSpawn = Instantiate(slotPrefab, target.position, target.rotation) as GameObject;

        invSpawn.transform.parent     = target.transform.parent;
        invSpawn.name                 = slotPrefix + "_" + target.name;
        invSpawn.transform.localScale = new Vector3(1, 1, 1);

        // Rename Enable / Disable Animators, this makes it easy to see inside the final animation
        // ENABLE -> DISABLE -> ObjectWrapper
        invSpawn.transform.GetChild(0).name             = this.getAnimatorName(target.name, true);
        invSpawn.transform.GetChild(0).GetChild(0).name = this.getAnimatorName(target.name, false);

        //Get the Object child of the prefab, and set the parent of your target item to the object slot.
        Transform objectWrapper = invSpawn.transform.GetChild(0).GetChild(0).GetChild(0);

        target.transform.parent = objectWrapper;

        //If you want the object to be enabled by default, set the object slot to active.
        if (enableDefault)
        {
            objectWrapper.transform.gameObject.SetActive(true);
        }

        //Call create Globals
        CreateGlobalDisable(inventoryDirectories, target.name);
    }
Esempio n. 13
0
    //Create the Global Disable animation
    private void CreateGlobalDisable(InventoryDirectories inventoryDirectories, string objName)
    {
        //Out directory, and our disableAll animation path
        string globalDir     = inventoryDirectories.pathToGenerated + "/Global Animations";
        string globalAnimLoc = globalDir + "/DISABLE_ALL - " + avatar.name + "_TEMPANIMXD.anim";;
        bool   exists        = CheckIfReplaced(globalAnimLoc);

        if (exists)
        {
            globalAnimLoc = globalDir + "/DISABLE_ALL - " + avatar.name + ".anim";
        }

        CreateAnimIfNotExists(inventoryDirectories, globalAnimLoc);

        AnimationClip anim = (AnimationClip)AssetDatabase.LoadAssetAtPath(globalAnimLoc, typeof(AnimationClip));

        SetCurveOrCreatePathToInv(inventoryDirectories, objName, anim, disableCurve(), enableCurve());

        CreateGlobalEnable(inventoryDirectories, objName, globalDir);
        if (!exists)
        {
            CopyAssetReqMemeXD(globalAnimLoc);
        }
    }