Beispiel #1
0
    public static Stickman Create(string name, CharPose charpose)
    {
        GameObject obj = new GameObject(name);

        obj.SetActive(false);
        Stickman stickman = obj.AddComponent <Stickman>();

        stickman._charPose = charpose;

        stickman._spine    = stickman.CreatePart("Spine", null, charpose.spine_mass, (int)charpose.spine_limit, (int)charpose.spine_angle);
        stickman._head     = stickman.CreatePart("Head", stickman._spine, charpose.head_mass, (int)charpose.head_limit, (int)charpose.head_angle);
        stickman._upArmL   = stickman.CreatePart("UpArmL", stickman._spine, charpose.upArmL_mass, (int)charpose.upArmL_limit, (int)charpose.upArmL_angle);
        stickman._upArmR   = stickman.CreatePart("UpArmR", stickman._spine, charpose.upArmR_mass, (int)charpose.upArmR_limit, (int)charpose.upArmR_angle);
        stickman._downArmR = stickman.CreatePart("DownArmR", stickman._upArmR, charpose.downArmR_mass, (int)charpose.downArmR_limit, (int)charpose.downArmR_angle);
        stickman._downArmL = stickman.CreatePart("DownArmL", stickman._upArmL, charpose.downArmL_mass, (int)charpose.downArmL_limit, (int)charpose.downArmL_angle);
        stickman._upLegL   = stickman.CreatePart("UpLegL", stickman._spine, charpose.upLegL_mass, (int)charpose.upLegL_limit, (int)charpose.upLegL_angle);
        stickman._upLegR   = stickman.CreatePart("UpLegR", stickman._spine, charpose.upLegR_mass, (int)charpose.upLegR_limit, (int)charpose.upLegR_angle);
        stickman._downLegL = stickman.CreatePart("DownLegL", stickman._upLegL, charpose.downLegL_mass, (int)charpose.downLegL_limit, (int)charpose.downLegL_angle);
        stickman._downLegR = stickman.CreatePart("DownLegR", stickman._upLegR, charpose.downLegR_mass, (int)charpose.downLegR_limit, (int)charpose.downLegR_angle);

        stickman._spine.Stickman    = stickman;
        stickman._head.Stickman     = stickman;
        stickman._upArmL.Stickman   = stickman;
        stickman._upArmR.Stickman   = stickman;
        stickman._downArmR.Stickman = stickman;
        stickman._downArmL.Stickman = stickman;
        stickman._upLegL.Stickman   = stickman;
        stickman._upLegR.Stickman   = stickman;
        stickman._downLegL.Stickman = stickman;
        stickman._downLegR.Stickman = stickman;


        stickman._headRigid = stickman._head.GetComponent <Rigidbody2D>();
        bool flag = true;

        stickman._head.CanHit    = flag;
        stickman._head.CanGetHit = flag;
        flag = true;
        stickman._spine.CanGetHit = flag;
        flag = true;
        stickman._downLegR.CanHit = flag;
        stickman._downLegL.CanHit = flag;
        stickman._downArmR.CanHit = flag;
        stickman._downArmL.CanHit = flag;
        flag = true;
        stickman._upLegR.CanGetHit = flag;
        stickman._upLegL.CanGetHit = flag;
        stickman._upArmR.CanGetHit = flag;
        stickman._upArmL.CanGetHit = flag;
        //stickman.UpdateMass();
        stickman.UpdateSize();
        stickman.UpdateJoints();

        obj.SetActive(true);
        return(stickman);
    }
Beispiel #2
0
    public static void SaveWorldZone()
    {
        currentZone.dos.Clear();
        DioramaObject[] allDioramaObjects = manager.currentModeParent.gameObject.GetComponentsInChildren <DioramaObject>();
        foreach (DioramaObject a in allDioramaObjects)
        {
            try
            {
                a.dos.savedPos      = a.gameObject.transform.localPosition;
                a.dos.savedRot      = a.gameObject.transform.localRotation;
                a.dos.savedScale    = a.gameObject.transform.localScale;
                a.dos.savedCharPose = new List <CharPose>();
                Transform[] allTrans = a.gameObject.GetComponentsInChildren <Transform>();
                for (int i = 0; i < allTrans.Count(); i++)
                {
                    CharPose next = new CharPose();
                    next.savedPos = allTrans[i].localPosition;
                    next.savedRot = allTrans[i].localRotation;
                    a.dos.savedCharPose.Add(next);
                }

                TextMeshPro tmp = a.gameObject.GetComponentInChildren <TextMeshPro>();
                if (tmp)
                {
                    a.text = tmp.text;
                }

                //IEventScale ies = a.gameObject.GetComponentInChildren<IEventScale>();
                //if (ies != null) {
                //    a.dos.savedScale = new Vector3(ies.GetScale(), ies.GetScale(), ies.GetScale());
                //}

                currentZone.dos.Add(a.dos);
            }
            catch { }
        }
    }
Beispiel #3
0
    IEnumerator RebuildGo(DioramaObjectSaver dos, Transform transform, bool addCollider = true)
    {
        GameObject go = null;

        if (dos.todID >= 0)
        {
            BundleItem t = TODV2.GetItemByID(dos.todID);

            string path = t.TopFolder.ToString() + @"\";
            path += t.BundleName + @"\" + (t.FolderPath.Replace(",", @"\")) + @"\";
            path += t.prefabName.Replace(".prefab", "");

            if (t.loadFromResources)
            {
                go = GameObject.Instantiate(Resources.Load(path, typeof(GameObject))) as GameObject;
            }
            else
            {
                try
                {
                    AssetBundle ab = AssetBundleManager.GetAssetBundle(t.BundleName).assetBundle;
                    go = Instantiate(ab.LoadAsset(t.PrefabName, typeof(GameObject))) as GameObject;
                    Common.ReassignTextures(go, t.HasLight);
                }
                catch (Exception e)
                {
                    Debug.Log(t.prefabName + " ID: " + t.id + " failed to load -- " + e.StackTrace);
                }
            }
            Common.ReassignTextures(go, t.HasLight);

            go.name                    = "Object";
            go.transform.parent        = transform;
            go.transform.localPosition = dos.savedPos;
            go.transform.localRotation = dos.savedRot;
            go.transform.localScale    = dos.savedScale;


            DioramaObject newDio = go.AddComponent <DioramaObject>();
            newDio.todID      = dos.todID;
            newDio.savedPos   = dos.savedPos;
            newDio.savedRot   = dos.savedRot;
            newDio.savedScale = dos.savedScale;

            newDio.gridScale = t.gridScale;
            newDio.layer     = dos.layer == 0 ? 1 : dos.layer;

            Common.DestroyAll(go);

            CheckAnimation(go);
            List <CharPose> pose     = dos.savedCharPose;
            Transform[]     allTrans = go.GetComponentsInChildren <Transform>();
            for (int i = 0; i < allTrans.Count(); i++)
            {
                CharPose next = pose[i];
                allTrans[i].localPosition = next.savedPos;
                allTrans[i].localRotation = next.savedRot;
            }

            TextMeshPro tmp = go.GetComponentInChildren <TextMeshPro>();
            if (tmp)
            {
                tmp.text = dos.text;
            }

            if (go.tag == "Untagged")
            {
                go.tag = "TableObject";
            }

            //IEventScale ies = go.GetComponentInChildren<IEventScale>();
            //if (ies != null)
            //{
            //    go.transform.localScale = Vector3.one;
            //    for (int i = 0; i < dos.savedScale.x; i++)
            //    {
            //        ies.ScaleUp();
            //    }
            //}
        }
        yield return(null);
    }